electron/shell/browser/api/electron_api_browser_window.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
3.4 KiB
C
Raw Normal View History

// Copyright (c) 2013 GitHub, Inc.
2014-04-25 09:49:37 +00:00
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
#include <string>
2013-11-22 06:23:19 +00:00
#include "base/cancelable_callback.h"
#include "shell/browser/api/electron_api_base_window.h"
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/browser/ui/drag_util.h"
#include "shell/common/gin_helper/error_thrower.h"
2022-06-29 19:55:47 +00:00
namespace electron::api {
class BrowserWindow : public BaseWindow,
refactor: inherit Observer classes privately, pt. 2 (#42237) * refactor: use private inheritance in PushNotifications * refactor: use private inheritance in electron::api::App * refactor: use private inheritance in electron::api::BrowserWindow * refactor: use private inheritance in electron::api::NativeTheme * refactor: use private inheritance in electron::api::Tray * refactor: use private inheritance in electron::api::Session * refactor: use private inheritance in electron::api::WebContents * refactor: use private inheritance in electron::api::DownloadItem * refactor: use private inheritance in electron::api::MenuBar * refactor: use private inheritance in ClearDataOperation * refactor: use private inheritance in electron::api::Screen * refactor: use private inheritance in electron::ElectronDesktopWindowTreeHostLinux * refactor: use private inheritance in SpellCheckerHolder * refactor: use private inheritance in electron::api::PowerMonitor * refactor: use private inheritance in electron::api::BaseWindow * refactor: use private inheritance in electron::api::AutoUpdater * refactor: use private inheritance in electron::api::Menu * refactor: use private inheritance in electron::api::NativeWindowViews * refactor: use private inheritance in electron::ElectronBrowserClient * refactor: use private inheritance in electron::AutofillPopupView * refactor: use private inheritance in GtkMessageBox * refactor: use private inheritance in electron::OffScreenRenderWidgetHostView * refactor: use private inheritance in electron::InspectableWebContents * refactor: use private inheritance in electron::ElectronUsbDelegate * refactor: use private inheritance in electron::LoginHandler * refactor: use private inheritance in WebFrameRenderer * refactor: use private inheritance in electron::ElectronSerialDelegate * refactor: use private inheritance in electron::ClientFrameViewLinux * refactor: use private inheritance in electron::ElectronHidDelegate * refactor: use private inheritance in IPCRenderer * refactor: use private inheritance in electron::WinCaptionButtonContainer * refactor: use private inheritance in electron::ElectronApiIPCHandlerImpl * refactor: use private inheritance in electron::api::ServiceWorkerContext * refactor: use private inheritance in ui::FileSelectHelper * refactor: use private inheritance in electron::api::WebContentsView * refactor: use private inheritance in electron::api::SimpleURLLoaderWrapper * refactor: use private inheritance in electron::api::InAppPurchase * refactor: use private inheritance in electron::api::Debugger * refactor: use private inheritance in electron::ElectronWebContentsUtilityHandlerImpl * refactor: use private inheritance in electron::OffScreenWebContentsView
2024-05-29 18:07:02 +00:00
private content::WebContentsObserver,
private ExtendedWebContentsObserver {
public:
static gin_helper::WrappableBase* New(gin_helper::ErrorThrower thrower,
gin::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
2015-10-01 05:45:59 +00:00
// Returns the BrowserWindow object from |native_window|.
static v8::Local<v8::Value> From(v8::Isolate* isolate,
NativeWindow* native_window);
base::WeakPtr<BrowserWindow> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
2017-02-16 18:58:02 +00:00
// disable copy
BrowserWindow(const BrowserWindow&) = delete;
BrowserWindow& operator=(const BrowserWindow&) = delete;
protected:
BrowserWindow(gin::Arguments* args, const gin_helper::Dictionary& options);
~BrowserWindow() override;
// content::WebContentsObserver:
void BeforeUnloadDialogCancelled() override;
void OnRendererUnresponsive(content::RenderProcessHost*) override;
void OnRendererResponsive(
content::RenderProcessHost* render_process_host) override;
void WebContentsDestroyed() override;
2018-02-22 06:57:03 +00:00
// ExtendedWebContentsObserver:
void OnSetContentBounds(const gfx::Rect& rect) override;
void OnActivateContents() override;
void OnPageTitleUpdated(const std::u16string& title,
bool explicit_set) override;
2018-02-22 06:57:03 +00:00
2014-11-25 04:43:25 +00:00
// NativeWindowObserver:
void RequestPreferredWidth(int* width) override;
void OnCloseButtonClicked(bool* prevent_default) override;
2020-06-29 20:15:28 +00:00
void OnWindowIsKeyChanged(bool is_key) override;
void UpdateWindowControlsOverlay(const gfx::Rect& bounding_rect) override;
// BaseWindow:
void OnWindowBlur() override;
void OnWindowFocus() override;
void OnWindowLeaveFullScreen() override;
void CloseImmediately() override;
void Focus() override;
void Blur() override;
void SetBackgroundColor(const std::string& color_name) override;
void OnWindowShow() override;
void OnWindowHide() override;
// BrowserWindow APIs.
void FocusOnWebView();
void BlurWebView();
bool IsWebViewFocused();
v8::Local<v8::Value> GetWebContents(v8::Isolate* isolate);
2016-05-20 13:22:15 +00:00
private:
// Helpers.
2016-06-17 07:57:03 +00:00
// Schedule a notification unresponsive event.
void ScheduleUnresponsiveEvent(int ms);
// Dispatch unresponsive event to observers.
void NotifyWindowUnresponsive();
// Closure that would be called when window is unresponsive when closing,
// it should be cancelled when we can prove that the window is responsive.
base::CancelableRepeatingClosure window_unresponsive_closure_;
v8::Global<v8::Value> web_contents_;
v8::Global<v8::Value> web_contents_view_;
base::WeakPtr<api::WebContents> api_web_contents_;
base::WeakPtrFactory<BrowserWindow> weak_factory_{this};
};
2022-06-29 19:55:47 +00:00
} // namespace electron::api
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_