diff --git a/filenames.auto.gni b/filenames.auto.gni index 7da200c9a07f..3bbcec5e8bbc 100644 --- a/filenames.auto.gni +++ b/filenames.auto.gni @@ -190,6 +190,7 @@ auto_filenames = { "lib/browser/api/auto-updater/auto-updater-native.js", "lib/browser/api/auto-updater/auto-updater-win.js", "lib/browser/api/auto-updater/squirrel-update-win.js", + "lib/browser/api/base-window.ts", "lib/browser/api/browser-view.ts", "lib/browser/api/browser-window.ts", "lib/browser/api/content-tracing.ts", @@ -216,7 +217,6 @@ auto_filenames = { "lib/browser/api/screen.ts", "lib/browser/api/session.ts", "lib/browser/api/system-preferences.ts", - "lib/browser/api/top-level-window.ts", "lib/browser/api/touch-bar.js", "lib/browser/api/tray.ts", "lib/browser/api/view.ts", diff --git a/filenames.gni b/filenames.gni index 3984417736bf..220d93a806ab 100644 --- a/filenames.gni +++ b/filenames.gni @@ -44,6 +44,8 @@ filenames = { "shell/browser/api/electron_api_app_mac.mm", "shell/browser/api/electron_api_auto_updater.cc", "shell/browser/api/electron_api_auto_updater.h", + "shell/browser/api/electron_api_base_window.cc", + "shell/browser/api/electron_api_base_window.h", "shell/browser/api/electron_api_browser_view.cc", "shell/browser/api/electron_api_browser_view.h", "shell/browser/api/electron_api_browser_window.cc", @@ -102,8 +104,6 @@ filenames = { "shell/browser/api/electron_api_system_preferences.h", "shell/browser/api/electron_api_system_preferences_mac.mm", "shell/browser/api/electron_api_system_preferences_win.cc", - "shell/browser/api/electron_api_top_level_window.cc", - "shell/browser/api/electron_api_top_level_window.h", "shell/browser/api/electron_api_tray.cc", "shell/browser/api/electron_api_tray.h", "shell/browser/api/electron_api_url_loader.cc", diff --git a/lib/browser/api/top-level-window.ts b/lib/browser/api/base-window.ts similarity index 59% rename from lib/browser/api/top-level-window.ts rename to lib/browser/api/base-window.ts index 084da0cb8ef3..ea9a4d0bc3d5 100644 --- a/lib/browser/api/top-level-window.ts +++ b/lib/browser/api/base-window.ts @@ -1,10 +1,10 @@ import { EventEmitter } from 'events'; -import type { TopLevelWindow as TLWT } from 'electron'; -const { TopLevelWindow } = process._linkedBinding('electron_browser_top_level_window') as { TopLevelWindow: typeof TLWT }; +import type { BaseWindow as TLWT } from 'electron'; +const { BaseWindow } = process._linkedBinding('electron_browser_base_window') as { BaseWindow: typeof TLWT }; -Object.setPrototypeOf(TopLevelWindow.prototype, EventEmitter.prototype); +Object.setPrototypeOf(BaseWindow.prototype, EventEmitter.prototype); -(TopLevelWindow.prototype as any)._init = function () { +(BaseWindow.prototype as any)._init = function () { // Avoid recursive require. const { app } = require('electron'); @@ -17,88 +17,88 @@ Object.setPrototypeOf(TopLevelWindow.prototype, EventEmitter.prototype); // Properties -Object.defineProperty(TopLevelWindow.prototype, 'autoHideMenuBar', { +Object.defineProperty(BaseWindow.prototype, 'autoHideMenuBar', { get: function () { return this.isMenuBarAutoHide(); }, set: function (autoHide) { this.setAutoHideMenuBar(autoHide); } }); -Object.defineProperty(TopLevelWindow.prototype, 'visibleOnAllWorkspaces', { +Object.defineProperty(BaseWindow.prototype, 'visibleOnAllWorkspaces', { get: function () { return this.isVisibleOnAllWorkspaces(); }, set: function (visible) { this.setVisibleOnAllWorkspaces(visible); } }); -Object.defineProperty(TopLevelWindow.prototype, 'fullScreen', { +Object.defineProperty(BaseWindow.prototype, 'fullScreen', { get: function () { return this.isFullScreen(); }, set: function (full) { this.setFullScreen(full); } }); -Object.defineProperty(TopLevelWindow.prototype, 'simpleFullScreen', { +Object.defineProperty(BaseWindow.prototype, 'simpleFullScreen', { get: function () { return this.isSimpleFullScreen(); }, set: function (simple) { this.setSimpleFullScreen(simple); } }); -Object.defineProperty(TopLevelWindow.prototype, 'kiosk', { +Object.defineProperty(BaseWindow.prototype, 'kiosk', { get: function () { return this.isKiosk(); }, set: function (kiosk) { this.setKiosk(kiosk); } }); -Object.defineProperty(TopLevelWindow.prototype, 'documentEdited', { +Object.defineProperty(BaseWindow.prototype, 'documentEdited', { get: function () { return this.isFullscreen(); }, set: function (edited) { this.setDocumentEdited(edited); } }); -Object.defineProperty(TopLevelWindow.prototype, 'shadow', { +Object.defineProperty(BaseWindow.prototype, 'shadow', { get: function () { return this.hasShadow(); }, set: function (shadow) { this.setHasShadow(shadow); } }); -Object.defineProperty(TopLevelWindow.prototype, 'representedFilename', { +Object.defineProperty(BaseWindow.prototype, 'representedFilename', { get: function () { return this.getRepresentedFilename(); }, set: function (filename) { this.setRepresentedFilename(filename); } }); -Object.defineProperty(TopLevelWindow.prototype, 'minimizable', { +Object.defineProperty(BaseWindow.prototype, 'minimizable', { get: function () { return this.isMinimizable(); }, set: function (min) { this.setMinimizable(min); } }); -Object.defineProperty(TopLevelWindow.prototype, 'title', { +Object.defineProperty(BaseWindow.prototype, 'title', { get: function () { return this.getTitle(); }, set: function (title) { this.setTitle(title); } }); -Object.defineProperty(TopLevelWindow.prototype, 'maximizable', { +Object.defineProperty(BaseWindow.prototype, 'maximizable', { get: function () { return this.isMaximizable(); }, set: function (max) { this.setMaximizable(max); } }); -Object.defineProperty(TopLevelWindow.prototype, 'resizable', { +Object.defineProperty(BaseWindow.prototype, 'resizable', { get: function () { return this.isResizable(); }, set: function (res) { this.setResizable(res); } }); -Object.defineProperty(TopLevelWindow.prototype, 'menuBarVisible', { +Object.defineProperty(BaseWindow.prototype, 'menuBarVisible', { get: function () { return this.isMenuBarVisible(); }, set: function (visible) { this.setMenuBarVisibility(visible); } }); -Object.defineProperty(TopLevelWindow.prototype, 'fullScreenable', { +Object.defineProperty(BaseWindow.prototype, 'fullScreenable', { get: function () { return this.isFullScreenable(); }, set: function (full) { this.setFullScreenable(full); } }); -Object.defineProperty(TopLevelWindow.prototype, 'closable', { +Object.defineProperty(BaseWindow.prototype, 'closable', { get: function () { return this.isClosable(); }, set: function (close) { this.setClosable(close); } }); -Object.defineProperty(TopLevelWindow.prototype, 'movable', { +Object.defineProperty(BaseWindow.prototype, 'movable', { get: function () { return this.isMovable(); }, set: function (move) { this.setMovable(move); } }); -TopLevelWindow.getFocusedWindow = () => { - return TopLevelWindow.getAllWindows().find((win) => win.isFocused()); +BaseWindow.getFocusedWindow = () => { + return BaseWindow.getAllWindows().find((win) => win.isFocused()); }; -module.exports = TopLevelWindow; +module.exports = BaseWindow; diff --git a/lib/browser/api/browser-window.ts b/lib/browser/api/browser-window.ts index 4323f81fa7a1..ee3fd194cbe2 100644 --- a/lib/browser/api/browser-window.ts +++ b/lib/browser/api/browser-window.ts @@ -1,12 +1,12 @@ -import { TopLevelWindow, WebContents, Event, BrowserView, TouchBar } from 'electron'; +import { BaseWindow, WebContents, Event, BrowserView, TouchBar } from 'electron'; import type { BrowserWindow as BWT } from 'electron'; const { BrowserWindow } = process._linkedBinding('electron_browser_window') as { BrowserWindow: typeof BWT }; -Object.setPrototypeOf(BrowserWindow.prototype, TopLevelWindow.prototype); +Object.setPrototypeOf(BrowserWindow.prototype, BaseWindow.prototype); (BrowserWindow.prototype as any)._init = function (this: BWT) { // Call parent class's _init. - (TopLevelWindow.prototype as any)._init.call(this); + (BaseWindow.prototype as any)._init.call(this); // Avoid recursive require. const { app } = require('electron'); @@ -74,12 +74,12 @@ const isBrowserWindow = (win: any) => { }; BrowserWindow.fromId = (id: number) => { - const win = TopLevelWindow.fromId(id); + const win = BaseWindow.fromId(id); return isBrowserWindow(win) ? win as any as BWT : null; }; BrowserWindow.getAllWindows = () => { - return TopLevelWindow.getAllWindows().filter(isBrowserWindow) as any[] as BWT[]; + return BaseWindow.getAllWindows().filter(isBrowserWindow) as any[] as BWT[]; }; BrowserWindow.getFocusedWindow = () => { diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index bf9ce5d14f98..81bc3c7784b0 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -1,6 +1,6 @@ 'use strict'; -const { TopLevelWindow, MenuItem, webContents } = require('electron'); +const { BaseWindow, MenuItem, webContents } = require('electron'); const { sortMenuItems } = require('@electron/internal/browser/api/menu-utils'); const EventEmitter = require('events').EventEmitter; const v8Util = process._linkedBinding('electron_common_v8_util'); @@ -46,7 +46,7 @@ Menu.prototype._shouldRegisterAcceleratorForCommandId = function (id) { Menu.prototype._executeCommand = function (event, id) { const command = this.commandsMap[id]; if (!command) return; - command.click(event, TopLevelWindow.getFocusedWindow(), webContents.getFocusedWebContents()); + command.click(event, BaseWindow.getFocusedWindow(), webContents.getFocusedWebContents()); }; Menu.prototype._menuWillShow = function () { @@ -72,14 +72,14 @@ Menu.prototype.popup = function (options = {}) { if (typeof positioningItem !== 'number') positioningItem = -1; // find which window to use - const wins = TopLevelWindow.getAllWindows(); + const wins = BaseWindow.getAllWindows(); if (!wins || wins.indexOf(window) === -1) { - window = TopLevelWindow.getFocusedWindow(); + window = BaseWindow.getFocusedWindow(); if (!window && wins && wins.length > 0) { window = wins[0]; } if (!window) { - throw new Error('Cannot open Menu without a TopLevelWindow present'); + throw new Error('Cannot open Menu without a BaseWindow present'); } } @@ -88,7 +88,7 @@ Menu.prototype.popup = function (options = {}) { }; Menu.prototype.closePopup = function (window) { - if (window instanceof TopLevelWindow) { + if (window instanceof BaseWindow) { this.closePopupAt(window.id); } else { // Passing -1 (invalid) would make closePopupAt close the all menu runners @@ -168,7 +168,7 @@ Menu.setApplicationMenu = function (menu) { menu._callMenuWillShow(); bindings.setApplicationMenu(menu); } else { - const windows = TopLevelWindow.getAllWindows(); + const windows = BaseWindow.getAllWindows(); return windows.map(w => w.setMenu(menu)); } }; diff --git a/lib/browser/api/module-list.ts b/lib/browser/api/module-list.ts index e931cff3ee9a..4045974901ba 100644 --- a/lib/browser/api/module-list.ts +++ b/lib/browser/api/module-list.ts @@ -4,6 +4,7 @@ export const browserModuleList: ElectronInternal.ModuleEntry[] = [ { name: 'app', loader: () => require('./app') }, { name: 'autoUpdater', loader: () => require('./auto-updater') }, + { name: 'BaseWindow', loader: () => require('./base-window') }, { name: 'BrowserView', loader: () => require('./browser-view') }, { name: 'BrowserWindow', loader: () => require('./browser-window') }, { name: 'contentTracing', loader: () => require('./content-tracing') }, @@ -25,7 +26,6 @@ export const browserModuleList: ElectronInternal.ModuleEntry[] = [ { name: 'screen', loader: () => require('./screen') }, { name: 'session', loader: () => require('./session') }, { name: 'systemPreferences', loader: () => require('./system-preferences') }, - { name: 'TopLevelWindow', loader: () => require('./top-level-window') }, { name: 'TouchBar', loader: () => require('./touch-bar') }, { name: 'Tray', loader: () => require('./tray') }, { name: 'View', loader: () => require('./view') }, diff --git a/lib/browser/api/module-names.ts b/lib/browser/api/module-names.ts index d8d24d0d4c10..d46a44231be8 100644 --- a/lib/browser/api/module-names.ts +++ b/lib/browser/api/module-names.ts @@ -7,6 +7,7 @@ export const browserModuleNames = [ 'app', 'autoUpdater', + 'BaseWindow', 'BrowserView', 'BrowserWindow', 'contentTracing', @@ -28,7 +29,6 @@ export const browserModuleNames = [ 'screen', 'session', 'systemPreferences', - 'TopLevelWindow', 'TouchBar', 'Tray', 'View', diff --git a/shell/browser/api/electron_api_top_level_window.cc b/shell/browser/api/electron_api_base_window.cc similarity index 51% rename from shell/browser/api/electron_api_top_level_window.cc rename to shell/browser/api/electron_api_base_window.cc index 9046c4ebea16..76465a615365 100644 --- a/shell/browser/api/electron_api_top_level_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#include "shell/browser/api/electron_api_top_level_window.h" +#include "shell/browser/api/electron_api_base_window.h" #include #include @@ -74,11 +74,11 @@ v8::Local ToBuffer(v8::Isolate* isolate, void* val, int size) { } // namespace -TopLevelWindow::TopLevelWindow(v8::Isolate* isolate, - const gin_helper::Dictionary& options) +BaseWindow::BaseWindow(v8::Isolate* isolate, + const gin_helper::Dictionary& options) : weak_factory_(this) { // The parent window. - gin::Handle parent; + gin::Handle parent; if (options.Get("parent", &parent) && !parent.IsEmpty()) parent_window_.Reset(isolate, parent.ToV8()); @@ -105,15 +105,15 @@ TopLevelWindow::TopLevelWindow(v8::Isolate* isolate, #endif } -TopLevelWindow::TopLevelWindow(gin_helper::Arguments* args, - const gin_helper::Dictionary& options) - : TopLevelWindow(args->isolate(), options) { +BaseWindow::BaseWindow(gin_helper::Arguments* args, + const gin_helper::Dictionary& options) + : BaseWindow(args->isolate(), options) { InitWithArgs(args); // Init window after everything has been setup. window()->InitFromOptions(options); } -TopLevelWindow::~TopLevelWindow() { +BaseWindow::~BaseWindow() { if (!window_->IsClosed()) window_->CloseImmediately(); @@ -125,15 +125,14 @@ TopLevelWindow::~TopLevelWindow() { self_ref_.Reset(); } -void TopLevelWindow::InitWith(v8::Isolate* isolate, - v8::Local wrapper) { +void BaseWindow::InitWith(v8::Isolate* isolate, v8::Local wrapper) { AttachAsUserData(window_.get()); - gin_helper::TrackableObject::InitWith(isolate, wrapper); + gin_helper::TrackableObject::InitWith(isolate, wrapper); // We can only append this window to parent window's child windows after this // window's JS wrapper gets initialized. if (!parent_window_.IsEmpty()) { - gin::Handle parent; + gin::Handle parent; gin::ConvertFromV8(isolate, GetParentWindow(), &parent); DCHECK(!parent.IsEmpty()); parent->child_windows_.Set(isolate, weak_map_id(), wrapper); @@ -143,13 +142,13 @@ void TopLevelWindow::InitWith(v8::Isolate* isolate, self_ref_.Reset(isolate, wrapper); } -void TopLevelWindow::WillCloseWindow(bool* prevent_default) { +void BaseWindow::WillCloseWindow(bool* prevent_default) { if (Emit("close")) { *prevent_default = true; } } -void TopLevelWindow::OnWindowClosed() { +void BaseWindow::OnWindowClosed() { // Invalidate weak ptrs before the Javascript object is destroyed, // there might be some delayed emit events which shouldn't be // triggered after this. @@ -165,136 +164,133 @@ void TopLevelWindow::OnWindowClosed() { Emit("closed"); RemoveFromParentChildWindows(); - TopLevelWindow::ResetBrowserViews(); + BaseWindow::ResetBrowserViews(); // Destroy the native class when window is closed. base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, GetDestroyClosure()); } -void TopLevelWindow::OnWindowEndSession() { +void BaseWindow::OnWindowEndSession() { Emit("session-end"); } -void TopLevelWindow::OnWindowBlur() { +void BaseWindow::OnWindowBlur() { EmitEventSoon("blur"); } -void TopLevelWindow::OnWindowFocus() { +void BaseWindow::OnWindowFocus() { EmitEventSoon("focus"); } -void TopLevelWindow::OnWindowShow() { +void BaseWindow::OnWindowShow() { Emit("show"); } -void TopLevelWindow::OnWindowHide() { +void BaseWindow::OnWindowHide() { Emit("hide"); } -void TopLevelWindow::OnWindowMaximize() { +void BaseWindow::OnWindowMaximize() { Emit("maximize"); } -void TopLevelWindow::OnWindowUnmaximize() { +void BaseWindow::OnWindowUnmaximize() { Emit("unmaximize"); } -void TopLevelWindow::OnWindowMinimize() { +void BaseWindow::OnWindowMinimize() { Emit("minimize"); } -void TopLevelWindow::OnWindowRestore() { +void BaseWindow::OnWindowRestore() { Emit("restore"); } -void TopLevelWindow::OnWindowWillResize(const gfx::Rect& new_bounds, - bool* prevent_default) { +void BaseWindow::OnWindowWillResize(const gfx::Rect& new_bounds, + bool* prevent_default) { if (Emit("will-resize", new_bounds)) { *prevent_default = true; } } -void TopLevelWindow::OnWindowResize() { +void BaseWindow::OnWindowResize() { Emit("resize"); } -void TopLevelWindow::OnWindowWillMove(const gfx::Rect& new_bounds, - bool* prevent_default) { +void BaseWindow::OnWindowWillMove(const gfx::Rect& new_bounds, + bool* prevent_default) { if (Emit("will-move", new_bounds)) { *prevent_default = true; } } -void TopLevelWindow::OnWindowMove() { +void BaseWindow::OnWindowMove() { Emit("move"); } -void TopLevelWindow::OnWindowMoved() { +void BaseWindow::OnWindowMoved() { Emit("moved"); } -void TopLevelWindow::OnWindowEnterFullScreen() { +void BaseWindow::OnWindowEnterFullScreen() { Emit("enter-full-screen"); } -void TopLevelWindow::OnWindowLeaveFullScreen() { +void BaseWindow::OnWindowLeaveFullScreen() { Emit("leave-full-screen"); } -void TopLevelWindow::OnWindowScrollTouchBegin() { +void BaseWindow::OnWindowScrollTouchBegin() { Emit("scroll-touch-begin"); } -void TopLevelWindow::OnWindowScrollTouchEnd() { +void BaseWindow::OnWindowScrollTouchEnd() { Emit("scroll-touch-end"); } -void TopLevelWindow::OnWindowSwipe(const std::string& direction) { +void BaseWindow::OnWindowSwipe(const std::string& direction) { Emit("swipe", direction); } -void TopLevelWindow::OnWindowRotateGesture(float rotation) { +void BaseWindow::OnWindowRotateGesture(float rotation) { Emit("rotate-gesture", rotation); } -void TopLevelWindow::OnWindowSheetBegin() { +void BaseWindow::OnWindowSheetBegin() { Emit("sheet-begin"); } -void TopLevelWindow::OnWindowSheetEnd() { +void BaseWindow::OnWindowSheetEnd() { Emit("sheet-end"); } -void TopLevelWindow::OnWindowEnterHtmlFullScreen() { +void BaseWindow::OnWindowEnterHtmlFullScreen() { Emit("enter-html-full-screen"); } -void TopLevelWindow::OnWindowLeaveHtmlFullScreen() { +void BaseWindow::OnWindowLeaveHtmlFullScreen() { Emit("leave-html-full-screen"); } -void TopLevelWindow::OnWindowAlwaysOnTopChanged() { +void BaseWindow::OnWindowAlwaysOnTopChanged() { Emit("always-on-top-changed", IsAlwaysOnTop()); } -void TopLevelWindow::OnExecuteAppCommand(const std::string& command_name) { +void BaseWindow::OnExecuteAppCommand(const std::string& command_name) { Emit("app-command", command_name); } -void TopLevelWindow::OnTouchBarItemResult( - const std::string& item_id, - const base::DictionaryValue& details) { +void BaseWindow::OnTouchBarItemResult(const std::string& item_id, + const base::DictionaryValue& details) { Emit("-touch-bar-interaction", item_id, details); } -void TopLevelWindow::OnNewWindowForTab() { +void BaseWindow::OnNewWindowForTab() { Emit("new-window-for-tab"); } #if defined(OS_WIN) -void TopLevelWindow::OnWindowMessage(UINT message, - WPARAM w_param, - LPARAM l_param) { +void BaseWindow::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) { if (IsWindowMessageHooked(message)) { messages_callback_map_[message].Run( ToBuffer(isolate(), static_cast(&w_param), sizeof(WPARAM)), @@ -303,120 +299,118 @@ void TopLevelWindow::OnWindowMessage(UINT message, } #endif -void TopLevelWindow::SetContentView(gin::Handle view) { +void BaseWindow::SetContentView(gin::Handle view) { ResetBrowserViews(); content_view_.Reset(isolate(), view.ToV8()); window_->SetContentView(view->view()); } -void TopLevelWindow::Close() { +void BaseWindow::Close() { window_->Close(); } -void TopLevelWindow::Focus() { +void BaseWindow::Focus() { window_->Focus(true); } -void TopLevelWindow::Blur() { +void BaseWindow::Blur() { window_->Focus(false); } -bool TopLevelWindow::IsFocused() { +bool BaseWindow::IsFocused() { return window_->IsFocused(); } -void TopLevelWindow::Show() { +void BaseWindow::Show() { window_->Show(); } -void TopLevelWindow::ShowInactive() { +void BaseWindow::ShowInactive() { // This method doesn't make sense for modal window. if (IsModal()) return; window_->ShowInactive(); } -void TopLevelWindow::Hide() { +void BaseWindow::Hide() { window_->Hide(); } -bool TopLevelWindow::IsVisible() { +bool BaseWindow::IsVisible() { return window_->IsVisible(); } -bool TopLevelWindow::IsEnabled() { +bool BaseWindow::IsEnabled() { return window_->IsEnabled(); } -void TopLevelWindow::SetEnabled(bool enable) { +void BaseWindow::SetEnabled(bool enable) { window_->SetEnabled(enable); } -void TopLevelWindow::Maximize() { +void BaseWindow::Maximize() { window_->Maximize(); } -void TopLevelWindow::Unmaximize() { +void BaseWindow::Unmaximize() { window_->Unmaximize(); } -bool TopLevelWindow::IsMaximized() { +bool BaseWindow::IsMaximized() { return window_->IsMaximized(); } -void TopLevelWindow::Minimize() { +void BaseWindow::Minimize() { window_->Minimize(); } -void TopLevelWindow::Restore() { +void BaseWindow::Restore() { window_->Restore(); } -bool TopLevelWindow::IsMinimized() { +bool BaseWindow::IsMinimized() { return window_->IsMinimized(); } -void TopLevelWindow::SetFullScreen(bool fullscreen) { +void BaseWindow::SetFullScreen(bool fullscreen) { window_->SetFullScreen(fullscreen); } -bool TopLevelWindow::IsFullscreen() { +bool BaseWindow::IsFullscreen() { return window_->IsFullscreen(); } -void TopLevelWindow::SetBounds(const gfx::Rect& bounds, - gin_helper::Arguments* args) { +void BaseWindow::SetBounds(const gfx::Rect& bounds, + gin_helper::Arguments* args) { bool animate = false; args->GetNext(&animate); window_->SetBounds(bounds, animate); } -gfx::Rect TopLevelWindow::GetBounds() { +gfx::Rect BaseWindow::GetBounds() { return window_->GetBounds(); } -bool TopLevelWindow::IsNormal() { +bool BaseWindow::IsNormal() { return window_->IsNormal(); } -gfx::Rect TopLevelWindow::GetNormalBounds() { +gfx::Rect BaseWindow::GetNormalBounds() { return window_->GetNormalBounds(); } -void TopLevelWindow::SetContentBounds(const gfx::Rect& bounds, - gin_helper::Arguments* args) { +void BaseWindow::SetContentBounds(const gfx::Rect& bounds, + gin_helper::Arguments* args) { bool animate = false; args->GetNext(&animate); window_->SetContentBounds(bounds, animate); } -gfx::Rect TopLevelWindow::GetContentBounds() { +gfx::Rect BaseWindow::GetContentBounds() { return window_->GetContentBounds(); } -void TopLevelWindow::SetSize(int width, - int height, - gin_helper::Arguments* args) { +void BaseWindow::SetSize(int width, int height, gin_helper::Arguments* args) { bool animate = false; gfx::Size size = window_->GetMinimumSize(); size.SetToMax(gfx::Size(width, height)); @@ -424,7 +418,7 @@ void TopLevelWindow::SetSize(int width, window_->SetSize(size, animate); } -std::vector TopLevelWindow::GetSize() { +std::vector BaseWindow::GetSize() { std::vector result(2); gfx::Size size = window_->GetSize(); result[0] = size.width(); @@ -432,15 +426,15 @@ std::vector TopLevelWindow::GetSize() { return result; } -void TopLevelWindow::SetContentSize(int width, - int height, - gin_helper::Arguments* args) { +void BaseWindow::SetContentSize(int width, + int height, + gin_helper::Arguments* args) { bool animate = false; args->GetNext(&animate); window_->SetContentSize(gfx::Size(width, height), animate); } -std::vector TopLevelWindow::GetContentSize() { +std::vector BaseWindow::GetContentSize() { std::vector result(2); gfx::Size size = window_->GetContentSize(); result[0] = size.width(); @@ -448,11 +442,11 @@ std::vector TopLevelWindow::GetContentSize() { return result; } -void TopLevelWindow::SetMinimumSize(int width, int height) { +void BaseWindow::SetMinimumSize(int width, int height) { window_->SetMinimumSize(gfx::Size(width, height)); } -std::vector TopLevelWindow::GetMinimumSize() { +std::vector BaseWindow::GetMinimumSize() { std::vector result(2); gfx::Size size = window_->GetMinimumSize(); result[0] = size.width(); @@ -460,11 +454,11 @@ std::vector TopLevelWindow::GetMinimumSize() { return result; } -void TopLevelWindow::SetMaximumSize(int width, int height) { +void BaseWindow::SetMaximumSize(int width, int height) { window_->SetMaximumSize(gfx::Size(width, height)); } -std::vector TopLevelWindow::GetMaximumSize() { +std::vector BaseWindow::GetMaximumSize() { std::vector result(2); gfx::Size size = window_->GetMaximumSize(); result[0] = size.width(); @@ -472,62 +466,61 @@ std::vector TopLevelWindow::GetMaximumSize() { return result; } -void TopLevelWindow::SetSheetOffset(double offsetY, - gin_helper::Arguments* args) { +void BaseWindow::SetSheetOffset(double offsetY, gin_helper::Arguments* args) { double offsetX = 0.0; args->GetNext(&offsetX); window_->SetSheetOffset(offsetX, offsetY); } -void TopLevelWindow::SetResizable(bool resizable) { +void BaseWindow::SetResizable(bool resizable) { window_->SetResizable(resizable); } -bool TopLevelWindow::IsResizable() { +bool BaseWindow::IsResizable() { return window_->IsResizable(); } -void TopLevelWindow::SetMovable(bool movable) { +void BaseWindow::SetMovable(bool movable) { window_->SetMovable(movable); } -bool TopLevelWindow::IsMovable() { +bool BaseWindow::IsMovable() { return window_->IsMovable(); } -void TopLevelWindow::SetMinimizable(bool minimizable) { +void BaseWindow::SetMinimizable(bool minimizable) { window_->SetMinimizable(minimizable); } -bool TopLevelWindow::IsMinimizable() { +bool BaseWindow::IsMinimizable() { return window_->IsMinimizable(); } -void TopLevelWindow::SetMaximizable(bool maximizable) { +void BaseWindow::SetMaximizable(bool maximizable) { window_->SetMaximizable(maximizable); } -bool TopLevelWindow::IsMaximizable() { +bool BaseWindow::IsMaximizable() { return window_->IsMaximizable(); } -void TopLevelWindow::SetFullScreenable(bool fullscreenable) { +void BaseWindow::SetFullScreenable(bool fullscreenable) { window_->SetFullScreenable(fullscreenable); } -bool TopLevelWindow::IsFullScreenable() { +bool BaseWindow::IsFullScreenable() { return window_->IsFullScreenable(); } -void TopLevelWindow::SetClosable(bool closable) { +void BaseWindow::SetClosable(bool closable) { window_->SetClosable(closable); } -bool TopLevelWindow::IsClosable() { +bool BaseWindow::IsClosable() { return window_->IsClosable(); } -void TopLevelWindow::SetAlwaysOnTop(bool top, gin_helper::Arguments* args) { +void BaseWindow::SetAlwaysOnTop(bool top, gin_helper::Arguments* args) { std::string level = "floating"; int relative_level = 0; args->GetNext(&level); @@ -538,29 +531,29 @@ void TopLevelWindow::SetAlwaysOnTop(bool top, gin_helper::Arguments* args) { window_->SetAlwaysOnTop(z_order, level, relative_level); } -bool TopLevelWindow::IsAlwaysOnTop() { +bool BaseWindow::IsAlwaysOnTop() { return window_->GetZOrderLevel() != ui::ZOrderLevel::kNormal; } -void TopLevelWindow::Center() { +void BaseWindow::Center() { window_->Center(); } -void TopLevelWindow::SetPosition(int x, int y, gin_helper::Arguments* args) { +void BaseWindow::SetPosition(int x, int y, gin_helper::Arguments* args) { bool animate = false; args->GetNext(&animate); window_->SetPosition(gfx::Point(x, y), animate); } -std::vector TopLevelWindow::GetPosition() { +std::vector BaseWindow::GetPosition() { std::vector result(2); gfx::Point pos = window_->GetPosition(); result[0] = pos.x(); result[1] = pos.y(); return result; } -void TopLevelWindow::MoveAbove(const std::string& sourceId, - gin_helper::Arguments* args) { +void BaseWindow::MoveAbove(const std::string& sourceId, + gin_helper::Arguments* args) { #if BUILDFLAG(ENABLE_DESKTOP_CAPTURER) if (!window_->MoveAbove(sourceId)) args->ThrowError("Invalid media source id"); @@ -569,120 +562,120 @@ void TopLevelWindow::MoveAbove(const std::string& sourceId, #endif } -void TopLevelWindow::MoveTop() { +void BaseWindow::MoveTop() { window_->MoveTop(); } -void TopLevelWindow::SetTitle(const std::string& title) { +void BaseWindow::SetTitle(const std::string& title) { window_->SetTitle(title); } -std::string TopLevelWindow::GetTitle() { +std::string BaseWindow::GetTitle() { return window_->GetTitle(); } -void TopLevelWindow::SetAccessibleTitle(const std::string& title) { +void BaseWindow::SetAccessibleTitle(const std::string& title) { window_->SetAccessibleTitle(title); } -std::string TopLevelWindow::GetAccessibleTitle() { +std::string BaseWindow::GetAccessibleTitle() { return window_->GetAccessibleTitle(); } -void TopLevelWindow::FlashFrame(bool flash) { +void BaseWindow::FlashFrame(bool flash) { window_->FlashFrame(flash); } -void TopLevelWindow::SetSkipTaskbar(bool skip) { +void BaseWindow::SetSkipTaskbar(bool skip) { window_->SetSkipTaskbar(skip); } -void TopLevelWindow::SetExcludedFromShownWindowsMenu(bool excluded) { +void BaseWindow::SetExcludedFromShownWindowsMenu(bool excluded) { window_->SetExcludedFromShownWindowsMenu(excluded); } -bool TopLevelWindow::IsExcludedFromShownWindowsMenu() { +bool BaseWindow::IsExcludedFromShownWindowsMenu() { return window_->IsExcludedFromShownWindowsMenu(); } -void TopLevelWindow::SetSimpleFullScreen(bool simple_fullscreen) { +void BaseWindow::SetSimpleFullScreen(bool simple_fullscreen) { window_->SetSimpleFullScreen(simple_fullscreen); } -bool TopLevelWindow::IsSimpleFullScreen() { +bool BaseWindow::IsSimpleFullScreen() { return window_->IsSimpleFullScreen(); } -void TopLevelWindow::SetKiosk(bool kiosk) { +void BaseWindow::SetKiosk(bool kiosk) { window_->SetKiosk(kiosk); } -bool TopLevelWindow::IsKiosk() { +bool BaseWindow::IsKiosk() { return window_->IsKiosk(); } -void TopLevelWindow::SetBackgroundColor(const std::string& color_name) { +void BaseWindow::SetBackgroundColor(const std::string& color_name) { SkColor color = ParseHexColor(color_name); window_->SetBackgroundColor(color); } -std::string TopLevelWindow::GetBackgroundColor() { +std::string BaseWindow::GetBackgroundColor() { return ToRGBHex(window_->GetBackgroundColor()); } -void TopLevelWindow::SetHasShadow(bool has_shadow) { +void BaseWindow::SetHasShadow(bool has_shadow) { window_->SetHasShadow(has_shadow); } -bool TopLevelWindow::HasShadow() { +bool BaseWindow::HasShadow() { return window_->HasShadow(); } -void TopLevelWindow::SetOpacity(const double opacity) { +void BaseWindow::SetOpacity(const double opacity) { window_->SetOpacity(opacity); } -double TopLevelWindow::GetOpacity() { +double BaseWindow::GetOpacity() { return window_->GetOpacity(); } -void TopLevelWindow::SetShape(const std::vector& rects) { +void BaseWindow::SetShape(const std::vector& rects) { window_->widget()->SetShape(std::make_unique>(rects)); } -void TopLevelWindow::SetRepresentedFilename(const std::string& filename) { +void BaseWindow::SetRepresentedFilename(const std::string& filename) { window_->SetRepresentedFilename(filename); } -std::string TopLevelWindow::GetRepresentedFilename() { +std::string BaseWindow::GetRepresentedFilename() { return window_->GetRepresentedFilename(); } -void TopLevelWindow::SetDocumentEdited(bool edited) { +void BaseWindow::SetDocumentEdited(bool edited) { window_->SetDocumentEdited(edited); } -bool TopLevelWindow::IsDocumentEdited() { +bool BaseWindow::IsDocumentEdited() { return window_->IsDocumentEdited(); } -void TopLevelWindow::SetIgnoreMouseEvents(bool ignore, - gin_helper::Arguments* args) { +void BaseWindow::SetIgnoreMouseEvents(bool ignore, + gin_helper::Arguments* args) { gin_helper::Dictionary options; bool forward = false; args->GetNext(&options) && options.Get("forward", &forward); return window_->SetIgnoreMouseEvents(ignore, forward); } -void TopLevelWindow::SetContentProtection(bool enable) { +void BaseWindow::SetContentProtection(bool enable) { return window_->SetContentProtection(enable); } -void TopLevelWindow::SetFocusable(bool focusable) { +void BaseWindow::SetFocusable(bool focusable) { return window_->SetFocusable(focusable); } -void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local value) { +void BaseWindow::SetMenu(v8::Isolate* isolate, v8::Local value) { auto context = isolate->GetCurrentContext(); gin::Handle menu; v8::Local object; @@ -705,19 +698,19 @@ void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local value) { } } -void TopLevelWindow::RemoveMenu() { +void BaseWindow::RemoveMenu() { menu_.Reset(); window_->SetMenu(nullptr); } -void TopLevelWindow::SetParentWindow(v8::Local value, - gin_helper::Arguments* args) { +void BaseWindow::SetParentWindow(v8::Local value, + gin_helper::Arguments* args) { if (IsModal()) { args->ThrowError("Can not be called for modal window"); return; } - gin::Handle parent; + gin::Handle parent; if (value->IsNull() || value->IsUndefined()) { RemoveFromParentChildWindows(); parent_window_.Reset(); @@ -728,16 +721,16 @@ void TopLevelWindow::SetParentWindow(v8::Local value, window_->SetParentWindow(parent->window_.get()); parent->child_windows_.Set(isolate(), weak_map_id(), GetWrapper()); } else { - args->ThrowError("Must pass TopLevelWindow instance or null"); + args->ThrowError("Must pass BaseWindow instance or null"); } } -void TopLevelWindow::SetBrowserView(v8::Local value) { +void BaseWindow::SetBrowserView(v8::Local value) { ResetBrowserViews(); AddBrowserView(value); } -void TopLevelWindow::AddBrowserView(v8::Local value) { +void BaseWindow::AddBrowserView(v8::Local value) { gin::Handle browser_view; if (value->IsObject() && gin::ConvertFromV8(isolate(), value, &browser_view)) { @@ -750,7 +743,7 @@ void TopLevelWindow::AddBrowserView(v8::Local value) { } } -void TopLevelWindow::RemoveBrowserView(v8::Local value) { +void BaseWindow::RemoveBrowserView(v8::Local value) { gin::Handle browser_view; if (value->IsObject() && gin::ConvertFromV8(isolate(), value, &browser_view)) { @@ -765,11 +758,11 @@ void TopLevelWindow::RemoveBrowserView(v8::Local value) { } } -std::string TopLevelWindow::GetMediaSourceId() const { +std::string BaseWindow::GetMediaSourceId() const { return window_->GetDesktopMediaID().ToString(); } -v8::Local TopLevelWindow::GetNativeWindowHandle() { +v8::Local BaseWindow::GetNativeWindowHandle() { // TODO(MarshallOfSound): Replace once // https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has // landed @@ -777,8 +770,7 @@ v8::Local TopLevelWindow::GetNativeWindowHandle() { return ToBuffer(isolate(), &handle, sizeof(handle)); } -void TopLevelWindow::SetProgressBar(double progress, - gin_helper::Arguments* args) { +void BaseWindow::SetProgressBar(double progress, gin_helper::Arguments* args) { gin_helper::Dictionary options; std::string mode; args->GetNext(&options) && options.Get("mode", &mode); @@ -796,140 +788,138 @@ void TopLevelWindow::SetProgressBar(double progress, window_->SetProgressBar(progress, state); } -void TopLevelWindow::SetOverlayIcon(const gfx::Image& overlay, - const std::string& description) { +void BaseWindow::SetOverlayIcon(const gfx::Image& overlay, + const std::string& description) { window_->SetOverlayIcon(overlay, description); } -void TopLevelWindow::SetVisibleOnAllWorkspaces(bool visible) { +void BaseWindow::SetVisibleOnAllWorkspaces(bool visible) { return window_->SetVisibleOnAllWorkspaces(visible); } -bool TopLevelWindow::IsVisibleOnAllWorkspaces() { +bool BaseWindow::IsVisibleOnAllWorkspaces() { return window_->IsVisibleOnAllWorkspaces(); } -void TopLevelWindow::SetAutoHideCursor(bool auto_hide) { +void BaseWindow::SetAutoHideCursor(bool auto_hide) { window_->SetAutoHideCursor(auto_hide); } -void TopLevelWindow::SetVibrancy(v8::Isolate* isolate, - v8::Local value) { +void BaseWindow::SetVibrancy(v8::Isolate* isolate, v8::Local value) { std::string type = gin::V8ToString(isolate, value); window_->SetVibrancy(type); } #if defined(OS_MACOSX) -void TopLevelWindow::SetTrafficLightPosition(const gfx::Point& position) { +void BaseWindow::SetTrafficLightPosition(const gfx::Point& position) { window_->SetTrafficLightPosition(position); } -gfx::Point TopLevelWindow::GetTrafficLightPosition() const { +gfx::Point BaseWindow::GetTrafficLightPosition() const { return window_->GetTrafficLightPosition(); } #endif -void TopLevelWindow::SetTouchBar( +void BaseWindow::SetTouchBar( std::vector items) { window_->SetTouchBar(std::move(items)); } -void TopLevelWindow::RefreshTouchBarItem(const std::string& item_id) { +void BaseWindow::RefreshTouchBarItem(const std::string& item_id) { window_->RefreshTouchBarItem(item_id); } -void TopLevelWindow::SetEscapeTouchBarItem( - gin_helper::PersistentDictionary item) { +void BaseWindow::SetEscapeTouchBarItem(gin_helper::PersistentDictionary item) { window_->SetEscapeTouchBarItem(std::move(item)); } -void TopLevelWindow::SelectPreviousTab() { +void BaseWindow::SelectPreviousTab() { window_->SelectPreviousTab(); } -void TopLevelWindow::SelectNextTab() { +void BaseWindow::SelectNextTab() { window_->SelectNextTab(); } -void TopLevelWindow::MergeAllWindows() { +void BaseWindow::MergeAllWindows() { window_->MergeAllWindows(); } -void TopLevelWindow::MoveTabToNewWindow() { +void BaseWindow::MoveTabToNewWindow() { window_->MoveTabToNewWindow(); } -void TopLevelWindow::ToggleTabBar() { +void BaseWindow::ToggleTabBar() { window_->ToggleTabBar(); } -void TopLevelWindow::AddTabbedWindow(NativeWindow* window, - gin_helper::Arguments* args) { +void BaseWindow::AddTabbedWindow(NativeWindow* window, + gin_helper::Arguments* args) { if (!window_->AddTabbedWindow(window)) args->ThrowError("AddTabbedWindow cannot be called by a window on itself."); } -void TopLevelWindow::SetWindowButtonVisibility(bool visible, - gin_helper::Arguments* args) { +void BaseWindow::SetWindowButtonVisibility(bool visible, + gin_helper::Arguments* args) { if (!window_->SetWindowButtonVisibility(visible)) { args->ThrowError("Not supported for this window"); } } -void TopLevelWindow::SetAutoHideMenuBar(bool auto_hide) { +void BaseWindow::SetAutoHideMenuBar(bool auto_hide) { window_->SetAutoHideMenuBar(auto_hide); } -bool TopLevelWindow::IsMenuBarAutoHide() { +bool BaseWindow::IsMenuBarAutoHide() { return window_->IsMenuBarAutoHide(); } -void TopLevelWindow::SetMenuBarVisibility(bool visible) { +void BaseWindow::SetMenuBarVisibility(bool visible) { window_->SetMenuBarVisibility(visible); } -bool TopLevelWindow::IsMenuBarVisible() { +bool BaseWindow::IsMenuBarVisible() { return window_->IsMenuBarVisible(); } -void TopLevelWindow::SetAspectRatio(double aspect_ratio, - gin_helper::Arguments* args) { +void BaseWindow::SetAspectRatio(double aspect_ratio, + gin_helper::Arguments* args) { gfx::Size extra_size; args->GetNext(&extra_size); window_->SetAspectRatio(aspect_ratio, extra_size); } -void TopLevelWindow::PreviewFile(const std::string& path, - gin_helper::Arguments* args) { +void BaseWindow::PreviewFile(const std::string& path, + gin_helper::Arguments* args) { std::string display_name; if (!args->GetNext(&display_name)) display_name = path; window_->PreviewFile(path, display_name); } -void TopLevelWindow::CloseFilePreview() { +void BaseWindow::CloseFilePreview() { window_->CloseFilePreview(); } -v8::Local TopLevelWindow::GetContentView() const { +v8::Local BaseWindow::GetContentView() const { if (content_view_.IsEmpty()) return v8::Null(isolate()); else return v8::Local::New(isolate(), content_view_); } -v8::Local TopLevelWindow::GetParentWindow() const { +v8::Local BaseWindow::GetParentWindow() const { if (parent_window_.IsEmpty()) return v8::Null(isolate()); else return v8::Local::New(isolate(), parent_window_); } -std::vector> TopLevelWindow::GetChildWindows() const { +std::vector> BaseWindow::GetChildWindows() const { return child_windows_.Values(isolate()); } -v8::Local TopLevelWindow::GetBrowserView( +v8::Local BaseWindow::GetBrowserView( gin_helper::Arguments* args) const { if (browser_views_.size() == 0) { return v8::Null(isolate()); @@ -944,7 +934,7 @@ v8::Local TopLevelWindow::GetBrowserView( } } -std::vector> TopLevelWindow::GetBrowserViews() const { +std::vector> BaseWindow::GetBrowserViews() const { std::vector> ret; for (auto const& views_iter : browser_views_) { @@ -954,11 +944,11 @@ std::vector> TopLevelWindow::GetBrowserViews() const { return ret; } -bool TopLevelWindow::IsModal() const { +bool BaseWindow::IsModal() const { return window_->is_modal(); } -bool TopLevelWindow::SetThumbarButtons(gin_helper::Arguments* args) { +bool BaseWindow::SetThumbarButtons(gin_helper::Arguments* args) { #if defined(OS_WIN) std::vector buttons; if (!args->GetNext(&buttons)) { @@ -974,7 +964,7 @@ bool TopLevelWindow::SetThumbarButtons(gin_helper::Arguments* args) { } #if defined(TOOLKIT_VIEWS) -void TopLevelWindow::SetIcon(gin::Handle icon) { +void BaseWindow::SetIcon(gin::Handle icon) { #if defined(OS_WIN) static_cast(window_.get()) ->SetIcon(icon->GetHICON(GetSystemMetrics(SM_CXSMICON)), @@ -987,37 +977,37 @@ void TopLevelWindow::SetIcon(gin::Handle icon) { #endif #if defined(OS_WIN) -bool TopLevelWindow::HookWindowMessage(UINT message, - const MessageCallback& callback) { +bool BaseWindow::HookWindowMessage(UINT message, + const MessageCallback& callback) { messages_callback_map_[message] = callback; return true; } -void TopLevelWindow::UnhookWindowMessage(UINT message) { +void BaseWindow::UnhookWindowMessage(UINT message) { messages_callback_map_.erase(message); } -bool TopLevelWindow::IsWindowMessageHooked(UINT message) { +bool BaseWindow::IsWindowMessageHooked(UINT message) { return base::Contains(messages_callback_map_, message); } -void TopLevelWindow::UnhookAllWindowMessages() { +void BaseWindow::UnhookAllWindowMessages() { messages_callback_map_.clear(); } -bool TopLevelWindow::SetThumbnailClip(const gfx::Rect& region) { +bool BaseWindow::SetThumbnailClip(const gfx::Rect& region) { auto* window = static_cast(window_.get()); return window->taskbar_host().SetThumbnailClip( window_->GetAcceleratedWidget(), region); } -bool TopLevelWindow::SetThumbnailToolTip(const std::string& tooltip) { +bool BaseWindow::SetThumbnailToolTip(const std::string& tooltip) { auto* window = static_cast(window_.get()); return window->taskbar_host().SetThumbnailToolTip( window_->GetAcceleratedWidget(), tooltip); } -void TopLevelWindow::SetAppDetails(const gin_helper::Dictionary& options) { +void BaseWindow::SetAppDetails(const gin_helper::Dictionary& options) { base::string16 app_id; base::FilePath app_icon_path; int app_icon_index = 0; @@ -1036,11 +1026,11 @@ void TopLevelWindow::SetAppDetails(const gin_helper::Dictionary& options) { } #endif -int32_t TopLevelWindow::GetID() const { +int32_t BaseWindow::GetID() const { return weak_map_id(); } -void TopLevelWindow::ResetBrowserViews() { +void BaseWindow::ResetBrowserViews() { for (auto& item : browser_views_) { gin::Handle browser_view; if (gin::ConvertFromV8(isolate(), @@ -1057,11 +1047,11 @@ void TopLevelWindow::ResetBrowserViews() { browser_views_.clear(); } -void TopLevelWindow::RemoveFromParentChildWindows() { +void BaseWindow::RemoveFromParentChildWindows() { if (parent_window_.IsEmpty()) return; - gin::Handle parent; + gin::Handle parent; if (!gin::ConvertFromV8(isolate(), GetParentWindow(), &parent) || parent.IsEmpty()) { return; @@ -1071,170 +1061,165 @@ void TopLevelWindow::RemoveFromParentChildWindows() { } // static -gin_helper::WrappableBase* TopLevelWindow::New(gin_helper::Arguments* args) { +gin_helper::WrappableBase* BaseWindow::New(gin_helper::Arguments* args) { gin_helper::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate()); args->GetNext(&options); - return new TopLevelWindow(args, options); + return new BaseWindow(args, options); } // static -void TopLevelWindow::BuildPrototype(v8::Isolate* isolate, - v8::Local prototype) { - prototype->SetClassName(gin::StringToV8(isolate, "TopLevelWindow")); +void BaseWindow::BuildPrototype(v8::Isolate* isolate, + v8::Local prototype) { + prototype->SetClassName(gin::StringToV8(isolate, "BaseWindow")); gin_helper::Destroyable::MakeDestroyable(isolate, prototype); gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) - .SetMethod("setContentView", &TopLevelWindow::SetContentView) - .SetMethod("close", &TopLevelWindow::Close) - .SetMethod("focus", &TopLevelWindow::Focus) - .SetMethod("blur", &TopLevelWindow::Blur) - .SetMethod("isFocused", &TopLevelWindow::IsFocused) - .SetMethod("show", &TopLevelWindow::Show) - .SetMethod("showInactive", &TopLevelWindow::ShowInactive) - .SetMethod("hide", &TopLevelWindow::Hide) - .SetMethod("isVisible", &TopLevelWindow::IsVisible) - .SetMethod("isEnabled", &TopLevelWindow::IsEnabled) - .SetMethod("setEnabled", &TopLevelWindow::SetEnabled) - .SetMethod("maximize", &TopLevelWindow::Maximize) - .SetMethod("unmaximize", &TopLevelWindow::Unmaximize) - .SetMethod("isMaximized", &TopLevelWindow::IsMaximized) - .SetMethod("minimize", &TopLevelWindow::Minimize) - .SetMethod("restore", &TopLevelWindow::Restore) - .SetMethod("isMinimized", &TopLevelWindow::IsMinimized) - .SetMethod("setFullScreen", &TopLevelWindow::SetFullScreen) - .SetMethod("isFullScreen", &TopLevelWindow::IsFullscreen) - .SetMethod("setBounds", &TopLevelWindow::SetBounds) - .SetMethod("getBounds", &TopLevelWindow::GetBounds) - .SetMethod("isNormal", &TopLevelWindow::IsNormal) - .SetMethod("getNormalBounds", &TopLevelWindow::GetNormalBounds) - .SetMethod("setSize", &TopLevelWindow::SetSize) - .SetMethod("getSize", &TopLevelWindow::GetSize) - .SetMethod("setContentBounds", &TopLevelWindow::SetContentBounds) - .SetMethod("getContentBounds", &TopLevelWindow::GetContentBounds) - .SetMethod("setContentSize", &TopLevelWindow::SetContentSize) - .SetMethod("getContentSize", &TopLevelWindow::GetContentSize) - .SetMethod("setMinimumSize", &TopLevelWindow::SetMinimumSize) - .SetMethod("getMinimumSize", &TopLevelWindow::GetMinimumSize) - .SetMethod("setMaximumSize", &TopLevelWindow::SetMaximumSize) - .SetMethod("getMaximumSize", &TopLevelWindow::GetMaximumSize) - .SetMethod("setSheetOffset", &TopLevelWindow::SetSheetOffset) - .SetMethod("moveAbove", &TopLevelWindow::MoveAbove) - .SetMethod("moveTop", &TopLevelWindow::MoveTop) - .SetMethod("setResizable", &TopLevelWindow::SetResizable) - .SetMethod("isResizable", &TopLevelWindow::IsResizable) - .SetMethod("setMovable", &TopLevelWindow::SetMovable) - .SetMethod("isMovable", &TopLevelWindow::IsMovable) - .SetMethod("setMinimizable", &TopLevelWindow::SetMinimizable) - .SetMethod("isMinimizable", &TopLevelWindow::IsMinimizable) - .SetMethod("setMaximizable", &TopLevelWindow::SetMaximizable) - .SetMethod("isMaximizable", &TopLevelWindow::IsMaximizable) - .SetMethod("setFullScreenable", &TopLevelWindow::SetFullScreenable) - .SetMethod("isFullScreenable", &TopLevelWindow::IsFullScreenable) - .SetMethod("setClosable", &TopLevelWindow::SetClosable) - .SetMethod("isClosable", &TopLevelWindow::IsClosable) - .SetMethod("setAlwaysOnTop", &TopLevelWindow::SetAlwaysOnTop) - .SetMethod("isAlwaysOnTop", &TopLevelWindow::IsAlwaysOnTop) - .SetMethod("center", &TopLevelWindow::Center) - .SetMethod("setPosition", &TopLevelWindow::SetPosition) - .SetMethod("getPosition", &TopLevelWindow::GetPosition) - .SetMethod("setTitle", &TopLevelWindow::SetTitle) - .SetMethod("getTitle", &TopLevelWindow::GetTitle) - .SetProperty("accessibleTitle", &TopLevelWindow::GetAccessibleTitle, - &TopLevelWindow::SetAccessibleTitle) - .SetMethod("flashFrame", &TopLevelWindow::FlashFrame) - .SetMethod("setSkipTaskbar", &TopLevelWindow::SetSkipTaskbar) - .SetMethod("setSimpleFullScreen", &TopLevelWindow::SetSimpleFullScreen) - .SetMethod("isSimpleFullScreen", &TopLevelWindow::IsSimpleFullScreen) - .SetMethod("setKiosk", &TopLevelWindow::SetKiosk) - .SetMethod("isKiosk", &TopLevelWindow::IsKiosk) - .SetMethod("setBackgroundColor", &TopLevelWindow::SetBackgroundColor) - .SetMethod("getBackgroundColor", &TopLevelWindow::GetBackgroundColor) - .SetMethod("setHasShadow", &TopLevelWindow::SetHasShadow) - .SetMethod("hasShadow", &TopLevelWindow::HasShadow) - .SetMethod("setOpacity", &TopLevelWindow::SetOpacity) - .SetMethod("getOpacity", &TopLevelWindow::GetOpacity) - .SetMethod("setShape", &TopLevelWindow::SetShape) - .SetMethod("setRepresentedFilename", - &TopLevelWindow::SetRepresentedFilename) - .SetMethod("getRepresentedFilename", - &TopLevelWindow::GetRepresentedFilename) - .SetMethod("setDocumentEdited", &TopLevelWindow::SetDocumentEdited) - .SetMethod("isDocumentEdited", &TopLevelWindow::IsDocumentEdited) - .SetMethod("setIgnoreMouseEvents", &TopLevelWindow::SetIgnoreMouseEvents) - .SetMethod("setContentProtection", &TopLevelWindow::SetContentProtection) - .SetMethod("setFocusable", &TopLevelWindow::SetFocusable) - .SetMethod("setMenu", &TopLevelWindow::SetMenu) - .SetMethod("removeMenu", &TopLevelWindow::RemoveMenu) - .SetMethod("setParentWindow", &TopLevelWindow::SetParentWindow) - .SetMethod("setBrowserView", &TopLevelWindow::SetBrowserView) - .SetMethod("addBrowserView", &TopLevelWindow::AddBrowserView) - .SetMethod("removeBrowserView", &TopLevelWindow::RemoveBrowserView) - .SetMethod("getMediaSourceId", &TopLevelWindow::GetMediaSourceId) - .SetMethod("getNativeWindowHandle", - &TopLevelWindow::GetNativeWindowHandle) - .SetMethod("setProgressBar", &TopLevelWindow::SetProgressBar) - .SetMethod("setOverlayIcon", &TopLevelWindow::SetOverlayIcon) + .SetMethod("setContentView", &BaseWindow::SetContentView) + .SetMethod("close", &BaseWindow::Close) + .SetMethod("focus", &BaseWindow::Focus) + .SetMethod("blur", &BaseWindow::Blur) + .SetMethod("isFocused", &BaseWindow::IsFocused) + .SetMethod("show", &BaseWindow::Show) + .SetMethod("showInactive", &BaseWindow::ShowInactive) + .SetMethod("hide", &BaseWindow::Hide) + .SetMethod("isVisible", &BaseWindow::IsVisible) + .SetMethod("isEnabled", &BaseWindow::IsEnabled) + .SetMethod("setEnabled", &BaseWindow::SetEnabled) + .SetMethod("maximize", &BaseWindow::Maximize) + .SetMethod("unmaximize", &BaseWindow::Unmaximize) + .SetMethod("isMaximized", &BaseWindow::IsMaximized) + .SetMethod("minimize", &BaseWindow::Minimize) + .SetMethod("restore", &BaseWindow::Restore) + .SetMethod("isMinimized", &BaseWindow::IsMinimized) + .SetMethod("setFullScreen", &BaseWindow::SetFullScreen) + .SetMethod("isFullScreen", &BaseWindow::IsFullscreen) + .SetMethod("setBounds", &BaseWindow::SetBounds) + .SetMethod("getBounds", &BaseWindow::GetBounds) + .SetMethod("isNormal", &BaseWindow::IsNormal) + .SetMethod("getNormalBounds", &BaseWindow::GetNormalBounds) + .SetMethod("setSize", &BaseWindow::SetSize) + .SetMethod("getSize", &BaseWindow::GetSize) + .SetMethod("setContentBounds", &BaseWindow::SetContentBounds) + .SetMethod("getContentBounds", &BaseWindow::GetContentBounds) + .SetMethod("setContentSize", &BaseWindow::SetContentSize) + .SetMethod("getContentSize", &BaseWindow::GetContentSize) + .SetMethod("setMinimumSize", &BaseWindow::SetMinimumSize) + .SetMethod("getMinimumSize", &BaseWindow::GetMinimumSize) + .SetMethod("setMaximumSize", &BaseWindow::SetMaximumSize) + .SetMethod("getMaximumSize", &BaseWindow::GetMaximumSize) + .SetMethod("setSheetOffset", &BaseWindow::SetSheetOffset) + .SetMethod("moveAbove", &BaseWindow::MoveAbove) + .SetMethod("moveTop", &BaseWindow::MoveTop) + .SetMethod("setResizable", &BaseWindow::SetResizable) + .SetMethod("isResizable", &BaseWindow::IsResizable) + .SetMethod("setMovable", &BaseWindow::SetMovable) + .SetMethod("isMovable", &BaseWindow::IsMovable) + .SetMethod("setMinimizable", &BaseWindow::SetMinimizable) + .SetMethod("isMinimizable", &BaseWindow::IsMinimizable) + .SetMethod("setMaximizable", &BaseWindow::SetMaximizable) + .SetMethod("isMaximizable", &BaseWindow::IsMaximizable) + .SetMethod("setFullScreenable", &BaseWindow::SetFullScreenable) + .SetMethod("isFullScreenable", &BaseWindow::IsFullScreenable) + .SetMethod("setClosable", &BaseWindow::SetClosable) + .SetMethod("isClosable", &BaseWindow::IsClosable) + .SetMethod("setAlwaysOnTop", &BaseWindow::SetAlwaysOnTop) + .SetMethod("isAlwaysOnTop", &BaseWindow::IsAlwaysOnTop) + .SetMethod("center", &BaseWindow::Center) + .SetMethod("setPosition", &BaseWindow::SetPosition) + .SetMethod("getPosition", &BaseWindow::GetPosition) + .SetMethod("setTitle", &BaseWindow::SetTitle) + .SetMethod("getTitle", &BaseWindow::GetTitle) + .SetProperty("accessibleTitle", &BaseWindow::GetAccessibleTitle, + &BaseWindow::SetAccessibleTitle) + .SetMethod("flashFrame", &BaseWindow::FlashFrame) + .SetMethod("setSkipTaskbar", &BaseWindow::SetSkipTaskbar) + .SetMethod("setSimpleFullScreen", &BaseWindow::SetSimpleFullScreen) + .SetMethod("isSimpleFullScreen", &BaseWindow::IsSimpleFullScreen) + .SetMethod("setKiosk", &BaseWindow::SetKiosk) + .SetMethod("isKiosk", &BaseWindow::IsKiosk) + .SetMethod("setBackgroundColor", &BaseWindow::SetBackgroundColor) + .SetMethod("getBackgroundColor", &BaseWindow::GetBackgroundColor) + .SetMethod("setHasShadow", &BaseWindow::SetHasShadow) + .SetMethod("hasShadow", &BaseWindow::HasShadow) + .SetMethod("setOpacity", &BaseWindow::SetOpacity) + .SetMethod("getOpacity", &BaseWindow::GetOpacity) + .SetMethod("setShape", &BaseWindow::SetShape) + .SetMethod("setRepresentedFilename", &BaseWindow::SetRepresentedFilename) + .SetMethod("getRepresentedFilename", &BaseWindow::GetRepresentedFilename) + .SetMethod("setDocumentEdited", &BaseWindow::SetDocumentEdited) + .SetMethod("isDocumentEdited", &BaseWindow::IsDocumentEdited) + .SetMethod("setIgnoreMouseEvents", &BaseWindow::SetIgnoreMouseEvents) + .SetMethod("setContentProtection", &BaseWindow::SetContentProtection) + .SetMethod("setFocusable", &BaseWindow::SetFocusable) + .SetMethod("setMenu", &BaseWindow::SetMenu) + .SetMethod("removeMenu", &BaseWindow::RemoveMenu) + .SetMethod("setParentWindow", &BaseWindow::SetParentWindow) + .SetMethod("setBrowserView", &BaseWindow::SetBrowserView) + .SetMethod("addBrowserView", &BaseWindow::AddBrowserView) + .SetMethod("removeBrowserView", &BaseWindow::RemoveBrowserView) + .SetMethod("getMediaSourceId", &BaseWindow::GetMediaSourceId) + .SetMethod("getNativeWindowHandle", &BaseWindow::GetNativeWindowHandle) + .SetMethod("setProgressBar", &BaseWindow::SetProgressBar) + .SetMethod("setOverlayIcon", &BaseWindow::SetOverlayIcon) .SetMethod("setVisibleOnAllWorkspaces", - &TopLevelWindow::SetVisibleOnAllWorkspaces) + &BaseWindow::SetVisibleOnAllWorkspaces) .SetMethod("isVisibleOnAllWorkspaces", - &TopLevelWindow::IsVisibleOnAllWorkspaces) + &BaseWindow::IsVisibleOnAllWorkspaces) #if defined(OS_MACOSX) - .SetMethod("setAutoHideCursor", &TopLevelWindow::SetAutoHideCursor) + .SetMethod("setAutoHideCursor", &BaseWindow::SetAutoHideCursor) #endif - .SetMethod("setVibrancy", &TopLevelWindow::SetVibrancy) + .SetMethod("setVibrancy", &BaseWindow::SetVibrancy) #if defined(OS_MACOSX) .SetMethod("setTrafficLightPosition", - &TopLevelWindow::SetTrafficLightPosition) + &BaseWindow::SetTrafficLightPosition) .SetMethod("getTrafficLightPosition", - &TopLevelWindow::GetTrafficLightPosition) + &BaseWindow::GetTrafficLightPosition) #endif - .SetMethod("_setTouchBarItems", &TopLevelWindow::SetTouchBar) - .SetMethod("_refreshTouchBarItem", &TopLevelWindow::RefreshTouchBarItem) - .SetMethod("_setEscapeTouchBarItem", - &TopLevelWindow::SetEscapeTouchBarItem) + .SetMethod("_setTouchBarItems", &BaseWindow::SetTouchBar) + .SetMethod("_refreshTouchBarItem", &BaseWindow::RefreshTouchBarItem) + .SetMethod("_setEscapeTouchBarItem", &BaseWindow::SetEscapeTouchBarItem) #if defined(OS_MACOSX) - .SetMethod("selectPreviousTab", &TopLevelWindow::SelectPreviousTab) - .SetMethod("selectNextTab", &TopLevelWindow::SelectNextTab) - .SetMethod("mergeAllWindows", &TopLevelWindow::MergeAllWindows) - .SetMethod("moveTabToNewWindow", &TopLevelWindow::MoveTabToNewWindow) - .SetMethod("toggleTabBar", &TopLevelWindow::ToggleTabBar) - .SetMethod("addTabbedWindow", &TopLevelWindow::AddTabbedWindow) + .SetMethod("selectPreviousTab", &BaseWindow::SelectPreviousTab) + .SetMethod("selectNextTab", &BaseWindow::SelectNextTab) + .SetMethod("mergeAllWindows", &BaseWindow::MergeAllWindows) + .SetMethod("moveTabToNewWindow", &BaseWindow::MoveTabToNewWindow) + .SetMethod("toggleTabBar", &BaseWindow::ToggleTabBar) + .SetMethod("addTabbedWindow", &BaseWindow::AddTabbedWindow) .SetMethod("setWindowButtonVisibility", - &TopLevelWindow::SetWindowButtonVisibility) + &BaseWindow::SetWindowButtonVisibility) .SetProperty("excludedFromShownWindowsMenu", - &TopLevelWindow::IsExcludedFromShownWindowsMenu, - &TopLevelWindow::SetExcludedFromShownWindowsMenu) + &BaseWindow::IsExcludedFromShownWindowsMenu, + &BaseWindow::SetExcludedFromShownWindowsMenu) #endif - .SetMethod("setAutoHideMenuBar", &TopLevelWindow::SetAutoHideMenuBar) - .SetMethod("isMenuBarAutoHide", &TopLevelWindow::IsMenuBarAutoHide) - .SetMethod("setMenuBarVisibility", &TopLevelWindow::SetMenuBarVisibility) - .SetMethod("isMenuBarVisible", &TopLevelWindow::IsMenuBarVisible) - .SetMethod("setAspectRatio", &TopLevelWindow::SetAspectRatio) - .SetMethod("previewFile", &TopLevelWindow::PreviewFile) - .SetMethod("closeFilePreview", &TopLevelWindow::CloseFilePreview) - .SetMethod("getContentView", &TopLevelWindow::GetContentView) - .SetMethod("getParentWindow", &TopLevelWindow::GetParentWindow) - .SetMethod("getChildWindows", &TopLevelWindow::GetChildWindows) - .SetMethod("getBrowserView", &TopLevelWindow::GetBrowserView) - .SetMethod("getBrowserViews", &TopLevelWindow::GetBrowserViews) - .SetMethod("isModal", &TopLevelWindow::IsModal) - .SetMethod("setThumbarButtons", &TopLevelWindow::SetThumbarButtons) + .SetMethod("setAutoHideMenuBar", &BaseWindow::SetAutoHideMenuBar) + .SetMethod("isMenuBarAutoHide", &BaseWindow::IsMenuBarAutoHide) + .SetMethod("setMenuBarVisibility", &BaseWindow::SetMenuBarVisibility) + .SetMethod("isMenuBarVisible", &BaseWindow::IsMenuBarVisible) + .SetMethod("setAspectRatio", &BaseWindow::SetAspectRatio) + .SetMethod("previewFile", &BaseWindow::PreviewFile) + .SetMethod("closeFilePreview", &BaseWindow::CloseFilePreview) + .SetMethod("getContentView", &BaseWindow::GetContentView) + .SetMethod("getParentWindow", &BaseWindow::GetParentWindow) + .SetMethod("getChildWindows", &BaseWindow::GetChildWindows) + .SetMethod("getBrowserView", &BaseWindow::GetBrowserView) + .SetMethod("getBrowserViews", &BaseWindow::GetBrowserViews) + .SetMethod("isModal", &BaseWindow::IsModal) + .SetMethod("setThumbarButtons", &BaseWindow::SetThumbarButtons) #if defined(TOOLKIT_VIEWS) - .SetMethod("setIcon", &TopLevelWindow::SetIcon) + .SetMethod("setIcon", &BaseWindow::SetIcon) #endif #if defined(OS_WIN) - .SetMethod("hookWindowMessage", &TopLevelWindow::HookWindowMessage) - .SetMethod("isWindowMessageHooked", - &TopLevelWindow::IsWindowMessageHooked) - .SetMethod("unhookWindowMessage", &TopLevelWindow::UnhookWindowMessage) + .SetMethod("hookWindowMessage", &BaseWindow::HookWindowMessage) + .SetMethod("isWindowMessageHooked", &BaseWindow::IsWindowMessageHooked) + .SetMethod("unhookWindowMessage", &BaseWindow::UnhookWindowMessage) .SetMethod("unhookAllWindowMessages", - &TopLevelWindow::UnhookAllWindowMessages) - .SetMethod("setThumbnailClip", &TopLevelWindow::SetThumbnailClip) - .SetMethod("setThumbnailToolTip", &TopLevelWindow::SetThumbnailToolTip) - .SetMethod("setAppDetails", &TopLevelWindow::SetAppDetails) + &BaseWindow::UnhookAllWindowMessages) + .SetMethod("setThumbnailClip", &BaseWindow::SetThumbnailClip) + .SetMethod("setThumbnailToolTip", &BaseWindow::SetThumbnailToolTip) + .SetMethod("setAppDetails", &BaseWindow::SetAppDetails) #endif - .SetProperty("id", &TopLevelWindow::GetID); + .SetProperty("id", &BaseWindow::GetID); } } // namespace api @@ -1243,27 +1228,26 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate, namespace { -using electron::api::TopLevelWindow; +using electron::api::BaseWindow; void Initialize(v8::Local exports, v8::Local unused, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - TopLevelWindow::SetConstructor(isolate, - base::BindRepeating(&TopLevelWindow::New)); + BaseWindow::SetConstructor(isolate, base::BindRepeating(&BaseWindow::New)); gin_helper::Dictionary constructor(isolate, - TopLevelWindow::GetConstructor(isolate) + BaseWindow::GetConstructor(isolate) ->GetFunction(context) .ToLocalChecked()); - constructor.SetMethod("fromId", &TopLevelWindow::FromWeakMapID); - constructor.SetMethod("getAllWindows", &TopLevelWindow::GetAll); + constructor.SetMethod("fromId", &BaseWindow::FromWeakMapID); + constructor.SetMethod("getAllWindows", &BaseWindow::GetAll); gin_helper::Dictionary dict(isolate, exports); - dict.Set("TopLevelWindow", constructor); + dict.Set("BaseWindow", constructor); } } // namespace -NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_top_level_window, Initialize) +NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_base_window, Initialize) diff --git a/shell/browser/api/electron_api_top_level_window.h b/shell/browser/api/electron_api_base_window.h similarity index 92% rename from shell/browser/api/electron_api_top_level_window.h rename to shell/browser/api/electron_api_base_window.h index 0102f4a8e886..64e3a3c87171 100644 --- a/shell/browser/api/electron_api_top_level_window.h +++ b/shell/browser/api/electron_api_base_window.h @@ -2,8 +2,8 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#ifndef SHELL_BROWSER_API_ELECTRON_API_TOP_LEVEL_WINDOW_H_ -#define SHELL_BROWSER_API_ELECTRON_API_TOP_LEVEL_WINDOW_H_ +#ifndef SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_ +#define SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_ #include #include @@ -25,27 +25,25 @@ namespace api { class View; -class TopLevelWindow : public gin_helper::TrackableObject, - public NativeWindowObserver { +class BaseWindow : public gin_helper::TrackableObject, + public NativeWindowObserver { public: static gin_helper::WrappableBase* New(gin_helper::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); - base::WeakPtr GetWeakPtr() { - return weak_factory_.GetWeakPtr(); - } + base::WeakPtr GetWeakPtr() { return weak_factory_.GetWeakPtr(); } NativeWindow* window() const { return window_.get(); } protected: // Common constructor. - TopLevelWindow(v8::Isolate* isolate, const gin_helper::Dictionary& options); - // Creating independent TopLevelWindow instance. - TopLevelWindow(gin_helper::Arguments* args, - const gin_helper::Dictionary& options); - ~TopLevelWindow() override; + BaseWindow(v8::Isolate* isolate, const gin_helper::Dictionary& options); + // Creating independent BaseWindow instance. + BaseWindow(gin_helper::Arguments* args, + const gin_helper::Dictionary& options); + ~BaseWindow() override; // TrackableObject: void InitWith(v8::Isolate* isolate, v8::Local wrapper) override; @@ -247,7 +245,7 @@ class TopLevelWindow : public gin_helper::TrackableObject, void EmitEventSoon(base::StringPiece eventName) { base::PostTask( FROM_HERE, {content::BrowserThread::UI}, - base::BindOnce(base::IgnoreResult(&TopLevelWindow::Emit), + base::BindOnce(base::IgnoreResult(&BaseWindow::Emit), weak_factory_.GetWeakPtr(), eventName)); } @@ -267,11 +265,11 @@ class TopLevelWindow : public gin_helper::TrackableObject, // Reference to JS wrapper to prevent garbage collection. v8::Global self_ref_; - base::WeakPtrFactory weak_factory_; + base::WeakPtrFactory weak_factory_; }; } // namespace api } // namespace electron -#endif // SHELL_BROWSER_API_ELECTRON_API_TOP_LEVEL_WINDOW_H_ +#endif // SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_ diff --git a/shell/browser/api/electron_api_browser_window.cc b/shell/browser/api/electron_api_browser_window.cc index 094e4e4ed5d4..7877a7a6d267 100644 --- a/shell/browser/api/electron_api_browser_window.cc +++ b/shell/browser/api/electron_api_browser_window.cc @@ -31,7 +31,7 @@ namespace api { BrowserWindow::BrowserWindow(gin::Arguments* args, const gin_helper::Dictionary& options) - : TopLevelWindow(args->isolate(), options), weak_factory_(this) { + : BaseWindow(args->isolate(), options), weak_factory_(this) { // Use options.webPreferences in WebContents. v8::Isolate* isolate = args->isolate(); gin_helper::Dictionary web_preferences = @@ -90,7 +90,7 @@ BrowserWindow::BrowserWindow(gin::Arguments* args, InitWithArgs(args); - // Install the content view after TopLevelWindow's JS code is initialized. + // Install the content view after BaseWindow's JS code is initialized. SetContentView(gin::CreateHandle(isolate, web_contents_view.get())); #if defined(OS_MACOSX) @@ -106,7 +106,7 @@ BrowserWindow::~BrowserWindow() { if (api_web_contents_) api_web_contents_->RemoveObserver(this); // Note that the OnWindowClosed will not be called after the destructor runs, - // since the window object is managed by the TopLevelWindow class. + // since the window object is managed by the BaseWindow class. if (web_contents()) Cleanup(); } @@ -277,9 +277,9 @@ void BrowserWindow::OnCloseButtonClicked(bool* prevent_default) { void BrowserWindow::OnWindowClosed() { Cleanup(); - // See TopLevelWindow::OnWindowClosed on why calling InvalidateWeakPtrs. + // See BaseWindow::OnWindowClosed on why calling InvalidateWeakPtrs. weak_factory_.InvalidateWeakPtrs(); - TopLevelWindow::OnWindowClosed(); + BaseWindow::OnWindowClosed(); } void BrowserWindow::OnWindowBlur() { @@ -290,7 +290,7 @@ void BrowserWindow::OnWindowBlur() { rwhv->SetActive(false); #endif - TopLevelWindow::OnWindowBlur(); + BaseWindow::OnWindowBlur(); } void BrowserWindow::OnWindowFocus() { @@ -304,7 +304,7 @@ void BrowserWindow::OnWindowFocus() { web_contents()->Focus(); #endif - TopLevelWindow::OnWindowFocus(); + BaseWindow::OnWindowFocus(); } void BrowserWindow::OnWindowResize() { @@ -312,11 +312,11 @@ void BrowserWindow::OnWindowResize() { if (!draggable_regions_.empty()) UpdateDraggableRegions(draggable_regions_); #endif - TopLevelWindow::OnWindowResize(); + BaseWindow::OnWindowResize(); } void BrowserWindow::OnWindowLeaveFullScreen() { - TopLevelWindow::OnWindowLeaveFullScreen(); + BaseWindow::OnWindowLeaveFullScreen(); #if defined(OS_MACOSX) if (web_contents()->IsFullscreenForCurrentTab()) web_contents()->ExitFullscreen(true); @@ -327,18 +327,18 @@ void BrowserWindow::Focus() { if (api_web_contents_->IsOffScreen()) FocusOnWebView(); else - TopLevelWindow::Focus(); + BaseWindow::Focus(); } void BrowserWindow::Blur() { if (api_web_contents_->IsOffScreen()) BlurWebView(); else - TopLevelWindow::Blur(); + BaseWindow::Blur(); } void BrowserWindow::SetBackgroundColor(const std::string& color_name) { - TopLevelWindow::SetBackgroundColor(color_name); + BaseWindow::SetBackgroundColor(color_name); auto* view = web_contents()->GetRenderWidgetHostView(); if (view) view->SetBackgroundColor(ParseHexColor(color_name)); @@ -355,29 +355,29 @@ void BrowserWindow::SetBackgroundColor(const std::string& color_name) { } void BrowserWindow::SetBrowserView(v8::Local value) { - TopLevelWindow::ResetBrowserViews(); - TopLevelWindow::AddBrowserView(value); + BaseWindow::ResetBrowserViews(); + BaseWindow::AddBrowserView(value); #if defined(OS_MACOSX) UpdateDraggableRegions(draggable_regions_); #endif } void BrowserWindow::AddBrowserView(v8::Local value) { - TopLevelWindow::AddBrowserView(value); + BaseWindow::AddBrowserView(value); #if defined(OS_MACOSX) UpdateDraggableRegions(draggable_regions_); #endif } void BrowserWindow::RemoveBrowserView(v8::Local value) { - TopLevelWindow::RemoveBrowserView(value); + BaseWindow::RemoveBrowserView(value); #if defined(OS_MACOSX) UpdateDraggableRegions(draggable_regions_); #endif } void BrowserWindow::ResetBrowserViews() { - TopLevelWindow::ResetBrowserViews(); + BaseWindow::ResetBrowserViews(); #if defined(OS_MACOSX) UpdateDraggableRegions(draggable_regions_); #endif @@ -397,7 +397,7 @@ void BrowserWindow::SetVibrancy(v8::Isolate* isolate, type.empty() ? !window_->transparent() : false); } - TopLevelWindow::SetVibrancy(isolate, value); + BaseWindow::SetVibrancy(isolate, value); } void BrowserWindow::FocusOnWebView() { @@ -464,12 +464,12 @@ void BrowserWindow::Cleanup() { void BrowserWindow::OnWindowShow() { web_contents()->WasShown(); - TopLevelWindow::OnWindowShow(); + BaseWindow::OnWindowShow(); } void BrowserWindow::OnWindowHide() { web_contents()->WasOccluded(); - TopLevelWindow::OnWindowHide(); + BaseWindow::OnWindowHide(); } // static @@ -520,8 +520,8 @@ v8::Local BrowserWindow::From(v8::Isolate* isolate, namespace { +using electron::api::BaseWindow; using electron::api::BrowserWindow; -using electron::api::TopLevelWindow; void Initialize(v8::Local exports, v8::Local unused, diff --git a/shell/browser/api/electron_api_browser_window.h b/shell/browser/api/electron_api_browser_window.h index a3c225fe6fa3..acef1b279029 100644 --- a/shell/browser/api/electron_api_browser_window.h +++ b/shell/browser/api/electron_api_browser_window.h @@ -10,7 +10,7 @@ #include #include "base/cancelable_callback.h" -#include "shell/browser/api/electron_api_top_level_window.h" +#include "shell/browser/api/electron_api_base_window.h" #include "shell/browser/api/electron_api_web_contents.h" #include "shell/common/gin_helper/error_thrower.h" @@ -18,7 +18,7 @@ namespace electron { namespace api { -class BrowserWindow : public TopLevelWindow, +class BrowserWindow : public BaseWindow, public content::RenderWidgetHost::InputEventObserver, public content::WebContentsObserver, public ExtendedWebContentsObserver { @@ -67,7 +67,7 @@ class BrowserWindow : public TopLevelWindow, void RequestPreferredWidth(int* width) override; void OnCloseButtonClicked(bool* prevent_default) override; - // TopLevelWindow: + // BaseWindow: void OnWindowClosed() override; void OnWindowBlur() override; void OnWindowFocus() override; diff --git a/shell/browser/api/electron_api_menu.h b/shell/browser/api/electron_api_menu.h index 110d06dd965e..04f54153cc48 100644 --- a/shell/browser/api/electron_api_menu.h +++ b/shell/browser/api/electron_api_menu.h @@ -10,7 +10,7 @@ #include "base/callback.h" #include "gin/arguments.h" -#include "shell/browser/api/electron_api_top_level_window.h" +#include "shell/browser/api/electron_api_base_window.h" #include "shell/browser/event_emitter_mixin.h" #include "shell/browser/ui/electron_menu_model.h" #include "shell/common/gin_helper/constructible.h" @@ -67,7 +67,7 @@ class Menu : public gin::Wrappable, void ExecuteCommand(int command_id, int event_flags) override; void OnMenuWillShow(ui::SimpleMenuModel* source) override; - virtual void PopupAt(TopLevelWindow* window, + virtual void PopupAt(BaseWindow* window, int x, int y, int positioning_item, diff --git a/shell/browser/api/electron_api_menu_mac.h b/shell/browser/api/electron_api_menu_mac.h index 3b3c066c5621..e09eba500695 100644 --- a/shell/browser/api/electron_api_menu_mac.h +++ b/shell/browser/api/electron_api_menu_mac.h @@ -23,7 +23,7 @@ class MenuMac : public Menu { explicit MenuMac(gin::Arguments* args); ~MenuMac() override; - void PopupAt(TopLevelWindow* window, + void PopupAt(BaseWindow* window, int x, int y, int positioning_item, diff --git a/shell/browser/api/electron_api_menu_mac.mm b/shell/browser/api/electron_api_menu_mac.mm index ecb0694c6a79..f96f9301a0d8 100644 --- a/shell/browser/api/electron_api_menu_mac.mm +++ b/shell/browser/api/electron_api_menu_mac.mm @@ -34,7 +34,7 @@ MenuMac::MenuMac(gin::Arguments* args) : Menu(args), weak_factory_(this) {} MenuMac::~MenuMac() = default; -void MenuMac::PopupAt(TopLevelWindow* window, +void MenuMac::PopupAt(BaseWindow* window, int x, int y, int positioning_item, diff --git a/shell/browser/api/electron_api_menu_views.cc b/shell/browser/api/electron_api_menu_views.cc index 4ff65ce94778..37da0bb5482b 100644 --- a/shell/browser/api/electron_api_menu_views.cc +++ b/shell/browser/api/electron_api_menu_views.cc @@ -21,7 +21,7 @@ MenuViews::MenuViews(gin::Arguments* args) : Menu(args), weak_factory_(this) {} MenuViews::~MenuViews() = default; -void MenuViews::PopupAt(TopLevelWindow* window, +void MenuViews::PopupAt(BaseWindow* window, int x, int y, int positioning_item, diff --git a/shell/browser/api/electron_api_menu_views.h b/shell/browser/api/electron_api_menu_views.h index d7aeb3c9c466..d323bdca9209 100644 --- a/shell/browser/api/electron_api_menu_views.h +++ b/shell/browser/api/electron_api_menu_views.h @@ -23,7 +23,7 @@ class MenuViews : public Menu { ~MenuViews() override; protected: - void PopupAt(TopLevelWindow* window, + void PopupAt(BaseWindow* window, int x, int y, int positioning_item, diff --git a/shell/common/gin_converters/native_window_converter.h b/shell/common/gin_converters/native_window_converter.h index 1b9022cbf397..d2ad9e0c44f6 100644 --- a/shell/common/gin_converters/native_window_converter.h +++ b/shell/common/gin_converters/native_window_converter.h @@ -6,7 +6,7 @@ #define SHELL_COMMON_GIN_CONVERTERS_NATIVE_WINDOW_CONVERTER_H_ #include "gin/converter.h" -#include "shell/browser/api/electron_api_top_level_window.h" +#include "shell/browser/api/electron_api_base_window.h" namespace gin { @@ -21,9 +21,9 @@ struct Converter { return true; } - electron::api::TopLevelWindow* window; - if (!gin::Converter::FromV8(isolate, val, - &window)) + electron::api::BaseWindow* window; + if (!gin::Converter::FromV8(isolate, val, + &window)) return false; *out = window->window(); return true; diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 0646ffca9553..2f4c29f4405f 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -52,7 +52,7 @@ V(electron_browser_protocol) \ V(electron_browser_session) \ V(electron_browser_system_preferences) \ - V(electron_browser_top_level_window) \ + V(electron_browser_base_window) \ V(electron_browser_tray) \ V(electron_browser_view) \ V(electron_browser_web_contents) \ diff --git a/spec-main/api-view-spec.ts b/spec-main/api-view-spec.ts index e29abbe48e41..5d23eea23bd3 100644 --- a/spec-main/api-view-spec.ts +++ b/spec-main/api-view-spec.ts @@ -1,15 +1,15 @@ import { closeWindow } from './window-helpers'; -import { TopLevelWindow, View } from 'electron/main'; +import { BaseWindow, View } from 'electron/main'; describe('View', () => { - let w: TopLevelWindow; + let w: BaseWindow; afterEach(async () => { await closeWindow(w as any); - w = null as unknown as TopLevelWindow; + w = null as unknown as BaseWindow; }); it('can be used as content view', () => { - w = new TopLevelWindow({ show: false }); + w = new BaseWindow({ show: false }); w.setContentView(new View()); }); }); diff --git a/spec-main/api-web-contents-view-spec.ts b/spec-main/api-web-contents-view-spec.ts index 6dcaca283a14..4388dc2678be 100644 --- a/spec-main/api-web-contents-view-spec.ts +++ b/spec-main/api-web-contents-view-spec.ts @@ -4,14 +4,14 @@ import * as path from 'path'; import { emittedOnce } from './events-helpers'; import { closeWindow } from './window-helpers'; -import { TopLevelWindow, WebContentsView } from 'electron/main'; +import { BaseWindow, WebContentsView } from 'electron/main'; describe('WebContentsView', () => { - let w: TopLevelWindow; - afterEach(() => closeWindow(w as any).then(() => { w = null as unknown as TopLevelWindow; })); + let w: BaseWindow; + afterEach(() => closeWindow(w as any).then(() => { w = null as unknown as BaseWindow; })); it('can be used as content view', () => { - w = new TopLevelWindow({ show: false }); + w = new BaseWindow({ show: false }); w.setContentView(new WebContentsView({})); }); diff --git a/typings/internal-electron.d.ts b/typings/internal-electron.d.ts index 35d24f360fd6..9557d03d60bd 100644 --- a/typings/internal-electron.d.ts +++ b/typings/internal-electron.d.ts @@ -99,13 +99,13 @@ declare namespace Electron { class View {} // Experimental views API - class TopLevelWindow { + class BaseWindow { constructor(args: {show: boolean}) setContentView(view: View): void - static fromId(id: number): TopLevelWindow; - static getAllWindows(): TopLevelWindow[]; + static fromId(id: number): BaseWindow; + static getAllWindows(): BaseWindow[]; isFocused(): boolean; - static getFocusedWindow(): TopLevelWindow | undefined; + static getFocusedWindow(): BaseWindow | undefined; } class WebContentsView { constructor(options: BrowserWindowConstructorOptions) @@ -128,7 +128,7 @@ declare namespace Electron { } namespace Main { - class TopLevelWindow extends Electron.TopLevelWindow {} + class BaseWindow extends Electron.BaseWindow {} class View extends Electron.View {} class WebContentsView extends Electron.WebContentsView {} }