From 6bd0b82b2e20279702283dc507f71833af71fa21 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 18:42:37 +0800 Subject: [PATCH] Store the devtools window in weak pointer. --- browser/native_window.cc | 18 +++++++++++++----- browser/native_window.h | 6 ++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/browser/native_window.cc b/browser/native_window.cc index e16c45f1ebab..b3e492dae936 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -181,8 +181,10 @@ bool NativeWindow::HasModalDialog() { } void NativeWindow::OpenDevTools() { - // For docked devtools we give it to brightray. - inspectable_web_contents()->ShowDevTools(); + if (devtools_window_) + devtools_window_->Focus(true); + else + inspectable_web_contents()->ShowDevTools(); } void NativeWindow::CloseDevTools() { @@ -472,11 +474,17 @@ void NativeWindow::Observe(int type, bool NativeWindow::DevToolsSetDockSide(const std::string& dock_side, bool* succeed) { - if (dock_side != "undocked") + if (dock_side != "undocked") { + // Switch to docked mode. + if (devtools_window_) { + devtools_window_->Close(); + devtools_window_.reset(); + } return false; + } CloseDevTools(); - Debug(GetWebContents()); + devtools_window_ = Debug(GetWebContents())->GetWeakPtr(); return true; } @@ -484,7 +492,7 @@ bool NativeWindow::DevToolsShow(const std::string& dock_side) { if (dock_side != "undocked") return false; - Debug(GetWebContents()); + devtools_window_ = Debug(GetWebContents())->GetWeakPtr(); return true; } diff --git a/browser/native_window.h b/browser/native_window.h index 1b3b38df7093..8a0c1ccfe41c 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -153,6 +153,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // Should be called by platform code when user want to close the window. virtual void CloseWebContents(); + base::WeakPtr GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } + content::WebContents* GetWebContents() const; content::WebContents* GetDevToolsWebContents() const; @@ -267,6 +271,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, base::WeakPtrFactory weak_factory_; + base::WeakPtr devtools_window_; + scoped_ptr devtools_delegate_; scoped_ptr dialog_manager_; scoped_ptr inspectable_web_contents_;