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