Deprecate ipc module for ipcRenderer
This commit is contained in:
parent
bd1f6e2edf
commit
828d911ed1
4 changed files with 32 additions and 14 deletions
16
atom/renderer/api/lib/ipc-renderer.coffee
Normal file
16
atom/renderer/api/lib/ipc-renderer.coffee
Normal file
|
@ -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
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -142,7 +142,10 @@ void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel,
|
|||
|
||||
v8::Local<v8::Object> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue