Store the devtools window in weak pointer.

This commit is contained in:
Cheng Zhao 2014-03-04 18:42:37 +08:00
parent 391468ece0
commit 6bd0b82b2e
2 changed files with 19 additions and 5 deletions

View file

@ -181,8 +181,10 @@ bool NativeWindow::HasModalDialog() {
} }
void NativeWindow::OpenDevTools() { void NativeWindow::OpenDevTools() {
// For docked devtools we give it to brightray. if (devtools_window_)
inspectable_web_contents()->ShowDevTools(); devtools_window_->Focus(true);
else
inspectable_web_contents()->ShowDevTools();
} }
void NativeWindow::CloseDevTools() { void NativeWindow::CloseDevTools() {
@ -472,11 +474,17 @@ void NativeWindow::Observe(int type,
bool NativeWindow::DevToolsSetDockSide(const std::string& dock_side, bool NativeWindow::DevToolsSetDockSide(const std::string& dock_side,
bool* succeed) { 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; return false;
}
CloseDevTools(); CloseDevTools();
Debug(GetWebContents()); devtools_window_ = Debug(GetWebContents())->GetWeakPtr();
return true; return true;
} }
@ -484,7 +492,7 @@ bool NativeWindow::DevToolsShow(const std::string& dock_side) {
if (dock_side != "undocked") if (dock_side != "undocked")
return false; return false;
Debug(GetWebContents()); devtools_window_ = Debug(GetWebContents())->GetWeakPtr();
return true; return true;
} }

View file

@ -153,6 +153,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
// Should be called by platform code when user want to close the window. // Should be called by platform code when user want to close the window.
virtual void CloseWebContents(); virtual void CloseWebContents();
base::WeakPtr<NativeWindow> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
content::WebContents* GetWebContents() const; content::WebContents* GetWebContents() const;
content::WebContents* GetDevToolsWebContents() const; content::WebContents* GetDevToolsWebContents() const;
@ -267,6 +271,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
base::WeakPtrFactory<NativeWindow> weak_factory_; base::WeakPtrFactory<NativeWindow> weak_factory_;
base::WeakPtr<NativeWindow> devtools_window_;
scoped_ptr<DevToolsDelegate> devtools_delegate_; scoped_ptr<DevToolsDelegate> devtools_delegate_;
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_; scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_; scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;