diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index bc2f5b81ee0b..bbabf3c5d6f4 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -66,8 +66,8 @@ createGuest = (embedder, params) -> guest.on event, (_, args...) -> embedder.send "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{guest.viewInstanceId}", event, args... - # Dispatch guest's asynchronous IPC messages to embedder. - guest.on 'ipc-message', (_, channel, args...) -> + # Dispatch guest's IPC messages to embedder. + guest.on 'ipc-message-host', (_, channel, args...) -> embedder.send "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{guest.viewInstanceId}", channel, args... # Autosize. diff --git a/atom/renderer/api/lib/ipc.coffee b/atom/renderer/api/lib/ipc.coffee index cf9e7af18aed..1dfb9b408334 100644 --- a/atom/renderer/api/lib/ipc.coffee +++ b/atom/renderer/api/lib/ipc.coffee @@ -16,6 +16,9 @@ class Ipc extends EventEmitter sendSync: (args...) -> JSON.parse ipc.sendSync('ipc-message-sync', [args...]) + sendToHost: (args...) -> + ipc.send 'ipc-message-host', [args...] + # Discarded sendChannel: -> @send.apply this, arguments sendChannelSync: -> @sendSync.apply this, arguments diff --git a/docs/api/ipc-renderer.md b/docs/api/ipc-renderer.md index b5f1157e6375..54dd3488817d 100644 --- a/docs/api/ipc-renderer.md +++ b/docs/api/ipc-renderer.md @@ -20,3 +20,10 @@ the `channel` event of `ipc` module, and returns by setting `event.returnValue`. **Note:** Usually developers should never use this API, since sending synchronous message would block the whole web page. + +## ipc.sendToHost(channel[, args...]) + +Like `ipc.send` but the message will be sent to the host page instead of the +browser process. + +This is mainly used by the page in `` to communicate with host page. diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index b13bf2a7d61a..bde67ed960a3 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -311,10 +311,10 @@ webview.addEventListener('close', function() { * `channel` String * `args` Array -Fired when the guest page has sent an asynchronous message to browser process. +Fired when the guest page has sent an asynchronous message to embedder page. -With `send` method and `ipc-message` event you can easily communicate between -guest page and embedder page: +With `sendToHost` method and `ipc-message` event you can easily communicate +between guest page and embedder page: ```javascript // In embedder page. @@ -329,7 +329,7 @@ webview.send('ping'); // In guest page. var ipc = require('ipc'); ipc.on('ping', function() { - ipc.send('pong'); + ipc.sendToHost('pong'); }) ``` diff --git a/spec/fixtures/pages/ipc-message.html b/spec/fixtures/pages/ipc-message.html index a54973c280dc..15bfef49c4da 100644 --- a/spec/fixtures/pages/ipc-message.html +++ b/spec/fixtures/pages/ipc-message.html @@ -1,7 +1,7 @@