Merge branch 'master' into native-window-open

This commit is contained in:
Ryohei Ikegami 2017-04-27 12:03:55 +09:00
commit 1d73e84a29
59 changed files with 989 additions and 241 deletions

View file

@ -56,6 +56,7 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (ev
let nodeIntegration = 'false'
let preloadScript = null
let isBackgroundPage = false
let appPath = null
for (let arg of process.argv) {
if (arg.indexOf('--guest-instance-id=') === 0) {
// This is a guest web view.
@ -69,13 +70,15 @@ for (let arg of process.argv) {
preloadScript = arg.substr(arg.indexOf('=') + 1)
} else if (arg === '--background-page') {
isBackgroundPage = true
} else if (arg.indexOf('--app-path=') === 0) {
appPath = arg.substr(arg.indexOf('=') + 1)
}
}
if (window.location.protocol === 'chrome-devtools:') {
// Override some inspector APIs.
require('./inspector')
nodeIntegration = 'true'
nodeIntegration = 'false'
} else if (window.location.protocol === 'chrome-extension:') {
// Add implementations of chrome API.
require('./chrome-api').injectTo(window.location.hostname, isBackgroundPage, window)
@ -116,6 +119,11 @@ if (nodeIntegration === 'true') {
} else {
global.__filename = __filename
global.__dirname = __dirname
if (appPath) {
// Search for module under the app directory
module.paths = module.paths.concat(Module._nodeModulePaths(appPath))
}
}
// Redirect window.onerror to uncaughtException.

View file

@ -32,6 +32,13 @@ const resolveURL = function (url) {
return a.href
}
// Use this method to ensure values expected as strings in the main process
// are convertible to strings in the renderer process. This ensures exceptions
// converting values to strings are thrown in this process.
const toString = (value) => {
return value != null ? `${value}` : value
}
const windowProxies = {}
const getOrCreateProxy = (ipcRenderer, guestId) => {
@ -82,7 +89,7 @@ function BrowserWindowProxy (ipcRenderer, guestId) {
}
this.postMessage = (message, targetOrigin) => {
ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', guestId, message, targetOrigin, window.location.origin)
ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', guestId, message, toString(targetOrigin), window.location.origin)
}
this.eval = (...args) => {
@ -113,7 +120,7 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNative
if (url != null && url !== '') {
url = resolveURL(url)
}
const guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, features)
const guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, toString(frameName), toString(features))
if (guestId != null) {
return getOrCreateProxy(ipcRenderer, guestId)
} else {
@ -123,11 +130,11 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNative
}
window.alert = function (message, title) {
ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', message, title)
ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', toString(message), toString(title))
}
window.confirm = function (message, title) {
return ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CONFIRM', message, title)
return ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CONFIRM', toString(message), toString(title))
}
// But we do not support prompt().
@ -159,7 +166,7 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNative
}
window.history.go = function (offset) {
sendHistoryOperation(ipcRenderer, 'goToOffset', offset)
sendHistoryOperation(ipcRenderer, 'goToOffset', +offset)
}
defineProperty(window.history, 'length', {