Use ipcRenderer in Electron's code

This commit is contained in:
Cheng Zhao 2015-11-10 15:29:43 +08:00
parent 828d911ed1
commit 6515a445a0
20 changed files with 32 additions and 34 deletions

View file

@ -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.

View file

@ -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'

View file

@ -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]

View file

@ -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) ->

View file

@ -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

View file

@ -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'

View file

@ -2,7 +2,7 @@
<body>
<script type="text/javascript" charset="utf-8">
window.localStorage.setItem('test', 'test');
var ipc = require('ipc');
var ipc = require('ipc-renderer');
ipc.on('getcount', function() {
ipc.send('count', window.localStorage.length);
})

View file

@ -3,7 +3,7 @@
<script type="text/javascript" charset="utf-8">
if (!window.test)
window.test = 'window'
require('ipc').send('answer', window.test);
require('ipc-renderer').send('answer', window.test);
</script>
</body>
</html>

View file

@ -1,7 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
var ipc = require('ipc');
var ipc = require('ipc-renderer');
ipc.sendSync('send-sync-message', 'message');
</script>
</body>

View file

@ -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);
});

View file

@ -1,4 +1,4 @@
var ipc = require('ipc');
var ipc = require('ipc-renderer');
window.onload = function() {
ipc.send('answer', typeof window.process);
}

View file

@ -2,7 +2,7 @@
<body>
<script src="../../static/jquery-2.0.3.min.js"></script>
<script type="text/javascript" charset="utf-8">
var ipc = require('ipc');
var ipc = require('ipc-renderer');
var port = location.search.substr("?port=".length);
$.ajax({
type: "GET",

View file

@ -3,7 +3,7 @@
<script type="text/javascript" charset="utf-8">
window.onbeforeunload = function() {
setTimeout(function() {
var ipc = require('ipc');
var ipc = require('ipc-renderer');
ipc.sendToHost('onbeforeunload');
}, 0);
return false;

View file

@ -1,7 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
require('ipc').send('hidden', document.hidden);
require('ipc-renderer').send('hidden', document.hidden);
</script>
</body>
</html>

View file

@ -2,7 +2,7 @@
<body>
<script type="text/javascript" charset="utf-8">
window.history.pushState(window.history.state, "test page", "foo.html")
require('ipc').sendToHost('history', window.history.length);
require('ipc-renderer').sendToHost('history', window.history.length);
</script>
</body>
</html>

View file

@ -1,7 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
require('ipc').sendToHost('channel', 'arg1', 'arg2');
require('ipc-renderer').sendToHost('channel', 'arg1', 'arg2');
</script>
</body>
</html>

View file

@ -2,7 +2,7 @@
<body>
<script type="text/javascript" charset="utf-8">
document.onkeyup = function(e) {
require('ipc').sendToHost('keyup', e.keyCode, e.shiftKey, e.ctrlKey);
require('ipc-renderer').sendToHost('keyup', e.keyCode, e.shiftKey, e.ctrlKey);
}
</script>
</body>

View file

@ -2,7 +2,7 @@
<body>
<script type="text/javascript" charset="utf-8">
document.onmouseup = function(e) {
require('ipc').sendToHost('mouseup', e.x, e.y, e.shiftKey, e.ctrlKey);
require('ipc-renderer').sendToHost('mouseup', e.x, e.y, e.shiftKey, e.ctrlKey);
}
</script>
</body>

View file

@ -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);
</script>
</body>
</html>

View file

@ -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) {