diff --git a/atom/browser/lib/guest-window-manager.coffee b/atom/browser/lib/guest-window-manager.coffee index 1e9ee13c71d7..af73db5c78b8 100644 --- a/atom/browser/lib/guest-window-manager.coffee +++ b/atom/browser/lib/guest-window-manager.coffee @@ -30,12 +30,13 @@ createGuest = (embedder, url, frameName, options) -> guest.loadURL url return guest.id + # Remember the embedder window's id. + options.webPreferences ?= {} + options.webPreferences.openerId = BrowserWindow.fromWebContents(embedder)?.id + guest = new BrowserWindow(options) guest.loadURL url - # Remember the embedder, will be used by window.opener methods. - v8Util.setHiddenValue guest.webContents, 'embedder', embedder - # When |embedder| is destroyed we should also destroy attached guest, and if # guest is closed by user then we should prevent |embedder| from double # closing guest. @@ -83,10 +84,3 @@ ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', (event, guestId ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', (event, guestId, method, args...) -> BrowserWindow.fromId(guestId)?.webContents?[method] args... - -ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_OPENER_ID', (event) -> - embedder = v8Util.getHiddenValue event.sender, 'embedder' - openerId = null - if embedder? - openerId = BrowserWindow.fromWebContents(embedder)?.id - event.returnValue = openerId diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 3d86df96dd76..382c28951dba 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -132,6 +132,12 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( if (web_preferences.GetInteger(options::kGuestInstanceID, &guest_instance_id)) command_line->AppendSwitchASCII(switches::kGuestInstanceID, base::IntToString(guest_instance_id)); + + // Pass the opener's window id. + int opener_id; + if (web_preferences.GetInteger(options::kOpenerID, &opener_id)) + command_line->AppendSwitchASCII(switches::kOpenerID, + base::IntToString(opener_id)); } // static diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 0303cf54693e..fe279bbf0493 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -91,6 +91,9 @@ const char kPageVisibility[] = "pageVisibility"; // Enable DirectWrite on Windows. const char kDirectWrite[] = "directWrite"; +// Opener window's ID. +const char kOpenerID[] = "openerId"; + // Web runtime features. const char kExperimentalFeatures[] = "experimentalFeatures"; const char kExperimentalCanvasFeatures[] = "experimentalCanvasFeatures"; @@ -143,6 +146,7 @@ const char kExperimentalCanvasFeatures[] = "experimental-canvas-features"; const char kOverlayScrollbars[] = "overlay-scrollbars"; const char kSharedWorker[] = "shared-worker"; const char kPageVisibility[] = "page-visiblity"; +const char kOpenerID[] = "opener-id"; } // namespace switches diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index 36c2be143146..d85e789c7b4d 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -52,6 +52,7 @@ extern const char kExperimentalCanvasFeatures[]; extern const char kOverlayScrollbars[]; extern const char kSharedWorker[]; extern const char kPageVisibility[]; +extern const char kOpenerID[]; } // namespace options @@ -81,6 +82,7 @@ extern const char kExperimentalCanvasFeatures[]; extern const char kOverlayScrollbars[]; extern const char kSharedWorker[]; extern const char kPageVisibility[]; +extern const char kOpenerID[]; } // namespace switches diff --git a/atom/renderer/lib/init.coffee b/atom/renderer/lib/init.coffee index d9f104f8d4fc..b9028f2dd6a5 100644 --- a/atom/renderer/lib/init.coffee +++ b/atom/renderer/lib/init.coffee @@ -30,6 +30,9 @@ for arg in process.argv if arg.indexOf('--guest-instance-id=') == 0 # This is a guest web view. process.guestInstanceId = parseInt arg.substr(arg.indexOf('=') + 1) + else if arg.indexOf('--opener-id=') == 0 + # This is a guest BrowserWindow. + process.openerId = parseInt arg.substr(arg.indexOf('=') + 1) else if arg.indexOf('--node-integration=') == 0 nodeIntegration = arg.substr arg.indexOf('=') + 1 else if arg.indexOf('--preload=') == 0 diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index ba15c7b3f61a..7279b232a99d 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -91,8 +91,8 @@ window.confirm = (message, title='') -> window.prompt = -> throw new Error('prompt() is and will not be supported.') -openerId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_OPENER_ID' -window.opener = BrowserWindowProxy.getOrCreate(openerId) if openerId? +if process.openerId? + window.opener = BrowserWindowProxy.getOrCreate process.openerId ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, sourceId, message, sourceOrigin) -> # Manually dispatch event instead of using postMessage because we also need to