Use ipcRenderer in Electron's code
This commit is contained in:
parent
828d911ed1
commit
6515a445a0
20 changed files with 32 additions and 34 deletions
|
@ -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.
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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) ->
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
2
spec/fixtures/api/localstorage.html
vendored
2
spec/fixtures/api/localstorage.html
vendored
|
@ -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);
|
||||
})
|
||||
|
|
2
spec/fixtures/api/preload.html
vendored
2
spec/fixtures/api/preload.html
vendored
|
@ -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>
|
||||
|
|
2
spec/fixtures/api/send-sync-message.html
vendored
2
spec/fixtures/api/send-sync-message.html
vendored
|
@ -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>
|
||||
|
|
4
spec/fixtures/module/preload-ipc.js
vendored
4
spec/fixtures/module/preload-ipc.js
vendored
|
@ -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);
|
||||
});
|
||||
|
|
2
spec/fixtures/module/send-later.js
vendored
2
spec/fixtures/module/send-later.js
vendored
|
@ -1,4 +1,4 @@
|
|||
var ipc = require('ipc');
|
||||
var ipc = require('ipc-renderer');
|
||||
window.onload = function() {
|
||||
ipc.send('answer', typeof window.process);
|
||||
}
|
||||
|
|
2
spec/fixtures/pages/basic-auth.html
vendored
2
spec/fixtures/pages/basic-auth.html
vendored
|
@ -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",
|
||||
|
|
2
spec/fixtures/pages/beforeunload-false.html
vendored
2
spec/fixtures/pages/beforeunload-false.html
vendored
|
@ -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;
|
||||
|
|
2
spec/fixtures/pages/document-hidden.html
vendored
2
spec/fixtures/pages/document-hidden.html
vendored
|
@ -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>
|
||||
|
|
2
spec/fixtures/pages/history.html
vendored
2
spec/fixtures/pages/history.html
vendored
|
@ -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>
|
||||
|
|
2
spec/fixtures/pages/ipc-message.html
vendored
2
spec/fixtures/pages/ipc-message.html
vendored
|
@ -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>
|
||||
|
|
2
spec/fixtures/pages/onkeyup.html
vendored
2
spec/fixtures/pages/onkeyup.html
vendored
|
@ -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>
|
||||
|
|
2
spec/fixtures/pages/onmouseup.html
vendored
2
spec/fixtures/pages/onmouseup.html
vendored
|
@ -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>
|
||||
|
|
2
spec/fixtures/pages/window-opener.html
vendored
2
spec/fixtures/pages/window-opener.html
vendored
|
@ -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>
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue