From d59fb55a81d4ef4ed337f634c0ee73358378640a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 18 Jul 2013 19:21:25 +0800 Subject: [PATCH] Add BrowserWindow.inspectElement(x, y) API. --- browser/api/atom_api_window.cc | 11 +++++++++++ browser/api/atom_api_window.h | 1 + browser/native_window.cc | 9 +++++++++ browser/native_window.h | 1 + 4 files changed, 22 insertions(+) diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 0f4f870fde47..184da2347fcf 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -417,6 +417,16 @@ v8::Handle Window::CloseDevTools(const v8::Arguments &args) { return v8::Undefined(); } +// static +v8::Handle Window::InspectElement(const v8::Arguments& args) { + UNWRAP_WINDOW_AND_CHECK; + + self->window_->InspectElement(args[0]->IntegerValue(), + args[1]->IntegerValue()); + + return v8::Undefined(); +} + // static v8::Handle Window::FocusOnWebView(const v8::Arguments &args) { UNWRAP_WINDOW_AND_CHECK; @@ -677,6 +687,7 @@ void Window::Initialize(v8::Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "isKiosk", IsKiosk); NODE_SET_PROTOTYPE_METHOD(t, "openDevTools", OpenDevTools); NODE_SET_PROTOTYPE_METHOD(t, "closeDevTools", CloseDevTools); + NODE_SET_PROTOTYPE_METHOD(t, "inspectElement", InspectElement); NODE_SET_PROTOTYPE_METHOD(t, "focusOnWebView", FocusOnWebView); NODE_SET_PROTOTYPE_METHOD(t, "blurWebView", BlurWebView); NODE_SET_PROTOTYPE_METHOD(t, diff --git a/browser/api/atom_api_window.h b/browser/api/atom_api_window.h index c9ffec213526..9831466a2255 100644 --- a/browser/api/atom_api_window.h +++ b/browser/api/atom_api_window.h @@ -78,6 +78,7 @@ class Window : public EventEmitter, static v8::Handle IsKiosk(const v8::Arguments &args); static v8::Handle OpenDevTools(const v8::Arguments &args); static v8::Handle CloseDevTools(const v8::Arguments &args); + static v8::Handle InspectElement(const v8::Arguments &args); static v8::Handle FocusOnWebView(const v8::Arguments &args); static v8::Handle BlurWebView(const v8::Arguments &args); static v8::Handle RestartHangMonitorTimeout( diff --git a/browser/native_window.cc b/browser/native_window.cc index cecbb7757c99..b7bed1717961 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -16,6 +16,7 @@ #include "browser/atom_javascript_dialog_manager.h" #include "browser/media/media_stream_devices_controller.h" #include "browser/window_list.h" +#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/invalidate_type.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_details.h" @@ -135,6 +136,14 @@ void NativeWindow::CloseDevTools() { inspectable_web_contents()->GetView()->CloseDevTools(); } +void NativeWindow::InspectElement(int x, int y) { + OpenDevTools(); + content::RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); + scoped_refptr agent( + content::DevToolsAgentHost::GetOrCreateFor(rvh)); + agent->InspectElement(x, y); +} + void NativeWindow::FocusOnWebView() { GetWebContents()->GetRenderViewHost()->Focus(); } diff --git a/browser/native_window.h b/browser/native_window.h index aa040ba04505..c6a6c8401d26 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -93,6 +93,7 @@ class NativeWindow : public content::WebContentsDelegate, virtual bool IsClosed() const { return is_closed_; } virtual void OpenDevTools(); virtual void CloseDevTools(); + virtual void InspectElement(int x, int y); virtual void FocusOnWebView(); virtual void BlurWebView(); virtual void RestartHangMonitorTimeout();