Merge pull request #3384 from atom/ipc-renderer

Use different names for "ipc" module in main and renderer processes
This commit is contained in:
Cheng Zhao 2015-11-10 17:29:07 +08:00
commit 0af1308ad7
44 changed files with 232 additions and 215 deletions

View file

@ -1,6 +1,6 @@
EventEmitter = require('events').EventEmitter EventEmitter = require('events').EventEmitter
app = require 'app' app = require 'app'
ipc = require 'ipc' ipc = require 'ipc-main'
deprecate = require 'deprecate' deprecate = require 'deprecate'
BrowserWindow = process.atomBinding('window').BrowserWindow BrowserWindow = process.atomBinding('window').BrowserWindow

View file

@ -0,0 +1,3 @@
{EventEmitter} = require 'events'
module.exports = new EventEmitter

View file

@ -1,3 +1,6 @@
EventEmitter = require('events').EventEmitter deprecate = require 'deprecate'
module.exports = new EventEmitter # This module is deprecated, we mirror everything from ipcRenderer.
deprecate.warn 'ipc module', 'ipcMain module'
module.exports = require 'ipc-main'

View file

@ -1,4 +1,4 @@
ipc = require 'ipc' ipc = require 'ipc-main'
# The history operation in renderer is redirected to browser. # The history operation in renderer is redirected to browser.
ipc.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) -> ipc.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) ->

View file

@ -2,7 +2,7 @@ EventEmitter = require('events').EventEmitter
Menu = require './menu' Menu = require './menu'
NavigationController = require './navigation-controller' NavigationController = require './navigation-controller'
binding = process.atomBinding 'web_contents' binding = process.atomBinding 'web_contents'
ipc = require 'ipc' ipc = require 'ipc-main'
nextId = 0 nextId = 0
getNextId = -> ++nextId getNextId = -> ++nextId

View file

@ -1,4 +1,4 @@
ipc = require 'ipc' ipc = require 'ipc-main'
webContents = require 'web-contents' webContents = require 'web-contents'
webViewManager = null # Doesn't exist in early initialization. webViewManager = null # Doesn't exist in early initialization.

View file

@ -1,4 +1,4 @@
ipc = require 'ipc' ipc = require 'ipc-main'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'
BrowserWindow = require 'browser-window' BrowserWindow = require 'browser-window'

View file

@ -1,4 +1,4 @@
ipc = require 'ipc' ipc = require 'ipc-main'
path = require 'path' path = require 'path'
objectsRegistry = require './objects-registry.js' objectsRegistry = require './objects-registry.js'
v8Util = process.atomBinding 'v8_util' v8Util = process.atomBinding 'v8_util'

View file

@ -0,0 +1,16 @@
binding = process.atomBinding 'ipc'
v8Util = process.atomBinding 'v8_util'
# Created by init.coffee.
ipcRenderer = v8Util.getHiddenValue global, 'ipc'
ipcRenderer.send = (args...) ->
binding.send 'ipc-message', [args...]
ipcRenderer.sendSync = (args...) ->
JSON.parse binding.sendSync('ipc-message-sync', [args...])
ipcRenderer.sendToHost = (args...) ->
binding.send 'ipc-message-host', [args...]
module.exports = ipcRenderer

View file

@ -1,21 +1,19 @@
deprecate = require 'deprecate' deprecate = require 'deprecate'
ipcRenderer = require 'ipc-renderer'
{EventEmitter} = require 'events'
binding = process.atomBinding 'ipc' # This module is deprecated, we mirror everything from ipcRenderer.
v8Util = process.atomBinding 'v8_util' deprecate.warn 'ipc module', 'ipcRenderer module'
# Created by init.coffee. # Routes events of ipcRenderer.
ipc = v8Util.getHiddenValue global, 'ipc' ipc = new EventEmitter
ipcRenderer.emit = (channel, event, args...) ->
ipc.send = (args...) -> ipc.emit channel, args...
binding.send 'ipc-message', [args...] EventEmitter::emit.apply ipcRenderer, arguments
ipc.sendSync = (args...) ->
JSON.parse binding.sendSync('ipc-message-sync', [args...])
ipc.sendToHost = (args...) ->
binding.send 'ipc-message-host', [args...]
# Deprecated. # Deprecated.
for method of ipcRenderer when method.startsWith 'send'
ipc[method] = ipcRenderer[method]
deprecate.rename ipc, 'sendChannel', 'send' deprecate.rename ipc, 'sendChannel', 'send'
deprecate.rename ipc, 'sendChannelSync', 'sendSync' deprecate.rename ipc, 'sendChannelSync', 'sendSync'

