Separate the webContents code in a new file.

This commit is contained in:
Cheng Zhao 2014-04-25 16:23:40 +08:00
parent c0875864dc
commit 23ccad4915
3 changed files with 25 additions and 22 deletions

View file

@ -0,0 +1,23 @@
EventEmitter = require('events').EventEmitter
ipc = require 'ipc'
module.exports.wrap = (webContents) ->
return null unless webContents.isAlive()
# webContents is an EventEmitter.
webContents.__proto__ = EventEmitter.prototype
# Add the send method.
webContents.send = (args...) ->
@_send 'ATOM_INTERNAL_MESSAGE', [args...]
# Dispatch IPC messages to the ipc module.
webContents.on 'ipc-message', (event, channel, args...) =>
Object.defineProperty event, 'sender', value: webContents
ipc.emit channel, event, args...
webContents.on 'ipc-message-sync', (event, channel, args...) =>
Object.defineProperty event, 'returnValue', set: (value) -> event.sendReply JSON.stringify(value)
Object.defineProperty event, 'sender', value: webContents
ipc.emit channel, event, args...
webContents