Don't rely on the global process object for message dispatching
This commit is contained in:
parent
c14c6a3521
commit
a10782cdea
3 changed files with 27 additions and 25 deletions
|
@ -1,26 +1,23 @@
|
||||||
EventEmitter = require('events').EventEmitter
|
binding = process.atomBinding 'ipc'
|
||||||
process = global.process
|
v8Util = process.atomBinding 'v8_util'
|
||||||
ipc = process.atomBinding('ipc')
|
|
||||||
|
|
||||||
class Ipc extends EventEmitter
|
# Created by init.coffee.
|
||||||
constructor: ->
|
ipc = v8Util.getHiddenValue global, 'ipc'
|
||||||
process.on 'ATOM_INTERNAL_MESSAGE', (args...) =>
|
|
||||||
@emit args...
|
|
||||||
|
|
||||||
window.addEventListener 'unload', (event) ->
|
ipc.on 'ATOM_INTERNAL_MESSAGE', (args...) ->
|
||||||
process.removeAllListeners 'ATOM_INTERNAL_MESSAGE'
|
@emit args...
|
||||||
|
|
||||||
send: (args...) ->
|
ipc.send = (args...) ->
|
||||||
ipc.send 'ipc-message', [args...]
|
binding.send 'ipc-message', [args...]
|
||||||
|
|
||||||
sendSync: (args...) ->
|
ipc.sendSync = (args...) ->
|
||||||
JSON.parse ipc.sendSync('ipc-message-sync', [args...])
|
JSON.parse binding.sendSync('ipc-message-sync', [args...])
|
||||||
|
|
||||||
sendToHost: (args...) ->
|
ipc.sendToHost = (args...) ->
|
||||||
ipc.send 'ipc-message-host', [args...]
|
binding.send 'ipc-message-host', [args...]
|
||||||
|
|
||||||
# Discarded
|
# Deprecated.
|
||||||
sendChannel: -> @send.apply this, arguments
|
ipc.sendChannel = ipc.send
|
||||||
sendChannelSync: -> @sendSync.apply this, arguments
|
ipc.sendChannelSync = ipc.sendSync
|
||||||
|
|
||||||
module.exports = new Ipc
|
module.exports = ipc
|
||||||
|
|
|
@ -29,10 +29,10 @@ namespace atom {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
v8::Handle<v8::Object> GetProcessObject(v8::Isolate* isolate,
|
v8::Handle<v8::Object> GetIPCObject(v8::Isolate* isolate,
|
||||||
v8::Handle<v8::Context> context) {
|
v8::Handle<v8::Context> context) {
|
||||||
v8::Handle<v8::String> key = mate::StringToV8(isolate, "process");
|
v8::Handle<v8::String> key = mate::StringToV8(isolate, "ipc");
|
||||||
return context->Global()->Get(key)->ToObject();
|
return context->Global()->GetHiddenValue(key)->ToObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<v8::Handle<v8::Value>> ListValueToVector(
|
std::vector<v8::Handle<v8::Value>> ListValueToVector(
|
||||||
|
@ -118,8 +118,8 @@ void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel,
|
||||||
isolate, args);
|
isolate, args);
|
||||||
arguments.insert(arguments.begin(), mate::ConvertToV8(isolate, channel));
|
arguments.insert(arguments.begin(), mate::ConvertToV8(isolate, channel));
|
||||||
|
|
||||||
v8::Handle<v8::Object> process = GetProcessObject(isolate, context);
|
v8::Handle<v8::Object> ipc = GetIPCObject(isolate, context);
|
||||||
node::MakeCallback(isolate, process, "emit", arguments.size(), &arguments[0]);
|
node::MakeCallback(isolate, ipc, "emit", arguments.size(), &arguments[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
process = global.process
|
process = global.process
|
||||||
|
events = require 'events'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
url = require 'url'
|
url = require 'url'
|
||||||
Module = require 'module'
|
Module = require 'module'
|
||||||
|
@ -21,6 +22,10 @@ globalPaths.push path.join(process.resourcesPath, 'app')
|
||||||
# Import common settings.
|
# Import common settings.
|
||||||
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init')
|
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init')
|
||||||
|
|
||||||
|
# The global variable will be used by ipc for event dispatching
|
||||||
|
v8Util = process.atomBinding 'v8_util'
|
||||||
|
v8Util.setHiddenValue global, 'ipc', new events.EventEmitter
|
||||||
|
|
||||||
# Process command line arguments.
|
# Process command line arguments.
|
||||||
nodeIntegration = 'false'
|
nodeIntegration = 'false'
|
||||||
for arg in process.argv
|
for arg in process.argv
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue