From: Cheng Zhao Date: Tue, 20 May 2014 12:58:11 +0000 (+0800) Subject: Make sure webContents is created when opening devtools. X-Git-Tag: v0.12.6~20 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=972bb2e9fba5ff6ce8b271701b5b787edfe515e0;p=electron.git Make sure webContents is created when opening devtools. Fixes atom/atom#2270. --- diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 3c4b7bbf..401cc66c 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -362,7 +362,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("flashFrame", &Window::FlashFrame) .SetMethod("setKiosk", &Window::SetKiosk) .SetMethod("isKiosk", &Window::IsKiosk) - .SetMethod("openDevTools", &Window::OpenDevTools) + .SetMethod("_openDevTools", &Window::OpenDevTools) .SetMethod("closeDevTools", &Window::CloseDevTools) .SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened) .SetMethod("inspectElement", &Window::InspectElement) diff --git a/atom/browser/api/lib/browser-window.coffee b/atom/browser/api/lib/browser-window.coffee index 051911e8..475541be 100644 --- a/atom/browser/api/lib/browser-window.coffee +++ b/atom/browser/api/lib/browser-window.coffee @@ -18,17 +18,6 @@ BrowserWindow::_init = -> @webContents = @getWebContents() @webContents.once 'destroyed', => @webContents = null - # Define getter for devToolsWebContents. - devToolsWebContents = null - @__defineGetter__ 'devToolsWebContents', -> - if @isDevToolsOpened() - # Get a new devToolsWebContents if previous one has been destroyed, it - # could happen when the devtools has been closed and then reopened. - devToolsWebContents = null unless devToolsWebContents?.isAlive() - devToolsWebContents ?= @getDevToolsWebContents() - else - devToolsWebContents = null - # Remember the window. id = BrowserWindow.windows.add this @@ -37,10 +26,12 @@ BrowserWindow::_init = -> @once 'closed', -> BrowserWindow.windows.remove id if BrowserWindow.windows.has id - # 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}" +BrowserWindow::openDevTools = -> + @_openDevTools() + + # Force devToolsWebContents to be created. + @devToolsWebContents = @getDevToolsWebContents() + @devToolsWebContents.once 'destroyed', => @devToolsWebContents = null BrowserWindow::toggleDevTools = -> if @isDevToolsOpened() then @closeDevTools() else @openDevTools() diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index 5e721233..38fef143 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -15,6 +15,11 @@ module.exports.wrap = (webContents) -> webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}" webContents.equal = (other) -> @getId() is other.getId() + # 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}" + # Dispatch IPC messages to the ipc module. webContents.on 'ipc-message', (event, channel, args...) => Object.defineProperty event, 'sender', value: webContents