2016-03-24 20:34:36 +00:00
|
|
|
'use strict'
|
2016-01-13 09:07:18 +00:00
|
|
|
|
2016-03-24 20:34:36 +00:00
|
|
|
const electron = require('electron')
|
|
|
|
const ipcMain = electron.ipcMain
|
|
|
|
const objectsRegistry = require('./objects-registry')
|
|
|
|
const v8Util = process.atomBinding('v8_util')
|
|
|
|
const IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-02-22 02:52:21 +00:00
|
|
|
// The internal properties of Function.
|
|
|
|
const FUNCTION_PROPERTIES = [
|
2016-03-24 20:34:36 +00:00
|
|
|
'length', 'name', 'arguments', 'caller', 'prototype'
|
|
|
|
]
|
2016-02-22 02:52:21 +00:00
|
|
|
|
2016-02-22 06:36:50 +00:00
|
|
|
// The remote functions in renderer processes.
|
|
|
|
// (webContentsId) => {id: Function}
|
2016-03-24 20:34:36 +00:00
|
|
|
let rendererFunctions = {}
|
2016-02-22 06:36:50 +00:00
|
|
|
|
2016-02-22 02:52:21 +00:00
|
|
|
// Return the description of object's members:
|
2016-03-24 20:34:36 +00:00
|
|
|
let getObjectMembers = function (object) {
|
|
|
|
let names = Object.getOwnPropertyNames(object)
|
2016-02-22 02:52:21 +00:00
|
|
|
// For Function, we should not override following properties even though they
|
|
|
|
// are "own" properties.
|
|
|
|
if (typeof object === 'function') {
|
|
|
|
names = names.filter((name) => {
|
2016-03-24 20:34:36 +00:00
|
|
|
return !FUNCTION_PROPERTIES.includes(name)
|
|
|
|
})
|
2016-02-22 02:52:21 +00:00
|
|
|
}
|
|
|
|
// Map properties to descriptors.
|
|
|
|
return names.map((name) => {
|
2016-03-24 20:34:36 +00:00
|
|
|
let descriptor = Object.getOwnPropertyDescriptor(object, name)
|
|
|
|
let member = {name, enumerable: descriptor.enumerable, writable: false}
|
2016-02-22 02:52:21 +00:00
|
|
|
if (descriptor.get === undefined && typeof object[name] === 'function') {
|
2016-03-24 20:34:36 +00:00
|
|
|
member.type = 'method'
|
2016-02-22 02:52:21 +00:00
|
|
|
} else {
|
2016-03-24 20:34:36 +00:00
|
|
|
if (descriptor.set || descriptor.writable) member.writable = true
|
|
|
|
member.type = 'get'
|
2016-02-22 02:52:21 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
return member
|
|
|
|
})
|
|
|
|
}
|
2016-02-22 02:52:21 +00:00
|
|
|
|
|
|
|
// Return the description of object's prototype.
|
2016-03-24 20:34:36 +00:00
|
|
|
let getObjectPrototype = function (object) {
|
|
|
|
let proto = Object.getPrototypeOf(object)
|
|
|
|
if (proto === null || proto === Object.prototype) return null
|
2016-02-22 02:52:21 +00:00
|
|
|
return {
|
2016-03-04 23:57:21 +00:00
|
|
|
members: getObjectMembers(proto),
|
2016-03-24 20:34:36 +00:00
|
|
|
proto: getObjectPrototype(proto)
|
|
|
|
}
|
|
|
|
}
|
2016-02-22 02:52:21 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Convert a real value into meta data.
|
2016-03-24 20:34:36 +00:00
|
|
|
var valueToMeta = function (sender, value, optimizeSimpleObject) {
|
|
|
|
var el, i, len, meta
|
2016-01-12 02:40:23 +00:00
|
|
|
if (optimizeSimpleObject == null) {
|
2016-03-24 20:34:36 +00:00
|
|
|
optimizeSimpleObject = false
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
meta = {
|
|
|
|
type: typeof value
|
2016-03-24 20:34:36 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
if (Buffer.isBuffer(value)) {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.type = 'buffer'
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
if (value === null) {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.type = 'value'
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.type = 'array'
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
if (value instanceof Error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.type = 'error'
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
if (value instanceof Date) {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.type = 'date'
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
if ((value != null ? value.constructor.name : void 0) === 'Promise') {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.type = 'promise'
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Treat simple objects as value.
|
2016-01-12 02:40:23 +00:00
|
|
|
if (optimizeSimpleObject && meta.type === 'object' && v8Util.getHiddenValue(value, 'simple')) {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.type = 'value'
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Treat the arguments object as array.
|
2016-01-13 09:07:18 +00:00
|
|
|
if (meta.type === 'object' && (value.hasOwnProperty('callee')) && (value.length != null)) {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.type = 'array'
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
if (meta.type === 'array') {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.members = []
|
2016-01-12 02:40:23 +00:00
|
|
|
for (i = 0, len = value.length; i < len; i++) {
|
2016-03-24 20:34:36 +00:00
|
|
|
el = value[i]
|
|
|
|
meta.members.push(valueToMeta(sender, el))
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
} else if (meta.type === 'object' || meta.type === 'function') {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.name = value.constructor.name
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:44:21 +00:00
|
|
|
// Reference the original value if it's an object, because when it's
|
|
|
|
// passed to renderer we would assume the renderer keeps a reference of
|
|
|
|
// it.
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.id = objectsRegistry.add(sender, value)
|
|
|
|
meta.members = getObjectMembers(value)
|
|
|
|
meta.proto = getObjectPrototype(value)
|
2016-01-12 02:40:23 +00:00
|
|
|
} else if (meta.type === 'buffer') {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.value = Array.prototype.slice.call(value, 0)
|
2016-01-12 02:40:23 +00:00
|
|
|
} else if (meta.type === 'promise') {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.then = valueToMeta(sender, function (v) { value.then(v) })
|
2016-01-12 02:40:23 +00:00
|
|
|
} else if (meta.type === 'error') {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.members = plainObjectToMeta(value)
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Error.name is not part of own properties.
|
2016-01-12 02:40:23 +00:00
|
|
|
meta.members.push({
|
|
|
|
name: 'name',
|
|
|
|
value: value.name
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
} else if (meta.type === 'date') {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.value = value.getTime()
|
2016-01-12 02:40:23 +00:00
|
|
|
} else {
|
2016-03-24 20:34:36 +00:00
|
|
|
meta.type = 'value'
|
|
|
|
meta.value = value
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
return meta
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Convert object to meta by value.
|
2016-03-24 20:34:36 +00:00
|
|
|
var plainObjectToMeta = function (obj) {
|
|
|
|
return Object.getOwnPropertyNames(obj).map(function (name) {
|
2016-01-12 02:40:23 +00:00
|
|
|
return {
|
|
|
|
name: name,
|
|
|
|
value: obj[name]
|
2016-03-24 20:34:36 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Convert Error into meta data.
|
2016-03-24 20:34:36 +00:00
|
|
|
var exceptionToMeta = function (error) {
|
2016-01-12 02:40:23 +00:00
|
|
|
return {
|
|
|
|
type: 'exception',
|
|
|
|
message: error.message,
|
|
|
|
stack: error.stack || error
|
2016-03-24 20:34:36 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Convert array of meta data from renderer into array of real values.
|
2016-03-24 20:34:36 +00:00
|
|
|
var unwrapArgs = function (sender, args) {
|
|
|
|
var metaToValue
|
|
|
|
metaToValue = function (meta) {
|
|
|
|
var i, len, member, ref, returnValue
|
2016-01-12 02:40:23 +00:00
|
|
|
switch (meta.type) {
|
|
|
|
case 'value':
|
2016-03-24 20:34:36 +00:00
|
|
|
return meta.value
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'remote-object':
|
2016-03-24 20:34:36 +00:00
|
|
|
return objectsRegistry.get(meta.id)
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'array':
|
2016-03-24 20:34:36 +00:00
|
|
|
return unwrapArgs(sender, meta.value)
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'buffer':
|
2016-03-24 20:34:36 +00:00
|
|
|
return new Buffer(meta.value)
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'date':
|
2016-03-24 20:34:36 +00:00
|
|
|
return new Date(meta.value)
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'promise':
|
|
|
|
return Promise.resolve({
|
|
|
|
then: metaToValue(meta.then)
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-03-25 19:28:43 +00:00
|
|
|
case 'object': {
|
2016-03-24 20:34:36 +00:00
|
|
|
let ret = {}
|
|
|
|
Object.defineProperty(ret.constructor, 'name', { value: meta.name })
|
2016-02-22 03:51:41 +00:00
|
|
|
|
2016-03-24 20:34:36 +00:00
|
|
|
ref = meta.members
|
2016-01-12 02:40:23 +00:00
|
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
2016-03-24 20:34:36 +00:00
|
|
|
member = ref[i]
|
|
|
|
ret[member.name] = metaToValue(member.value)
|
|
|
|
}
|
|
|
|
return ret
|
2016-03-25 19:28:43 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'function-with-return-value':
|
2016-03-24 20:34:36 +00:00
|
|
|
returnValue = metaToValue(meta.value)
|
|
|
|
return function () {
|
|
|
|
return returnValue
|
|
|
|
}
|
2016-03-25 19:28:43 +00:00
|
|
|
case 'function': {
|
2016-01-14 18:35:29 +00:00
|
|
|
// Cache the callbacks in renderer.
|
2016-03-24 20:34:36 +00:00
|
|
|
let webContentsId = sender.getId()
|
|
|
|
let callbacks = rendererFunctions[webContentsId]
|
2016-02-22 06:36:50 +00:00
|
|
|
if (!callbacks) {
|
2016-03-24 20:34:36 +00:00
|
|
|
callbacks = rendererFunctions[webContentsId] = new IDWeakMap()
|
|
|
|
sender.once('render-view-deleted', function (event, id) {
|
|
|
|
callbacks.clear()
|
|
|
|
delete rendererFunctions[id]
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-01-13 09:07:18 +00:00
|
|
|
|
2016-03-24 20:34:36 +00:00
|
|
|
if (callbacks.has(meta.id)) return callbacks.get(meta.id)
|
|
|
|
|
|
|
|
let callIntoRenderer = function (...args) {
|
|
|
|
if ((webContentsId in rendererFunctions) && !sender.isDestroyed()) {
|
2016-04-06 23:21:26 +00:00
|
|
|
sender.send('ELECTRON_RENDERER_CALLBACK', meta.id, valueToMeta(sender, args))
|
2016-03-24 20:34:36 +00:00
|
|
|
} else {
|
|
|
|
throw new Error(`Attempting to call a function in a renderer window that has been closed or released. Function provided here: ${meta.location}.`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v8Util.setDestructor(callIntoRenderer, function () {
|
|
|
|
if ((webContentsId in rendererFunctions) && !sender.isDestroyed()) {
|
2016-04-06 23:21:26 +00:00
|
|
|
sender.send('ELECTRON_RENDERER_RELEASE_CALLBACK', meta.id)
|
2016-03-24 20:34:36 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
callbacks.set(meta.id, callIntoRenderer)
|
|
|
|
return callIntoRenderer
|
2016-03-25 19:28:43 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
default:
|
2016-03-24 20:34:36 +00:00
|
|
|
throw new TypeError(`Unknown type: ${meta.type}`)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
}
|
|
|
|
return args.map(metaToValue)
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:44:21 +00:00
|
|
|
// Call a function and send reply asynchronously if it's a an asynchronous
|
|
|
|
// style function and the caller didn't pass a callback.
|
2016-03-24 20:34:36 +00:00
|
|
|
var callFunction = function (event, func, caller, args) {
|
|
|
|
var funcMarkedAsync, funcName, funcPassedCallback, ref, ret
|
|
|
|
funcMarkedAsync = v8Util.getHiddenValue(func, 'asynchronous')
|
|
|
|
funcPassedCallback = typeof args[args.length - 1] === 'function'
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
|
|
|
if (funcMarkedAsync && !funcPassedCallback) {
|
2016-03-24 20:34:36 +00:00
|
|
|
args.push(function (ret) {
|
|
|
|
event.returnValue = valueToMeta(event.sender, ret, true)
|
|
|
|
})
|
|
|
|
return func.apply(caller, args)
|
2016-01-12 02:40:23 +00:00
|
|
|
} else {
|
2016-03-24 20:34:36 +00:00
|
|
|
ret = func.apply(caller, args)
|
|
|
|
event.returnValue = valueToMeta(event.sender, ret, true)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-01-14 18:44:21 +00:00
|
|
|
// Catch functions thrown further down in function invocation and wrap
|
|
|
|
// them with the function name so it's easier to trace things like
|
|
|
|
// `Error processing argument -1.`
|
2016-03-24 20:34:36 +00:00
|
|
|
funcName = ((ref = func.name) != null) ? ref : 'anonymous'
|
|
|
|
throw new Error(`Could not call remote function '${funcName}'. Check that the function signature is correct. Underlying error: ${error.message}`)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_REQUIRE', function (event, module) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = valueToMeta(event.sender, process.mainModule.require(module))
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_GET_BUILTIN', function (event, module) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = valueToMeta(event.sender, electron[module])
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_GLOBAL', function (event, name) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = valueToMeta(event.sender, global[name])
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_CURRENT_WINDOW', function (event) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = valueToMeta(event.sender, event.sender.getOwnerBrowserWindow())
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_CURRENT_WEB_CONTENTS', function (event) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = valueToMeta(event.sender, event.sender)
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_CONSTRUCTOR', function (event, id, args) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
args = unwrapArgs(event.sender, args)
|
|
|
|
let constructor = objectsRegistry.get(id)
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:44:21 +00:00
|
|
|
// Call new with array of arguments.
|
|
|
|
// http://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible
|
2016-03-30 21:06:50 +00:00
|
|
|
let obj = new (Function.prototype.bind.apply(constructor, [null].concat(args)))
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = valueToMeta(event.sender, obj)
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_FUNCTION_CALL', function (event, id, args) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
args = unwrapArgs(event.sender, args)
|
|
|
|
let func = objectsRegistry.get(id)
|
|
|
|
return callFunction(event, func, global, args)
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_MEMBER_CONSTRUCTOR', function (event, id, method, args) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
args = unwrapArgs(event.sender, args)
|
|
|
|
let constructor = objectsRegistry.get(id)[method]
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Call new with array of arguments.
|
2016-03-30 21:06:50 +00:00
|
|
|
let obj = new (Function.prototype.bind.apply(constructor, [null].concat(args)))
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = valueToMeta(event.sender, obj)
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_MEMBER_CALL', function (event, id, method, args) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
args = unwrapArgs(event.sender, args)
|
|
|
|
let obj = objectsRegistry.get(id)
|
|
|
|
return callFunction(event, obj[method], obj, args)
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_MEMBER_SET', function (event, id, name, value) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
let obj = objectsRegistry.get(id)
|
|
|
|
obj[name] = value
|
|
|
|
event.returnValue = null
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_MEMBER_GET', function (event, id, name) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
let obj = objectsRegistry.get(id)
|
|
|
|
event.returnValue = valueToMeta(event.sender, obj[name])
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_DEREFERENCE', function (event, id) {
|
2016-03-24 20:34:36 +00:00
|
|
|
return objectsRegistry.remove(event.sender.getId(), id)
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_GUEST_WEB_CONTENTS', function (event, guestInstanceId) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
let guestViewManager = require('./guest-view-manager')
|
|
|
|
event.returnValue = valueToMeta(event.sender, guestViewManager.getGuest(guestInstanceId))
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcMain.on('ELECTRON_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', function (event, requestId, guestInstanceId, method, ...args) {
|
2016-01-12 02:40:23 +00:00
|
|
|
try {
|
2016-03-24 20:34:36 +00:00
|
|
|
let guestViewManager = require('./guest-view-manager')
|
|
|
|
let guest = guestViewManager.getGuest(guestInstanceId)
|
2016-02-25 18:05:01 +00:00
|
|
|
if (requestId) {
|
2016-03-24 20:34:36 +00:00
|
|
|
const responseCallback = function (result) {
|
2016-04-06 23:21:26 +00:00
|
|
|
event.sender.send(`ELECTRON_RENDERER_ASYNC_CALL_TO_GUEST_VIEW_RESPONSE_${requestId}`, result)
|
2016-03-24 20:34:36 +00:00
|
|
|
}
|
|
|
|
args.push(responseCallback)
|
2016-02-25 18:05:01 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
guest[method].apply(guest, args)
|
2016-01-19 22:49:40 +00:00
|
|
|
} catch (error) {
|
2016-03-24 20:34:36 +00:00
|
|
|
event.returnValue = exceptionToMeta(error)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:34:36 +00:00
|
|
|
})
|