diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index f502425749ed..7486f4f5b626 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -417,7 +417,8 @@ void Window::InspectElement(const v8::FunctionCallbackInfo& args) { // static void Window::DebugDevTools(const v8::FunctionCallbackInfo& args) { UNWRAP_WINDOW_AND_CHECK; - self->window_->DebugDevTools(); + if (self->window_->IsDevToolsOpened()) + NativeWindow::Debug(self->window_->GetDevToolsWebContents()); } // static diff --git a/browser/native_window.cc b/browser/native_window.cc index 7bd45ee0b63d..3d3d38474c10 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -101,6 +101,14 @@ NativeWindow* NativeWindow::Create(base::DictionaryValue* options) { return Create(content::WebContents::Create(create_params), options); } +// static +NativeWindow* NativeWindow::Debug(content::WebContents* web_contents) { + base::DictionaryValue options; + NativeWindow* window = NativeWindow::Create(&options); + window->devtools_delegate_.reset(new DevToolsDelegate(window, web_contents)); + return window; +} + // static NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) { // Stupid iterating. @@ -203,16 +211,6 @@ void NativeWindow::InspectElement(int x, int y) { agent->InspectElement(x, y); } -void NativeWindow::DebugDevTools() { - if (!IsDevToolsOpened()) - return; - - base::DictionaryValue options; - NativeWindow* window = NativeWindow::Create(&options); - window->devtools_delegate_.reset(new DevToolsDelegate( - window, GetDevToolsWebContents())); -} - void NativeWindow::FocusOnWebView() { GetWebContents()->GetRenderViewHost()->Focus(); } diff --git a/browser/native_window.h b/browser/native_window.h index 6d97c3aabbe8..1e02dee817d7 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -72,13 +72,19 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual ~NativeWindow(); - // Create window with existing WebContents. + // Create window with existing WebContents, the caller is responsible for + // managing the window's live. static NativeWindow* Create(content::WebContents* web_contents, base::DictionaryValue* options); - // Create window with new WebContents. + // Create window with new WebContents, the caller is responsible for + // managing the window's live. static NativeWindow* Create(base::DictionaryValue* options); + // Creates a devtools window to debug the WebContents, the returned window + // will manage its own life. + static NativeWindow* Debug(content::WebContents* web_contents); + // Find a window from its process id and routing id. static NativeWindow* FromRenderView(int process_id, int routing_id); @@ -125,9 +131,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual bool IsDevToolsOpened(); virtual void InspectElement(int x, int y); - // Creates a new window to debug the devtools. - virtual void DebugDevTools(); - virtual void FocusOnWebView(); virtual void BlurWebView(); virtual bool IsWebViewFocused();