]> khamidou — GitHub mirrors - electron.git/commitdiff
Separate the webContents code in a new file.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 25 Apr 2014 08:23:40 +0000 (16:23 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 25 Apr 2014 08:23:40 +0000 (16:23 +0800)
atom.gyp
atom/browser/api/lib/browser-window.coffee
atom/browser/api/lib/web-contents.coffee [new file with mode: 0644]

index 2e2bc035932747a0493f648a1432132a98445aeb..016260065ba68a005fdd59823cbd146416adf614 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -24,6 +24,7 @@
       'atom/browser/api/lib/menu-item.coffee',
       'atom/browser/api/lib/power-monitor.coffee',
       'atom/browser/api/lib/protocol.coffee',
+      'atom/browser/api/lib/web-contents.coffee',
       'atom/browser/lib/init.coffee',
       'atom/browser/lib/objects-registry.coffee',
       'atom/browser/lib/rpc-server.coffee',
index f4e3a23ef69bc686b2914f5ee0c59565407f92cd..a09c3fe71a18c07fff1592b4e72a1e27689ec290 100644 (file)
@@ -1,32 +1,11 @@
 EventEmitter = require('events').EventEmitter
 IDWeakMap = require 'id-weak-map'
 app = require 'app'
-ipc = require 'ipc'
+wrapWebContents = require('web-contents').wrap
 
 BrowserWindow = process.atomBinding('window').BrowserWindow
 BrowserWindow::__proto__ = EventEmitter.prototype
 
-wrapWebContents = (webContents) ->
-  return null unless webContents.isAlive()
-  # webContents is an EventEmitter.
-  webContents.__proto__ = EventEmitter.prototype
-
-  # Wrap around the send method.
-  webContents.send = (args...) ->
-    @_send 'ATOM_INTERNAL_MESSAGE', [args...]
-
-  # Dispatch the ipc messages.
-  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...) =>
-    set = (value) -> event.sendReply JSON.stringify(value)
-    Object.defineProperty event, 'returnValue', {set}
-    Object.defineProperty event, 'sender', value: webContents
-    ipc.emit channel, event, args...
-
-  webContents
-
 # Store all created windows in the weak map.
 BrowserWindow.windows = new IDWeakMap
 
diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee
new file mode 100644 (file)
index 0000000..f3795af
--- /dev/null
@@ -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