View file

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

View file

@ -31,6 +31,7 @@
#include "third_party/WebKit/public/web/WebScriptSource.h" #include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebView.h" #include "third_party/WebKit/public/web/WebView.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "native_mate/dictionary.h"
namespace atom { namespace atom {
@ -142,7 +143,12 @@ void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel,
v8::Local<v8::Object> ipc; v8::Local<v8::Object> ipc;
if (GetIPCObject(isolate, context, &ipc)) { if (GetIPCObject(isolate, context, &ipc)) {
mate::EmitEvent(isolate, ipc, channel, ListValueToVector(isolate, args)); auto args_vector = ListValueToVector(isolate, args);
// Insert the Event object, event.sender is ipc.
mate::Dictionary event = mate::Dictionary::CreateEmpty(isolate);
event.Set("sender", ipc);
args_vector.insert(args_vector.begin(), event.GetHandle());
mate::EmitEvent(isolate, ipc, channel, args_vector);
} }
} }

View file

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

View file

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

View file

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

View file

@ -36,7 +36,7 @@
* [content-tracing](api/content-tracing.md) * [content-tracing](api/content-tracing.md)
* [dialog](api/dialog.md) * [dialog](api/dialog.md)
* [global-shortcut](api/global-shortcut.md) * [global-shortcut](api/global-shortcut.md)
* [ipc (main process)](api/ipc-main-process.md) * [ipc-main](api/ipc-main.md)
* [menu](api/menu.md) * [menu](api/menu.md)
* [menu-item](api/menu-item.md) * [menu-item](api/menu-item.md)
* [power-monitor](api/power-monitor.md) * [power-monitor](api/power-monitor.md)
@ -48,7 +48,7 @@
### Modules for the Renderer Process (Web Page): ### Modules for the Renderer Process (Web Page):
* [ipc (renderer)](api/ipc-renderer.md) * [ipc-renderer](api/ipc-renderer.md)
* [remote](api/remote.md) * [remote](api/remote.md)
* [web-frame](api/web-frame.md) * [web-frame](api/web-frame.md)

View file

