From: Cheng Zhao Date: Tue, 30 Apr 2013 08:27:14 +0000 (+0800) Subject: Add API to get any global variable from browser. X-Git-Tag: v0.1.0~233 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a06c9b806bc10ff6ad9cad1f58a7e3fe0d34ca2e;p=electron.git Add API to get any global variable from browser. --- diff --git a/browser/atom/rpc_server.coffee b/browser/atom/rpc_server.coffee index 3cb9f741..e431f625 100644 --- a/browser/atom/rpc_server.coffee +++ b/browser/atom/rpc_server.coffee @@ -54,6 +54,12 @@ ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) -> catch e event.result = type: 'error', value: e.message +ipc.on 'ATOM_BROWSER_GLOBAL', (event, processId, routingId, name) -> + try + event.result = new Meta(processId, routingId, global[name]) + catch e + event.result = type: 'error', value: e.message + ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, processId, routingId) -> try windows = objectsRegistry.getAllWindows() diff --git a/renderer/api/lib/remote.coffee b/renderer/api/lib/remote.coffee index 3e10de20..91c8d5b0 100644 --- a/renderer/api/lib/remote.coffee +++ b/renderer/api/lib/remote.coffee @@ -103,3 +103,14 @@ exports.getObject = (id) -> exports.getCurrentWindow = -> meta = ipc.sendChannelSync 'ATOM_BROWSER_CURRENT_WINDOW' metaToValue meta + +# Get a global object in browser. +exports.getGlobal = (name) -> + meta = ipc.sendChannelSync 'ATOM_BROWSER_GLOBAL', name + metaToValue meta + +# Get the process object in browser. +processCache = null +exports.__defineGetter__ 'process', -> + processCache = exports.getGlobal('process') unless processCache? + processCache