diff --git a/atom/browser/api/atom_api_browser_window.cc b/atom/browser/api/atom_api_browser_window.cc index 33695d5ef293..3607db755157 100644 --- a/atom/browser/api/atom_api_browser_window.cc +++ b/atom/browser/api/atom_api_browser_window.cc @@ -154,7 +154,6 @@ void BrowserWindow::Init(v8::Isolate* isolate, options, parent.IsEmpty() ? nullptr : parent->window_.get())); web_contents->SetOwnerWindow(window_.get()); - window_->set_is_offscreen_dummy(api_web_contents_->IsOffScreen()); // Tell the content module to initialize renderer widget with transparent // mode. diff --git a/atom/browser/atom_download_manager_delegate.cc b/atom/browser/atom_download_manager_delegate.cc index 6df090f9cf26..21ceaad5942a 100644 --- a/atom/browser/atom_download_manager_delegate.cc +++ b/atom/browser/atom_download_manager_delegate.cc @@ -10,6 +10,7 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/native_window.h" #include "atom/browser/ui/file_dialog.h" +#include "atom/browser/web_contents_preferences.h" #include "base/bind.h" #include "base/files/file_util.h" #include "chrome/common/pref_names.h" @@ -89,12 +90,15 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated( if (relay) window = relay->window.get(); + auto* web_preferences = WebContentsPreferences::From(web_contents); + bool offscreen = !web_preferences || web_preferences->IsEnabled("offscreen"); + base::FilePath path; GetItemSavePath(item, &path); // Show save dialog if save path was not set already on item file_dialog::DialogSettings settings; settings.parent_window = window; - settings.force_detached = window->is_offscreen_dummy(); + settings.force_detached = offscreen; settings.title = item->GetURL().spec(); settings.default_path = default_path; if (path.empty() && file_dialog::ShowSaveDialog(settings, &path)) { diff --git a/atom/browser/atom_javascript_dialog_manager.cc b/atom/browser/atom_javascript_dialog_manager.cc index 16eab2989dbf..70e2b43200e3 100644 --- a/atom/browser/atom_javascript_dialog_manager.cc +++ b/atom/browser/atom_javascript_dialog_manager.cc @@ -55,19 +55,25 @@ void AtomJavaScriptDialogManager::RunJavaScriptDialog( origin_counts_[origin]++; + auto* web_preferences = WebContentsPreferences::From(web_contents); std::string checkbox; - if (origin_counts_[origin] > 1) { - auto* web_preferences = WebContentsPreferences::From(web_contents); - if (web_preferences && - web_preferences->IsEnabled("safeDialogs") && - !web_preferences->dict()->GetString("safeDialogsMessage", &checkbox)) { - checkbox = "Prevent this app from creating additional dialogs"; - } + if (origin_counts_[origin] > 1 && + web_preferences && + web_preferences->IsEnabled("safeDialogs") && + !web_preferences->dict()->GetString("safeDialogsMessage", &checkbox)) { + checkbox = "Prevent this app from creating additional dialogs"; + } + + // Don't set parent for offscreen window. + NativeWindow* window = nullptr; + if (web_preferences && !web_preferences->IsEnabled("offscreen")) { + auto* relay = NativeWindowRelay::FromWebContents(web_contents); + if (relay) + window = relay->window.get(); } - auto* relay = NativeWindowRelay::FromWebContents(web_contents); atom::ShowMessageBox( - relay ? relay->window.get() : nullptr, + window, atom::MessageBoxType::MESSAGE_BOX_TYPE_NONE, buttons, -1, 0, atom::MessageBoxOptions::MESSAGE_BOX_NONE, "", base::UTF16ToUTF8(message_text), "", checkbox, diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 98a90efd6e57..9f5724c3d64d 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -11,6 +11,7 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/native_window.h" #include "atom/browser/ui/file_dialog.h" +#include "atom/browser/web_contents_preferences.h" #include "atom/browser/web_dialog_helper.h" #include "atom/common/atom_constants.h" #include "base/files/file_util.h" @@ -150,7 +151,8 @@ bool IsDevToolsFileSystemAdded( } // namespace CommonWebContentsDelegate::CommonWebContentsDelegate() - : ignore_menu_shortcuts_(false), + : offscreen_(false), + ignore_menu_shortcuts_(false), html_fullscreen_(false), native_fullscreen_(false), devtools_file_system_indexer_(new DevToolsFileSystemIndexer) { @@ -168,6 +170,10 @@ void CommonWebContentsDelegate::InitWithWebContents( printing::PrintViewManagerBasic::CreateForWebContents(web_contents); printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents); + // Determien whether the WebContents is offscreen. + auto* web_preferences = WebContentsPreferences::From(web_contents); + offscreen_ = !web_preferences || web_preferences->IsEnabled("offscreen"); + // Create InspectableWebContents. web_contents_.reset(brightray::InspectableWebContents::Create(web_contents)); web_contents_->SetDelegate(this); @@ -243,8 +249,7 @@ void CommonWebContentsDelegate::RunFileChooser( content::RenderFrameHost* render_frame_host, const content::FileChooserParams& params) { if (!web_dialog_helper_) - web_dialog_helper_.reset(new WebDialogHelper( - owner_window(), owner_window()->is_offscreen_dummy())); + web_dialog_helper_.reset(new WebDialogHelper(owner_window(), offscreen_)); web_dialog_helper_->RunFileChooser(render_frame_host, params); } @@ -252,8 +257,7 @@ void CommonWebContentsDelegate::EnumerateDirectory(content::WebContents* guest, int request_id, const base::FilePath& path) { if (!web_dialog_helper_) - web_dialog_helper_.reset(new WebDialogHelper( - owner_window(), owner_window()->is_offscreen_dummy())); + web_dialog_helper_.reset(new WebDialogHelper(owner_window(), offscreen_)); web_dialog_helper_->EnumerateDirectory(guest, request_id, path); } @@ -301,7 +305,7 @@ void CommonWebContentsDelegate::DevToolsSaveToFile( } else { file_dialog::DialogSettings settings; settings.parent_window = owner_window(); - settings.force_detached = owner_window()->is_offscreen_dummy(); + settings.force_detached = offscreen_; settings.title = url; settings.default_path = base::FilePath::FromUTF8Unsafe(url); if (!file_dialog::ShowSaveDialog(settings, &path)) { @@ -368,7 +372,7 @@ void CommonWebContentsDelegate::DevToolsAddFileSystem( std::vector paths; file_dialog::DialogSettings settings; settings.parent_window = owner_window(); - settings.force_detached = owner_window()->is_offscreen_dummy(); + settings.force_detached = offscreen_; settings.properties = file_dialog::FILE_DIALOG_OPEN_DIRECTORY; if (!file_dialog::ShowOpenDialog(settings, &paths)) return; diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index a7a29db33cc3..54475213b43d 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -141,6 +141,7 @@ class CommonWebContentsDelegate // The window that this WebContents belongs to. base::WeakPtr owner_window_; + bool offscreen_; bool ignore_menu_shortcuts_; // Whether window is fullscreened by HTML5 api. diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index ee8ba1dc87da..1acf6dee4bd2 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -32,7 +32,6 @@ NativeWindow::NativeWindow( aspect_ratio_(0.0), parent_(parent), is_modal_(false), - is_osr_dummy_(false), browser_view_(nullptr), weak_factory_(this) { options.Get(options::kFrame, &has_frame_); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 219463ac1568..e0c94320d168 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -271,9 +271,6 @@ class NativeWindow : public base::SupportsUserData { bool transparent() const { return transparent_; } bool enable_larger_than_screen() const { return enable_larger_than_screen_; } - void set_is_offscreen_dummy(bool is_dummy) { is_osr_dummy_ = is_dummy; } - bool is_offscreen_dummy() const { return is_osr_dummy_; } - NativeBrowserView* browser_view() const { return browser_view_; } NativeWindow* parent() const { return parent_; } bool is_modal() const { return is_modal_; } @@ -319,9 +316,6 @@ class NativeWindow : public base::SupportsUserData { // Is this a modal window. bool is_modal_; - // Is this a dummy window for an offscreen WebContents. - bool is_osr_dummy_; - // The browser view layer. NativeBrowserView* browser_view_; diff --git a/atom/browser/ui/message_box_mac.mm b/atom/browser/ui/message_box_mac.mm index 17c66043a27f..5c3802464c6b 100644 --- a/atom/browser/ui/message_box_mac.mm +++ b/atom/browser/ui/message_box_mac.mm @@ -146,8 +146,7 @@ int ShowMessageBox(NativeWindow* parent_window, // Use runModal for synchronous alert without parent, since we don't have a // window to wait for. - if (!parent_window || !parent_window->GetNativeWindow() || - parent_window->is_offscreen_dummy()) + if (!parent_window) return [[alert autorelease] runModal]; int ret_code = -1; @@ -185,8 +184,7 @@ void ShowMessageBox(NativeWindow* parent_window, // Use runModal for synchronous alert without parent, since we don't have a // window to wait for. - if (!parent_window || !parent_window->GetNativeWindow() || - parent_window->is_offscreen_dummy()) { + if (!parent_window) { int ret = [[alert autorelease] runModal]; callback.Run(ret, alert.suppressionButton.state == NSOnState); } else {