mirror of
https://github.com/electron/electron.git
synced 2026-02-04 04:05:36 -05:00
Store the devtools window in weak pointer.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user