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'
|
v8Util = process.atomBinding 'v8_util'
|
||||||
CallbacksRegistry = require 'callbacks-registry'
|
CallbacksRegistry = require 'callbacks-registry'
|
||||||
|
|
||||||
|
@ -119,11 +119,11 @@ metaToPlainObject = (meta) ->
|
||||||
obj
|
obj
|
||||||
|
|
||||||
# Browser calls a callback in renderer.
|
# 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)
|
callbacksRegistry.apply id, metaToValue(args)
|
||||||
|
|
||||||
# A callback in browser is released.
|
# A callback in browser is released.
|
||||||
ipc.on 'ATOM_RENDERER_RELEASE_CALLBACK', (id) ->
|
ipc.on 'ATOM_RENDERER_RELEASE_CALLBACK', (event, id) ->
|
||||||
callbacksRegistry.remove id
|
callbacksRegistry.remove id
|
||||||
|
|
||||||
# Get remote module.
|
# Get remote module.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc-renderer'
|
||||||
remote = require 'remote'
|
remote = require 'remote'
|
||||||
|
|
||||||
# Helper function to resolve relative url.
|
# Helper function to resolve relative url.
|
||||||
|
@ -11,7 +11,7 @@ resolveUrl = (url) ->
|
||||||
class BrowserWindowProxy
|
class BrowserWindowProxy
|
||||||
constructor: (@guestId) ->
|
constructor: (@guestId) ->
|
||||||
@closed = false
|
@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
|
if guestId is @guestId
|
||||||
@closed = true
|
@closed = true
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ if guestId?
|
||||||
postMessage: (message, targetOrigin='*') ->
|
postMessage: (message, targetOrigin='*') ->
|
||||||
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', guestId, message, targetOrigin, location.origin
|
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
|
# Manually dispatch event instead of using postMessage because we also need to
|
||||||
# set event.source.
|
# set event.source.
|
||||||
event = document.createEvent 'Event'
|
event = document.createEvent 'Event'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc-renderer'
|
||||||
webFrame = require 'web-frame'
|
webFrame = require 'web-frame'
|
||||||
|
|
||||||
requestId = 0
|
requestId = 0
|
||||||
|
@ -37,16 +37,16 @@ dispatchEvent = (webView, event, args...) ->
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
registerEvents: (webView, viewInstanceId) ->
|
registerEvents: (webView, viewInstanceId) ->
|
||||||
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, args...) ->
|
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, domEvent, args...) ->
|
||||||
dispatchEvent webView, event, 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 = new Event('ipc-message')
|
||||||
domEvent.channel = channel
|
domEvent.channel = channel
|
||||||
domEvent.args = [args...]
|
domEvent.args = [args...]
|
||||||
webView.dispatchEvent domEvent
|
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')
|
domEvent = new Event('size-changed')
|
||||||
for f, i in ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
|
for f, i in ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
|
||||||
domEvent[f] = args[i]
|
domEvent[f] = args[i]
|
||||||
|
|
|
@ -135,7 +135,7 @@ class WebViewImpl
|
||||||
guestViewInternal.setSize @guestInstanceId, normal: newSize
|
guestViewInternal.setSize @guestInstanceId, normal: newSize
|
||||||
|
|
||||||
createGuest: ->
|
createGuest: ->
|
||||||
guestViewInternal.createGuest @buildParams(), (guestInstanceId) =>
|
guestViewInternal.createGuest @buildParams(), (event, guestInstanceId) =>
|
||||||
@attachWindow guestInstanceId
|
@attachWindow guestInstanceId
|
||||||
|
|
||||||
dispatchEvent: (webViewEvent) ->
|
dispatchEvent: (webViewEvent) ->
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
assert = require 'assert'
|
assert = require 'assert'
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc-renderer'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
remote = require 'remote'
|
remote = require 'remote'
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ describe 'ipc module', ->
|
||||||
describe 'ipc.sender.send', ->
|
describe 'ipc.sender.send', ->
|
||||||
it 'should work when sending an object containing id property', (done) ->
|
it 'should work when sending an object containing id property', (done) ->
|
||||||
obj = id: 1, name: 'ly'
|
obj = id: 1, name: 'ly'
|
||||||
ipc.once 'message', (message) ->
|
ipc.once 'message', (event, message) ->
|
||||||
assert.deepEqual message, obj
|
assert.deepEqual message, obj
|
||||||
done()
|
done()
|
||||||
ipc.send 'message', obj
|
ipc.send 'message', obj
|
||||||
|
|
|
@ -78,7 +78,7 @@ describe 'session module', ->
|
||||||
# A 5 MB mock pdf.
|
# A 5 MB mock pdf.
|
||||||
mockPDF = new Buffer 1024 * 1024 * 5
|
mockPDF = new Buffer 1024 * 1024 * 5
|
||||||
contentDisposition = 'inline; filename="mock.pdf"'
|
contentDisposition = 'inline; filename="mock.pdf"'
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc-renderer'
|
||||||
downloadFilePath = path.join fixtures, 'mock.pdf'
|
downloadFilePath = path.join fixtures, 'mock.pdf'
|
||||||
downloadServer = http.createServer (req, res) ->
|
downloadServer = http.createServer (req, res) ->
|
||||||
res.writeHead 200, {
|
res.writeHead 200, {
|
||||||
|
@ -94,8 +94,7 @@ describe 'session module', ->
|
||||||
{port} = downloadServer.address()
|
{port} = downloadServer.address()
|
||||||
ipc.sendSync 'set-download-option', false
|
ipc.sendSync 'set-download-option', false
|
||||||
w.loadUrl "#{url}:#{port}"
|
w.loadUrl "#{url}:#{port}"
|
||||||
ipc.once 'download-done', (state, url, mimeType, receivedBytes,
|
ipc.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) ->
|
||||||
totalBytes, disposition, filename) ->
|
|
||||||
assert.equal state, 'completed'
|
assert.equal state, 'completed'
|
||||||
assert.equal filename, 'mock.pdf'
|
assert.equal filename, 'mock.pdf'
|
||||||
assert.equal url, "http://127.0.0.1:#{port}/"
|
assert.equal url, "http://127.0.0.1:#{port}/"
|
||||||
|
@ -112,8 +111,7 @@ describe 'session module', ->
|
||||||
{port} = downloadServer.address()
|
{port} = downloadServer.address()
|
||||||
ipc.sendSync 'set-download-option', true
|
ipc.sendSync 'set-download-option', true
|
||||||
w.loadUrl "#{url}:#{port}/"
|
w.loadUrl "#{url}:#{port}/"
|
||||||
ipc.once 'download-done', (state, url, mimeType, receivedBytes,
|
ipc.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) ->
|
||||||
totalBytes, disposition, filename) ->
|
|
||||||
assert.equal state, 'cancelled'
|
assert.equal state, 'cancelled'
|
||||||
assert.equal filename, 'mock.pdf'
|
assert.equal filename, 'mock.pdf'
|
||||||
assert.equal mimeType, 'application/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>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
window.localStorage.setItem('test', 'test');
|
window.localStorage.setItem('test', 'test');
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc-renderer');
|
||||||
ipc.on('getcount', function() {
|
ipc.on('getcount', function() {
|
||||||
ipc.send('count', window.localStorage.length);
|
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">
|
<script type="text/javascript" charset="utf-8">
|
||||||
if (!window.test)
|
if (!window.test)
|
||||||
window.test = 'window'
|
window.test = 'window'
|
||||||
require('ipc').send('answer', window.test);
|
require('ipc-renderer').send('answer', window.test);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
2
spec/fixtures/api/send-sync-message.html
vendored
2
spec/fixtures/api/send-sync-message.html
vendored
|
@ -1,7 +1,7 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc-renderer');
|
||||||
ipc.sendSync('send-sync-message', 'message');
|
ipc.sendSync('send-sync-message', 'message');
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</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');
|
var ipc = require('ipc-renderer');
|
||||||
ipc.on('ping', function(message) {
|
ipc.on('ping', function(event, message) {
|
||||||
ipc.sendToHost('pong', 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() {
|
window.onload = function() {
|
||||||
ipc.send('answer', typeof window.process);
|
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>
|
<body>
|
||||||
<script src="../../static/jquery-2.0.3.min.js"></script>
|
<script src="../../static/jquery-2.0.3.min.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc-renderer');
|
||||||
var port = location.search.substr("?port=".length);
|
var port = location.search.substr("?port=".length);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
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">
|
<script type="text/javascript" charset="utf-8">
|
||||||
window.onbeforeunload = function() {
|
window.onbeforeunload = function() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc-renderer');
|
||||||
ipc.sendToHost('onbeforeunload');
|
ipc.sendToHost('onbeforeunload');
|
||||||
}, 0);
|
}, 0);
|
||||||
return false;
|
return false;
|
||||||
|
|
2
spec/fixtures/pages/document-hidden.html
vendored
2
spec/fixtures/pages/document-hidden.html
vendored
|
@ -1,7 +1,7 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
require('ipc').send('hidden', document.hidden);
|
require('ipc-renderer').send('hidden', document.hidden);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
2
spec/fixtures/pages/history.html
vendored
2
spec/fixtures/pages/history.html
vendored
|
@ -2,7 +2,7 @@
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
window.history.pushState(window.history.state, "test page", "foo.html")
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
2
spec/fixtures/pages/ipc-message.html
vendored
2
spec/fixtures/pages/ipc-message.html
vendored
|
@ -1,7 +1,7 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
require('ipc').sendToHost('channel', 'arg1', 'arg2');
|
require('ipc-renderer').sendToHost('channel', 'arg1', 'arg2');
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
2
spec/fixtures/pages/onkeyup.html
vendored
2
spec/fixtures/pages/onkeyup.html
vendored
|
@ -2,7 +2,7 @@
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
document.onkeyup = function(e) {
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
2
spec/fixtures/pages/onmouseup.html
vendored
2
spec/fixtures/pages/onmouseup.html
vendored
|
@ -2,7 +2,7 @@
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
document.onmouseup = function(e) {
|
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>
|
</script>
|
||||||
</body>
|
</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)
|
if (window.opener !== null)
|
||||||
window.opener.postMessage(typeof window.opener, '*');
|
window.opener.postMessage(typeof window.opener, '*');
|
||||||
else
|
else
|
||||||
require('ipc').send('opener', window.opener);
|
require('ipc-renderer').send('opener', window.opener);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
require('coffee-script/register'); // Supports .coffee tests.
|
require('coffee-script/register'); // Supports .coffee tests.
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc-renderer');
|
||||||
|
|
||||||
// Rediret all output to browser.
|
// Rediret all output to browser.
|
||||||
if (isCi) {
|
if (isCi) {
|
||||||
|
|
Loading…
Reference in a new issue