electron/shell/browser/api/electron_api_browser_window.h
Charles Kerr ae0c55c0b1
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 13:07:02 -05:00

89 lines
2.9 KiB
C++

// Copyright (c) 2013 GitHub, Inc.
// 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>
#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"
namespace electron::api {
class BrowserWindow : public BaseWindow,
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);
// 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();
}
// 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 WebContentsDestroyed() override;
// ExtendedWebContentsObserver:
void OnSetContentBounds(const gfx::Rect& rect) override;
void OnActivateContents() override;
void OnPageTitleUpdated(const std::u16string& title,
bool explicit_set) override;
// NativeWindowObserver:
void RequestPreferredWidth(int* width) override;
void OnCloseButtonClicked(bool* prevent_default) override;
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);
private:
// Helpers.
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};
};
} // namespace electron::api
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_