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

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

Issue 10117016: Implementation for switching between recently used tabs using ctrl tilde or quoteleft. Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Uploaded as per comments Created 8 years, 6 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
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 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 // OS_WIN 10 #endif // OS_WIN
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 #include "chrome/browser/ui/panels/panel.h" 123 #include "chrome/browser/ui/panels/panel.h"
124 #include "chrome/browser/ui/panels/panel_manager.h" 124 #include "chrome/browser/ui/panels/panel_manager.h"
125 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" 125 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
126 #include "chrome/browser/ui/status_bubble.h" 126 #include "chrome/browser/ui/status_bubble.h"
127 #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" 127 #include "chrome/browser/ui/sync/browser_synced_window_delegate.h"
128 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 128 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
129 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 129 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
130 #include "chrome/browser/ui/tabs/dock_info.h" 130 #include "chrome/browser/ui/tabs/dock_info.h"
131 #include "chrome/browser/ui/tabs/tab_finder.h" 131 #include "chrome/browser/ui/tabs/tab_finder.h"
132 #include "chrome/browser/ui/tabs/tab_menu_model.h" 132 #include "chrome/browser/ui/tabs/tab_menu_model.h"
133 #include "chrome/browser/ui/tabs/tab_mru_list_manager.h"
133 #include "chrome/browser/ui/tabs/tab_strip_model.h" 134 #include "chrome/browser/ui/tabs/tab_strip_model.h"
134 #include "chrome/browser/ui/web_applications/web_app_ui.h" 135 #include "chrome/browser/ui/web_applications/web_app_ui.h"
135 #include "chrome/browser/ui/webui/feedback_ui.h" 136 #include "chrome/browser/ui/webui/feedback_ui.h"
136 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 137 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
137 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" 138 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
138 #include "chrome/browser/ui/webui/options2/content_settings_handler2.h" 139 #include "chrome/browser/ui/webui/options2/content_settings_handler2.h"
139 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 140 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
140 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 141 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
141 #include "chrome/browser/ui/window_sizer.h" 142 #include "chrome/browser/ui/window_sizer.h"
142 #include "chrome/browser/upgrade_detector.h" 143 #include "chrome/browser/upgrade_detector.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 341
341 /////////////////////////////////////////////////////////////////////////////// 342 ///////////////////////////////////////////////////////////////////////////////
342 // Browser, Constructors, Creation, Showing: 343 // Browser, Constructors, Creation, Showing:
343 344
344 Browser::Browser(Type type, Profile* profile) 345 Browser::Browser(Type type, Profile* profile)
345 : type_(type), 346 : type_(type),
346 profile_(profile), 347 profile_(profile),
347 window_(NULL), 348 window_(NULL),
348 ALLOW_THIS_IN_INITIALIZER_LIST( 349 ALLOW_THIS_IN_INITIALIZER_LIST(
349 tab_strip_model_(new TabStripModel(this, profile))), 350 tab_strip_model_(new TabStripModel(this, profile))),
351 ALLOW_THIS_IN_INITIALIZER_LIST(
sky 2012/05/29 19:48:27 No need for ALLOW_THIS_IN_INITIALIAZER_LIST here.
NaveenBobbili (Motorola) 2012/06/05 05:34:16 Done.
352 tab_mru_list_manager_(new TabMRUListManager())),
350 command_updater_(this), 353 command_updater_(this),
351 app_type_(APP_TYPE_HOST), 354 app_type_(APP_TYPE_HOST),
352 chrome_updater_factory_(this), 355 chrome_updater_factory_(this),
353 is_attempting_to_close_browser_(false), 356 is_attempting_to_close_browser_(false),
354 cancel_download_confirmation_state_(NOT_PROMPTED), 357 cancel_download_confirmation_state_(NOT_PROMPTED),
355 show_state_(ui::SHOW_STATE_DEFAULT), 358 show_state_(ui::SHOW_STATE_DEFAULT),
356 is_session_restore_(false), 359 is_session_restore_(false),
357 weak_factory_(this), 360 weak_factory_(this),
358 block_command_execution_(false), 361 block_command_execution_(false),
359 last_blocked_command_id_(-1), 362 last_blocked_command_id_(-1),
360 last_blocked_command_disposition_(CURRENT_TAB), 363 last_blocked_command_disposition_(CURRENT_TAB),
361 pending_web_app_action_(NONE), 364 pending_web_app_action_(NONE),
362 ALLOW_THIS_IN_INITIALIZER_LIST( 365 ALLOW_THIS_IN_INITIALIZER_LIST(
363 content_setting_bubble_model_delegate_( 366 content_setting_bubble_model_delegate_(
364 new BrowserContentSettingBubbleModelDelegate(this))), 367 new BrowserContentSettingBubbleModelDelegate(this))),
365 ALLOW_THIS_IN_INITIALIZER_LIST( 368 ALLOW_THIS_IN_INITIALIZER_LIST(
366 toolbar_model_delegate_( 369 toolbar_model_delegate_(
367 new BrowserToolbarModelDelegate(this))), 370 new BrowserToolbarModelDelegate(this))),
368 ALLOW_THIS_IN_INITIALIZER_LIST( 371 ALLOW_THIS_IN_INITIALIZER_LIST(
369 tab_restore_service_delegate_( 372 tab_restore_service_delegate_(
370 new BrowserTabRestoreServiceDelegate(this))), 373 new BrowserTabRestoreServiceDelegate(this))),
371 ALLOW_THIS_IN_INITIALIZER_LIST( 374 ALLOW_THIS_IN_INITIALIZER_LIST(
372 synced_window_delegate_( 375 synced_window_delegate_(
373 new BrowserSyncedWindowDelegate(this))), 376 new BrowserSyncedWindowDelegate(this))),
374 bookmark_bar_state_(BookmarkBar::HIDDEN), 377 bookmark_bar_state_(BookmarkBar::HIDDEN),
375 window_has_shown_(false) { 378 window_has_shown_(false) {
376 tab_strip_model_->AddObserver(this); 379 tab_strip_model_->AddObserver(this);
380 tab_strip_model_->AddObserver(tab_mru_list_manager_.get());
sky 2012/05/29 19:48:28 TabMRUListManager should take care of adding/remov
NaveenBobbili (Motorola) 2012/06/05 05:34:16 Done.
377 381
378 toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get())); 382 toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get()));
379 383
380 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, 384 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
381 content::NotificationService::AllSources()); 385 content::NotificationService::AllSources());
382 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 386 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
383 content::Source<Profile>(profile_->GetOriginalProfile())); 387 content::Source<Profile>(profile_->GetOriginalProfile()));
384 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 388 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
385 content::Source<Profile>(profile_->GetOriginalProfile())); 389 content::Source<Profile>(profile_->GetOriginalProfile()));
386 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 390 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 Browser::~Browser() { 450 Browser::~Browser() {
447 ProfileSyncService* service = 451 ProfileSyncService* service =
448 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 452 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
449 if (service) 453 if (service)
450 service->RemoveObserver(this); 454 service->RemoveObserver(this);
451 455
452 // The tab strip should not have any tabs at this point. 456 // The tab strip should not have any tabs at this point.
453 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) 457 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers())
454 DCHECK(tab_strip_model_->empty()); 458 DCHECK(tab_strip_model_->empty());
455 tab_strip_model_->RemoveObserver(this); 459 tab_strip_model_->RemoveObserver(this);
460 tab_strip_model_->RemoveObserver(tab_mru_list_manager_.get());
456 461
457 BrowserList::RemoveBrowser(this); 462 BrowserList::RemoveBrowser(this);
458 463
459 SessionService* session_service = 464 SessionService* session_service =
460 SessionServiceFactory::GetForProfile(profile_); 465 SessionServiceFactory::GetForProfile(profile_);
461 if (session_service) 466 if (session_service)
462 session_service->WindowClosed(session_id_); 467 session_service->WindowClosed(session_id_);
463 468
464 TabRestoreService* tab_restore_service = 469 TabRestoreService* tab_restore_service =
465 TabRestoreServiceFactory::GetForProfile(profile()); 470 TabRestoreServiceFactory::GetForProfile(profile());
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 } 1415 }
1411 1416
1412 void Browser::CloseTab() { 1417 void Browser::CloseTab() {
1413 content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); 1418 content::RecordAction(UserMetricsAction("CloseTab_Accelerator"));
1414 if (CanCloseTab()) 1419 if (CanCloseTab())
1415 tab_strip_model_->CloseSelectedTabs(); 1420 tab_strip_model_->CloseSelectedTabs();
1416 } 1421 }
1417 1422
1418 void Browser::SelectNextTab() { 1423 void Browser::SelectNextTab() {
1419 content::RecordAction(UserMetricsAction("SelectNextTab")); 1424 content::RecordAction(UserMetricsAction("SelectNextTab"));
1420 tab_strip_model_->SelectNextTab(); 1425 TabContentsWrapper* contents = tab_mru_list_manager_->GetNextMRUTab();
sky 2012/05/29 19:48:28 Don't change selectnexttab.
NaveenBobbili (Motorola) 2012/06/05 05:34:16 This creeped in by mistake.Done
1426 if (contents)
1427 tab_strip_model_->SelectNextTab();
1421 } 1428 }
1422 1429
1423 void Browser::SelectPreviousTab() { 1430 void Browser::SelectPreviousTab() {
1424 content::RecordAction(UserMetricsAction("SelectPrevTab")); 1431 content::RecordAction(UserMetricsAction("SelectPrevTab"));
1425 tab_strip_model_->SelectPreviousTab(); 1432 tab_strip_model_->SelectPreviousTab();
1426 } 1433 }
1427 1434
1428 void Browser::OpenTabpose() { 1435 void Browser::OpenTabpose() {
1429 #if defined(OS_MACOSX) 1436 #if defined(OS_MACOSX)
1430 if (!CommandLine::ForCurrentProcess()->HasSwitch( 1437 if (!CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 23 matching lines...) Expand all
1454 content::RecordAction(UserMetricsAction("SelectNumberedTab")); 1461 content::RecordAction(UserMetricsAction("SelectNumberedTab"));
1455 ActivateTabAt(index, true); 1462 ActivateTabAt(index, true);
1456 } 1463 }
1457 } 1464 }
1458 1465
1459 void Browser::SelectLastTab() { 1466 void Browser::SelectLastTab() {
1460 content::RecordAction(UserMetricsAction("SelectLastTab")); 1467 content::RecordAction(UserMetricsAction("SelectLastTab"));
1461 tab_strip_model_->SelectLastTab(); 1468 tab_strip_model_->SelectLastTab();
1462 } 1469 }
1463 1470
1471 void Browser::SelectNextMRUTab() {
1472 content::RecordAction(UserMetricsAction("SelectNextMRUTab"));
1473 TabContentsWrapper* contents = tab_mru_list_manager_->GetNextMRUTab();
1474 if (contents)
1475 ActivateTabAt(tab_strip_model_->GetIndexOfTabContents(contents), true);
1476 }
1477
1464 void Browser::DuplicateTab() { 1478 void Browser::DuplicateTab() {
1465 content::RecordAction(UserMetricsAction("Duplicate")); 1479 content::RecordAction(UserMetricsAction("Duplicate"));
1466 DuplicateContentsAt(active_index()); 1480 DuplicateContentsAt(active_index());
1467 } 1481 }
1468 1482
1469 void Browser::WriteCurrentURLToClipboard() { 1483 void Browser::WriteCurrentURLToClipboard() {
1470 // TODO(ericu): There isn't currently a metric for this. Should there be? 1484 // TODO(ericu): There isn't currently a metric for this. Should there be?
1471 // We don't appear to track the action when it comes from the 1485 // We don't appear to track the action when it comes from the
1472 // RenderContextViewMenu. 1486 // RenderContextViewMenu.
1473 1487
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break; 2581 case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break;
2568 case IDC_CLEAR_BROWSING_DATA: OpenClearBrowsingDataDialog(); break; 2582 case IDC_CLEAR_BROWSING_DATA: OpenClearBrowsingDataDialog(); break;
2569 case IDC_IMPORT_SETTINGS: OpenImportSettingsDialog(); break; 2583 case IDC_IMPORT_SETTINGS: OpenImportSettingsDialog(); break;
2570 case IDC_ABOUT: OpenAboutChromeDialog(); break; 2584 case IDC_ABOUT: OpenAboutChromeDialog(); break;
2571 case IDC_UPGRADE_DIALOG: OpenUpdateChromeDialog(); break; 2585 case IDC_UPGRADE_DIALOG: OpenUpdateChromeDialog(); break;
2572 case IDC_VIEW_INCOMPATIBILITIES: ShowAboutConflictsTab(); break; 2586 case IDC_VIEW_INCOMPATIBILITIES: ShowAboutConflictsTab(); break;
2573 case IDC_HELP_PAGE: ShowHelpTab(); break; 2587 case IDC_HELP_PAGE: ShowHelpTab(); break;
2574 case IDC_SHOW_SYNC_SETUP: ShowSyncSetup(SyncPromoUI::SOURCE_MENU); 2588 case IDC_SHOW_SYNC_SETUP: ShowSyncSetup(SyncPromoUI::SOURCE_MENU);
2575 break; 2589 break;
2576 case IDC_TOGGLE_SPEECH_INPUT: ToggleSpeechInput(); break; 2590 case IDC_TOGGLE_SPEECH_INPUT: ToggleSpeechInput(); break;
2591 case IDC_SELECT_NEXT_MRU_TAB: SelectNextMRUTab(); break;
2577 2592
2578 default: 2593 default:
2579 LOG(WARNING) << "Received Unimplemented Command: " << id; 2594 LOG(WARNING) << "Received Unimplemented Command: " << id;
2580 break; 2595 break;
2581 } 2596 }
2582 } 2597 }
2583 2598
2584 //////////////////////////////////////////////////////////////////////////////// 2599 ////////////////////////////////////////////////////////////////////////////////
2585 // Browser, TabRestoreServiceObserver: 2600 // Browser, TabRestoreServiceObserver:
2586 2601
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after
4072 // Navigation commands 4087 // Navigation commands
4073 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); 4088 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window);
4074 4089
4075 // Window management commands 4090 // Window management commands
4076 // TODO(rohitrao): Disable fullscreen on non-Lion? 4091 // TODO(rohitrao): Disable fullscreen on non-Lion?
4077 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, 4092 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN,
4078 !(is_type_panel() && is_app())); 4093 !(is_type_panel() && is_app()));
4079 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); 4094 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
4080 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, 4095 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
4081 normal_window); 4096 normal_window);
4097 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_MRU_TAB,
sky 2012/05/29 19:48:28 Only enable if enabled in about:flags.
NaveenBobbili (Motorola) 2012/06/05 05:34:16 Done.
4098 normal_window);
4082 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); 4099 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
4083 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); 4100 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
4084 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); 4101 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
4085 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); 4102 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
4086 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); 4103 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
4087 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); 4104 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
4088 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); 4105 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
4089 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); 4106 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
4090 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); 4107 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
4091 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); 4108 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
5109 if (contents && !allow_js_access) { 5126 if (contents && !allow_js_access) {
5110 contents->web_contents()->GetController().LoadURL( 5127 contents->web_contents()->GetController().LoadURL(
5111 target_url, 5128 target_url,
5112 content::Referrer(), 5129 content::Referrer(),
5113 content::PAGE_TRANSITION_LINK, 5130 content::PAGE_TRANSITION_LINK,
5114 std::string()); // No extra headers. 5131 std::string()); // No extra headers.
5115 } 5132 }
5116 5133
5117 return contents != NULL; 5134 return contents != NULL;
5118 } 5135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698