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

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

Issue 18507: More scaffolding for back/forward, start of WebContents (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/idle_timer.h" 6 #include "base/idle_timer.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
11 #include "chrome/browser/metrics/user_metrics.h"
12 #include "chrome/browser/tab_contents/tab_contents_type.h"
13 #include "chrome/common/page_transition_types.h"
11 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
12 #include "chrome/common/pref_service.h" 15 #include "chrome/common/pref_service.h"
13 #include "net/base/cookie_monster.h" 16 #include "net/base/cookie_monster.h"
14 #include "net/base/cookie_policy.h" 17 #include "net/base/cookie_policy.h"
15 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
16 #include "net/base/registry_controlled_domain.h" 19 #include "net/base/registry_controlled_domain.h"
17 #include "net/url_request/url_request_context.h" 20 #include "net/url_request/url_request_context.h"
21 #include "webkit/glue/window_open_disposition.h"
18 22
19 #if defined(OS_WIN) 23 #if defined(OS_WIN)
20 24
21 #include <windows.h> 25 #include <windows.h>
22 #include <shellapi.h> 26 #include <shellapi.h>
23 27
24 #include "chrome/browser/browser.h" 28 #include "chrome/browser/browser.h"
25 29
26 #include "chrome/app/locales/locale_settings.h" 30 #include "chrome/app/locales/locale_settings.h"
27 #include "chrome/browser/automation/ui_controls.h" 31 #include "chrome/browser/automation/ui_controls.h"
28 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/browser_shutdown.h" 33 #include "chrome/browser/browser_shutdown.h"
30 #include "chrome/browser/browser_url_handler.h" 34 #include "chrome/browser/browser_url_handler.h"
31 #include "chrome/browser/browser_window.h" 35 #include "chrome/browser/browser_window.h"
32 #include "chrome/browser/cert_store.h" 36 #include "chrome/browser/cert_store.h"
33 #include "chrome/browser/character_encoding.h" 37 #include "chrome/browser/character_encoding.h"
34 #include "chrome/browser/debugger/debugger_window.h" 38 #include "chrome/browser/debugger/debugger_window.h"
35 #include "chrome/browser/dock_info.h" 39 #include "chrome/browser/dock_info.h"
36 #include "chrome/browser/dom_ui/new_tab_ui.h" 40 #include "chrome/browser/dom_ui/new_tab_ui.h"
37 #include "chrome/browser/download/save_package.h" 41 #include "chrome/browser/download/save_package.h"
38 #include "chrome/browser/history_tab_ui.h" 42 #include "chrome/browser/history_tab_ui.h"
39 #include "chrome/browser/metrics/user_metrics.h"
40 #include "chrome/browser/options_window.h" 43 #include "chrome/browser/options_window.h"
41 #include "chrome/browser/net/url_fixer_upper.h" 44 #include "chrome/browser/net/url_fixer_upper.h"
42 #include "chrome/browser/plugin_process_host.h" 45 #include "chrome/browser/plugin_process_host.h"
43 #include "chrome/browser/plugin_service.h" 46 #include "chrome/browser/plugin_service.h"
44 #include "chrome/browser/profile.h" 47 #include "chrome/browser/profile.h"
45 #include "chrome/browser/sessions/session_service.h" 48 #include "chrome/browser/sessions/session_service.h"
46 #include "chrome/browser/ssl/ssl_error_info.h" 49 #include "chrome/browser/ssl/ssl_error_info.h"
47 #include "chrome/browser/tab_contents/interstitial_page.h" 50 #include "chrome/browser/tab_contents/interstitial_page.h"
48 #include "chrome/browser/tab_contents/navigation_controller.h" 51 #include "chrome/browser/tab_contents/navigation_controller.h"
49 #include "chrome/browser/tab_contents/navigation_entry.h" 52 #include "chrome/browser/tab_contents/navigation_entry.h"
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 return; 543 return;
541 } 544 }
542 } 545 }
543 546
544 TabContents* contents = CreateTabContentsForURL(url, GURL(), profile_, 547 TabContents* contents = CreateTabContentsForURL(url, GURL(), profile_,
545 PageTransition::LINK, false, 548 PageTransition::LINK, false,
546 NULL); 549 NULL);
547 AddNewContents(NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), true); 550 AddNewContents(NULL, contents, NEW_FOREGROUND_TAB, gfx::Rect(), true);
548 } 551 }
549 552
553 #endif // OS_WIN
554
550 /////////////////////////////////////////////////////////////////////////////// 555 ///////////////////////////////////////////////////////////////////////////////
551 // Browser, Assorted browser commands: 556 // Browser, Assorted browser commands:
552 557
553 void Browser::GoBack() { 558 void Browser::GoBack() {
554 UserMetrics::RecordAction(L"Back", profile_); 559 UserMetrics::RecordAction(L"Back", profile_);
555 560
556 // If we are showing an interstitial, just hide it. 561 // If we are showing an interstitial, just hide it.
557 TabContents* current_tab = GetSelectedTabContents(); 562 TabContents* current_tab = GetSelectedTabContents();
558 WebContents* web_contents = current_tab->AsWebContents(); 563 WebContents* web_contents = current_tab->AsWebContents();
559 if (web_contents && web_contents->interstitial_page()) { 564 if (web_contents && web_contents->interstitial_page()) {
560 // The GoBack() case is a special case when an interstitial is shown because 565 // The GoBack() case is a special case when an interstitial is shown because
561 // the "previous" page is still available, just hidden by the interstitial. 566 // the "previous" page is still available, just hidden by the interstitial.
562 // We treat the back as a "Don't proceed", this hides the interstitial and 567 // We treat the back as a "Don't proceed", this hides the interstitial and
563 // reveals the previous page. 568 // reveals the previous page.
564 web_contents->interstitial_page()->DontProceed(); 569 web_contents->interstitial_page()->DontProceed();
565 return; 570 return;
566 } 571 }
567 if (current_tab->controller()->CanGoBack()) 572 if (current_tab->controller()->CanGoBack())
568 current_tab->controller()->GoBack(); 573 current_tab->controller()->GoBack();
569 } 574 }
570 575
571 void Browser::GoForward() { 576 void Browser::GoForward() {
572 UserMetrics::RecordAction(L"Forward", profile_); 577 UserMetrics::RecordAction(L"Forward", profile_);
573 if (GetSelectedTabContents()->controller()->CanGoForward()) 578 if (GetSelectedTabContents()->controller()->CanGoForward())
574 GetSelectedTabContents()->controller()->GoForward(); 579 GetSelectedTabContents()->controller()->GoForward();
575 } 580 }
576 581
582
577 void Browser::Reload() { 583 void Browser::Reload() {
578 UserMetrics::RecordAction(L"Reload", profile_); 584 UserMetrics::RecordAction(L"Reload", profile_);
579 585
580 // If we are showing an interstitial, treat this as an OpenURL. 586 // If we are showing an interstitial, treat this as an OpenURL.
581 TabContents* current_tab = GetSelectedTabContents(); 587 TabContents* current_tab = GetSelectedTabContents();
582 if (current_tab) { 588 if (current_tab) {
583 WebContents* web_contents = current_tab->AsWebContents(); 589 WebContents* web_contents = current_tab->AsWebContents();
584 if (web_contents && web_contents->showing_interstitial_page()) { 590 if (web_contents && web_contents->showing_interstitial_page()) {
585 NavigationEntry* entry = current_tab->controller()->GetActiveEntry(); 591 NavigationEntry* entry = current_tab->controller()->GetActiveEntry();
586 DCHECK(entry); // Should exist if interstitial is showing. 592 DCHECK(entry); // Should exist if interstitial is showing.
587 OpenURL(entry->url(), GURL(), CURRENT_TAB, PageTransition::RELOAD); 593 OpenURL(entry->url(), GURL(), CURRENT_TAB, PageTransition::RELOAD);
588 return; 594 return;
589 } 595 }
590 } 596 }
591 597
592 if (current_tab) { 598 if (current_tab) {
593 // As this is caused by a user action, give the focus to the page. 599 // As this is caused by a user action, give the focus to the page.
594 current_tab->Focus(); 600 current_tab->Focus();
595 current_tab->controller()->Reload(true); 601 current_tab->controller()->Reload(true);
596 } 602 }
597 } 603 }
598 604
605
599 void Browser::Home() { 606 void Browser::Home() {
600 UserMetrics::RecordAction(L"Home", profile_); 607 UserMetrics::RecordAction(L"Home", profile_);
601 GURL homepage_url = GetHomePage(); 608 GURL homepage_url = GetHomePage();
602 GetSelectedTabContents()->controller()->LoadURL( 609 GetSelectedTabContents()->controller()->LoadURL(
603 homepage_url, GURL(), PageTransition::AUTO_BOOKMARK); 610 homepage_url, GURL(), PageTransition::AUTO_BOOKMARK);
604 } 611 }
605 612
613 #if defined(OS_WIN)
606 void Browser::OpenCurrentURL() { 614 void Browser::OpenCurrentURL() {
607 UserMetrics::RecordAction(L"LoadURL", profile_); 615 UserMetrics::RecordAction(L"LoadURL", profile_);
608 LocationBarView* lbv = GetLocationBarView(); 616 LocationBarView* lbv = GetLocationBarView();
609 if (lbv) { 617 if (lbv) {
610 OpenURL(GURL(lbv->location_input()), GURL(), lbv->disposition(), 618 OpenURL(GURL(lbv->location_input()), GURL(), lbv->disposition(),
611 lbv->transition()); 619 lbv->transition());
612 } 620 }
613 } 621 }
614 622
615 void Browser::Go() { 623 void Browser::Go() {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 // crashes, e.g. from Windows sending WM_COMMANDs at random times during 1092 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
1085 // window construction. This probably could use closer examination someday. 1093 // window construction. This probably could use closer examination someday.
1086 if (!GetSelectedTabContents()) 1094 if (!GetSelectedTabContents())
1087 return; 1095 return;
1088 1096
1089 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command"; 1097 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command";
1090 1098
1091 // The order of commands in this switch statement must match the function 1099 // The order of commands in this switch statement must match the function
1092 // declaration order in browser.h! 1100 // declaration order in browser.h!
1093 switch (id) { 1101 switch (id) {
1094 #if defined(OS_WIN)
1095 // Navigation commands 1102 // Navigation commands
1096 case IDC_BACK: GoBack(); break; 1103 case IDC_BACK: GoBack(); break;
1097 case IDC_FORWARD: GoForward(); break; 1104 case IDC_FORWARD: GoForward(); break;
1105 #if defined(OS_WIN)
1098 case IDC_RELOAD: Reload(); break; 1106 case IDC_RELOAD: Reload(); break;
1099 case IDC_HOME: Home(); break; 1107 case IDC_HOME: Home(); break;
1100 case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; 1108 case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break;
1101 case IDC_GO: Go(); break; 1109 case IDC_GO: Go(); break;
1102 case IDC_STOP: Stop(); break; 1110 case IDC_STOP: Stop(); break;
1103 1111
1104 // Window management commands 1112 // Window management commands
1105 case IDC_NEW_WINDOW: NewWindow(); break; 1113 case IDC_NEW_WINDOW: NewWindow(); break;
1106 case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break; 1114 case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break;
1107 case IDC_NEW_WINDOW_PROFILE_0: 1115 case IDC_NEW_WINDOW_PROFILE_0:
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 1301
1294 if (!defer_load) { 1302 if (!defer_load) {
1295 // Load the initial URL before adding the new tab contents to the tab strip 1303 // Load the initial URL before adding the new tab contents to the tab strip
1296 // so that the tab contents has navigation state. 1304 // so that the tab contents has navigation state.
1297 contents->controller()->LoadURL(url, referrer, transition); 1305 contents->controller()->LoadURL(url, referrer, transition);
1298 } 1306 }
1299 1307
1300 return contents; 1308 return contents;
1301 } 1309 }
1302 1310
1311 #endif // OS_WIN
1312
1303 bool Browser::CanDuplicateContentsAt(int index) { 1313 bool Browser::CanDuplicateContentsAt(int index) {
1304 TabContents* contents = GetTabContentsAt(index); 1314 TabContents* contents = GetTabContentsAt(index);
1305 DCHECK(contents); 1315 DCHECK(contents);
1306 1316
1307 NavigationController* nc = contents->controller(); 1317 NavigationController* nc = contents->controller();
1308 return nc ? (nc->active_contents() && nc->GetLastCommittedEntry()) : false; 1318 return nc ? (nc->active_contents() && nc->GetLastCommittedEntry()) : false;
1309 } 1319 }
1310 1320
1321 #if defined(OS_WIN)
1322
1311 void Browser::DuplicateContentsAt(int index) { 1323 void Browser::DuplicateContentsAt(int index) {
1312 TabContents* contents = GetTabContentsAt(index); 1324 TabContents* contents = GetTabContentsAt(index);
1313 TabContents* new_contents = NULL; 1325 TabContents* new_contents = NULL;
1314 DCHECK(contents); 1326 DCHECK(contents);
1315 1327
1316 if (type_ == TYPE_NORMAL) { 1328 if (type_ == TYPE_NORMAL) {
1317 // If this is a tabbed browser, just create a duplicate tab inside the same 1329 // If this is a tabbed browser, just create a duplicate tab inside the same
1318 // window next to the tab being duplicated. 1330 // window next to the tab being duplicated.
1319 new_contents = contents->controller()->Clone()->active_contents(); 1331 new_contents = contents->controller()->Clone()->active_contents();
1320 // If you duplicate a tab that is not selected, we need to make sure to 1332 // If you duplicate a tab that is not selected, we need to make sure to
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 normal_window); 2039 normal_window);
2028 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, normal_window); 2040 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, normal_window);
2029 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, normal_window); 2041 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, normal_window);
2030 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, 2042 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES,
2031 normal_window); 2043 normal_window);
2032 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, normal_window); 2044 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, normal_window);
2033 command_updater_.UpdateCommandEnabled(IDC_ABOUT, normal_window); 2045 command_updater_.UpdateCommandEnabled(IDC_ABOUT, normal_window);
2034 } 2046 }
2035 } 2047 }
2036 2048
2037 #if defined(OS_WIN)
2038
2039 void Browser::UpdateCommandsForTabState() { 2049 void Browser::UpdateCommandsForTabState() {
2040 TabContents* current_tab = GetSelectedTabContents(); 2050 TabContents* current_tab = GetSelectedTabContents();
2041 if (!current_tab) // May be NULL during tab restore. 2051 if (!current_tab) // May be NULL during tab restore.
2042 return; 2052 return;
2043 2053
2044 // Navigation commands 2054 // Navigation commands
2045 NavigationController* nc = current_tab->controller(); 2055 NavigationController* nc = current_tab->controller();
2046 command_updater_.UpdateCommandEnabled(IDC_BACK, nc->CanGoBack()); 2056 command_updater_.UpdateCommandEnabled(IDC_BACK, nc->CanGoBack());
2047 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc->CanGoForward()); 2057 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc->CanGoForward());
2048 2058
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 command_updater_.UpdateCommandEnabled(IDC_GO, !is_loading); 2107 command_updater_.UpdateCommandEnabled(IDC_GO, !is_loading);
2098 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); 2108 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
2099 } 2109 }
2100 2110
2101 void Browser::SetStarredButtonToggled(bool starred) { 2111 void Browser::SetStarredButtonToggled(bool starred) {
2102 ToolbarStarToggle* star_button = window_->GetStarButton(); 2112 ToolbarStarToggle* star_button = window_->GetStarButton();
2103 if (star_button) 2113 if (star_button)
2104 star_button->SetToggled(starred); 2114 star_button->SetToggled(starred);
2105 } 2115 }
2106 2116
2117 #if defined(OS_WIN)
2118
2107 /////////////////////////////////////////////////////////////////////////////// 2119 ///////////////////////////////////////////////////////////////////////////////
2108 // Browser, UI update coalescing and handling (private): 2120 // Browser, UI update coalescing and handling (private):
2109 2121
2110 void Browser::UpdateToolbar(bool should_restore_state) { 2122 void Browser::UpdateToolbar(bool should_restore_state) {
2111 window_->UpdateToolbar(GetSelectedTabContents(), should_restore_state); 2123 window_->UpdateToolbar(GetSelectedTabContents(), should_restore_state);
2112 } 2124 }
2113 2125
2114 void Browser::ScheduleUIUpdate(const TabContents* source, 2126 void Browser::ScheduleUIUpdate(const TabContents* source,
2115 unsigned changed_flags) { 2127 unsigned changed_flags) {
2116 // Synchronously update the URL. 2128 // Synchronously update the URL.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2225 UpdateVector::iterator cur_update = scheduled_updates_.begin(); 2237 UpdateVector::iterator cur_update = scheduled_updates_.begin();
2226 while (cur_update != scheduled_updates_.end()) { 2238 while (cur_update != scheduled_updates_.end()) {
2227 if (cur_update->source == contents) { 2239 if (cur_update->source == contents) {
2228 cur_update = scheduled_updates_.erase(cur_update); 2240 cur_update = scheduled_updates_.erase(cur_update);
2229 } else { 2241 } else {
2230 ++cur_update; 2242 ++cur_update;
2231 } 2243 }
2232 } 2244 }
2233 } 2245 }
2234 2246
2247 #endif // OS_WIN
2248
2235 /////////////////////////////////////////////////////////////////////////////// 2249 ///////////////////////////////////////////////////////////////////////////////
2236 // Browser, Getters for UI (private): 2250 // Browser, Getters for UI (private):
2237 2251
2238 LocationBarView* Browser::GetLocationBarView() const { 2252 LocationBarView* Browser::GetLocationBarView() const {
2239 return window_->GetLocationBarView(); 2253 return window_->GetLocationBarView();
2240 } 2254 }
2241 2255
2242 GoButton* Browser::GetGoButton() { 2256 GoButton* Browser::GetGoButton() {
2243 return window_->GetGoButton(); 2257 return window_->GetGoButton();
2244 } 2258 }
2245 2259
2246 StatusBubble* Browser::GetStatusBubble() { 2260 StatusBubble* Browser::GetStatusBubble() {
2247 return window_->GetStatusBubble(); 2261 return window_->GetStatusBubble();
2248 } 2262 }
2249 2263
2264 #if defined(OS_WIN)
2250 /////////////////////////////////////////////////////////////////////////////// 2265 ///////////////////////////////////////////////////////////////////////////////
2251 // Browser, Session restore functions (private): 2266 // Browser, Session restore functions (private):
2252 2267
2253 void Browser::SyncHistoryWithTabs(int index) { 2268 void Browser::SyncHistoryWithTabs(int index) {
2254 if (!profile()->HasSessionService()) 2269 if (!profile()->HasSessionService())
2255 return; 2270 return;
2256 SessionService* session_service = profile()->GetSessionService(); 2271 SessionService* session_service = profile()->GetSessionService();
2257 if (session_service) { 2272 if (session_service) {
2258 for (int i = index; i < tab_count(); ++i) { 2273 for (int i = index; i < tab_count(); ++i) {
2259 TabContents* contents = GetTabContentsAt(i); 2274 TabContents* contents = GetTabContentsAt(i);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 std::wstring window_pref(prefs::kBrowserWindowPlacement); 2442 std::wstring window_pref(prefs::kBrowserWindowPlacement);
2428 window_pref.append(L"_"); 2443 window_pref.append(L"_");
2429 window_pref.append(app_name); 2444 window_pref.append(app_name);
2430 PrefService* prefs = g_browser_process->local_state(); 2445 PrefService* prefs = g_browser_process->local_state();
2431 DCHECK(prefs); 2446 DCHECK(prefs);
2432 2447
2433 prefs->RegisterDictionaryPref(window_pref.c_str()); 2448 prefs->RegisterDictionaryPref(window_pref.c_str());
2434 } 2449 }
2435 2450
2436 #endif // OS_WIN 2451 #endif // OS_WIN
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698