diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index c12effeb35dd..12aa099ee390 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -516,6 +516,18 @@ void Window::GetDevTools(const v8::FunctionCallbackInfo& args) { args.GetReturnValue().Set(devtools); } +// static +void Window::ExecuteJavaScriptInDevTools( + const v8::FunctionCallbackInfo& 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& args) { UNWRAP_WINDOW_AND_CHECK; @@ -700,6 +712,8 @@ void Window::Initialize(v8::Handle 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); diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index b16bb70a2e78..f12bce1da8cb 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -105,6 +105,8 @@ class Window : public EventEmitter, // APIs for devtools. static void GetDevTools(const v8::FunctionCallbackInfo& args); + static void ExecuteJavaScriptInDevTools( + const v8::FunctionCallbackInfo& args); // APIs for NavigationController. static void LoadURL(const v8::FunctionCallbackInfo& args); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 43c7cda0d1e7..e2384cd958bc 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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, diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index c274d5e4488d..27349b192e45 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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();