DevTools: fix DevTools Window lifetime with fast_unload_controller

In case of undocked DevTools, we rely on NOTIFICATION_TAB_CLOSING to
figure out the moment to destroy DevTools window. However,
fast_unload_controller detaches WebContents from browser after
receivign beforeunload ack, so we'll never destroy associated
DevTools window.

This patch triggers DevTools window destruction in result of
WebContentsDestroyed callback on front_end WebContents.

BUG=315502
R=pfeldman@chromium.org

Review URL: https://codereview.chromium.org/61553004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233269 0039d316-1c4b-4281-b951-d872f2087c98
parent b6d55b6b
...@@ -187,6 +187,7 @@ class DevToolsWindow::FrontendWebContentsObserver ...@@ -187,6 +187,7 @@ class DevToolsWindow::FrontendWebContentsObserver
virtual void AboutToNavigateRenderView( virtual void AboutToNavigateRenderView(
content::RenderViewHost* render_view_host) OVERRIDE; content::RenderViewHost* render_view_host) OVERRIDE;
virtual void DocumentOnLoadCompletedInMainFrame(int32 page_id) OVERRIDE; virtual void DocumentOnLoadCompletedInMainFrame(int32 page_id) OVERRIDE;
virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
DevToolsWindow* devtools_window_; DevToolsWindow* devtools_window_;
DISALLOW_COPY_AND_ASSIGN(FrontendWebContentsObserver); DISALLOW_COPY_AND_ASSIGN(FrontendWebContentsObserver);
...@@ -198,6 +199,11 @@ DevToolsWindow::FrontendWebContentsObserver::FrontendWebContentsObserver( ...@@ -198,6 +199,11 @@ DevToolsWindow::FrontendWebContentsObserver::FrontendWebContentsObserver(
devtools_window_(devtools_window) { devtools_window_(devtools_window) {
} }
void DevToolsWindow::FrontendWebContentsObserver::WebContentsDestroyed(
content::WebContents* contents) {
delete devtools_window_;
}
DevToolsWindow::FrontendWebContentsObserver::~FrontendWebContentsObserver() { DevToolsWindow::FrontendWebContentsObserver::~FrontendWebContentsObserver() {
} }
...@@ -257,6 +263,10 @@ DictionaryValue* CreateFileSystemValue( ...@@ -257,6 +263,10 @@ DictionaryValue* CreateFileSystemValue(
const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp";
DevToolsWindow::~DevToolsWindow() { DevToolsWindow::~DevToolsWindow() {
content::DevToolsManager::GetInstance()->ClientHostClosing(
frontend_host_.get());
UpdateBrowserToolbar();
DevToolsWindows* instances = &g_instances.Get(); DevToolsWindows* instances = &g_instances.Get();
DevToolsWindows::iterator it( DevToolsWindows::iterator it(
std::find(instances->begin(), instances->end(), this)); std::find(instances->begin(), instances->end(), this));
...@@ -601,9 +611,6 @@ DevToolsWindow::DevToolsWindow(Profile* profile, ...@@ -601,9 +611,6 @@ DevToolsWindow::DevToolsWindow(Profile* profile,
entry->GetFavicon().valid = true; entry->GetFavicon().valid = true;
// Register on-load actions. // Register on-load actions.
content::Source<content::NavigationController> nav_controller_source(
&web_contents_->GetController());
registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, nav_controller_source);
registrar_.Add( registrar_.Add(
this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
content::Source<ThemeService>( content::Source<ThemeService>(
...@@ -740,22 +747,8 @@ DevToolsDockSide DevToolsWindow::SideFromString( ...@@ -740,22 +747,8 @@ DevToolsDockSide DevToolsWindow::SideFromString(
void DevToolsWindow::Observe(int type, void DevToolsWindow::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (type == chrome::NOTIFICATION_TAB_CLOSING) { DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
if (content::Source<content::NavigationController>(source).ptr() == UpdateTheme();
&web_contents_->GetController()) {
// This happens when browser closes all of its tabs as a result
// of window.Close event.
// Notify manager that this DevToolsClientHost no longer exists and
// initiate self-destuct here.
content::DevToolsManager::GetInstance()->ClientHostClosing(
frontend_host_.get());
UpdateBrowserToolbar();
delete this;
}
} else {
DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
UpdateTheme();
}
} }
content::WebContents* DevToolsWindow::OpenURLFromTab( content::WebContents* DevToolsWindow::OpenURLFromTab(
...@@ -807,9 +800,9 @@ void DevToolsWindow::CloseContents(content::WebContents* source) { ...@@ -807,9 +800,9 @@ void DevToolsWindow::CloseContents(content::WebContents* source) {
if (inspected_window) if (inspected_window)
inspected_window->UpdateDevTools(); inspected_window->UpdateDevTools();
// In case of docked web_contents_, we own it so delete here. // In case of docked web_contents_, we own it so delete here.
// Embedding DevTools window will be deleted as a result of
// WebContentsDestroyed callback.
delete web_contents_; delete web_contents_;
delete this;
} }
void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment