diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 7de71cc7fce9..79787d26fee0 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -142,7 +142,7 @@ void AtomBrowserClient::RenderProcessWillLaunch( content::WebContents* web_contents = GetWebContentsFromProcessID(process_id); ProcessPreferences process_prefs; process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents); - process_prefs.native_window_open = WebContentsPreferences::IsNativeWindowOpenEnabled(web_contents); + process_prefs.native_window_open = WebContentsPreferences::UsesNativeWindowOpen(web_contents); AddProcessPreferences(host->GetID(), process_prefs); // ensure the ProcessPreferences is removed later host->AddObserver(this); diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 8346d664170d..550673347155 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -102,6 +102,8 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( // integration. if (IsSandboxed(web_contents)) command_line->AppendSwitch(switches::kEnableSandbox); + if (UsesNativeWindowOpen(web_contents)) + command_line->AppendSwitch(switches::kNativeWindowOpen); // The preload script. base::FilePath::StringType preload; @@ -208,7 +210,7 @@ bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) { return sandboxed; } -bool WebContentsPreferences::IsNativeWindowOpenEnabled(content::WebContents* web_contents) { +bool WebContentsPreferences::UsesNativeWindowOpen(content::WebContents* web_contents) { WebContentsPreferences* self; if (!web_contents) return false; diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 37a88dd552f3..f046cdfc99ac 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -38,7 +38,7 @@ class WebContentsPreferences content::WebContents* web_contents, base::CommandLine* command_line); static bool IsSandboxed(content::WebContents* web_contents); - static bool IsNativeWindowOpenEnabled(content::WebContents* web_contents); + static bool UsesNativeWindowOpen(content::WebContents* web_contents); // Modify the WebPreferences according to |web_contents|'s preferences. static void OverrideWebkitPrefs( diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 6db479ceb75c..b0099a42550e 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -163,6 +163,7 @@ const char kGuestInstanceID[] = "guest-instance-id"; const char kOpenerID[] = "opener-id"; const char kScrollBounce[] = "scroll-bounce"; const char kHiddenPage[] = "hidden-page"; +const char kNativeWindowOpen[] = "native-window-open"; // Widevine options // Path to Widevine CDM binaries. diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index abe3856cd870..8d0de3d372fb 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -89,6 +89,7 @@ extern const char kGuestInstanceID[]; extern const char kOpenerID[]; extern const char kScrollBounce[]; extern const char kHiddenPage[]; +extern const char kNativeWindowOpen[]; extern const char kWidevineCdmPath[]; extern const char kWidevineCdmVersion[]; diff --git a/lib/renderer/override.js b/lib/renderer/override.js index f31e9c0e8cdc..fdeb6605a5cc 100644 --- a/lib/renderer/override.js +++ b/lib/renderer/override.js @@ -4,5 +4,6 @@ const {ipcRenderer} = require('electron') const {guestInstanceId, openerId} = process const hiddenPage = process.argv.includes('--hidden-page') +const usesNativeWindowOpen = process.argv.includes('--native-window-open') -require('./window-setup')(ipcRenderer, guestInstanceId, openerId, hiddenPage) +require('./window-setup')(ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNativeWindowOpen) diff --git a/lib/renderer/window-setup.js b/lib/renderer/window-setup.js index 21f0741a22aa..510c46e3e0a6 100644 --- a/lib/renderer/window-setup.js +++ b/lib/renderer/window-setup.js @@ -99,7 +99,7 @@ const getHistoryOperation = function (ipcRenderer, ...args) { return ipcRenderer.sendSync('ELECTRON_SYNC_NAVIGATION_CONTROLLER', ...args) } -module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => { +module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNativeWindowOpen) => { if (guestInstanceId == null) { // Override default window.close. window.close = function () { @@ -107,16 +107,18 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => { } } - // Make the browser window or guest view emit "new-window" event. - window.open = function (url, frameName, features) { - if (url != null && url !== '') { - url = resolveURL(url) - } - const guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, features) - if (guestId != null) { - return getOrCreateProxy(ipcRenderer, guestId) - } else { - return null + if (!usesNativeWindowOpen) { + // Make the browser window or guest view emit "new-window" event. + window.open = function (url, frameName, features) { + if (url != null && url !== '') { + url = resolveURL(url) + } + const guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, features) + if (guestId != null) { + return getOrCreateProxy(ipcRenderer, guestId) + } else { + return null + } } }