Pass opener ID in command line

This commit is contained in:
Cheng Zhao 2015-12-17 21:27:14 +08:00
parent c7bfd5f09d
commit 0282d424bf
6 changed files with 21 additions and 12 deletions

View file

@ -30,12 +30,13 @@ createGuest = (embedder, url, frameName, options) ->
guest.loadURL url guest.loadURL url
return guest.id return guest.id
# Remember the embedder window's id.
options.webPreferences ?= {}
options.webPreferences.openerId = BrowserWindow.fromWebContents(embedder)?.id
guest = new BrowserWindow(options) guest = new BrowserWindow(options)
guest.loadURL url 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 # When |embedder| is destroyed we should also destroy attached guest, and if
# guest is closed by user then we should prevent |embedder| from double # guest is closed by user then we should prevent |embedder| from double
# closing guest. # 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...) -> ipcMain.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', (event, guestId, method, args...) ->
BrowserWindow.fromId(guestId)?.webContents?[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

View file

@ -132,6 +132,12 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
if (web_preferences.GetInteger(options::kGuestInstanceID, &guest_instance_id)) if (web_preferences.GetInteger(options::kGuestInstanceID, &guest_instance_id))
command_line->AppendSwitchASCII(switches::kGuestInstanceID, command_line->AppendSwitchASCII(switches::kGuestInstanceID,
base::IntToString(guest_instance_id)); 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 // static

View file

@ -91,6 +91,9 @@ const char kPageVisibility[] = "pageVisibility";
// Enable DirectWrite on Windows. // Enable DirectWrite on Windows.
const char kDirectWrite[] = "directWrite"; const char kDirectWrite[] = "directWrite";
// Opener window's ID.
const char kOpenerID[] = "openerId";
// Web runtime features. // Web runtime features.
const char kExperimentalFeatures[] = "experimentalFeatures"; const char kExperimentalFeatures[] = "experimentalFeatures";
const char kExperimentalCanvasFeatures[] = "experimentalCanvasFeatures"; const char kExperimentalCanvasFeatures[] = "experimentalCanvasFeatures";
@ -143,6 +146,7 @@ const char kExperimentalCanvasFeatures[] = "experimental-canvas-features";
const char kOverlayScrollbars[] = "overlay-scrollbars"; const char kOverlayScrollbars[] = "overlay-scrollbars";
const char kSharedWorker[] = "shared-worker"; const char kSharedWorker[] = "shared-worker";
const char kPageVisibility[] = "page-visiblity"; const char kPageVisibility[] = "page-visiblity";
const char kOpenerID[] = "opener-id";
} // namespace switches } // namespace switches

View file

@ -52,6 +52,7 @@ extern const char kExperimentalCanvasFeatures[];
extern const char kOverlayScrollbars[]; extern const char kOverlayScrollbars[];
extern const char kSharedWorker[]; extern const char kSharedWorker[];
extern const char kPageVisibility[]; extern const char kPageVisibility[];
extern const char kOpenerID[];
} // namespace options } // namespace options
@ -81,6 +82,7 @@ extern const char kExperimentalCanvasFeatures[];
extern const char kOverlayScrollbars[]; extern const char kOverlayScrollbars[];
extern const char kSharedWorker[]; extern const char kSharedWorker[];
extern const char kPageVisibility[]; extern const char kPageVisibility[];
extern const char kOpenerID[];
} // namespace switches } // namespace switches

View file

@ -30,6 +30,9 @@ for arg in process.argv
if arg.indexOf('--guest-instance-id=') == 0 if arg.indexOf('--guest-instance-id=') == 0
# This is a guest web view. # This is a guest web view.
process.guestInstanceId = parseInt arg.substr(arg.indexOf('=') + 1) 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 else if arg.indexOf('--node-integration=') == 0
nodeIntegration = arg.substr arg.indexOf('=') + 1 nodeIntegration = arg.substr arg.indexOf('=') + 1
else if arg.indexOf('--preload=') == 0 else if arg.indexOf('--preload=') == 0

View file

@ -91,8 +91,8 @@ window.confirm = (message, title='') ->
window.prompt = -> window.prompt = ->
throw new Error('prompt() is and will not be supported.') throw new Error('prompt() is and will not be supported.')
openerId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_OPENER_ID' if process.openerId?
window.opener = BrowserWindowProxy.getOrCreate(openerId) if openerId? window.opener = BrowserWindowProxy.getOrCreate process.openerId
ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, sourceId, message, sourceOrigin) -> ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, sourceId, message, sourceOrigin) ->
# Manually dispatch event instead of using postMessage because we also need to # Manually dispatch event instead of using postMessage because we also need to