@ -1,76 +0,0 @@
# ipc (main process)
The `ipc` module, when used in the main process, handles asynchronous and
synchronous messages sent from a renderer process (web page). Messages sent from
a renderer will be emitted to this module.
## Sending Messages
It is also possible to send messages from the main process to the renderer
process, see [WebContents.send](web-contents.md#webcontentssendchannel-args)
for more information.
- When sending a message, the event name is the `channel`.
- To reply a synchronous message, you need to set `event.returnValue`.
- To send an asynchronous back to the sender, you can use
`event.sender.send(...)`.
An example of sending and handling messages between the render and main
processes:
```javascript
// In main process.
var ipc = require('ipc');
ipc.on('asynchronous-message', function(event, arg) {
console.log(arg); // prints "ping"
event.sender.send('asynchronous-reply', 'pong');
});
ipc.on('synchronous-message', function(event, arg) {
console.log(arg); // prints "ping"
event.returnValue = 'pong';
});
```
```javascript
// In renderer process (web page).
var ipc = require('ipc');
console.log(ipc.sendSync('synchronous-message', 'ping')); // prints "pong"
ipc.on('asynchronous-reply', function(arg) {
console.log(arg); // prints "pong"
});
ipc.send('asynchronous-message', 'ping');
```
## Listening for Messages
The `ipc` module has the following method to listen for events:
### `ipc.on(channel, callback)`
* `channel` String - The event name.
* `callback` Function
When the event occurs the `callback` is called with an `event` object and a
message, `arg`.
## IPC Events
The `event` object passed to the `callback` has the following methods:
### `Event.returnValue`
Set this to the value to be returned in a synchronous message.
### `Event.sender`
Returns the `WebContents` that sent the message.
### `Event.sender.send(channel[, arg1][, arg2][, ...])`
* `channel` String - The event name.
* `arg` (optional)
This sends an asynchronous message back to the render process. Optionally, there
can be one or a series of arguments, `arg`, which can have any type.

71
docs/api/ipc-main.md Normal file
View file

@ -0,0 +1,71 @@
# ipcMain
The `ipcMain` module, when used in the main process, handles asynchronous and
synchronous messages sent from a renderer process (web page). Messages sent from
a renderer will be emitted to this module.
## Sending Messages
It is also possible to send messages from the main process to the renderer
process, see [WebContents.send][webcontents-send] for more information.
* When sending a message, the event name is the `channel`.
* To reply a synchronous message, you need to set `event.returnValue`.
* To send an asynchronous back to the sender, you can use
`event.sender.send(...)`.
An example of sending and handling messages between the render and main
processes:
```javascript
// In main process.
var ipcMain = require('ipc-main');
ipcMain.on('asynchronous-message', function(event, arg) {
console.log(arg); // prints "ping"
event.sender.send('asynchronous-reply', 'pong');
});
ipcMain.on('synchronous-message', function(event, arg) {
console.log(arg); // prints "ping"
event.returnValue = 'pong';
});
```
```javascript
// In renderer process (web page).
var ipcRenderer = require('ipc-renderer');
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
ipcRenderer.on('asynchronous-reply', function(event, arg) {
console.log(arg); // prints "pong"
});
ipcRenderer.send('asynchronous-message', 'ping');
```
## Listening for Messages
The `ipcMain` module has the following method to listen for events:
### `ipcMain.on(channel, callback)`
* `channel` String - The event name.
* `callback` Function
When the event occurs the `callback` is called with an `event` object and a
message, `arg`.
## IPC Event
The `event` object passed to the `callback` has the following methods:
### `event.returnValue`
Set this to the value to be returned in a synchronous message.
### `event.sender`
Returns the `webContents` that sent the message, you can call
`event.sender.send` to reply to the asynchronous message, see
[WebContents.send][webcontents-send] for more information.
[webcontents-send]: web-contents.md#webcontentssendchannel-args

View file

@ -1,52 +1,55 @@
# ipc (renderer) # ipcRenderer
The `ipc` module provides a few methods so you can send synchronous and The `ipcRenderer` module provides a few methods so you can send synchronous and
asynchronous messages from the render process (web page) to the main process. asynchronous messages from the render process (web page) to the main process.
You can also receive replies from the main process. You can also receive replies from the main process.
**Note:** If you want to make use of modules in the main process from the renderer See [ipcMain](ipc-main.md) for code examples.
process, you might consider using the [remote](remote.md) module.
See [ipc (main process)](ipc-main-process.md) for code examples. ## Listening for Messages
## Methods The `ipcRenderer` module has the following method to listen for events:
The `ipc` module has the following methods for sending messages: ### `ipcRenderer.on(channel, callback)`
**Note:** When using these methods to send a `message` you must also listen * `channel` String - The event name.
for it in the main process with [`ipc (main process)`](ipc-main-process.md). * `callback` Function
### `ipc.send(channel[, arg1][, arg2][, ...])` When the event occurs the `callback` is called with an `event` object and
arbitrary arguments.
## Sending Messages
The `ipcRenderer` module has the following methods for sending messages:
### `ipcRenderer.send(channel[, arg1][, arg2][, ...])`
* `channel` String - The event name. * `channel` String - The event name.
* `arg` (optional) * `arg` (optional)
Send an event to the main process asynchronously via a `channel`. Optionally, Send an event to the main process asynchronously via a `channel`, you can also
there can be a message: one or a series of arguments, `arg`, which can have any send arbitrary arguments. The main process handles it by listening for the
type. The main process handles it by listening for the `channel` event with `channel` event with `ipcMain`.
`ipc`.
### `ipc.sendSync(channel[, arg1][, arg2][, ...])` ### `ipcRenderer.sendSync(channel[, arg1][, arg2][, ...])`
* `channel` String - The event name. * `channel` String - The event name.
* `arg` (optional) * `arg` (optional)
Send an event to the main process synchronously via a `channel`. Optionally, Send an event to the main process synchronously via a `channel`, you can also
there can be a message: one or a series of arguments, `arg`, which can have any send arbitrary arguments. The main process handles it by listening for the
type. The main process handles it by listening for the `channel` event with `channel` event with `ipcMain`.
`ipc`.
The main process handles it by listening for the `channel` event with `ipc` and The main process handles it by listening for the `channel` event with `ipc` and
replies by setting the `event.returnValue`. replies by setting the `event.returnValue`.
**Note:** Sending a synchronous message will block the whole renderer process so __Note:__ Sending a synchronous message will block the whole renderer process,
using this method is not recommended. unless you know what you are doing you should never use it.
### `ipc.sendToHost(channel[, arg1][, arg2][, ...])` ### `ipcRenderer.sendToHost(channel[, arg1][, arg2][, ...])`
* `channel` String - The event name. * `channel` String - The event name.
* `arg` (optional) * `arg` (optional)
Like `ipc.send` but the event will be sent to the host page in a `<webview>` Like `ipcRenderer.send` but the event will be sent to the `<webview>` element in
instead of the main process. Optionally, there can be a message: one or a series the host page instead of the main process.
of arguments, `arg`, which can have any type.

View file

@ -510,13 +510,14 @@ Starts inspecting element at position (`x`, `y`).
Opens the developer tools for the service worker context. Opens the developer tools for the service worker context.
### `webContents.send(channel[, args...])` ### `webContents.send(channel[, arg1][, arg2][, ...])`
* `channel` String * `channel` String
* `args...` (optional) * `arg` (optional)
Send `args...` to the web page via `channel` in an asynchronous message, the web Send an asynchronous message to renderer process via `channel`, you can also
page can handle it by listening to the `channel` event of the `ipc` module. send arbitrary arguments. The renderer process can handle the message by
listening to the `channel` event with the `ipcRenderer` module.
An example of sending messages from the main process to the renderer process: An example of sending messages from the main process to the renderer process:
@ -537,7 +538,7 @@ app.on('ready', function() {
<html> <html>
<body> <body>
<script> <script>
require('ipc').on('ping', function(message) { require('ipcRenderer').on('ping', function(event, message) {
console.log(message); // Prints "whoooooooh!" console.log(message); // Prints "whoooooooh!"
}); });
</script> </script>
@ -545,13 +546,6 @@ app.on('ready', function() {
</html> </html>
``` ```
**Note:**
1. The IPC message handler in web pages does not have an `event` parameter,
which is different from the handlers in the main process.
2. There is no way to send synchronous messages from the main process to a
renderer process, because it would be very easy to cause dead locks.
### `webContents.enableDeviceEmulation(parameters)` ### `webContents.enableDeviceEmulation(parameters)`
`parameters` Object, properties: `parameters` Object, properties:

View file

@ -355,15 +355,16 @@ Prints `webview`'s web page. Same with `webContents.print([options])`.
Prints webview's web page as PDF, Same with `webContents.printToPDF(options, callback)` Prints webview's web page as PDF, Same with `webContents.printToPDF(options, callback)`
### `<webview>.send(channel[, args...])` ### `<webview>.send(channel[, arg1][, arg2][, ...])`
* `channel` String * `channel` String
* `arg` (optional) * `arg` (optional)
Send `args..` to guest page via `channel` in asynchronous message, the guest Send an asynchronous message to renderer process via `channel`, you can also
page can handle it by listening to the `channel` event of `ipc` module. send arbitrary arguments. The renderer process can handle the message by
listening to the `channel` event with the `ipcRenderer` module.
See [WebContents.send](web-contents.md#webcontentssendchannel-args) for See [webContents.send](web-contents.md#webcontentssendchannel-args) for
examples. examples.
### `<webview>.sendInputEvent(event)` ### `<webview>.sendInputEvent(event)`
@ -372,7 +373,7 @@ examples.
Sends an input `event` to the page. Sends an input `event` to the page.
See [WebContents.sendInputEvent](web-contents.md##webcontentssendinputeventevent) See [webContents.sendInputEvent](web-contents.md##webcontentssendinputeventevent)
for detailed description of `event` object. for detailed description of `event` object.
## DOM events ## DOM events

View file

@ -46,7 +46,7 @@ _main.js_
```javascript ```javascript
var app = require('app'); var app = require('app');
var ipc = require('ipc'); var ipcMain = require('ipc-main');
var BrowserWindow = require('browser-window'); var BrowserWindow = require('browser-window');
var onlineStatusWindow; var onlineStatusWindow;
@ -55,7 +55,7 @@ app.on('ready', function() {
onlineStatusWindow.loadUrl('file://' + __dirname + '/online-status.html'); onlineStatusWindow.loadUrl('file://' + __dirname + '/online-status.html');
}); });
ipc.on('online-status-changed', function(event, status) { ipcMain.on('online-status-changed', function(event, status) {
console.log(status); console.log(status);
}); });
``` ```
@ -67,9 +67,9 @@ _online-status.html_
<html> <html>
<body> <body>
<script> <script>
var ipc = require('ipc'); var ipcRenderer = require('ipc-renderer');
var updateOnlineStatus = function() { var updateOnlineStatus = function() {
ipc.send('online-status-changed', navigator.onLine ? 'online' : 'offline'); ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline');
}; };
window.addEventListener('online', updateOnlineStatus); window.addEventListener('online', updateOnlineStatus);

View file

@ -18,6 +18,7 @@
'atom/browser/api/lib/dialog.coffee', 'atom/browser/api/lib/dialog.coffee',
'atom/browser/api/lib/global-shortcut.coffee', 'atom/browser/api/lib/global-shortcut.coffee',
'atom/browser/api/lib/ipc.coffee', 'atom/browser/api/lib/ipc.coffee',
'atom/browser/api/lib/ipc-main.coffee',
'atom/browser/api/lib/menu.coffee', 'atom/browser/api/lib/menu.coffee',
'atom/browser/api/lib/menu-item.coffee', 'atom/browser/api/lib/menu-item.coffee',
'atom/browser/api/lib/navigation-controller.coffee', 'atom/browser/api/lib/navigation-controller.coffee',
@ -50,6 +51,7 @@
'atom/renderer/lib/web-view/web-view-attributes.coffee', 'atom/renderer/lib/web-view/web-view-attributes.coffee',
'atom/renderer/lib/web-view/web-view-constants.coffee', 'atom/renderer/lib/web-view/web-view-constants.coffee',
'atom/renderer/api/lib/ipc.coffee', 'atom/renderer/api/lib/ipc.coffee',
'atom/renderer/api/lib/ipc-renderer.coffee',
'atom/renderer/api/lib/remote.coffee', 'atom/renderer/api/lib/remote.coffee',
'atom/renderer/api/lib/screen.coffee', 'atom/renderer/api/lib/screen.coffee',
'atom/renderer/api/lib/web-frame.coffee', 'atom/renderer/api/lib/web-frame.coffee',

View file

@ -201,12 +201,12 @@ describe 'browser-window module', ->
describe '"web-preferences" option', -> describe '"web-preferences" option', ->
afterEach -> afterEach ->
remote.require('ipc').removeAllListeners('answer') remote.require('ipc-main').removeAllListeners('answer')
describe '"preload" option', -> describe '"preload" option', ->
it 'loads the script before other scripts in window', (done) -> it 'loads the script before other scripts in window', (done) ->
preload = path.join fixtures, 'module', 'set-global.js' preload = path.join fixtures, 'module', 'set-global.js'
remote.require('ipc').once 'answer', (event, test) -> remote.require('ipc-main').once 'answer', (event, test) ->
assert.equal(test, 'preload') assert.equal(test, 'preload')
done() done()
w.destroy() w.destroy()
@ -219,7 +219,7 @@ describe 'browser-window module', ->
describe '"node-integration" option', -> describe '"node-integration" option', ->
it 'disables node integration when specified to false', (done) -> it 'disables node integration when specified to false', (done) ->
preload = path.join fixtures, 'module', 'send-later.js' preload = path.join fixtures, 'module', 'send-later.js'
remote.require('ipc').once 'answer', (event, test) -> remote.require('ipc-main').once 'answer', (event, test) ->
assert.equal(test, 'undefined') assert.equal(test, 'undefined')
done() done()
w.destroy() w.destroy()

View file

@ -3,7 +3,7 @@ path = require 'path'
http = require 'http' http = require 'http'
url = require 'url' url = require 'url'
remote = require 'remote' remote = require 'remote'
formidable = require 'formidable' multiparty = require 'multiparty'
crashReporter = remote.require 'crash-reporter' crashReporter = remote.require 'crash-reporter'
BrowserWindow = remote.require 'browser-window' BrowserWindow = remote.require 'browser-window'
@ -26,10 +26,8 @@ describe 'crash-reporter module', ->
@timeout 120000 @timeout 120000
server = http.createServer (req, res) -> server = http.createServer (req, res) ->
server.close() server.close()
form = new formidable.IncomingForm() form = new multiparty.Form()
process.throwDeprecation = false
form.parse req, (error, fields, files) -> form.parse req, (error, fields, files) ->
process.throwDeprecation = true
assert.equal fields['prod'], 'Electron' assert.equal fields['prod'], 'Electron'
assert.equal fields['ver'], process.versions['electron'] assert.equal fields['ver'], process.versions['electron']
assert.equal fields['process_type'], 'renderer' assert.equal fields['process_type'], 'renderer'
@ -39,7 +37,6 @@ describe 'crash-reporter module', ->
assert.equal fields['_productName'], 'Zombies' assert.equal fields['_productName'], 'Zombies'
assert.equal fields['_companyName'], 'Umbrella Corporation' assert.equal fields['_companyName'], 'Umbrella Corporation'
assert.equal fields['_version'], require('remote').require('app').getVersion() assert.equal fields['_version'], require('remote').require('app').getVersion()
assert files['upload_file_minidump']['name']?
res.end('abc-123-def') res.end('abc-123-def')
done() done()

View file

@ -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
@ -83,7 +83,7 @@ describe 'ipc module', ->
it 'does not crash when reply is not sent and browser is destroyed', (done) -> it 'does not crash when reply is not sent and browser is destroyed', (done) ->
@timeout 10000 @timeout 10000
w = new BrowserWindow(show: false) w = new BrowserWindow(show: false)
remote.require('ipc').once 'send-sync-message', (event) -> remote.require('ipc-main').once 'send-sync-message', (event) ->
event.returnValue = null event.returnValue = null
w.destroy() w.destroy()
done() done()

View file

@ -60,9 +60,9 @@ describe 'session module', ->
describe 'session.clearStorageData(options)', -> describe 'session.clearStorageData(options)', ->
fixtures = path.resolve __dirname, 'fixtures' fixtures = path.resolve __dirname, 'fixtures'
it 'clears localstorage data', (done) -> it 'clears localstorage data', (done) ->
ipc = remote.require('ipc') ipcMain = remote.require('ipc-main')
ipc.on 'count', (event, count) -> ipcMain.on 'count', (event, count) ->
ipc.removeAllListeners 'count' ipcMain.removeAllListeners 'count'
assert not count assert not count
done() done()
w.loadUrl 'file://' + path.join(fixtures, 'api', 'localstorage.html') w.loadUrl 'file://' + path.join(fixtures, 'api', 'localstorage.html')
@ -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'

View file

@ -407,7 +407,7 @@ describe 'asar package', ->
describe 'asar protocol', -> describe 'asar protocol', ->
url = require 'url' url = require 'url'
remote = require 'remote' remote = require 'remote'
ipc = remote.require 'ipc' ipc = remote.require 'ipc-main'
BrowserWindow = remote.require 'browser-window' BrowserWindow = remote.require 'browser-window'
it 'can request a file in package', (done) -> it 'can request a file in package', (done) ->

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,7 +5,7 @@
"version": "0.1.0", "version": "0.1.0",
"devDependencies": { "devDependencies": {
"basic-auth": "^1.0.0", "basic-auth": "^1.0.0",
"formidable": "1.0.16", "multiparty": "4.1.2",
"graceful-fs": "3.0.5", "graceful-fs": "3.0.5",
"mocha": "2.1.0", "mocha": "2.1.0",
"q": "0.9.7", "q": "0.9.7",

View file

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

View file

@ -1,5 +1,5 @@
var app = require('app'); var app = require('app');
var ipc = require('ipc'); var ipc = require('ipc-main');
var dialog = require('dialog'); var dialog = require('dialog');
var path = require('path'); var path = require('path');
var BrowserWindow = require('browser-window'); var BrowserWindow = require('browser-window');
@ -9,6 +9,7 @@ process.port = 0; // will be used by crash-reporter spec.
app.commandLine.appendSwitch('js-flags', '--expose_gc'); app.commandLine.appendSwitch('js-flags', '--expose_gc');
app.commandLine.appendSwitch('ignore-certificate-errors'); app.commandLine.appendSwitch('ignore-certificate-errors');
app.commandLine.appendSwitch('disable-renderer-backgrounding');
// Accessing stdout in the main process will result in the process.stdout // Accessing stdout in the main process will result in the process.stdout
// throwing UnknownSystemError in renderer process sometimes. This line makes // throwing UnknownSystemError in renderer process sometimes. This line makes
@ -78,7 +79,7 @@ app.on('ready', function() {
// For session's download test, listen 'will-download' event in browser, and // For session's download test, listen 'will-download' event in browser, and
// reply the result to renderer for verifying // reply the result to renderer for verifying
var downloadFilePath = path.join(__dirname, '..', 'fixtures', 'mock.pdf'); var downloadFilePath = path.join(__dirname, '..', 'fixtures', 'mock.pdf');
require('ipc').on('set-download-option', function(event, need_cancel) { ipc.on('set-download-option', function(event, need_cancel) {
window.webContents.session.once('will-download', window.webContents.session.once('will-download',
function(e, item, webContents) { function(e, item, webContents) {
item.setSavePath(downloadFilePath); item.setSavePath(downloadFilePath);