standardize by hand
This commit is contained in:
parent
cfdfdc8ccc
commit
e6698102c9
13 changed files with 34 additions and 33 deletions
|
@ -5,12 +5,12 @@ const ipcMain = require('electron').ipcMain
|
||||||
// The history operation in renderer is redirected to browser.
|
// The history operation in renderer is redirected to browser.
|
||||||
ipcMain.on('ATOM_SHELL_NAVIGATION_CONTROLLER', function (event, method, ...args) {
|
ipcMain.on('ATOM_SHELL_NAVIGATION_CONTROLLER', function (event, method, ...args) {
|
||||||
var ref
|
var ref
|
||||||
return (ref = event.sender)[method].apply(ref, args)
|
(ref = event.sender)[method].apply(ref, args)
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', function (event, method, ...args) {
|
ipcMain.on('ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', function (event, method, ...args) {
|
||||||
var ref
|
var ref
|
||||||
return event.returnValue = (ref = event.sender)[method].apply(ref, args)
|
event.returnValue = (ref = event.sender)[method].apply(ref, args)
|
||||||
})
|
})
|
||||||
|
|
||||||
// JavaScript implementation of Chromium's NavigationController.
|
// JavaScript implementation of Chromium's NavigationController.
|
||||||
|
@ -41,10 +41,10 @@ var NavigationController = (function () {
|
||||||
// Go to index.
|
// Go to index.
|
||||||
this.currentIndex = this.pendingIndex
|
this.currentIndex = this.pendingIndex
|
||||||
this.pendingIndex = -1
|
this.pendingIndex = -1
|
||||||
return this.history[this.currentIndex] = url
|
this.history[this.currentIndex] = url
|
||||||
} else if (replaceEntry) {
|
} else if (replaceEntry) {
|
||||||
// Non-user initialized navigation.
|
// Non-user initialized navigation.
|
||||||
return this.history[this.currentIndex] = url
|
this.history[this.currentIndex] = url
|
||||||
} else {
|
} else {
|
||||||
// Normal navigation. Clear history.
|
// Normal navigation. Clear history.
|
||||||
this.history = this.history.slice(0, this.currentIndex + 1)
|
this.history = this.history.slice(0, this.currentIndex + 1)
|
||||||
|
@ -111,7 +111,7 @@ var NavigationController = (function () {
|
||||||
this.history = []
|
this.history = []
|
||||||
this.currentIndex = -1
|
this.currentIndex = -1
|
||||||
this.pendingIndex = -1
|
this.pendingIndex = -1
|
||||||
return this.inPageIndex = -1
|
this.inPageIndex = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
NavigationController.prototype.goBack = function () {
|
NavigationController.prototype.goBack = function () {
|
||||||
|
|
|
@ -87,7 +87,7 @@ let wrapWebContents = function (webContents) {
|
||||||
method = ref1[name]
|
method = ref1[name]
|
||||||
if (method instanceof Function) {
|
if (method instanceof Function) {
|
||||||
(function (name, method) {
|
(function (name, method) {
|
||||||
return webContents[name] = function () {
|
webContents[name] = function () {
|
||||||
return method.apply(controller, arguments)
|
return method.apply(controller, arguments)
|
||||||
}
|
}
|
||||||
})(name, method)
|
})(name, method)
|
||||||
|
@ -104,8 +104,7 @@ let wrapWebContents = function (webContents) {
|
||||||
const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
|
const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
|
||||||
this.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', requestId, method, args)
|
this.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', requestId, method, args)
|
||||||
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
||||||
if (callback)
|
if (callback) callback(result)
|
||||||
callback(result)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,22 +116,26 @@ let wrapWebContents = function (webContents) {
|
||||||
callback = hasUserGesture
|
callback = hasUserGesture
|
||||||
hasUserGesture = false
|
hasUserGesture = false
|
||||||
}
|
}
|
||||||
if (this.getURL() && !this.isLoading())
|
if (this.getURL() && !this.isLoading()) {
|
||||||
return asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture)
|
return asyncWebFrameMethods.call(this, requestId, 'executeJavaScript', callback, code, hasUserGesture)
|
||||||
else
|
} else {
|
||||||
return this.once('did-finish-load', asyncWebFrameMethods.bind(this, requestId, 'executeJavaScript', callback, code, hasUserGesture))
|
return this.once('did-finish-load', asyncWebFrameMethods.bind(this, requestId, 'executeJavaScript', callback, code, hasUserGesture))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Dispatch IPC messages to the ipc module.
|
// Dispatch IPC messages to the ipc module.
|
||||||
webContents.on('ipc-message', function (event, [channel, ...args]) {
|
webContents.on('ipc-message', function (event, [channel, ...args]) {
|
||||||
return ipcMain.emit.apply(ipcMain, [channel, event].concat(args))
|
return ipcMain.emit.apply(ipcMain, [channel, event].concat(args))
|
||||||
})
|
})
|
||||||
webContents.on('ipc-message-sync', function (event, [channel, ...args]) {
|
webContents.on('ipc-message-sync', function (event, [channel, ...args]) {
|
||||||
|
/* eslint-disable */
|
||||||
|
// standard complains: Getter is not present
|
||||||
Object.defineProperty(event, 'returnValue', {
|
Object.defineProperty(event, 'returnValue', {
|
||||||
set: function (value) {
|
set: function (value) {
|
||||||
return event.sendReply(JSON.stringify(value))
|
return event.sendReply(JSON.stringify(value))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
/* eslint-enable */
|
||||||
return ipcMain.emit.apply(ipcMain, [channel, event].concat(args))
|
return ipcMain.emit.apply(ipcMain, [channel, event].concat(args))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ if (process.platform === 'win32') {
|
||||||
|
|
||||||
// Always returns EOF for stdin stream.
|
// Always returns EOF for stdin stream.
|
||||||
var Readable = require('stream').Readable
|
var Readable = require('stream').Readable
|
||||||
var stdin = new Readable
|
var stdin = new Readable()
|
||||||
stdin.push(null)
|
stdin.push(null)
|
||||||
process.__defineGetter__('stdin', function () {
|
process.__defineGetter__('stdin', function () {
|
||||||
return stdin
|
return stdin
|
||||||
|
|
|
@ -20,7 +20,7 @@ class CallbacksRegistry {
|
||||||
// Capture the location of the function and put it in the ID string,
|
// Capture the location of the function and put it in the ID string,
|
||||||
// so that release errors can be tracked down easily.
|
// so that release errors can be tracked down easily.
|
||||||
regexp = /at (.*)/gi
|
regexp = /at (.*)/gi
|
||||||
stackString = (new Error).stack
|
stackString = (new Error()).stack
|
||||||
while ((match = regexp.exec(stackString)) !== null) {
|
while ((match = regexp.exec(stackString)) !== null) {
|
||||||
location = match[1]
|
location = match[1]
|
||||||
if (location.indexOf('(native)') !== -1) {
|
if (location.indexOf('(native)') !== -1) {
|
||||||
|
|
|
@ -23,9 +23,9 @@ deprecate.rename = function (object, oldName, newName) {
|
||||||
return this[newName].apply(this, arguments)
|
return this[newName].apply(this, arguments)
|
||||||
}
|
}
|
||||||
if (typeof object === 'function') {
|
if (typeof object === 'function') {
|
||||||
return object.prototype[oldName] = newMethod
|
object.prototype[oldName] = newMethod
|
||||||
} else {
|
} else {
|
||||||
return object[oldName] = newMethod
|
object[oldName] = newMethod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ deprecate.rename = function (object, oldName, newName) {
|
||||||
deprecate.member = function (object, method, member) {
|
deprecate.member = function (object, method, member) {
|
||||||
var warned
|
var warned
|
||||||
warned = false
|
warned = false
|
||||||
return object.prototype[method] = function () {
|
object.prototype[method] = function () {
|
||||||
if (!(warned || process.noDeprecation)) {
|
if (!(warned || process.noDeprecation)) {
|
||||||
warned = true
|
warned = true
|
||||||
deprecate.warn(method, member + '.' + method)
|
deprecate.warn(method, member + '.' + method)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* globals $, xit */
|
/* globals $ */
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
const asar = process.binding('atom_common_asar')
|
const asar = process.binding('atom_common_asar')
|
||||||
|
|
|
@ -6,7 +6,7 @@ const EventEmitter = require('events').EventEmitter
|
||||||
deprecate.warn('ipc module', 'require("electron").ipcRenderer')
|
deprecate.warn('ipc module', 'require("electron").ipcRenderer')
|
||||||
|
|
||||||
// Routes events of ipcRenderer.
|
// Routes events of ipcRenderer.
|
||||||
var ipc = new EventEmitter
|
var ipc = new EventEmitter()
|
||||||
|
|
||||||
ipcRenderer.emit = function (channel, event, ...args) {
|
ipcRenderer.emit = function (channel, event, ...args) {
|
||||||
ipc.emit.apply(ipc, [channel].concat(args))
|
ipc.emit.apply(ipc, [channel].concat(args))
|
||||||
|
|
|
@ -5,11 +5,11 @@ const CallbacksRegistry = require('electron').CallbacksRegistry
|
||||||
const v8Util = process.atomBinding('v8_util')
|
const v8Util = process.atomBinding('v8_util')
|
||||||
const IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap
|
const IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap
|
||||||
|
|
||||||
const callbacksRegistry = new CallbacksRegistry
|
const callbacksRegistry = new CallbacksRegistry()
|
||||||
|
|
||||||
var includes = [].includes
|
var includes = [].includes
|
||||||
|
|
||||||
var remoteObjectCache = new IDWeakMap
|
var remoteObjectCache = new IDWeakMap()
|
||||||
|
|
||||||
// Check for circular reference.
|
// Check for circular reference.
|
||||||
var isCircular = function (field, visited) {
|
var isCircular = function (field, visited) {
|
||||||
|
@ -48,7 +48,7 @@ var wrapArgs = function (args, visited) {
|
||||||
} else if ((value != null ? value.constructor.name : void 0) === 'Promise') {
|
} else if ((value != null ? value.constructor.name : void 0) === 'Promise') {
|
||||||
return {
|
return {
|
||||||
type: 'promise',
|
type: 'promise',
|
||||||
then: valueToMeta(function (v) { value.then(v); })
|
then: valueToMeta(function (v) { value.then(v) })
|
||||||
}
|
}
|
||||||
} else if ((value != null) && typeof value === 'object' && v8Util.getHiddenValue(value, 'atomId')) {
|
} else if ((value != null) && typeof value === 'object' && v8Util.getHiddenValue(value, 'atomId')) {
|
||||||
return {
|
return {
|
||||||
|
@ -94,8 +94,7 @@ var wrapArgs = function (args, visited) {
|
||||||
// This matches |getObjectMemebers| in rpc-server.
|
// This matches |getObjectMemebers| in rpc-server.
|
||||||
let setObjectMembers = function (object, metaId, members) {
|
let setObjectMembers = function (object, metaId, members) {
|
||||||
for (let member of members) {
|
for (let member of members) {
|
||||||
if (object.hasOwnProperty(member.name))
|
if (object.hasOwnProperty(member.name)) continue
|
||||||
continue
|
|
||||||
|
|
||||||
let descriptor = { enumerable: member.enumerable }
|
let descriptor = { enumerable: member.enumerable }
|
||||||
if (member.type === 'method') {
|
if (member.type === 'method') {
|
||||||
|
@ -134,8 +133,7 @@ let setObjectMembers = function (object, metaId, members) {
|
||||||
// Populate object's prototype from descriptor.
|
// Populate object's prototype from descriptor.
|
||||||
// This matches |getObjectPrototype| in rpc-server.
|
// This matches |getObjectPrototype| in rpc-server.
|
||||||
let setObjectPrototype = function (object, metaId, descriptor) {
|
let setObjectPrototype = function (object, metaId, descriptor) {
|
||||||
if (descriptor === null)
|
if (descriptor === null) return
|
||||||
return
|
|
||||||
let proto = {}
|
let proto = {}
|
||||||
setObjectMembers(proto, metaId, descriptor.members)
|
setObjectMembers(proto, metaId, descriptor.members)
|
||||||
setObjectPrototype(proto, metaId, descriptor.proto)
|
setObjectPrototype(proto, metaId, descriptor.proto)
|
||||||
|
@ -169,8 +167,7 @@ let metaToValue = function (meta) {
|
||||||
case 'exception':
|
case 'exception':
|
||||||
throw new Error(meta.message + '\n' + meta.stack)
|
throw new Error(meta.message + '\n' + meta.stack)
|
||||||
default:
|
default:
|
||||||
if (remoteObjectCache.has(meta.id))
|
if (remoteObjectCache.has(meta.id)) return remoteObjectCache.get(meta.id)
|
||||||
return remoteObjectCache.get(meta.id)
|
|
||||||
|
|
||||||
if (meta.type === 'function') {
|
if (meta.type === 'function') {
|
||||||
// A shadow class to represent the remote function object.
|
// A shadow class to represent the remote function object.
|
||||||
|
@ -220,7 +217,7 @@ var metaToPlainObject = function (meta) {
|
||||||
obj = (function () {
|
obj = (function () {
|
||||||
switch (meta.type) {
|
switch (meta.type) {
|
||||||
case 'error':
|
case 'error':
|
||||||
return new Error
|
return new Error()
|
||||||
default:
|
default:
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ globalPaths.push(path.join(__dirname, 'api', 'exports'))
|
||||||
// The global variable will be used by ipc for event dispatching
|
// The global variable will be used by ipc for event dispatching
|
||||||
var v8Util = process.atomBinding('v8_util')
|
var v8Util = process.atomBinding('v8_util')
|
||||||
|
|
||||||
v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter)
|
v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter())
|
||||||
|
|
||||||
// Use electron module after everything is ready.
|
// Use electron module after everything is ready.
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* globals Event */
|
||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const ipcRenderer = require('electron').ipcRenderer
|
const ipcRenderer = require('electron').ipcRenderer
|
||||||
|
@ -199,7 +201,7 @@ if (process.openerId != null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcRenderer.on('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', function (event, isVisible, isMinimized) {
|
ipcRenderer.on('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', function (event, isVisible, isMinimized) {
|
||||||
var hasChanged = _isVisible != isVisible || _isMinimized != isMinimized
|
var hasChanged = _isVisible !== isVisible || _isMinimized !== isMinimized
|
||||||
|
|
||||||
if (hasChanged) {
|
if (hasChanged) {
|
||||||
_isVisible = isVisible
|
_isVisible = isVisible
|
||||||
|
|
|
@ -40,7 +40,7 @@ class WebViewAttribute {
|
||||||
setValueIgnoreMutation (value) {
|
setValueIgnoreMutation (value) {
|
||||||
this.ignoreMutation = true
|
this.ignoreMutation = true
|
||||||
this.setValue(value)
|
this.setValue(value)
|
||||||
return this.ignoreMutation = false
|
this.ignoreMutation = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defines this attribute as a property on the webview node.
|
// Defines this attribute as a property on the webview node.
|
||||||
|
|
|
@ -423,8 +423,7 @@ var registerWebViewElement = function () {
|
||||||
let requestId = getNextId()
|
let requestId = getNextId()
|
||||||
ipcRenderer.send('ATOM_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', requestId, internal.guestInstanceId, 'executeJavaScript', code, hasUserGesture)
|
ipcRenderer.send('ATOM_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', requestId, internal.guestInstanceId, 'executeJavaScript', code, hasUserGesture)
|
||||||
ipcRenderer.once(`ATOM_RENDERER_ASYNC_CALL_TO_GUEST_VIEW_RESPONSE_${requestId}`, function (event, result) {
|
ipcRenderer.once(`ATOM_RENDERER_ASYNC_CALL_TO_GUEST_VIEW_RESPONSE_${requestId}`, function (event, result) {
|
||||||
if (callback)
|
if (callback) callback(result)
|
||||||
callback(result)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue