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() {
// 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;
}

View file

@ -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<NativeWindow> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
content::WebContents* GetWebContents() const;
content::WebContents* GetDevToolsWebContents() const;
@ -267,6 +271,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
base::WeakPtrFactory<NativeWindow> weak_factory_;
base::WeakPtr<NativeWindow> devtools_window_;
scoped_ptr<DevToolsDelegate> devtools_delegate_;
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;