]> khamidou — GitHub mirrors - electron.git/commitdiff
Add API to execute javascript in devtools.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 8 Apr 2014 04:50:12 +0000 (12:50 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 8 Apr 2014 04:50:12 +0000 (12:50 +0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h

index c12effeb35dd94b58b035ed106d5101f9083d7e9..12aa099ee3909503412ca3317cc3eb544aaede58 100644 (file)
@@ -516,6 +516,18 @@ void Window::GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
   args.GetReturnValue().Set(devtools);
 }
 
+// static
+void Window::ExecuteJavaScriptInDevTools(
+    const v8::FunctionCallbackInfo<v8::Value>& args) {
+  UNWRAP_WINDOW_AND_CHECK;
+
+  std::string code;
+  if (!FromV8Arguments(args, &code))
+    return node::ThrowTypeError("Bad argument");
+
+  self->window_->ExecuteJavaScriptInDevTools(code);
+}
+
 // static
 void Window::LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args) {
   UNWRAP_WINDOW_AND_CHECK;
@@ -700,6 +712,8 @@ void Window::Initialize(v8::Handle<v8::Object> target) {
   NODE_SET_PROTOTYPE_METHOD(t, "isCrashed", IsCrashed);
 
   NODE_SET_PROTOTYPE_METHOD(t, "getDevTools", GetDevTools);
+  NODE_SET_PROTOTYPE_METHOD(
+      t, "executeJavaScriptInDevTools", ExecuteJavaScriptInDevTools);
 
   NODE_SET_PROTOTYPE_METHOD(t, "loadUrl", LoadURL);
   NODE_SET_PROTOTYPE_METHOD(t, "getUrl", GetURL);
index b16bb70a2e78a8b83774f45e410baa5e89971360..f12bce1da8cb516851f49b41c898a8c65c746c4e 100644 (file)
@@ -105,6 +105,8 @@ class Window : public EventEmitter,
 
   // APIs for devtools.
   static void GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args);
+  static void ExecuteJavaScriptInDevTools(
+      const v8::FunctionCallbackInfo<v8::Value>& args);
 
   // APIs for NavigationController.
   static void LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args);
index 43c7cda0d1e7f664e64b152757ab621a1271c292..e2384cd958bcde8c38bb8ee8f520b7fa07a221bc 100644 (file)
@@ -225,6 +225,11 @@ 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();
 }
@@ -612,10 +617,7 @@ void NativeWindow::CallDevToolsFunction(const std::string& function_name,
       }
     }
   }
-  base::string16 javascript =
-      base::ASCIIToUTF16(function_name + "(" + params + ");");
-  GetDevToolsWebContents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
-      string16(), javascript);
+  ExecuteJavaScriptInDevTools(function_name + "(" + params + ");");
 }
 
 void NativeWindow::OnRendererMessage(const string16& channel,
index c274d5e4488d7d530c5001fa231aa6feedc36f82..27349b192e4545e8980e8272a06d81e4c66155e8 100644 (file)
@@ -136,6 +136,7 @@ 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();