]> khamidou — GitHub mirrors - electron.git/commitdiff
Add getter for devToolsWebContents.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 25 Apr 2014 02:48:11 +0000 (10:48 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 25 Apr 2014 02:48:11 +0000 (10:48 +0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/api/lib/browser-window.coffee
atom/browser/native_window.cc
atom/browser/native_window.h

index ceb300b448bad371b45c06d589bb349a064ce9ca..c0a9d1f5879604edd6f7cf42f266a563791e0a57 100644 (file)
@@ -336,18 +336,6 @@ mate::Handle<WebContents> 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)
index 5c3927926bfeb820000165b6869c9dd83c0c2ad9..d119f965724cdac7c8deeffa25f10f182a5894a8 100644 (file)
@@ -106,10 +106,6 @@ class Window : public mate::EventEmitter,
   mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
   mate::Handle<WebContents> 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();
index eb3d01e73eda076a498c3ecae2d7a91b316274c2..d9cfb5ac47a84290079abea63e986fe2197a849e 100644 (file)
@@ -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
index e4627d2ec2eb4049beb7b0a6b5ef0d0c6ec1a9c8..c695b6aaac6483212d30f2599b7158a471dee039 100644 (file)
@@ -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,
index f10e509e4e92ab50b24dd403ecd235b88c07addd..7c97bfe28006b9e13da12fdc24b1a50fbcd71b85 100644 (file)
@@ -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();