]> khamidou — GitHub mirrors - electron.git/commitdiff
Add sendToHost method
authorCheng Zhao <zcbenz@gmail.com>
Wed, 17 Dec 2014 19:09:11 +0000 (11:09 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 17 Dec 2014 19:09:11 +0000 (11:09 -0800)
atom/browser/lib/guest-view-manager.coffee
atom/renderer/api/lib/ipc.coffee
docs/api/ipc-renderer.md
docs/api/web-view-tag.md
spec/fixtures/pages/ipc-message.html

index bc2f5b81ee0bbeb1d541382ed15c5ff888d1a4d5..bbabf3c5d6f4d5730a24ac200c41becf5a941f67 100644 (file)
@@ -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.
index cf9e7af18aed24c9e4473b1be5290b9c8bf3ca25..1dfb9b408334cfbdbb2d839f5d605a5fbcfe71d3 100644 (file)
@@ -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
index b5f1157e6375c9514d682377e2f164260a10fadd..54dd3488817deaa3552fadb18bd342880c905175 100644 (file)
@@ -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 `<webview>` to communicate with host page.
index b13bf2a7d61a44e7a2334dc03bb7752cf3290c7b..bde67ed960a3f376aaf00555aebc063c7df18403 100644 (file)
@@ -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');
 })
 ```
 
index a54973c280dc0ba20b3d9292af5ede1779983fc1..15bfef49c4da9d0ca94ad83dc582479994781cfc 100644 (file)
@@ -1,7 +1,7 @@
 <html>
 <body>
 <script type="text/javascript" charset="utf-8">
-  require('ipc').send('channel', 'arg1', 'arg2');
+  require('ipc').sendToHost('channel', 'arg1', 'arg2');
 </script>
 </body>
 </html>