Browse Source

refactor: rename TopLevelWindow to BaseWindow (#24305)

Cheng Zhao 4 years ago
parent
commit
ef3579eae3

+ 1 - 1
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",

+ 2 - 2
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",

+ 23 - 23
lib/browser/api/top-level-window.ts → 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;

+ 5 - 5
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 = () => {

+ 7 - 7
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));
   }
 };

+ 1 - 1
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') },

+ 1 - 1
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',

File diff suppressed because it is too large
+ 180 - 190
shell/browser/api/electron_api_base_window.cc


+ 13 - 15
shell/browser/api/electron_api_top_level_window.h → 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 <map>
 #include <memory>
@@ -25,27 +25,25 @@ namespace api {
 
 class View;
 
-class TopLevelWindow : public gin_helper::TrackableObject<TopLevelWindow>,
-                       public NativeWindowObserver {
+class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
+                   public NativeWindowObserver {
  public:
   static gin_helper::WrappableBase* New(gin_helper::Arguments* args);
 
   static void BuildPrototype(v8::Isolate* isolate,
                              v8::Local<v8::FunctionTemplate> prototype);
 
-  base::WeakPtr<TopLevelWindow> GetWeakPtr() {
-    return weak_factory_.GetWeakPtr();
-  }
+  base::WeakPtr<BaseWindow> 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<v8::Object> wrapper) override;
@@ -247,7 +245,7 @@ class TopLevelWindow : public gin_helper::TrackableObject<TopLevelWindow>,
   void EmitEventSoon(base::StringPiece eventName) {
     base::PostTask(
         FROM_HERE, {content::BrowserThread::UI},
-        base::BindOnce(base::IgnoreResult(&TopLevelWindow::Emit<Args...>),
+        base::BindOnce(base::IgnoreResult(&BaseWindow::Emit<Args...>),
                        weak_factory_.GetWeakPtr(), eventName));
   }
 
@@ -267,11 +265,11 @@ class TopLevelWindow : public gin_helper::TrackableObject<TopLevelWindow>,
   // Reference to JS wrapper to prevent garbage collection.
   v8::Global<v8::Value> self_ref_;
 
-  base::WeakPtrFactory<TopLevelWindow> weak_factory_;
+  base::WeakPtrFactory<BaseWindow> 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_

+ 21 - 21
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<View>(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<v8::Value> value) {
-  TopLevelWindow::ResetBrowserViews();
-  TopLevelWindow::AddBrowserView(value);
+  BaseWindow::ResetBrowserViews();
+  BaseWindow::AddBrowserView(value);
 #if defined(OS_MACOSX)
   UpdateDraggableRegions(draggable_regions_);
 #endif
 }
 
 void BrowserWindow::AddBrowserView(v8::Local<v8::Value> value) {
-  TopLevelWindow::AddBrowserView(value);
+  BaseWindow::AddBrowserView(value);
 #if defined(OS_MACOSX)
   UpdateDraggableRegions(draggable_regions_);
 #endif
 }
 
 void BrowserWindow::RemoveBrowserView(v8::Local<v8::Value> 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<v8::Value> BrowserWindow::From(v8::Isolate* isolate,
 
 namespace {
 
+using electron::api::BaseWindow;
 using electron::api::BrowserWindow;
-using electron::api::TopLevelWindow;
 
 void Initialize(v8::Local<v8::Object> exports,
                 v8::Local<v8::Value> unused,

+ 3 - 3
shell/browser/api/electron_api_browser_window.h

@@ -10,7 +10,7 @@
 #include <vector>
 
 #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;

+ 2 - 2
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<Menu>,
   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,

+ 1 - 1
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,

+ 1 - 1
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,

+ 1 - 1
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,

+ 1 - 1
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,

+ 4 - 4
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<electron::NativeWindow*> {
       return true;
     }
 
-    electron::api::TopLevelWindow* window;
-    if (!gin::Converter<electron::api::TopLevelWindow*>::FromV8(isolate, val,
-                                                                &window))
+    electron::api::BaseWindow* window;
+    if (!gin::Converter<electron::api::BaseWindow*>::FromV8(isolate, val,
+                                                            &window))
       return false;
     *out = window->window();
     return true;

+ 1 - 1
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)       \

+ 4 - 4
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());
   });
 });

+ 4 - 4
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({}));
   });
 

+ 5 - 5
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 {}
   }

Some files were not shown because too many files changed in this diff