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

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

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