Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chrome/browser/devtools/devtools_window.cc

Issue 61553004: DevTools: fix DevTools Window lifetime with fast_unload_controller (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: call UpdateBrowserToolbar in DevToolsWindow destructor unconditionally Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "chrome/browser/devtools/devtools_window.h" 4 #include "chrome/browser/devtools/devtools_window.h"
5 5
6 #include <algorithm> 6 #include <algorithm>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 : public content::WebContentsObserver { 180 : public content::WebContentsObserver {
181 public: 181 public:
182 explicit FrontendWebContentsObserver(DevToolsWindow* window); 182 explicit FrontendWebContentsObserver(DevToolsWindow* window);
183 virtual ~FrontendWebContentsObserver(); 183 virtual ~FrontendWebContentsObserver();
184 184
185 private: 185 private:
186 // contents::WebContentsObserver: 186 // contents::WebContentsObserver:
187 virtual void AboutToNavigateRenderView( 187 virtual void AboutToNavigateRenderView(
188 content::RenderViewHost* render_view_host) OVERRIDE; 188 content::RenderViewHost* render_view_host) OVERRIDE;
189 virtual void DocumentOnLoadCompletedInMainFrame(int32 page_id) OVERRIDE; 189 virtual void DocumentOnLoadCompletedInMainFrame(int32 page_id) OVERRIDE;
190 virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
190 191
191 DevToolsWindow* devtools_window_; 192 DevToolsWindow* devtools_window_;
192 DISALLOW_COPY_AND_ASSIGN(FrontendWebContentsObserver); 193 DISALLOW_COPY_AND_ASSIGN(FrontendWebContentsObserver);
193 }; 194 };
194 195
195 DevToolsWindow::FrontendWebContentsObserver::FrontendWebContentsObserver( 196 DevToolsWindow::FrontendWebContentsObserver::FrontendWebContentsObserver(
196 DevToolsWindow* devtools_window) 197 DevToolsWindow* devtools_window)
197 : WebContentsObserver(devtools_window->web_contents()), 198 : WebContentsObserver(devtools_window->web_contents()),
198 devtools_window_(devtools_window) { 199 devtools_window_(devtools_window) {
199 } 200 }
200 201
202 void DevToolsWindow::FrontendWebContentsObserver::WebContentsDestroyed(
203 content::WebContents* contents) {
204 delete devtools_window_;
205 }
206
201 DevToolsWindow::FrontendWebContentsObserver::~FrontendWebContentsObserver() { 207 DevToolsWindow::FrontendWebContentsObserver::~FrontendWebContentsObserver() {
202 } 208 }
203 209
204 void DevToolsWindow::FrontendWebContentsObserver::AboutToNavigateRenderView( 210 void DevToolsWindow::FrontendWebContentsObserver::AboutToNavigateRenderView(
205 content::RenderViewHost* render_view_host) { 211 content::RenderViewHost* render_view_host) {
206 content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host); 212 content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host);
207 } 213 }
208 214
209 void DevToolsWindow::FrontendWebContentsObserver:: 215 void DevToolsWindow::FrontendWebContentsObserver::
210 DocumentOnLoadCompletedInMainFrame(int32 page_id) { 216 DocumentOnLoadCompletedInMainFrame(int32 page_id) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 file_system_value->SetString("rootURL", file_system.root_url); 256 file_system_value->SetString("rootURL", file_system.root_url);
251 file_system_value->SetString("fileSystemPath", file_system.file_system_path); 257 file_system_value->SetString("fileSystemPath", file_system.file_system_path);
252 return file_system_value; 258 return file_system_value;
253 } 259 }
254 260
255 } // namespace 261 } // namespace
256 262
257 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; 263 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp";
258 264
259 DevToolsWindow::~DevToolsWindow() { 265 DevToolsWindow::~DevToolsWindow() {
266 content::DevToolsManager::GetInstance()->ClientHostClosing(
267 frontend_host_.get());
268 UpdateBrowserToolbar();
269
260 DevToolsWindows* instances = &g_instances.Get(); 270 DevToolsWindows* instances = &g_instances.Get();
261 DevToolsWindows::iterator it( 271 DevToolsWindows::iterator it(
262 std::find(instances->begin(), instances->end(), this)); 272 std::find(instances->begin(), instances->end(), this));
263 DCHECK(it != instances->end()); 273 DCHECK(it != instances->end());
264 instances->erase(it); 274 instances->erase(it);
265 275
266 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); 276 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin());
267 jobs_it != indexing_jobs_.end(); ++jobs_it) { 277 jobs_it != indexing_jobs_.end(); ++jobs_it) {
268 jobs_it->second->Stop(); 278 jobs_it->second->Stop();
269 } 279 }
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 604
595 g_instances.Get().push_back(this); 605 g_instances.Get().push_back(this);
596 606
597 // Wipe out page icon so that the default application icon is used. 607 // Wipe out page icon so that the default application icon is used.
598 content::NavigationEntry* entry = 608 content::NavigationEntry* entry =
599 web_contents_->GetController().GetActiveEntry(); 609 web_contents_->GetController().GetActiveEntry();
600 entry->GetFavicon().image = gfx::Image(); 610 entry->GetFavicon().image = gfx::Image();
601 entry->GetFavicon().valid = true; 611 entry->GetFavicon().valid = true;
602 612
603 // Register on-load actions. 613 // Register on-load actions.
604 content::Source<content::NavigationController> nav_controller_source(
605 &web_contents_->GetController());
606 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, nav_controller_source);
607 registrar_.Add( 614 registrar_.Add(
608 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 615 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
609 content::Source<ThemeService>( 616 content::Source<ThemeService>(
610 ThemeServiceFactory::GetForProfile(profile_))); 617 ThemeServiceFactory::GetForProfile(profile_)));
611 618
612 // There is no inspected_rvh in case of shared workers. 619 // There is no inspected_rvh in case of shared workers.
613 if (inspected_rvh) 620 if (inspected_rvh)
614 inspected_contents_observer_.reset(new InspectedWebContentsObserver( 621 inspected_contents_observer_.reset(new InspectedWebContentsObserver(
615 content::WebContents::FromRenderViewHost(inspected_rvh))); 622 content::WebContents::FromRenderViewHost(inspected_rvh)));
616 623
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 return DEVTOOLS_DOCK_SIDE_RIGHT; 740 return DEVTOOLS_DOCK_SIDE_RIGHT;
734 if (dock_side == kDockSideBottom) 741 if (dock_side == kDockSideBottom)
735 return DEVTOOLS_DOCK_SIDE_BOTTOM; 742 return DEVTOOLS_DOCK_SIDE_BOTTOM;
736 return (dock_side == kDockSideMinimized) ? 743 return (dock_side == kDockSideMinimized) ?
737 DEVTOOLS_DOCK_SIDE_MINIMIZED : DEVTOOLS_DOCK_SIDE_UNDOCKED; 744 DEVTOOLS_DOCK_SIDE_MINIMIZED : DEVTOOLS_DOCK_SIDE_UNDOCKED;
738 } 745 }
739 746
740 void DevToolsWindow::Observe(int type, 747 void DevToolsWindow::Observe(int type,
741 const content::NotificationSource& source, 748 const content::NotificationSource& source,
742 const content::NotificationDetails& details) { 749 const content::NotificationDetails& details) {
743 if (type == chrome::NOTIFICATION_TAB_CLOSING) { 750 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
744 if (content::Source<content::NavigationController>(source).ptr() == 751 UpdateTheme();
745 &web_contents_->GetController()) {
746 // This happens when browser closes all of its tabs as a result
747 // of window.Close event.
748 // Notify manager that this DevToolsClientHost no longer exists and
749 // initiate self-destuct here.
750 content::DevToolsManager::GetInstance()->ClientHostClosing(
751 frontend_host_.get());
752 UpdateBrowserToolbar();
753 delete this;
754 }
755 } else {
756 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
757 UpdateTheme();
758 }
759 } 752 }
760 753
761 content::WebContents* DevToolsWindow::OpenURLFromTab( 754 content::WebContents* DevToolsWindow::OpenURLFromTab(
762 content::WebContents* source, 755 content::WebContents* source,
763 const content::OpenURLParams& params) { 756 const content::OpenURLParams& params) {
764 if (!params.url.SchemeIs(chrome::kChromeDevToolsScheme)) { 757 if (!params.url.SchemeIs(chrome::kChromeDevToolsScheme)) {
765 content::WebContents* inspected_web_contents = GetInspectedWebContents(); 758 content::WebContents* inspected_web_contents = GetInspectedWebContents();
766 return inspected_web_contents ? 759 return inspected_web_contents ?
767 inspected_web_contents->OpenURL(params) : NULL; 760 inspected_web_contents->OpenURL(params) : NULL;
768 } 761 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 } 793 }
801 } 794 }
802 795
803 void DevToolsWindow::CloseContents(content::WebContents* source) { 796 void DevToolsWindow::CloseContents(content::WebContents* source) {
804 CHECK(IsDocked()); 797 CHECK(IsDocked());
805 // Update dev tools to reflect removed dev tools window. 798 // Update dev tools to reflect removed dev tools window.
806 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); 799 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
807 if (inspected_window) 800 if (inspected_window)
808 inspected_window->UpdateDevTools(); 801 inspected_window->UpdateDevTools();
809 // In case of docked web_contents_, we own it so delete here. 802 // In case of docked web_contents_, we own it so delete here.
803 // Embedding DevTools window will be deleted as a result of
804 // WebContentsDestroyed callback.
810 delete web_contents_; 805 delete web_contents_;
811
812 delete this;
813 } 806 }
814 807
815 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, 808 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab,
816 bool proceed, 809 bool proceed,
817 bool* proceed_to_fire_unload) { 810 bool* proceed_to_fire_unload) {
818 if (proceed) { 811 if (proceed) {
819 content::DevToolsManager::GetInstance()->ClientHostClosing( 812 content::DevToolsManager::GetInstance()->ClientHostClosing(
820 frontend_host_.get()); 813 frontend_host_.get());
821 } 814 }
822 *proceed_to_fire_unload = proceed; 815 *proceed_to_fire_unload = proceed;
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 return inspected_contents_observer_ ? 1399 return inspected_contents_observer_ ?
1407 inspected_contents_observer_->web_contents() : NULL; 1400 inspected_contents_observer_->web_contents() : NULL;
1408 } 1401 }
1409 1402
1410 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { 1403 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() {
1411 is_loaded_ = true; 1404 is_loaded_ = true;
1412 UpdateTheme(); 1405 UpdateTheme();
1413 DoAction(); 1406 DoAction();
1414 AddDevToolsExtensionsToClient(); 1407 AddDevToolsExtensionsToClient();
1415 } 1408 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698