From 6515a445a0175102ab4e34be66723b9cd9cf6fd8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Nov 2015 15:29:43 +0800 Subject: [PATCH] Use ipcRenderer in Electron's code --- atom/renderer/api/lib/remote.coffee | 6 +++--- atom/renderer/lib/override.coffee | 6 +++--- atom/renderer/lib/web-view/guest-view-internal.coffee | 10 +++++----- atom/renderer/lib/web-view/web-view.coffee | 2 +- spec/api-ipc-spec.coffee | 4 ++-- spec/api-session-spec.coffee | 8 +++----- spec/fixtures/api/localstorage.html | 2 +- spec/fixtures/api/preload.html | 2 +- spec/fixtures/api/send-sync-message.html | 2 +- spec/fixtures/module/preload-ipc.js | 4 ++-- spec/fixtures/module/send-later.js | 2 +- spec/fixtures/pages/basic-auth.html | 2 +- spec/fixtures/pages/beforeunload-false.html | 2 +- spec/fixtures/pages/document-hidden.html | 2 +- spec/fixtures/pages/history.html | 2 +- spec/fixtures/pages/ipc-message.html | 2 +- spec/fixtures/pages/onkeyup.html | 2 +- spec/fixtures/pages/onmouseup.html | 2 +- spec/fixtures/pages/window-opener.html | 2 +- spec/static/index.html | 2 +- 20 files changed, 32 insertions(+), 34 deletions(-) diff --git a/atom/renderer/api/lib/remote.coffee b/atom/renderer/api/lib/remote.coffee index 2de14d54152..5d5905ba24a 100644 --- a/atom/renderer/api/lib/remote.coffee +++ b/atom/renderer/api/lib/remote.coffee @@ -1,4 +1,4 @@ -ipc = require 'ipc' +ipc = require 'ipc-renderer' v8Util = process.atomBinding 'v8_util' CallbacksRegistry = require 'callbacks-registry' @@ -119,11 +119,11 @@ metaToPlainObject = (meta) -> obj # Browser calls a callback in renderer. -ipc.on 'ATOM_RENDERER_CALLBACK', (id, args) -> +ipc.on 'ATOM_RENDERER_CALLBACK', (event, id, args) -> callbacksRegistry.apply id, metaToValue(args) # A callback in browser is released. -ipc.on 'ATOM_RENDERER_RELEASE_CALLBACK', (id) -> +ipc.on 'ATOM_RENDERER_RELEASE_CALLBACK', (event, id) -> callbacksRegistry.remove id # Get remote module. diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index 93cf8b8357e..e54a0e9685c 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -1,4 +1,4 @@ -ipc = require 'ipc' +ipc = require 'ipc-renderer' remote = require 'remote' # Helper function to resolve relative url. @@ -11,7 +11,7 @@ resolveUrl = (url) -> class BrowserWindowProxy constructor: (@guestId) -> @closed = false - ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', (guestId) => + ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', (event, guestId) => if guestId is @guestId @closed = true @@ -99,7 +99,7 @@ if guestId? postMessage: (message, targetOrigin='*') -> ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', guestId, message, targetOrigin, location.origin -ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (guestId, message, sourceOrigin) -> +ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, guestId, message, sourceOrigin) -> # Manually dispatch event instead of using postMessage because we also need to # set event.source. event = document.createEvent 'Event' diff --git a/atom/renderer/lib/web-view/guest-view-internal.coffee b/atom/renderer/lib/web-view/guest-view-internal.coffee index 2852d112287..37dc25f9ee0 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.coffee +++ b/atom/renderer/lib/web-view/guest-view-internal.coffee @@ -1,4 +1,4 @@ -ipc = require 'ipc' +ipc = require 'ipc-renderer' webFrame = require 'web-frame' requestId = 0 @@ -37,16 +37,16 @@ dispatchEvent = (webView, event, args...) -> module.exports = registerEvents: (webView, viewInstanceId) -> - ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, args...) -> - dispatchEvent webView, event, args... + ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, domEvent, args...) -> + dispatchEvent webView, domEvent, args... - ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}", (channel, args...) -> + ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}", (event, channel, args...) -> domEvent = new Event('ipc-message') domEvent.channel = channel domEvent.args = [args...] webView.dispatchEvent domEvent - ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}", (args...) -> + ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}", (event, args...) -> domEvent = new Event('size-changed') for f, i in ['oldWidth', 'oldHeight', 'newWidth', 'newHeight'] domEvent[f] = args[i] diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index 3a563101f00..3dc54b258d5 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -135,7 +135,7 @@ class WebViewImpl guestViewInternal.setSize @guestInstanceId, normal: newSize createGuest: -> - guestViewInternal.createGuest @buildParams(), (guestInstanceId) => + guestViewInternal.createGuest @buildParams(), (event, guestInstanceId) => @attachWindow guestInstanceId dispatchEvent: (webViewEvent) -> diff --git a/spec/api-ipc-spec.coffee b/spec/api-ipc-spec.coffee index 1155aa73e83..e5028c602b1 100644 --- a/spec/api-ipc-spec.coffee +++ b/spec/api-ipc-spec.coffee @@ -1,5 +1,5 @@ assert = require 'assert' -ipc = require 'ipc' +ipc = require 'ipc-renderer' path = require 'path' remote = require 'remote' @@ -70,7 +70,7 @@ describe 'ipc module', -> describe 'ipc.sender.send', -> it 'should work when sending an object containing id property', (done) -> obj = id: 1, name: 'ly' - ipc.once 'message', (message) -> + ipc.once 'message', (event, message) -> assert.deepEqual message, obj done() ipc.send 'message', obj diff --git a/spec/api-session-spec.coffee b/spec/api-session-spec.coffee index 9e083d27c0f..8baca1557cc 100644 --- a/spec/api-session-spec.coffee +++ b/spec/api-session-spec.coffee @@ -78,7 +78,7 @@ describe 'session module', -> # A 5 MB mock pdf. mockPDF = new Buffer 1024 * 1024 * 5 contentDisposition = 'inline; filename="mock.pdf"' - ipc = require 'ipc' + ipc = require 'ipc-renderer' downloadFilePath = path.join fixtures, 'mock.pdf' downloadServer = http.createServer (req, res) -> res.writeHead 200, { @@ -94,8 +94,7 @@ describe 'session module', -> {port} = downloadServer.address() ipc.sendSync 'set-download-option', false w.loadUrl "#{url}:#{port}" - ipc.once 'download-done', (state, url, mimeType, receivedBytes, - totalBytes, disposition, filename) -> + ipc.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) -> assert.equal state, 'completed' assert.equal filename, 'mock.pdf' assert.equal url, "http://127.0.0.1:#{port}/" @@ -112,8 +111,7 @@ describe 'session module', -> {port} = downloadServer.address() ipc.sendSync 'set-download-option', true w.loadUrl "#{url}:#{port}/" - ipc.once 'download-done', (state, url, mimeType, receivedBytes, - totalBytes, disposition, filename) -> + ipc.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) -> assert.equal state, 'cancelled' assert.equal filename, 'mock.pdf' assert.equal mimeType, 'application/pdf' diff --git a/spec/fixtures/api/localstorage.html b/spec/fixtures/api/localstorage.html index 8110a0b4be6..d1450e93c98 100644 --- a/spec/fixtures/api/localstorage.html +++ b/spec/fixtures/api/localstorage.html @@ -2,7 +2,7 @@ diff --git a/spec/fixtures/api/send-sync-message.html b/spec/fixtures/api/send-sync-message.html index d6fe83f907e..40bae94b810 100644 --- a/spec/fixtures/api/send-sync-message.html +++ b/spec/fixtures/api/send-sync-message.html @@ -1,7 +1,7 @@ diff --git a/spec/fixtures/module/preload-ipc.js b/spec/fixtures/module/preload-ipc.js index 9b6e0201248..76bd481cab6 100644 --- a/spec/fixtures/module/preload-ipc.js +++ b/spec/fixtures/module/preload-ipc.js @@ -1,4 +1,4 @@ -var ipc = require('ipc'); -ipc.on('ping', function(message) { +var ipc = require('ipc-renderer'); +ipc.on('ping', function(event, message) { ipc.sendToHost('pong', message); }); diff --git a/spec/fixtures/module/send-later.js b/spec/fixtures/module/send-later.js index fce96b84b78..9cd5bfd3885 100644 --- a/spec/fixtures/module/send-later.js +++ b/spec/fixtures/module/send-later.js @@ -1,4 +1,4 @@ -var ipc = require('ipc'); +var ipc = require('ipc-renderer'); window.onload = function() { ipc.send('answer', typeof window.process); } diff --git a/spec/fixtures/pages/basic-auth.html b/spec/fixtures/pages/basic-auth.html index aa95546a9c1..f2b9fab199f 100644 --- a/spec/fixtures/pages/basic-auth.html +++ b/spec/fixtures/pages/basic-auth.html @@ -2,7 +2,7 @@ diff --git a/spec/fixtures/pages/history.html b/spec/fixtures/pages/history.html index b5029d63892..ef008353597 100644 --- a/spec/fixtures/pages/history.html +++ b/spec/fixtures/pages/history.html @@ -2,7 +2,7 @@ diff --git a/spec/fixtures/pages/ipc-message.html b/spec/fixtures/pages/ipc-message.html index 15bfef49c4d..65e347275c2 100644 --- a/spec/fixtures/pages/ipc-message.html +++ b/spec/fixtures/pages/ipc-message.html @@ -1,7 +1,7 @@ diff --git a/spec/fixtures/pages/onkeyup.html b/spec/fixtures/pages/onkeyup.html index 99e6c3e9838..87e6dc596b5 100644 --- a/spec/fixtures/pages/onkeyup.html +++ b/spec/fixtures/pages/onkeyup.html @@ -2,7 +2,7 @@ diff --git a/spec/fixtures/pages/onmouseup.html b/spec/fixtures/pages/onmouseup.html index 1fd38bc7211..ea486fdf80e 100644 --- a/spec/fixtures/pages/onmouseup.html +++ b/spec/fixtures/pages/onmouseup.html @@ -2,7 +2,7 @@ diff --git a/spec/fixtures/pages/window-opener.html b/spec/fixtures/pages/window-opener.html index 226b57dbd70..a7b59bd1a45 100644 --- a/spec/fixtures/pages/window-opener.html +++ b/spec/fixtures/pages/window-opener.html @@ -4,7 +4,7 @@ if (window.opener !== null) window.opener.postMessage(typeof window.opener, '*'); else - require('ipc').send('opener', window.opener); + require('ipc-renderer').send('opener', window.opener); diff --git a/spec/static/index.html b/spec/static/index.html index 879d769860e..e7c69f5ba7d 100644 --- a/spec/static/index.html +++ b/spec/static/index.html @@ -29,7 +29,7 @@ } require('coffee-script/register'); // Supports .coffee tests. - var ipc = require('ipc'); + var ipc = require('ipc-renderer'); // Rediret all output to browser. if (isCi) {