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

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 17571018: Reland fast tab closure behind a flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Diff against original patch Created 7 years, 5 months 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 | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/cocoa/browser_window_controller.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 4
5 #include "chrome/browser/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // defined(OS_WIN) 10 #endif // defined(OS_WIN)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #include "chrome/browser/ui/browser_tab_contents.h" 101 #include "chrome/browser/ui/browser_tab_contents.h"
102 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" 102 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
103 #include "chrome/browser/ui/browser_tab_strip_model_delegate.h" 103 #include "chrome/browser/ui/browser_tab_strip_model_delegate.h"
104 #include "chrome/browser/ui/browser_tabstrip.h" 104 #include "chrome/browser/ui/browser_tabstrip.h"
105 #include "chrome/browser/ui/browser_toolbar_model_delegate.h" 105 #include "chrome/browser/ui/browser_toolbar_model_delegate.h"
106 #include "chrome/browser/ui/browser_ui_prefs.h" 106 #include "chrome/browser/ui/browser_ui_prefs.h"
107 #include "chrome/browser/ui/browser_window.h" 107 #include "chrome/browser/ui/browser_window.h"
108 #include "chrome/browser/ui/chrome_pages.h" 108 #include "chrome/browser/ui/chrome_pages.h"
109 #include "chrome/browser/ui/chrome_select_file_policy.h" 109 #include "chrome/browser/ui/chrome_select_file_policy.h"
110 #include "chrome/browser/ui/extensions/shell_window.h" 110 #include "chrome/browser/ui/extensions/shell_window.h"
111 #include "chrome/browser/ui/fast_unload_controller.h"
111 #include "chrome/browser/ui/find_bar/find_bar.h" 112 #include "chrome/browser/ui/find_bar/find_bar.h"
112 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 113 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
113 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 114 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
114 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 115 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
115 #include "chrome/browser/ui/global_error/global_error.h" 116 #include "chrome/browser/ui/global_error/global_error.h"
116 #include "chrome/browser/ui/global_error/global_error_service.h" 117 #include "chrome/browser/ui/global_error/global_error_service.h"
117 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 118 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
118 #include "chrome/browser/ui/omnibox/location_bar.h" 119 #include "chrome/browser/ui/omnibox/location_bar.h"
119 #include "chrome/browser/ui/search/search_delegate.h" 120 #include "chrome/browser/ui/search/search_delegate.h"
120 #include "chrome/browser/ui/search/search_model.h" 121 #include "chrome/browser/ui/search/search_model.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 "https://www.google.com/support/chrome/bin/request.py?contact_type=" 227 "https://www.google.com/support/chrome/bin/request.py?contact_type="
227 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; 228 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2";
228 229
229 // How long we wait before updating the browser chrome while loading a page. 230 // How long we wait before updating the browser chrome while loading a page.
230 const int kUIUpdateCoalescingTimeMS = 200; 231 const int kUIUpdateCoalescingTimeMS = 200;
231 232
232 BrowserWindow* CreateBrowserWindow(Browser* browser) { 233 BrowserWindow* CreateBrowserWindow(Browser* browser) {
233 return BrowserWindow::CreateBrowserWindow(browser); 234 return BrowserWindow::CreateBrowserWindow(browser);
234 } 235 }
235 236
237 // Is the fast tab unload experiment enabled?
238 bool FastTabUnloadEnabled() {
sky 2013/06/27 16:13:16 IsFastTabUnloadEnabled?
239 return CommandLine::ForCurrentProcess()->HasSwitch(
240 switches::kEnableFastUnload);
241 }
242
236 } // namespace 243 } // namespace
237 244
238 //////////////////////////////////////////////////////////////////////////////// 245 ////////////////////////////////////////////////////////////////////////////////
239 // Browser, CreateParams: 246 // Browser, CreateParams:
240 247
241 Browser::CreateParams::CreateParams(Profile* profile, 248 Browser::CreateParams::CreateParams(Profile* profile,
242 chrome::HostDesktopType host_desktop_type) 249 chrome::HostDesktopType host_desktop_type)
243 : type(TYPE_TABBED), 250 : type(TYPE_TABBED),
244 profile(profile), 251 profile(profile),
245 host_desktop_type(host_desktop_type), 252 host_desktop_type(host_desktop_type),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(), 332 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(),
326 params.profile)), 333 params.profile)),
327 app_name_(params.app_name), 334 app_name_(params.app_name),
328 app_type_(params.app_type), 335 app_type_(params.app_type),
329 chrome_updater_factory_(this), 336 chrome_updater_factory_(this),
330 cancel_download_confirmation_state_(NOT_PROMPTED), 337 cancel_download_confirmation_state_(NOT_PROMPTED),
331 override_bounds_(params.initial_bounds), 338 override_bounds_(params.initial_bounds),
332 initial_show_state_(params.initial_show_state), 339 initial_show_state_(params.initial_show_state),
333 is_session_restore_(params.is_session_restore), 340 is_session_restore_(params.is_session_restore),
334 host_desktop_type_(params.host_desktop_type), 341 host_desktop_type_(params.host_desktop_type),
335 unload_controller_(new chrome::UnloadController(this)),
336 weak_factory_(this), 342 weak_factory_(this),
337 content_setting_bubble_model_delegate_( 343 content_setting_bubble_model_delegate_(
338 new BrowserContentSettingBubbleModelDelegate(this)), 344 new BrowserContentSettingBubbleModelDelegate(this)),
339 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)), 345 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)),
340 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)), 346 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)),
341 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)), 347 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)),
342 bookmark_bar_state_(BookmarkBar::HIDDEN), 348 bookmark_bar_state_(BookmarkBar::HIDDEN),
343 command_controller_(new chrome::BrowserCommandController( 349 command_controller_(new chrome::BrowserCommandController(
344 this, g_browser_process->profile_manager())), 350 this, g_browser_process->profile_manager())),
345 window_has_shown_(false) { 351 window_has_shown_(false) {
346 // If this causes a crash then a window is being opened using a profile type 352 // If this causes a crash then a window is being opened using a profile type
347 // that is disallowed by policy. The crash prevents the disabled window type 353 // that is disallowed by policy. The crash prevents the disabled window type
348 // from opening at all, but the path that triggered it should be fixed. 354 // from opening at all, but the path that triggered it should be fixed.
349 CHECK(IncognitoModePrefs::CanOpenBrowser(profile_)); 355 CHECK(IncognitoModePrefs::CanOpenBrowser(profile_));
350 356
357 // TODO(jeremy): Move to initializer list once flag is removed.
358 if (FastTabUnloadEnabled())
359 fast_unload_controller_.reset(new chrome::FastUnloadController(this));
360 else
361 unload_controller_.reset(new chrome::UnloadController(this));
362
351 if (!app_name_.empty()) 363 if (!app_name_.empty())
352 chrome::RegisterAppPrefs(app_name_, profile_); 364 chrome::RegisterAppPrefs(app_name_, profile_);
353 tab_strip_model_->AddObserver(this); 365 tab_strip_model_->AddObserver(this);
354 366
355 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get())); 367 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get()));
356 search_model_.reset(new SearchModel()); 368 search_model_.reset(new SearchModel());
357 search_delegate_.reset( 369 search_delegate_.reset(
358 new SearchDelegate(search_model_.get(), toolbar_model_.get())); 370 new SearchDelegate(search_model_.get(), toolbar_model_.get()));
359 371
360 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 372 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 } 590 }
579 } 591 }
580 592
581 /////////////////////////////////////////////////////////////////////////////// 593 ///////////////////////////////////////////////////////////////////////////////
582 // Browser, OnBeforeUnload handling: 594 // Browser, OnBeforeUnload handling:
583 595
584 bool Browser::ShouldCloseWindow() { 596 bool Browser::ShouldCloseWindow() {
585 if (!CanCloseWithInProgressDownloads()) 597 if (!CanCloseWithInProgressDownloads())
586 return false; 598 return false;
587 599
588 return unload_controller_->ShouldCloseWindow(); 600 if (FastTabUnloadEnabled())
601 return fast_unload_controller_->ShouldCloseWindow();
602 else
sky 2013/06/27 16:13:16 nit: no else after a return.
603 return unload_controller_->ShouldCloseWindow();
589 } 604 }
590 605
591 bool Browser::HasCompletedUnloadProcessing() const { 606 bool Browser::HasCompletedUnloadProcessing() const {
607 DCHECK(FastTabUnloadEnabled());
608 return fast_unload_controller_->HasCompletedUnloadProcessing();
609 }
610
611 bool Browser::HasCompletedUnloadProcessing() const {
592 return unload_controller_->HasCompletedUnloadProcessing(); 612 return unload_controller_->HasCompletedUnloadProcessing();
593 } 613 }
594 614
595 bool Browser::IsAttemptingToCloseBrowser() const { 615 bool Browser::IsAttemptingToCloseBrowser() const {
596 return unload_controller_->is_attempting_to_close_browser(); 616 if (FastTabUnloadEnabled())
617 return fast_unload_controller_->is_attempting_to_close_browser();
618 else
sky 2013/06/27 16:13:16 same nit here.
619 return unload_controller_->is_attempting_to_close_browser();
597 } 620 }
598 621
599 void Browser::OnWindowClosing() { 622 void Browser::OnWindowClosing() {
600 if (!ShouldCloseWindow()) 623 if (!ShouldCloseWindow())
601 return; 624 return;
602 625
603 // Application should shutdown on last window close if the user is explicitly 626 // Application should shutdown on last window close if the user is explicitly
604 // trying to quit, or if there is nothing keeping the browser alive (such as 627 // trying to quit, or if there is nothing keeping the browser alive (such as
605 // AppController on the Mac, or BackgroundContentsService for background 628 // AppController on the Mac, or BackgroundContentsService for background
606 // pages). 629 // pages).
(...skipping 22 matching lines...) Expand all
629 652
630 if (tab_restore_service && is_type_tabbed() && tab_strip_model_->count()) 653 if (tab_restore_service && is_type_tabbed() && tab_strip_model_->count())
631 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); 654 tab_restore_service->BrowserClosing(tab_restore_service_delegate());
632 655
633 // TODO(sky): convert session/tab restore to use notification. 656 // TODO(sky): convert session/tab restore to use notification.
634 content::NotificationService::current()->Notify( 657 content::NotificationService::current()->Notify(
635 chrome::NOTIFICATION_BROWSER_CLOSING, 658 chrome::NOTIFICATION_BROWSER_CLOSING,
636 content::Source<Browser>(this), 659 content::Source<Browser>(this),
637 content::NotificationService::NoDetails()); 660 content::NotificationService::NoDetails());
638 661
639 tab_strip_model_->CloseAllTabs(); 662 if (!FastTabUnloadEnabled())
663 tab_strip_model_->CloseAllTabs();
640 } 664 }
641 665
642 //////////////////////////////////////////////////////////////////////////////// 666 ////////////////////////////////////////////////////////////////////////////////
643 // In-progress download termination handling: 667 // In-progress download termination handling:
644 668
645 void Browser::InProgressDownloadResponse(bool cancel_downloads) { 669 void Browser::InProgressDownloadResponse(bool cancel_downloads) {
646 if (cancel_downloads) { 670 if (cancel_downloads) {
647 cancel_download_confirmation_state_ = RESPONSE_RECEIVED; 671 cancel_download_confirmation_state_ = RESPONSE_RECEIVED;
648 chrome::CloseWindow(this); 672 chrome::CloseWindow(this);
649 return; 673 return;
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 } 1191 }
1168 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); 1192 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1169 } 1193 }
1170 1194
1171 void Browser::HandleKeyboardEvent(content::WebContents* source, 1195 void Browser::HandleKeyboardEvent(content::WebContents* source,
1172 const NativeWebKeyboardEvent& event) { 1196 const NativeWebKeyboardEvent& event) {
1173 window()->HandleKeyboardEvent(event); 1197 window()->HandleKeyboardEvent(event);
1174 } 1198 }
1175 1199
1176 bool Browser::TabsNeedBeforeUnloadFired() { 1200 bool Browser::TabsNeedBeforeUnloadFired() {
1177 return unload_controller_->TabsNeedBeforeUnloadFired(); 1201 if (FastTabUnloadEnabled())
1202 return fast_unload_controller_->TabsNeedBeforeUnloadFired();
1203 else
sky 2013/06/27 16:13:16 and here.
1204 return unload_controller_->TabsNeedBeforeUnloadFired();
1178 } 1205 }
1179 1206
1180 bool Browser::IsMouseLocked() const { 1207 bool Browser::IsMouseLocked() const {
1181 return fullscreen_controller_->IsMouseLocked(); 1208 return fullscreen_controller_->IsMouseLocked();
1182 } 1209 }
1183 1210
1184 void Browser::OnWindowDidShow() { 1211 void Browser::OnWindowDidShow() {
1185 if (window_has_shown_) 1212 if (window_has_shown_)
1186 return; 1213 return;
1187 window_has_shown_ = true; 1214 window_has_shown_ = true;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 bool is_loading = source->IsLoading(); 1330 bool is_loading = source->IsLoading();
1304 command_controller_->LoadingStateChanged(is_loading, false); 1331 command_controller_->LoadingStateChanged(is_loading, false);
1305 if (GetStatusBubble()) { 1332 if (GetStatusBubble()) {
1306 GetStatusBubble()->SetStatus(CoreTabHelper::FromWebContents( 1333 GetStatusBubble()->SetStatus(CoreTabHelper::FromWebContents(
1307 tab_strip_model_->GetActiveWebContents())->GetStatusText()); 1334 tab_strip_model_->GetActiveWebContents())->GetStatusText());
1308 } 1335 }
1309 } 1336 }
1310 } 1337 }
1311 1338
1312 void Browser::CloseContents(WebContents* source) { 1339 void Browser::CloseContents(WebContents* source) {
1313 if (unload_controller_->CanCloseContents(source)) 1340 bool can_close_contents;
1341 if (FastTabUnloadEnabled())
1342 can_close_contents = fast_unload_controller_->CanCloseContents(source);
1343 else
1344 can_close_contents = unload_controller_->CanCloseContents(source);
1345
1346 if (can_close_contents)
1314 chrome::CloseWebContents(this, source, true); 1347 chrome::CloseWebContents(this, source, true);
1315 } 1348 }
1316 1349
1317 void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { 1350 void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) {
1318 if (!IsPopupOrPanel(source)) { 1351 if (!IsPopupOrPanel(source)) {
1319 NOTREACHED() << "moving invalid browser type"; 1352 NOTREACHED() << "moving invalid browser type";
1320 return; 1353 return;
1321 } 1354 }
1322 window_->SetBounds(pos); 1355 window_->SetBounds(pos);
1323 } 1356 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 return false; 1399 return false;
1367 } 1400 }
1368 1401
1369 gfx::Rect Browser::GetRootWindowResizerRect() const { 1402 gfx::Rect Browser::GetRootWindowResizerRect() const {
1370 return window_->GetRootWindowResizerRect(); 1403 return window_->GetRootWindowResizerRect();
1371 } 1404 }
1372 1405
1373 void Browser::BeforeUnloadFired(WebContents* web_contents, 1406 void Browser::BeforeUnloadFired(WebContents* web_contents,
1374 bool proceed, 1407 bool proceed,
1375 bool* proceed_to_fire_unload) { 1408 bool* proceed_to_fire_unload) {
1376 *proceed_to_fire_unload = 1409 if (FastTabUnloadEnabled())
sky 2013/06/27 16:13:16 nit: use {} for multi-line ones.
1377 unload_controller_->BeforeUnloadFired(web_contents, proceed); 1410 *proceed_to_fire_unload =
1411 fast_unload_controller_->BeforeUnloadFired(web_contents, proceed);
1412 else
1413 *proceed_to_fire_unload =
1414 unload_controller_->BeforeUnloadFired(web_contents, proceed);
1378 } 1415 }
1379 1416
1380 bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) { 1417 bool Browser::ShouldFocusLocationBarByDefault(WebContents* source) {
1381 const content::NavigationEntry* entry = 1418 const content::NavigationEntry* entry =
1382 source->GetController().GetActiveEntry(); 1419 source->GetController().GetActiveEntry();
1383 if (entry) { 1420 if (entry) {
1384 GURL url = entry->GetURL(); 1421 GURL url = entry->GetURL();
1385 GURL virtual_url = entry->GetVirtualURL(); 1422 GURL virtual_url = entry->GetVirtualURL();
1386 if ((url.SchemeIs(chrome::kChromeUIScheme) && 1423 if ((url.SchemeIs(chrome::kChromeUIScheme) &&
1387 url.host() == chrome::kChromeUINewTabHost) || 1424 url.host() == chrome::kChromeUINewTabHost) ||
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 if (contents && !allow_js_access) { 2254 if (contents && !allow_js_access) {
2218 contents->web_contents()->GetController().LoadURL( 2255 contents->web_contents()->GetController().LoadURL(
2219 target_url, 2256 target_url,
2220 content::Referrer(), 2257 content::Referrer(),
2221 content::PAGE_TRANSITION_LINK, 2258 content::PAGE_TRANSITION_LINK,
2222 std::string()); // No extra headers. 2259 std::string()); // No extra headers.
2223 } 2260 }
2224 2261
2225 return contents != NULL; 2262 return contents != NULL;
2226 } 2263 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/cocoa/browser_window_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698