diff --git a/atom/renderer/api/lib/ipc-renderer.coffee b/atom/renderer/api/lib/ipc-renderer.coffee new file mode 100644 index 000000000000..29004d212b56 --- /dev/null +++ b/atom/renderer/api/lib/ipc-renderer.coffee @@ -0,0 +1,16 @@ +binding = process.atomBinding 'ipc' +v8Util = process.atomBinding 'v8_util' + +# Created by init.coffee. +ipcRenderer = v8Util.getHiddenValue global, 'ipc' + +ipcRenderer.send = (args...) -> + binding.send 'ipc-message', [args...] + +ipcRenderer.sendSync = (args...) -> + JSON.parse binding.sendSync('ipc-message-sync', [args...]) + +ipcRenderer.sendToHost = (args...) -> + binding.send 'ipc-message-host', [args...] + +module.exports = ipcRenderer diff --git a/atom/renderer/api/lib/ipc.coffee b/atom/renderer/api/lib/ipc.coffee index 01eeb4b6da14..e2fcdcd86e8a 100644 --- a/atom/renderer/api/lib/ipc.coffee +++ b/atom/renderer/api/lib/ipc.coffee @@ -1,21 +1,19 @@ deprecate = require 'deprecate' +ipcRenderer = require 'ipc-renderer' +{EventEmitter} = require 'events' -binding = process.atomBinding 'ipc' -v8Util = process.atomBinding 'v8_util' +# This module is deprecated, we mirror everything from ipcRenderer. +deprecate.warn 'ipc module', 'ipcRenderer module' -# Created by init.coffee. -ipc = v8Util.getHiddenValue global, 'ipc' - -ipc.send = (args...) -> - binding.send 'ipc-message', [args...] - -ipc.sendSync = (args...) -> - JSON.parse binding.sendSync('ipc-message-sync', [args...]) - -ipc.sendToHost = (args...) -> - binding.send 'ipc-message-host', [args...] +# Routes events of ipcRenderer. +ipc = new EventEmitter +ipcRenderer.emit = (channel, event, args...) -> + ipc.emit channel, args... + EventEmitter::emit.apply ipcRenderer, arguments # Deprecated. +for method of ipcRenderer when method.startsWith 'send' + ipc[method] = ipcRenderer[method] deprecate.rename ipc, 'sendChannel', 'send' deprecate.rename ipc, 'sendChannelSync', 'sendSync' diff --git a/atom/renderer/atom_render_view_observer.cc b/atom/renderer/atom_render_view_observer.cc index 456ca5ba4b24..ecd9401420f8 100644 --- a/atom/renderer/atom_render_view_observer.cc +++ b/atom/renderer/atom_render_view_observer.cc @@ -142,7 +142,10 @@ void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel, v8::Local ipc; if (GetIPCObject(isolate, context, &ipc)) { - mate::EmitEvent(isolate, ipc, channel, ListValueToVector(isolate, args)); + auto args_vector = ListValueToVector(isolate, args); + // Insert a dummy Event object. + args_vector.insert(args_vector.begin(), v8::Object::New(isolate)); + mate::EmitEvent(isolate, ipc, channel, args_vector); } } diff --git a/filenames.gypi b/filenames.gypi index fe05c34c3422..93cb4f3e07aa 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -50,6 +50,7 @@ 'atom/renderer/lib/web-view/web-view-attributes.coffee', 'atom/renderer/lib/web-view/web-view-constants.coffee', 'atom/renderer/api/lib/ipc.coffee', + 'atom/renderer/api/lib/ipc-renderer.coffee', 'atom/renderer/api/lib/remote.coffee', 'atom/renderer/api/lib/screen.coffee', 'atom/renderer/api/lib/web-frame.coffee',