From c5f8fbf471bda38fccf854dfd1608f080ac55018 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Apr 2014 10:48:11 +0800 Subject: [PATCH] Add getter for devToolsWebContents. --- atom/browser/api/atom_api_window.cc | 15 --------------- atom/browser/api/atom_api_window.h | 4 ---- atom/browser/api/lib/browser-window.coffee | 12 ++++++++++++ atom/browser/native_window.cc | 8 ++------ atom/browser/native_window.h | 1 - 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index ceb300b448ba..c0a9d1f58796 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -336,18 +336,6 @@ mate::Handle Window::GetDevToolsWebContents( return WebContents::Create(isolate, window_->GetDevToolsWebContents()); } -mate::Dictionary Window::GetDevTools(v8::Isolate* isolate) { - mate::Dictionary dict(mate::Dictionary::CreateEmpty(isolate)); - content::WebContents* web_contents = window_->GetDevToolsWebContents(); - dict.Set("processId", web_contents->GetRenderProcessHost()->GetID()); - dict.Set("routingId", web_contents->GetRoutingID()); - return dict; -} - -void Window::ExecuteJavaScriptInDevTools(const std::string& code) { - window_->ExecuteJavaScriptInDevTools(code); -} - void Window::LoadURL(const GURL& url) { NavigationController& controller = window_->GetWebContents()->GetController(); @@ -439,9 +427,6 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("capturePage", &Window::CapturePage) .SetMethod("getWebContents", &Window::GetWebContents) .SetMethod("getDevToolsWebContents", &Window::GetDevToolsWebContents) - .SetMethod("getDevTools", &Window::GetDevTools) - .SetMethod("executeJavaScriptInDevTools", - &Window::ExecuteJavaScriptInDevTools) .SetMethod("loadUrl", &Window::LoadURL) .SetMethod("canGoBack", &Window::CanGoBack) .SetMethod("canGoForward", &Window::CanGoForward) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 5c3927926bfe..d119f965724c 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -106,10 +106,6 @@ class Window : public mate::EventEmitter, mate::Handle GetWebContents(v8::Isolate* isolate) const; mate::Handle GetDevToolsWebContents(v8::Isolate* isolate) const; - // APIs for devtools. - mate::Dictionary GetDevTools(v8::Isolate* isolate); - void ExecuteJavaScriptInDevTools(const std::string& code); - // APIs for NavigationController. void LoadURL(const GURL& url); bool CanGoBack(); diff --git a/atom/browser/api/lib/browser-window.coffee b/atom/browser/api/lib/browser-window.coffee index eb3d01e73eda..d9cfb5ac47a8 100644 --- a/atom/browser/api/lib/browser-window.coffee +++ b/atom/browser/api/lib/browser-window.coffee @@ -14,7 +14,14 @@ BrowserWindow::_init = -> menu = app.getApplicationMenu() @setMenu menu if menu? + # Define getter for webContents. @webContents = @getWebContents() + @__devToolsWebContents = null + @__defineGetter__ 'devToolsWebContents', -> + if @isDevToolsOpened() + @__devToolsWebContents ?= @getDevToolsWebContents() + else + @__devToolsWebContents = null # Remember the window. id = BrowserWindow.windows.add this @@ -73,5 +80,10 @@ 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 module.exports = BrowserWindow diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index e4627d2ec2eb..c695b6aaac64 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -229,11 +229,6 @@ void NativeWindow::InspectElement(int x, int y) { agent->InspectElement(x, y); } -void NativeWindow::ExecuteJavaScriptInDevTools(const std::string& script) { - GetDevToolsWebContents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame( - string16(), base::UTF8ToUTF16(script)); -} - void NativeWindow::FocusOnWebView() { GetWebContents()->GetRenderViewHost()->Focus(); } @@ -628,7 +623,8 @@ void NativeWindow::CallDevToolsFunction(const std::string& function_name, } } } - ExecuteJavaScriptInDevTools(function_name + "(" + params + ");"); + GetDevToolsWebContents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame( + string16(), base::UTF8ToUTF16(function_name + "(" + params + ");")); } void NativeWindow::OnRendererMessage(const string16& channel, diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index f10e509e4e92..7c97bfe28006 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -136,7 +136,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual void CloseDevTools(); virtual bool IsDevToolsOpened(); virtual void InspectElement(int x, int y); - virtual void ExecuteJavaScriptInDevTools(const std::string& script); virtual void FocusOnWebView(); virtual void BlurWebView();