From 702f1631a3d4eb2a2e68c965facba0d59291b78b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 6 Mar 2018 15:18:45 +0900 Subject: [PATCH] Remove NativeWindow::FromWebContents --- atom/browser/atom_javascript_dialog_manager.cc | 4 +++- atom/browser/native_window.cc | 10 ---------- atom/browser/native_window.h | 3 --- atom/browser/web_contents_preferences.cc | 13 ++++++++----- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/atom/browser/atom_javascript_dialog_manager.cc b/atom/browser/atom_javascript_dialog_manager.cc index 1f0536b4c2..4168be3536 100644 --- a/atom/browser/atom_javascript_dialog_manager.cc +++ b/atom/browser/atom_javascript_dialog_manager.cc @@ -64,8 +64,10 @@ void AtomJavaScriptDialogManager::RunJavaScriptDialog( checkbox_string = "Prevent this app from creating additional dialogs"; } } + + auto* relay = NativeWindowRelay::FromWebContents(web_contents); atom::ShowMessageBox( - NativeWindow::FromWebContents(web_contents), + relay ? relay->window.get() : nullptr, atom::MessageBoxType::MESSAGE_BOX_TYPE_NONE, buttons, -1, 0, atom::MessageBoxOptions::MESSAGE_BOX_NONE, "", base::UTF16ToUTF8(message_text), "", checkbox_string, diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index c4bc75c6db..0514917166 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -76,16 +76,6 @@ NativeWindow::~NativeWindow() { NotifyWindowClosed(); } -// static -NativeWindow* NativeWindow::FromWebContents( - content::WebContents* web_contents) { - for (const auto& window : WindowList::GetWindows()) { - if (window->web_contents() == web_contents) - return window; - } - return nullptr; -} - void NativeWindow::InitFromOptions(const mate::Dictionary& options) { // Setup window from options. int x = -1, y = -1; diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 491bc51d0a..c0a65ef675 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -64,9 +64,6 @@ class NativeWindow : public base::SupportsUserData, const mate::Dictionary& options, NativeWindow* parent = nullptr); - // Find a window from its WebContents - static NativeWindow* FromWebContents(content::WebContents* web_contents); - void InitFromOptions(const mate::Dictionary& options); virtual void Close() = 0; diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 7951c36b45..4165087421 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -209,11 +209,14 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( if (manager) { auto embedder = manager->GetEmbedder(guest_instance_id); if (embedder) { - auto window = NativeWindow::FromWebContents(embedder); - if (window) { - const bool visible = window->IsVisible() && !window->IsMinimized(); - if (!visible) { - command_line->AppendSwitch(switches::kHiddenPage); + auto* relay = NativeWindowRelay::FromWebContents(web_contents); + if (relay) { + auto* window = relay->window.get(); + if (window) { + const bool visible = window->IsVisible() && !window->IsMinimized(); + if (!visible) { + command_line->AppendSwitch(switches::kHiddenPage); + } } } }