Pass opener ID in command line
This commit is contained in:
parent
c7bfd5f09d
commit
0282d424bf
6 changed files with 21 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue