Make remote.getCurrentWindow() work in <webview>

This commit is contained in:
Cheng Zhao 2014-10-26 19:30:53 +08:00
parent 10a8f3c884
commit 404e08c0e7
11 changed files with 66 additions and 48 deletions

View file

@ -1,4 +1,5 @@
EventEmitter = require('events').EventEmitter
process = global.process
ipc = process.atomBinding('ipc')
class Ipc extends EventEmitter

View file

@ -1,6 +1,7 @@
process = global.process
ipc = require 'ipc'
CallbacksRegistry = require 'callbacks-registry'
v8Util = process.atomBinding 'v8_util'
CallbacksRegistry = require 'callbacks-registry'
callbacksRegistry = new CallbacksRegistry
@ -110,7 +111,7 @@ exports.require = (module) ->
windowCache = null
exports.getCurrentWindow = ->
return windowCache if windowCache?
meta = ipc.sendChannelSync 'ATOM_BROWSER_CURRENT_WINDOW'
meta = ipc.sendChannelSync 'ATOM_BROWSER_CURRENT_WINDOW', process.guestInstanceId
windowCache = metaToValue meta
# Get a global object in browser.

View file

@ -21,17 +21,14 @@ globalPaths.push path.join(process.resourcesPath, 'app')
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init.js')
# Process command line arguments.
isGuest = false
nodeIntegration = 'false'
for arg in process.argv
if arg is '--guest'
if arg.indexOf('--guest-instance-id=') == 0
# This is a guest web view.
isGuest = true
process.guestInstanceId = parseInt arg.substr(arg.indexOf('=') + 1)
# Set the frame name to make AtomRendererClient recognize this guest.
require('web-frame').setName 'ATOM_SHELL_GUEST_WEB_VIEW'
else
index = arg.indexOf '--node-integration='
continue unless index == 0
else if arg.indexOf('--node-integration=') == 0
nodeIntegration = arg.substr arg.indexOf('=') + 1
if location.protocol is 'chrome-devtools:'
@ -44,7 +41,7 @@ else
# Override default web functions.
require path.join(__dirname, 'override')
# Load webview tag implementation.
require path.join(__dirname, 'web-view') unless isGuest
require path.join(__dirname, 'web-view') unless process.guestInstanceId?
if nodeIntegration in ['true', 'all', 'except-iframe', 'manual-enable-iframe']
# Export node bindings to global.

View file

@ -1,43 +1,43 @@
process = global.process
remote = require 'remote'
# Override default window.close, see:
# https://github.com/atom/atom-shell/issues/70
window.close = ->
require('remote').getCurrentWindow().close()
unless process.guestInstanceId?
# Override default window.close, see:
window.close = ->
remote.getCurrentWindow().close()
# Override default window.open.
window.open = (url, name, features) ->
options = {}
for feature in features.split ','
[name, value] = feature.split '='
options[name] =
if value is 'yes'
true
else if value is 'no'
false
else
value
# Override default window.open.
window.open = (url, name, features) ->
options = {}
for feature in features.split ','
[name, value] = feature.split '='
options[name] =
if value is 'yes'
true
else if value is 'no'
false
else
value
options.x ?= options.left
options.y ?= options.top
options.title ?= name
options.width ?= 800
options.height ?= 600
options.x ?= options.left
options.y ?= options.top
options.title ?= name
options.width ?= 800
options.height ?= 600
BrowserWindow = require('remote').require 'browser-window'
browser = new BrowserWindow options
browser.loadUrl url
browser
BrowserWindow = require('remote').require 'browser-window'
browser = new BrowserWindow options
browser.loadUrl url
browser
# Use the dialog API to implement alert().
window.alert = (message, title='') ->
remote = require 'remote'
dialog = remote.require 'dialog'
buttons = ['OK']
dialog.showMessageBox remote.getCurrentWindow(), {message, title, buttons}
# And the confirm().
window.confirm = (message, title='') ->
remote = require 'remote'
dialog = remote.require 'dialog'
buttons = ['OK', 'Cancel']
not dialog.showMessageBox remote.getCurrentWindow(), {message, title, buttons}