diff --git a/atom/browser/api/atom_api_browser_window.cc b/atom/browser/api/atom_api_browser_window.cc index 6a6e4f02c4..def0640862 100644 --- a/atom/browser/api/atom_api_browser_window.cc +++ b/atom/browser/api/atom_api_browser_window.cc @@ -1082,8 +1082,11 @@ void BrowserWindow::ToggleTabBar() { window_->ToggleTabBar(); } -void BrowserWindow::AddTabbedWindow(NativeWindow* window) { - window_->AddTabbedWindow(window); +void BrowserWindow::AddTabbedWindow(NativeWindow* window, + mate::Arguments* args) { + const bool windowAdded = window_->AddTabbedWindow(window); + if (!windowAdded) + args->ThrowError("AddTabbedWindow cannot be called by a window on itself."); } void BrowserWindow::SetVibrancy(mate::Arguments* args) { diff --git a/atom/browser/api/atom_api_browser_window.h b/atom/browser/api/atom_api_browser_window.h index 65f3a10f7a..768d975e46 100644 --- a/atom/browser/api/atom_api_browser_window.h +++ b/atom/browser/api/atom_api_browser_window.h @@ -243,7 +243,7 @@ class BrowserWindow : public mate::TrackableObject, void MergeAllWindows(); void MoveTabToNewWindow(); void ToggleTabBar(); - void AddTabbedWindow(NativeWindow* window); + void AddTabbedWindow(NativeWindow* window, mate::Arguments* args); void SetVibrancy(mate::Arguments* args); void SetTouchBar(const std::vector& items); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index a96b65424a..1222151248 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -336,7 +336,8 @@ void NativeWindow::MoveTabToNewWindow() { void NativeWindow::ToggleTabBar() { } -void NativeWindow::AddTabbedWindow(NativeWindow* window) { +bool NativeWindow::AddTabbedWindow(NativeWindow* window) { + return true; // for non-Mac platforms } void NativeWindow::SetVibrancy(const std::string& filename) { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 5661f6237d..7f12f5a23b 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -192,7 +192,7 @@ class NativeWindow : public base::SupportsUserData, virtual void MergeAllWindows(); virtual void MoveTabToNewWindow(); virtual void ToggleTabBar(); - virtual void AddTabbedWindow(NativeWindow* window); + virtual bool AddTabbedWindow(NativeWindow* window); // Webview APIs. virtual void FocusOnWebView(); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index a54e24b466..2d856aa9a9 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -109,7 +109,7 @@ class NativeWindowMac : public NativeWindow { void MergeAllWindows() override; void MoveTabToNewWindow() override; void ToggleTabBar() override; - void AddTabbedWindow(NativeWindow* window) override; + bool AddTabbedWindow(NativeWindow* window) override; void SetVibrancy(const std::string& type) override; void SetTouchBar( diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 72dd45728f..f4ceaafd12 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1671,10 +1671,14 @@ void NativeWindowMac::ToggleTabBar() { } } -void NativeWindowMac::AddTabbedWindow(NativeWindow* window) { - if ([window_ respondsToSelector:@selector(addTabbedWindow:ordered:)]) { - [window_ addTabbedWindow:window->GetNativeWindow() ordered:NSWindowAbove]; +bool NativeWindowMac::AddTabbedWindow(NativeWindow* window) { + if (window_.get() == window->GetNativeWindow()) { + return false; + } else { + if ([window_ respondsToSelector:@selector(addTabbedWindow:ordered:)]) + [window_ addTabbedWindow:window->GetNativeWindow() ordered:NSWindowAbove]; } + return true; } void NativeWindowMac::SetRenderWidgetHostOpaque(bool opaque) { diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 3033eb6a1f..9afccc7966 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -733,6 +733,12 @@ describe('BrowserWindow module', () => { done() }) }) + + it('throws when called on itself', () => { + assert.throws(() => { + w.addTabbedWindow(w) + }, /AddTabbedWindow cannot be called by a window on itself./) + }) }) describe('BrowserWindow.setVibrancy(type)', () => {