Avoid using processId and routingId directly.

This commit is contained in:
Cheng Zhao 2014-04-25 16:45:14 +08:00
parent 23ccad4915
commit 1bba15cb7f
4 changed files with 26 additions and 39 deletions

View file

@ -40,7 +40,7 @@ BrowserWindow::_init = ->
# Tell the rpc server that a render view has been deleted and we need to
# release all objects owned by it.
@webContents.on 'render-view-deleted', (event, processId, routingId) ->
process.emit 'ATOM_BROWSER_RELEASE_RENDER_VIEW', processId, routingId
process.emit 'ATOM_BROWSER_RELEASE_RENDER_VIEW', "#{processId}-#{routingId}"
BrowserWindow::toggleDevTools = ->
if @isDevToolsOpened() then @closeDevTools() else @openDevTools()
@ -71,17 +71,13 @@ BrowserWindow.getFocusedWindow = ->
windows = BrowserWindow.getAllWindows()
return window for window in windows when window.isFocused()
BrowserWindow.fromProcessIdAndRoutingId = (processId, routingId) ->
BrowserWindow.fromWebContents = (webContents) ->
windows = BrowserWindow.getAllWindows()
return window for window in windows when window.getProcessId() == processId and
window.getRoutingId() == routingId
return window for window in windows when webContents.equal window.webContents
BrowserWindow.fromDevTools = (processId, routingId) ->
BrowserWindow.fromDevToolsWebContents = (webContents) ->
windows = BrowserWindow.getAllWindows()
for window in windows when window.isDevToolsOpened()
devtools = window.getDevTools()
return window if devtools.processId == processId and
devtools.routingId == routingId
return window for window in windows when webContents.equal window.devToolsWebContents
# Helpers.
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
@ -98,9 +94,6 @@ BrowserWindow::stop = -> @webContents.stop()
BrowserWindow::getRoutingId = -> @webContents.getRoutingId()
BrowserWindow::getProcessId = -> @webContents.getProcessId()
BrowserWindow::isCrashed = -> @webContents.isCrashed()
BrowserWindow::getDevTools = ->
processId: @devToolsWebContents.getProcessId()
routingId: @devToolsWebContents.getRoutingId()
BrowserWindow::executeJavaScriptInDevTools = (code) ->
@devToolsWebContents.executeJavaScript code

View file

@ -7,10 +7,14 @@ module.exports.wrap = (webContents) ->
# webContents is an EventEmitter.
webContents.__proto__ = EventEmitter.prototype
# Add the send method.
# WebContents::send(channel, args..)
webContents.send = (args...) ->
@_send 'ATOM_INTERNAL_MESSAGE', [args...]
# The processId and routingId and identify a webContents.
webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
webContents.equal = (other) -> @getId() is other.getId()
# Dispatch IPC messages to the ipc module.
webContents.on 'ipc-message', (event, channel, args...) =>
Object.defineProperty event, 'sender', value: webContents