ladybird/UI/AppKit/Interface/LadybirdWebView.h
Andreas Kling 42f89bb679 LibWebView: Fast-close pages without beforeunload prompts
Track whether WebContent still needs a beforeunload check and let the
frontends immediately remove a tab or window when no prompt can be
shown. WebContent still receives the close request so pagehide, unload,
and cleanup steps can run.

When the visible view is removed immediately, keep detached ownership of
the WebContent page until it reports that the top-level traversable
closed. If no acknowledgement arrives, release detached ownership and
ask ProcessManager to shut down the unused WebContent process.
2026-05-26 20:40:25 +02:00

77 lines
2.2 KiB
Objective-C

/*
* Copyright (c) 2023-2026, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <AK/Function.h>
#include <AK/StringUtils.h>
#include <LibGfx/Forward.h>
#include <LibURL/Forward.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWeb/HTML/AudioPlayState.h>
#include <LibWebView/Forward.h>
#import <Cocoa/Cocoa.h>
@protocol LadybirdWebViewObserver <NSObject>
- (String const&)onCreateNewTab:(Optional<URL::URL> const&)url
activateTab:(Web::HTML::ActivateTab)activate_tab;
- (String const&)onCreateChildTab:(Optional<URL::URL> const&)url
activateTab:(Web::HTML::ActivateTab)activate_tab
pageIndex:(u64)page_index;
- (void)onLoadStart:(URL::URL const&)url isRedirect:(BOOL)is_redirect;
- (void)onLoadFinish:(URL::URL const&)url;
- (void)onURLChange:(URL::URL const&)url;
- (void)onTitleChange:(Utf16String const&)title;
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap;
- (void)onAudioPlayStateChange:(Web::HTML::AudioPlayState)play_state;
- (void)onEnterFullscreenWindow;
- (void)onExitFullscreenWindow;
- (void)onFindInPageResult:(size_t)current_match_index
totalMatchCount:(Optional<size_t> const&)total_match_count;
@end
@interface LadybirdWebView : NSView <NSMenuDelegate, NSTextInputClient>
- (instancetype)init:(id<LadybirdWebViewObserver>)observer;
- (instancetype)initAsChild:(id<LadybirdWebViewObserver>)observer
parent:(LadybirdWebView*)parent
pageIndex:(u64)page_index;
- (void)loadURL:(URL::URL const&)url;
- (WebView::ViewImplementation&)view;
- (String const&)handle;
- (void)setWindowPosition:(Gfx::IntPoint)position;
- (void)setWindowSize:(Gfx::IntSize)size;
- (void)handleResize;
- (void)handleDevicePixelRatioChange;
- (void)handleDisplayRefreshRateChange;
- (void)handleEnteredFullScreen;
- (void)handleExitedFullScreen;
- (void)handleExitFullScreen;
- (void)handleVisibility:(BOOL)is_visible;
- (void)findInPage:(NSString*)query
caseSensitivity:(CaseSensitivity)case_sensitivity;
- (void)findInPageNextMatch;
- (void)findInPagePreviousMatch;
- (void)requestClose;
- (Function<void()>)prepareForImmediateClose;
- (BOOL)needsBeforeUnloadCheck;
@end