2016-03-25 19:57:17 +00:00
|
|
|
'use strict'
|
2016-02-22 02:52:21 +00:00
|
|
|
|
2016-03-25 19:57:17 +00:00
|
|
|
const v8Util = process.atomBinding('v8_util')
|
2016-07-25 07:39:09 +00:00
|
|
|
const {ipcRenderer, isPromise, CallbacksRegistry} = require('electron')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-29 00:35:49 +00:00
|
|
|
const callbacksRegistry = new CallbacksRegistry()
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-07-11 17:28:01 +00:00
|
|
|
const remoteObjectCache = v8Util.createIDWeakMap()
|
2016-02-17 07:57:46 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Convert the arguments object into an array of meta data.
|
2016-07-11 17:28:01 +00:00
|
|
|
const wrapArgs = function (args, visited) {
|
2016-01-12 02:40:23 +00:00
|
|
|
if (visited == null) {
|
2016-07-11 17:28:01 +00:00
|
|
|
visited = new Set()
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-07-11 17:28:01 +00:00
|
|
|
|
|
|
|
const valueToMeta = function (value) {
|
2016-07-11 17:39:21 +00:00
|
|
|
// Check for circular reference.
|
|
|
|
if (visited.has(value)) {
|
2016-01-12 02:40:23 +00:00
|
|
|
return {
|
2016-07-11 17:28:01 +00:00
|
|
|
type: 'value',
|
|
|
|
value: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Array.isArray(value)) {
|
2016-07-11 17:39:21 +00:00
|
|
|
visited.add(value)
|
2016-07-11 17:28:01 +00:00
|
|
|
let meta = {
|
2016-01-12 02:40:23 +00:00
|
|
|
type: 'array',
|
2016-07-11 17:28:01 +00:00
|
|
|
value: wrapArgs(value, visited)
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-07-11 17:28:01 +00:00
|
|
|
visited.delete(value)
|
|
|
|
return meta
|
2016-07-25 07:39:09 +00:00
|
|
|
} else if (ArrayBuffer.isView(value)) {
|
2016-01-12 02:40:23 +00:00
|
|
|
return {
|
|
|
|
type: 'buffer',
|
|
|
|
value: Array.prototype.slice.call(value, 0)
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
} else if (value instanceof Date) {
|
|
|
|
return {
|
|
|
|
type: 'date',
|
|
|
|
value: value.getTime()
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
} else if ((value != null) && typeof value === 'object') {
|
2016-05-25 05:38:35 +00:00
|
|
|
if (isPromise(value)) {
|
2016-04-20 05:26:49 +00:00
|
|
|
return {
|
|
|
|
type: 'promise',
|
2016-05-23 22:07:01 +00:00
|
|
|
then: valueToMeta(function (onFulfilled, onRejected) {
|
|
|
|
value.then(onFulfilled, onRejected)
|
|
|
|
})
|
2016-04-20 05:26:49 +00:00
|
|
|
}
|
|
|
|
} else if (v8Util.getHiddenValue(value, 'atomId')) {
|
|
|
|
return {
|
|
|
|
type: 'remote-object',
|
|
|
|
id: v8Util.getHiddenValue(value, 'atomId')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 17:28:01 +00:00
|
|
|
let meta = {
|
2016-01-12 02:40:23 +00:00
|
|
|
type: 'object',
|
2016-07-06 20:06:48 +00:00
|
|
|
name: value.constructor != null ? value.constructor.name : '',
|
2016-01-12 02:40:23 +00:00
|
|
|
members: []
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-07-11 17:39:21 +00:00
|
|
|
visited.add(value)
|
2016-07-11 17:28:01 +00:00
|
|
|
for (let prop in value) {
|
|
|
|
meta.members.push({
|
2016-01-12 02:40:23 +00:00
|
|
|
name: prop,
|
2016-07-11 17:28:01 +00:00
|
|
|
value: valueToMeta(value[prop])
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-07-11 17:28:01 +00:00
|
|
|
visited.delete(value)
|
|
|
|
return meta
|
2016-01-12 02:40:23 +00:00
|
|
|
} else if (typeof value === 'function' && v8Util.getHiddenValue(value, 'returnValue')) {
|
|
|
|
return {
|
|
|
|
type: 'function-with-return-value',
|
|
|
|
value: valueToMeta(value())
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
} else if (typeof value === 'function') {
|
|
|
|
return {
|
|
|
|
type: 'function',
|
|
|
|
id: callbacksRegistry.add(value),
|
|
|
|
location: v8Util.getHiddenValue(value, 'location')
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
type: 'value',
|
|
|
|
value: value
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
|
|
|
return Array.prototype.slice.call(args).map(valueToMeta)
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-02-22 02:52:21 +00:00
|
|
|
// Populate object's members from descriptors.
|
2016-04-01 06:45:36 +00:00
|
|
|
// The |ref| will be kept referenced by |members|.
|
2016-02-22 02:52:21 +00:00
|
|
|
// This matches |getObjectMemebers| in rpc-server.
|
2016-07-11 17:28:01 +00:00
|
|
|
const setObjectMembers = function (ref, object, metaId, members) {
|
2016-02-22 02:52:21 +00:00
|
|
|
for (let member of members) {
|
2016-03-29 00:35:49 +00:00
|
|
|
if (object.hasOwnProperty(member.name)) continue
|
2016-02-22 02:52:21 +00:00
|
|
|
|
2016-03-25 19:57:17 +00:00
|
|
|
let descriptor = { enumerable: member.enumerable }
|
2016-02-22 02:52:21 +00:00
|
|
|
if (member.type === 'method') {
|
2016-08-16 20:54:21 +00:00
|
|
|
const remoteMemberFunction = function () {
|
2016-02-22 02:52:21 +00:00
|
|
|
if (this && this.constructor === remoteMemberFunction) {
|
|
|
|
// Constructor call.
|
2016-04-06 23:21:26 +00:00
|
|
|
let ret = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_CONSTRUCTOR', metaId, member.name, wrapArgs(arguments))
|
2016-03-25 19:57:17 +00:00
|
|
|
return metaToValue(ret)
|
2016-02-22 02:52:21 +00:00
|
|
|
} else {
|
|
|
|
// Call member function.
|
2016-04-06 23:21:26 +00:00
|
|
|
let ret = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_CALL', metaId, member.name, wrapArgs(arguments))
|
2016-03-25 19:57:17 +00:00
|
|
|
return metaToValue(ret)
|
2016-02-22 02:52:21 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-08-16 20:54:21 +00:00
|
|
|
|
2016-08-17 20:58:48 +00:00
|
|
|
let descriptorFunction = proxyFunctionProperties(remoteMemberFunction, metaId, member.name)
|
2016-08-16 20:54:21 +00:00
|
|
|
|
2016-04-01 06:26:30 +00:00
|
|
|
descriptor.get = function () {
|
2016-08-16 20:54:21 +00:00
|
|
|
descriptorFunction.ref = ref // The member should reference its object.
|
|
|
|
return descriptorFunction
|
2016-04-01 06:26:30 +00:00
|
|
|
}
|
|
|
|
// Enable monkey-patch the method
|
|
|
|
descriptor.set = function (value) {
|
2016-08-16 20:54:21 +00:00
|
|
|
descriptorFunction = value
|
2016-04-01 06:26:30 +00:00
|
|
|
return value
|
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
descriptor.configurable = true
|
2016-02-22 02:52:21 +00:00
|
|
|
} else if (member.type === 'get') {
|
2016-03-25 19:57:17 +00:00
|
|
|
descriptor.get = function () {
|
2016-04-06 23:21:26 +00:00
|
|
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_GET', metaId, member.name))
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-02-22 02:52:21 +00:00
|
|
|
|
|
|
|
// Only set setter when it is writable.
|
|
|
|
if (member.writable) {
|
2016-03-25 19:57:17 +00:00
|
|
|
descriptor.set = function (value) {
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_SET', metaId, member.name, value)
|
2016-03-25 19:57:17 +00:00
|
|
|
return value
|
|
|
|
}
|
2016-02-22 02:52:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:57:17 +00:00
|
|
|
Object.defineProperty(object, member.name, descriptor)
|
2016-02-22 02:52:21 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-02-22 02:52:21 +00:00
|
|
|
|
|
|
|
// Populate object's prototype from descriptor.
|
|
|
|
// This matches |getObjectPrototype| in rpc-server.
|
2016-07-11 17:28:01 +00:00
|
|
|
const setObjectPrototype = function (ref, object, metaId, descriptor) {
|
2016-03-29 00:35:49 +00:00
|
|
|
if (descriptor === null) return
|
2016-03-25 19:57:17 +00:00
|
|
|
let proto = {}
|
2016-04-01 06:45:36 +00:00
|
|
|
setObjectMembers(ref, proto, metaId, descriptor.members)
|
|
|
|
setObjectPrototype(ref, proto, metaId, descriptor.proto)
|
2016-03-25 19:57:17 +00:00
|
|
|
Object.setPrototypeOf(object, proto)
|
|
|
|
}
|
2016-02-22 02:52:21 +00:00
|
|
|
|
2016-08-17 20:58:48 +00:00
|
|
|
// Wrap function in Proxy for accessing remote properties
|
|
|
|
const proxyFunctionProperties = function (remoteMemberFunction, metaId, name) {
|
|
|
|
let loaded = false
|
|
|
|
const loadRemoteProperties = () => {
|
|
|
|
if (loaded) return
|
|
|
|
loaded = true
|
|
|
|
const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_GET', metaId, name)
|
|
|
|
setObjectMembers(remoteMemberFunction, remoteMemberFunction, meta.id, meta.members)
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Proxy(remoteMemberFunction, {
|
|
|
|
get: (target, property, receiver) => {
|
|
|
|
if (!target.hasOwnProperty(property)) loadRemoteProperties()
|
|
|
|
return target[property]
|
|
|
|
},
|
|
|
|
ownKeys: (target) => {
|
|
|
|
loadRemoteProperties()
|
|
|
|
return Object.getOwnPropertyNames(target)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor: (target, property) => {
|
|
|
|
let descriptor = Object.getOwnPropertyDescriptor(target, property)
|
|
|
|
if (descriptor != null) return descriptor
|
|
|
|
loadRemoteProperties()
|
|
|
|
return Object.getOwnPropertyDescriptor(target, property)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Convert meta data from browser into real value.
|
2016-07-11 17:28:01 +00:00
|
|
|
const metaToValue = function (meta) {
|
2016-03-25 19:57:17 +00:00
|
|
|
var el, i, len, ref1, results, ret
|
2016-01-12 02:40:23 +00:00
|
|
|
switch (meta.type) {
|
|
|
|
case 'value':
|
2016-03-25 19:57:17 +00:00
|
|
|
return meta.value
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'array':
|
2016-03-25 19:57:17 +00:00
|
|
|
ref1 = meta.members
|
|
|
|
results = []
|
2016-01-12 02:40:23 +00:00
|
|
|
for (i = 0, len = ref1.length; i < len; i++) {
|
2016-03-25 19:57:17 +00:00
|
|
|
el = ref1[i]
|
|
|
|
results.push(metaToValue(el))
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
return results
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'buffer':
|
2016-07-25 07:40:22 +00:00
|
|
|
return Buffer.from(meta.value)
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'promise':
|
|
|
|
return Promise.resolve({
|
|
|
|
then: metaToValue(meta.then)
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'error':
|
2016-03-25 19:57:17 +00:00
|
|
|
return metaToPlainObject(meta)
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'date':
|
2016-03-25 19:57:17 +00:00
|
|
|
return new Date(meta.value)
|
2016-01-12 02:40:23 +00:00
|
|
|
case 'exception':
|
2016-03-25 19:57:17 +00:00
|
|
|
throw new Error(meta.message + '\n' + meta.stack)
|
2016-01-12 02:40:23 +00:00
|
|
|
default:
|
2016-03-29 00:35:49 +00:00
|
|
|
if (remoteObjectCache.has(meta.id)) return remoteObjectCache.get(meta.id)
|
2016-02-22 02:52:21 +00:00
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
if (meta.type === 'function') {
|
2016-01-14 18:35:29 +00:00
|
|
|
// A shadow class to represent the remote function object.
|
2016-03-25 19:57:17 +00:00
|
|
|
let remoteFunction = function () {
|
2016-02-22 02:52:21 +00:00
|
|
|
if (this && this.constructor === remoteFunction) {
|
|
|
|
// Constructor call.
|
2016-04-06 23:21:26 +00:00
|
|
|
let obj = ipcRenderer.sendSync('ELECTRON_BROWSER_CONSTRUCTOR', meta.id, wrapArgs(arguments))
|
2016-02-22 02:52:21 +00:00
|
|
|
// Returning object in constructor will replace constructed object
|
|
|
|
// with the returned object.
|
|
|
|
// http://stackoverflow.com/questions/1978049/what-values-can-a-constructor-return-to-avoid-returning-this
|
2016-03-25 19:57:17 +00:00
|
|
|
return metaToValue(obj)
|
2016-02-22 02:52:21 +00:00
|
|
|
} else {
|
|
|
|
// Function call.
|
2016-04-06 23:21:26 +00:00
|
|
|
let obj = ipcRenderer.sendSync('ELECTRON_BROWSER_FUNCTION_CALL', meta.id, wrapArgs(arguments))
|
2016-03-25 19:57:17 +00:00
|
|
|
return metaToValue(obj)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
|
|
|
ret = remoteFunction
|
2016-01-12 02:40:23 +00:00
|
|
|
} else {
|
2016-03-25 19:57:17 +00:00
|
|
|
ret = {}
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2016-02-22 02:52:21 +00:00
|
|
|
// Populate delegate members.
|
2016-04-01 06:45:36 +00:00
|
|
|
setObjectMembers(ret, ret, meta.id, meta.members)
|
2016-02-22 02:52:21 +00:00
|
|
|
// Populate delegate prototype.
|
2016-04-01 06:45:36 +00:00
|
|
|
setObjectPrototype(ret, ret, meta.id, meta.proto)
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-02-22 02:52:21 +00:00
|
|
|
// Set constructor.name to object's name.
|
2016-03-25 19:57:17 +00:00
|
|
|
Object.defineProperty(ret.constructor, 'name', { value: meta.name })
|
2016-02-17 07:57:46 +00:00
|
|
|
|
2016-01-14 19:10:12 +00:00
|
|
|
// Track delegate object's life time, and tell the browser to clean up
|
|
|
|
// when the object is GCed.
|
2016-04-26 07:10:27 +00:00
|
|
|
v8Util.setRemoteObjectFreer(ret, meta.id)
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Remember object's id.
|
2016-03-25 19:57:17 +00:00
|
|
|
v8Util.setHiddenValue(ret, 'atomId', meta.id)
|
|
|
|
remoteObjectCache.set(meta.id, ret)
|
|
|
|
return ret
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Construct a plain object from the meta.
|
2016-07-11 17:28:01 +00:00
|
|
|
const metaToPlainObject = function (meta) {
|
2016-03-25 19:57:17 +00:00
|
|
|
var i, len, obj, ref1
|
|
|
|
obj = (function () {
|
2016-01-12 02:40:23 +00:00
|
|
|
switch (meta.type) {
|
|
|
|
case 'error':
|
2016-03-29 00:35:49 +00:00
|
|
|
return new Error()
|
2016-01-12 02:40:23 +00:00
|
|
|
default:
|
2016-03-25 19:57:17 +00:00
|
|
|
return {}
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
})()
|
|
|
|
ref1 = meta.members
|
2016-01-12 02:40:23 +00:00
|
|
|
for (i = 0, len = ref1.length; i < len; i++) {
|
2016-03-25 19:57:17 +00:00
|
|
|
let {name, value} = ref1[i]
|
|
|
|
obj[name] = value
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
return obj
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Browser calls a callback in renderer.
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcRenderer.on('ELECTRON_RENDERER_CALLBACK', function (event, id, args) {
|
2016-05-19 22:28:08 +00:00
|
|
|
callbacksRegistry.apply(id, metaToValue(args))
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// A callback in browser is released.
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcRenderer.on('ELECTRON_RENDERER_RELEASE_CALLBACK', function (event, id) {
|
2016-05-19 22:28:08 +00:00
|
|
|
callbacksRegistry.remove(id)
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// List all built-in modules in browser process.
|
2016-03-25 19:57:17 +00:00
|
|
|
const browserModules = require('../../browser/api/exports/electron')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// And add a helper receiver for each one.
|
2016-05-18 04:55:48 +00:00
|
|
|
for (let name of Object.getOwnPropertyNames(browserModules)) {
|
|
|
|
Object.defineProperty(exports, name, {
|
2016-03-25 19:57:17 +00:00
|
|
|
get: function () {
|
|
|
|
return exports.getBuiltin(name)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 19:10:12 +00:00
|
|
|
// Get remote module.
|
2016-03-25 19:57:17 +00:00
|
|
|
exports.require = function (module) {
|
2016-04-06 23:21:26 +00:00
|
|
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_REQUIRE', module))
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Alias to remote.require('electron').xxx.
|
2016-03-25 19:57:17 +00:00
|
|
|
exports.getBuiltin = function (module) {
|
2016-04-06 23:21:26 +00:00
|
|
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_GET_BUILTIN', module))
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-02-22 04:26:41 +00:00
|
|
|
// Get current BrowserWindow.
|
2016-03-25 19:57:17 +00:00
|
|
|
exports.getCurrentWindow = function () {
|
2016-04-06 23:21:26 +00:00
|
|
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WINDOW'))
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Get current WebContents object.
|
2016-03-25 19:57:17 +00:00
|
|
|
exports.getCurrentWebContents = function () {
|
2016-04-06 23:21:26 +00:00
|
|
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WEB_CONTENTS'))
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Get a global object in browser.
|
2016-03-25 19:57:17 +00:00
|
|
|
exports.getGlobal = function (name) {
|
2016-04-06 23:21:26 +00:00
|
|
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_GLOBAL', name))
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Get the process object in browser.
|
2016-03-25 19:57:17 +00:00
|
|
|
exports.__defineGetter__('process', function () {
|
|
|
|
return exports.getGlobal('process')
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Create a funtion that will return the specifed value when called in browser.
|
2016-03-25 19:57:17 +00:00
|
|
|
exports.createFunctionWithReturnValue = function (returnValue) {
|
2016-07-11 17:28:01 +00:00
|
|
|
const func = function () {
|
2016-03-25 19:57:17 +00:00
|
|
|
return returnValue
|
|
|
|
}
|
|
|
|
v8Util.setHiddenValue(func, 'returnValue', true)
|
|
|
|
return func
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Get the guest WebContents from guestInstanceId.
|
2016-03-25 19:57:17 +00:00
|
|
|
exports.getGuestWebContents = function (guestInstanceId) {
|
2016-07-11 17:28:01 +00:00
|
|
|
const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId)
|
2016-03-25 19:57:17 +00:00
|
|
|
return metaToValue(meta)
|
|
|
|
}
|