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

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

Issue 17428: Issue 358: Can't open a new tab by middle-clicking home button... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 9 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/browser.h ('k') | chrome/browser/location_bar.h » ('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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/browser.h" 5 #include "chrome/browser/browser.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/idle_timer.h" 8 #include "base/idle_timer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 545 }
546 } 546 }
547 547
548 // Otherwise, just create a new tab. 548 // Otherwise, just create a new tab.
549 AddTabWithURL(url, GURL(), PageTransition::AUTO_BOOKMARK, true, NULL); 549 AddTabWithURL(url, GURL(), PageTransition::AUTO_BOOKMARK, true, NULL);
550 } 550 }
551 551
552 /////////////////////////////////////////////////////////////////////////////// 552 ///////////////////////////////////////////////////////////////////////////////
553 // Browser, Assorted browser commands: 553 // Browser, Assorted browser commands:
554 554
555 void Browser::GoBack() { 555 void Browser::GoBack(WindowOpenDisposition disposition) {
556 UserMetrics::RecordAction(L"Back", profile_); 556 UserMetrics::RecordAction(L"Back", profile_);
557 557
558 // If we are showing an interstitial, just hide it. 558 // If we are showing an interstitial, just hide it.
559 TabContents* current_tab = GetSelectedTabContents(); 559 TabContents* current_tab = GetSelectedTabContents();
560 WebContents* web_contents = current_tab->AsWebContents(); 560 WebContents* web_contents = current_tab->AsWebContents();
561 if (web_contents && web_contents->interstitial_page()) { 561 if (web_contents && web_contents->interstitial_page()) {
562 // The GoBack() case is a special case when an interstitial is shown because 562 // The GoBack() case is a special case when an interstitial is shown because
563 // the "previous" page is still available, just hidden by the interstitial. 563 // the "previous" page is still available, just hidden by the interstitial.
564 // We treat the back as a "Don't proceed", this hides the interstitial and 564 // We treat the back as a "Don't proceed", this hides the interstitial and
565 // reveals the previous page. 565 // reveals the previous page.
566 web_contents->interstitial_page()->DontProceed(); 566 web_contents->interstitial_page()->DontProceed();
567 return; 567 return;
568 } 568 }
569 if (current_tab->controller()->CanGoBack()) 569
570 current_tab->controller()->GoBack(); 570 if (current_tab->controller()->CanGoBack()) {
571 NavigationController* controller = 0;
572 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB){
573 controller = GetSelectedTabContents()->controller()->Clone();
574 tabstrip_model_.AddTabContents(
575 controller->active_contents(), -1,
576 PageTransition::LINK, disposition == NEW_FOREGROUND_TAB);
577 } else {
578 // Default disposition is CURRENT_TAB.
579 controller = current_tab->controller();
580 }
581 controller->GoBack();
582 }
571 } 583 }
572 584
573 void Browser::GoForward() { 585 void Browser::GoForward(WindowOpenDisposition disp) {
574 UserMetrics::RecordAction(L"Forward", profile_); 586 UserMetrics::RecordAction(L"Forward", profile_);
575 if (GetSelectedTabContents()->controller()->CanGoForward()) 587 if (GetSelectedTabContents()->controller()->CanGoForward()) {
576 GetSelectedTabContents()->controller()->GoForward(); 588 NavigationController* controller = 0;
589 if (disp == NEW_FOREGROUND_TAB || disp == NEW_BACKGROUND_TAB) {
590 controller = GetSelectedTabContents()->controller()->Clone();
591 tabstrip_model_.AddTabContents(
592 controller->active_contents(), -1,
593 PageTransition::LINK, disp == NEW_FOREGROUND_TAB);
594 } else {
595 // Default disposition is CURRENT_TAB.
596 controller = GetSelectedTabContents()->controller();
597 }
598 controller->GoForward();
599 }
577 } 600 }
578 601
579 void Browser::Reload() { 602 void Browser::Reload() {
580 UserMetrics::RecordAction(L"Reload", profile_); 603 UserMetrics::RecordAction(L"Reload", profile_);
581 604
582 // If we are showing an interstitial, treat this as an OpenURL. 605 // If we are showing an interstitial, treat this as an OpenURL.
583 TabContents* current_tab = GetSelectedTabContents(); 606 TabContents* current_tab = GetSelectedTabContents();
584 if (current_tab) { 607 if (current_tab) {
585 WebContents* web_contents = current_tab->AsWebContents(); 608 WebContents* web_contents = current_tab->AsWebContents();
586 if (web_contents && web_contents->showing_interstitial_page()) { 609 if (web_contents && web_contents->showing_interstitial_page()) {
587 NavigationEntry* entry = current_tab->controller()->GetActiveEntry(); 610 NavigationEntry* entry = current_tab->controller()->GetActiveEntry();
588 DCHECK(entry); // Should exist if interstitial is showing. 611 DCHECK(entry); // Should exist if interstitial is showing.
589 OpenURL(entry->url(), GURL(), CURRENT_TAB, PageTransition::RELOAD); 612 OpenURL(entry->url(), GURL(), CURRENT_TAB, PageTransition::RELOAD);
590 return; 613 return;
591 } 614 }
592 } 615 }
593 616
594 if (current_tab) { 617 if (current_tab) {
595 // As this is caused by a user action, give the focus to the page. 618 // As this is caused by a user action, give the focus to the page.
596 current_tab->Focus(); 619 current_tab->Focus();
597 current_tab->controller()->Reload(true); 620 current_tab->controller()->Reload(true);
598 } 621 }
599 } 622 }
600 623
601 void Browser::Home() { 624 void Browser::Home(WindowOpenDisposition disposition) {
602 UserMetrics::RecordAction(L"Home", profile_); 625 UserMetrics::RecordAction(L"Home", profile_);
603 GURL homepage_url = GetHomePage(); 626 OpenURL(GetHomePage(), GURL(), disposition, PageTransition::AUTO_BOOKMARK);
604 GetSelectedTabContents()->controller()->LoadURL(
605 homepage_url, GURL(), PageTransition::AUTO_BOOKMARK);
606 } 627 }
607 628
608 void Browser::OpenCurrentURL() { 629 void Browser::OpenCurrentURL() {
609 UserMetrics::RecordAction(L"LoadURL", profile_); 630 UserMetrics::RecordAction(L"LoadURL", profile_);
610 LocationBar* location_bar = window_->GetLocationBar(); 631 LocationBar* location_bar = window_->GetLocationBar();
611 OpenURL(GURL(WideToUTF8(location_bar->GetInputString())), GURL(), 632 OpenURL(GURL(WideToUTF8(location_bar->GetInputString())), GURL(),
612 location_bar->GetWindowOpenDisposition(), 633 location_bar->GetWindowOpenDisposition(),
613 location_bar->GetPageTransition()); 634 location_bar->GetPageTransition());
614 } 635 }
615 636
616 void Browser::Go() { 637 void Browser::Go(WindowOpenDisposition disposition) {
617 UserMetrics::RecordAction(L"Go", profile_); 638 UserMetrics::RecordAction(L"Go", profile_);
618 window_->GetLocationBar()->AcceptInput(); 639 window_->GetLocationBar()->AcceptInputWithDisposition(disposition);
619 } 640 }
620 641
621 void Browser::Stop() { 642 void Browser::Stop() {
622 UserMetrics::RecordAction(L"Stop", profile_); 643 UserMetrics::RecordAction(L"Stop", profile_);
623 GetSelectedTabContents()->Stop(); 644 GetSelectedTabContents()->Stop();
624 } 645 }
625 646
626 void Browser::NewWindow() { 647 void Browser::NewWindow() {
627 UserMetrics::RecordAction(L"NewWindow", profile_); 648 UserMetrics::RecordAction(L"NewWindow", profile_);
628 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); 649 Browser::OpenEmptyWindow(profile_->GetOriginalProfile());
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 if (index != TabStripModel::kNoTab) { 1117 if (index != TabStripModel::kNoTab) {
1097 if (index_result) 1118 if (index_result)
1098 *index_result = index; 1119 *index_result = index;
1099 return *it; 1120 return *it;
1100 } 1121 }
1101 } 1122 }
1102 1123
1103 return NULL; 1124 return NULL;
1104 } 1125 }
1105 1126
1106 /////////////////////////////////////////////////////////////////////////////// 1127 void Browser::ExecuteCommandWithDisposition(
1107 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: 1128 int id, WindowOpenDisposition disposition) {
1108
1109 void Browser::ExecuteCommand(int id) {
1110 // No commands are enabled if there is not yet any selected tab. 1129 // No commands are enabled if there is not yet any selected tab.
1111 // TODO(pkasting): It seems like we should not need this, because either 1130 // TODO(pkasting): It seems like we should not need this, because either
1112 // most/all commands should not have been enabled yet anyway or the ones that 1131 // most/all commands should not have been enabled yet anyway or the ones that
1113 // are enabled should be global, or safe themselves against having no selected 1132 // are enabled should be global, or safe themselves against having no selected
1114 // tab. However, Ben says he tried removing this before and got lots of 1133 // tab. However, Ben says he tried removing this before and got lots of
1115 // crashes, e.g. from Windows sending WM_COMMANDs at random times during 1134 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
1116 // window construction. This probably could use closer examination someday. 1135 // window construction. This probably could use closer examination someday.
1117 if (!GetSelectedTabContents()) 1136 if (!GetSelectedTabContents())
1118 return; 1137 return;
1119 1138
1120 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command"; 1139 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command";
1121 1140
1122 // The order of commands in this switch statement must match the function 1141 // The order of commands in this switch statement must match the function
1123 // declaration order in browser.h! 1142 // declaration order in browser.h!
1124 switch (id) { 1143 switch (id) {
1125 // Navigation commands 1144 // Navigation commands
1126 case IDC_BACK: GoBack(); break; 1145 case IDC_BACK: GoBack(disposition); break;
1127 case IDC_FORWARD: GoForward(); break; 1146 case IDC_FORWARD: GoForward(disposition); break;
1128 case IDC_RELOAD: Reload(); break; 1147 case IDC_RELOAD: Reload(); break;
1129 case IDC_HOME: Home(); break; 1148 case IDC_HOME: Home(disposition); break;
1130 case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; 1149 case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break;
1131 case IDC_GO: Go(); break; 1150 case IDC_GO: Go(disposition); break;
1132 case IDC_STOP: Stop(); break; 1151 case IDC_STOP: Stop(); break;
1133 1152
1134 // Window management commands 1153 // Window management commands
1135 case IDC_NEW_WINDOW: NewWindow(); break; 1154 case IDC_NEW_WINDOW: NewWindow(); break;
1136 case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break; 1155 case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break;
1137 case IDC_NEW_WINDOW_PROFILE_0: 1156 case IDC_NEW_WINDOW_PROFILE_0:
1138 case IDC_NEW_WINDOW_PROFILE_1: 1157 case IDC_NEW_WINDOW_PROFILE_1:
1139 case IDC_NEW_WINDOW_PROFILE_2: 1158 case IDC_NEW_WINDOW_PROFILE_2:
1140 case IDC_NEW_WINDOW_PROFILE_3: 1159 case IDC_NEW_WINDOW_PROFILE_3:
1141 case IDC_NEW_WINDOW_PROFILE_4: 1160 case IDC_NEW_WINDOW_PROFILE_4:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 #endif 1295 #endif
1277 case IDC_HELP_PAGE: OpenHelpTab(); break; 1296 case IDC_HELP_PAGE: OpenHelpTab(); break;
1278 1297
1279 default: 1298 default:
1280 LOG(WARNING) << "Received Unimplemented Command: " << id; 1299 LOG(WARNING) << "Received Unimplemented Command: " << id;
1281 break; 1300 break;
1282 } 1301 }
1283 } 1302 }
1284 1303
1285 /////////////////////////////////////////////////////////////////////////////// 1304 ///////////////////////////////////////////////////////////////////////////////
1305 // Browser, CommandUpdater::CommandUpdaterDelegate implementation:
1306
1307 void Browser::ExecuteCommand(int id) {
1308 ExecuteCommandWithDisposition(id, CURRENT_TAB);
1309 }
1310
1311 ///////////////////////////////////////////////////////////////////////////////
1286 // Browser, TabStripModelDelegate implementation: 1312 // Browser, TabStripModelDelegate implementation:
1287 1313
1288 GURL Browser::GetBlankTabURL() const { 1314 GURL Browser::GetBlankTabURL() const {
1289 return GURL(chrome::kChromeUINewTabURL); 1315 return GURL(chrome::kChromeUINewTabURL);
1290 } 1316 }
1291 1317
1292 void Browser::CreateNewStripWithContents(TabContents* detached_contents, 1318 void Browser::CreateNewStripWithContents(TabContents* detached_contents,
1293 const gfx::Rect& window_bounds, 1319 const gfx::Rect& window_bounds,
1294 const DockInfo& dock_info) { 1320 const DockInfo& dock_info) {
1295 DCHECK(type_ == TYPE_NORMAL); 1321 DCHECK(type_ == TYPE_NORMAL);
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 2521
2496 // We need to register the window position pref. 2522 // We need to register the window position pref.
2497 std::wstring window_pref(prefs::kBrowserWindowPlacement); 2523 std::wstring window_pref(prefs::kBrowserWindowPlacement);
2498 window_pref.append(L"_"); 2524 window_pref.append(L"_");
2499 window_pref.append(app_name); 2525 window_pref.append(app_name);
2500 PrefService* prefs = g_browser_process->local_state(); 2526 PrefService* prefs = g_browser_process->local_state();
2501 DCHECK(prefs); 2527 DCHECK(prefs);
2502 2528
2503 prefs->RegisterDictionaryPref(window_pref.c_str()); 2529 prefs->RegisterDictionaryPref(window_pref.c_str());
2504 } 2530 }
OLDNEW
« no previous file with comments | « chrome/browser/browser.h ('k') | chrome/browser/location_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698