| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
| 26 #include "gfx/point.h" | 26 #include "gfx/point.h" |
| 27 #include "chrome/app/chrome_dll_resource.h" | 27 #include "chrome/app/chrome_dll_resource.h" |
| 28 #include "chrome/browser/autofill/autofill_manager.h" | 28 #include "chrome/browser/autofill/autofill_manager.h" |
| 29 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 30 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" | 30 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
| 31 #endif // defined(OS_WIN) | 31 #endif // defined(OS_WIN) |
| 32 #include "chrome/browser/bookmarks/bookmark_model.h" | 32 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 33 #include "chrome/browser/bookmarks/bookmark_utils.h" | 33 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 34 #include "chrome/browser/browser_list.h" | 34 #include "chrome/browser/browser_list.h" |
| 35 #include "chrome/browser/browser_navigator.h" |
| 35 #include "chrome/browser/browser_process.h" | 36 #include "chrome/browser/browser_process.h" |
| 36 #include "chrome/browser/browser_shutdown.h" | 37 #include "chrome/browser/browser_shutdown.h" |
| 37 #include "chrome/browser/browser_window.h" | 38 #include "chrome/browser/browser_window.h" |
| 38 #include "chrome/browser/browser_url_handler.h" | 39 #include "chrome/browser/browser_url_handler.h" |
| 39 #include "chrome/browser/character_encoding.h" | 40 #include "chrome/browser/character_encoding.h" |
| 40 #include "chrome/browser/debugger/devtools_manager.h" | 41 #include "chrome/browser/debugger/devtools_manager.h" |
| 41 #include "chrome/browser/debugger/devtools_toggle_action.h" | 42 #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 42 #include "chrome/browser/debugger/devtools_window.h" | 43 #include "chrome/browser/debugger/devtools_window.h" |
| 43 #include "chrome/browser/dock_info.h" | 44 #include "chrome/browser/dock_info.h" |
| 44 #include "chrome/browser/dom_ui/filebrowse_ui.h" | 45 #include "chrome/browser/dom_ui/filebrowse_ui.h" |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 604 |
| 604 ExtensionPrefs::LaunchType launch_type = | 605 ExtensionPrefs::LaunchType launch_type = |
| 605 extensions_service->extension_prefs()->GetLaunchType(extension->id()); | 606 extensions_service->extension_prefs()->GetLaunchType(extension->id()); |
| 606 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); | 607 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); |
| 607 int add_type = TabStripModel::ADD_SELECTED; | 608 int add_type = TabStripModel::ADD_SELECTED; |
| 608 if (launch_type == ExtensionPrefs::LAUNCH_PINNED) | 609 if (launch_type == ExtensionPrefs::LAUNCH_PINNED) |
| 609 add_type |= TabStripModel::ADD_PINNED; | 610 add_type |= TabStripModel::ADD_PINNED; |
| 610 | 611 |
| 611 // TODO(erikkay): START_PAGE doesn't seem like the right transition in all | 612 // TODO(erikkay): START_PAGE doesn't seem like the right transition in all |
| 612 // cases. | 613 // cases. |
| 613 AddTabWithURLParams params(extension->GetFullLaunchURL(), | 614 browser::NavigateParams params(browser, extension->GetFullLaunchURL(), |
| 614 PageTransition::START_PAGE); | 615 PageTransition::START_PAGE); |
| 615 params.add_types = add_type; | 616 params.tabstrip_add_types = add_type; |
| 616 | 617 |
| 617 // Launch the application in the existing TabContents, if it was supplied. | 618 // Launch the application in the existing TabContents, if it was supplied. |
| 618 if (existing_tab) { | 619 if (existing_tab) { |
| 619 TabStripModel* model = browser->tabstrip_model(); | 620 TabStripModel* model = browser->tabstrip_model(); |
| 620 int tab_index = model->GetIndexOfTabContents(existing_tab); | 621 int tab_index = model->GetIndexOfTabContents(existing_tab); |
| 621 | 622 |
| 622 existing_tab->OpenURL(extension->GetFullLaunchURL(), existing_tab->GetURL(), | 623 existing_tab->OpenURL(extension->GetFullLaunchURL(), existing_tab->GetURL(), |
| 623 CURRENT_TAB, PageTransition::LINK); | 624 CURRENT_TAB, PageTransition::LINK); |
| 624 if (params.add_types & TabStripModel::ADD_PINNED) | 625 if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) |
| 625 model->SetTabPinned(tab_index, true); | 626 model->SetTabPinned(tab_index, true); |
| 626 if (params.add_types & TabStripModel::ADD_SELECTED) | 627 if (params.tabstrip_add_types & TabStripModel::ADD_SELECTED) |
| 627 model->SelectTabContentsAt(tab_index, true); | 628 model->SelectTabContentsAt(tab_index, true); |
| 628 | 629 |
| 629 contents = existing_tab; | 630 contents = existing_tab; |
| 630 } else { | 631 } else { |
| 631 contents = browser->AddTabWithURL(¶ms); | 632 params.disposition = NEW_FOREGROUND_TAB; |
| 633 browser::Navigate(¶ms); |
| 634 contents = params.target_contents; |
| 632 } | 635 } |
| 633 | 636 |
| 634 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN) | 637 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN) |
| 635 browser->window()->SetFullscreen(true); | 638 browser->window()->SetFullscreen(true); |
| 636 | 639 |
| 637 return contents; | 640 return contents; |
| 638 } | 641 } |
| 639 | 642 |
| 640 // static | 643 // static |
| 641 void Browser::OpenBookmarkManagerWindow(Profile* profile) { | 644 void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 //////////////////////////////////////////////////////////////////////////////// | 912 //////////////////////////////////////////////////////////////////////////////// |
| 910 // Browser, Tab adding/showing functions: | 913 // Browser, Tab adding/showing functions: |
| 911 | 914 |
| 912 int Browser::GetIndexForInsertionDuringRestore(int relative_index) { | 915 int Browser::GetIndexForInsertionDuringRestore(int relative_index) { |
| 913 return (tab_handler_->GetTabStripModel()->insertion_policy() == | 916 return (tab_handler_->GetTabStripModel()->insertion_policy() == |
| 914 TabStripModel::INSERT_AFTER) ? tab_count() : relative_index; | 917 TabStripModel::INSERT_AFTER) ? tab_count() : relative_index; |
| 915 } | 918 } |
| 916 | 919 |
| 917 TabContents* Browser::AddSelectedTabWithURL(const GURL& url, | 920 TabContents* Browser::AddSelectedTabWithURL(const GURL& url, |
| 918 PageTransition::Type transition) { | 921 PageTransition::Type transition) { |
| 919 AddTabWithURLParams params(url, transition); | 922 browser::NavigateParams params(this, url, transition); |
| 920 return AddTabWithURL(¶ms); | 923 params.disposition = NEW_FOREGROUND_TAB; |
| 921 } | 924 browser::Navigate(¶ms); |
| 922 | 925 return params.target_contents; |
| 923 Browser::AddTabWithURLParams::AddTabWithURLParams( | |
| 924 const GURL& a_url, | |
| 925 PageTransition::Type a_transition) | |
| 926 : url(a_url), | |
| 927 transition(a_transition), | |
| 928 index(-1), | |
| 929 add_types(TabStripModel::ADD_SELECTED), | |
| 930 instance(NULL), | |
| 931 target(NULL) { | |
| 932 } | |
| 933 | |
| 934 Browser::AddTabWithURLParams::~AddTabWithURLParams() { | |
| 935 } | |
| 936 | |
| 937 TabContents* Browser::AddTabWithURL(AddTabWithURLParams* params) { | |
| 938 TabContents* contents = NULL; | |
| 939 if (CanSupportWindowFeature(FEATURE_TABSTRIP) || tabstrip_model()->empty()) { | |
| 940 GURL url_to_load = params->url; | |
| 941 if (url_to_load.is_empty()) | |
| 942 url_to_load = GetHomePage(); | |
| 943 contents = CreateTabContentsForURL(url_to_load, params->referrer, profile_, | |
| 944 params->transition, false, | |
| 945 params->instance); | |
| 946 contents->SetExtensionAppById(params->extension_app_id); | |
| 947 tab_handler_->GetTabStripModel()->AddTabContents(contents, params->index, | |
| 948 params->transition, | |
| 949 params->add_types); | |
| 950 // TODO(sky): figure out why this is needed. Without it we seem to get | |
| 951 // failures in startup tests. | |
| 952 // By default, content believes it is not hidden. When adding contents | |
| 953 // in the background, tell it that it's hidden. | |
| 954 if ((params->add_types & TabStripModel::ADD_SELECTED) == 0) { | |
| 955 // TabStripModel::AddTabContents invokes HideContents if not foreground. | |
| 956 contents->WasHidden(); | |
| 957 } | |
| 958 params->target = this; | |
| 959 } else { | |
| 960 // We're in an app window or a popup window. Find an existing browser to | |
| 961 // open this URL in, creating one if none exists. | |
| 962 Browser* browser = | |
| 963 BrowserList::FindBrowserWithFeature(profile_, FEATURE_TABSTRIP); | |
| 964 if (!browser) | |
| 965 browser = Browser::Create(profile_); | |
| 966 contents = browser->AddTabWithURL(params); | |
| 967 DCHECK(params->target); | |
| 968 } | |
| 969 return contents; | |
| 970 } | 926 } |
| 971 | 927 |
| 972 TabContents* Browser::AddTab(TabContents* tab_contents, | 928 TabContents* Browser::AddTab(TabContents* tab_contents, |
| 973 PageTransition::Type type) { | 929 PageTransition::Type type) { |
| 974 tab_handler_->GetTabStripModel()->AddTabContents( | 930 tab_handler_->GetTabStripModel()->AddTabContents( |
| 975 tab_contents, -1, type, TabStripModel::ADD_SELECTED); | 931 tab_contents, -1, type, TabStripModel::ADD_SELECTED); |
| 976 return tab_contents; | 932 return tab_contents; |
| 977 } | 933 } |
| 978 | 934 |
| 979 void Browser::AddTabContents(TabContents* new_contents, | 935 void Browser::AddTabContents(TabContents* new_contents, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 WindowOpenDisposition disp) { | 1027 WindowOpenDisposition disp) { |
| 1072 NavigationController& controller = | 1028 NavigationController& controller = |
| 1073 GetOrCloneTabForDisposition(disp)->controller(); | 1029 GetOrCloneTabForDisposition(disp)->controller(); |
| 1074 if (index < 0 || index >= controller.entry_count()) | 1030 if (index < 0 || index >= controller.entry_count()) |
| 1075 return false; | 1031 return false; |
| 1076 controller.GoToIndex(index); | 1032 controller.GoToIndex(index); |
| 1077 return true; | 1033 return true; |
| 1078 } | 1034 } |
| 1079 | 1035 |
| 1080 void Browser::ShowSingletonTab(const GURL& url) { | 1036 void Browser::ShowSingletonTab(const GURL& url) { |
| 1081 // In case the URL was rewritten by the BrowserURLHandler we need to ensure | 1037 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); |
| 1082 // that we do not open another URL that will get redirected to the rewritten | 1038 params.disposition = SINGLETON_TAB; |
| 1083 // URL. | 1039 params.show_window = true; |
| 1084 GURL rewritten_url(url); | 1040 browser::Navigate(¶ms); |
| 1085 bool reverse_on_redirect = false; | |
| 1086 BrowserURLHandler::RewriteURLIfNecessary(&rewritten_url, profile_, | |
| 1087 &reverse_on_redirect); | |
| 1088 | |
| 1089 // See if we already have a tab with the given URL and select it if so. | |
| 1090 TabStripModel* model = tab_handler_->GetTabStripModel(); | |
| 1091 for (int i = 0; i < model->count(); i++) { | |
| 1092 TabContents* tc = model->GetTabContentsAt(i); | |
| 1093 if (CompareURLsIgnoreRef(tc->GetURL(), url) || | |
| 1094 CompareURLsIgnoreRef(tc->GetURL(), rewritten_url)) { | |
| 1095 model->SelectTabContentsAt(i, false); | |
| 1096 return; | |
| 1097 } | |
| 1098 } | |
| 1099 | |
| 1100 // Otherwise, just create a new tab. | |
| 1101 AddSelectedTabWithURL(url, PageTransition::AUTO_BOOKMARK); | |
| 1102 } | 1041 } |
| 1103 | 1042 |
| 1104 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { | 1043 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { |
| 1105 #if !defined(OS_MACOSX) | 1044 #if !defined(OS_MACOSX) |
| 1106 const bool show_main_ui = (type() == TYPE_NORMAL) && !is_fullscreen; | 1045 const bool show_main_ui = (type() == TYPE_NORMAL) && !is_fullscreen; |
| 1107 #else | 1046 #else |
| 1108 const bool show_main_ui = (type() == TYPE_NORMAL); | 1047 const bool show_main_ui = (type() == TYPE_NORMAL); |
| 1109 #endif | 1048 #endif |
| 1110 | 1049 |
| 1111 bool main_not_fullscreen_or_popup = | 1050 bool main_not_fullscreen_or_popup = |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 | 1232 |
| 1294 void Browser::OpenCurrentURL() { | 1233 void Browser::OpenCurrentURL() { |
| 1295 UserMetrics::RecordAction(UserMetricsAction("LoadURL"), profile_); | 1234 UserMetrics::RecordAction(UserMetricsAction("LoadURL"), profile_); |
| 1296 LocationBar* location_bar = window_->GetLocationBar(); | 1235 LocationBar* location_bar = window_->GetLocationBar(); |
| 1297 WindowOpenDisposition open_disposition = | 1236 WindowOpenDisposition open_disposition = |
| 1298 location_bar->GetWindowOpenDisposition(); | 1237 location_bar->GetWindowOpenDisposition(); |
| 1299 if (OpenInstant(open_disposition)) | 1238 if (OpenInstant(open_disposition)) |
| 1300 return; | 1239 return; |
| 1301 | 1240 |
| 1302 GURL url(WideToUTF8(location_bar->GetInputString())); | 1241 GURL url(WideToUTF8(location_bar->GetInputString())); |
| 1303 | 1242 browser::NavigateParams params(this, url, location_bar->GetPageTransition()); |
| 1243 params.disposition = open_disposition; |
| 1304 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least | 1244 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least |
| 1305 // inherit the opener. In some cases the tabstrip will determine the group | 1245 // inherit the opener. In some cases the tabstrip will determine the group |
| 1306 // should be inherited, in which case the group is inherited instead of the | 1246 // should be inherited, in which case the group is inherited instead of the |
| 1307 // opener. | 1247 // opener. |
| 1308 OpenURLAtIndex(NULL, url, GURL(), open_disposition, | 1248 params.tabstrip_add_types = |
| 1309 location_bar->GetPageTransition(), -1, | 1249 TabStripModel::ADD_FORCE_INDEX | TabStripModel::ADD_INHERIT_OPENER; |
| 1310 TabStripModel::ADD_FORCE_INDEX | | 1250 browser::Navigate(¶ms); |
| 1311 TabStripModel::ADD_INHERIT_OPENER); | |
| 1312 } | 1251 } |
| 1313 | 1252 |
| 1314 void Browser::Stop() { | 1253 void Browser::Stop() { |
| 1315 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_); | 1254 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_); |
| 1316 GetSelectedTabContents()->Stop(); | 1255 GetSelectedTabContents()->Stop(); |
| 1317 } | 1256 } |
| 1318 | 1257 |
| 1319 void Browser::NewWindow() { | 1258 void Browser::NewWindow() { |
| 1320 if (browser_defaults::kAlwaysOpenIncognitoWindow && | 1259 if (browser_defaults::kAlwaysOpenIncognitoWindow && |
| 1321 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito)) { | 1260 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito)) { |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 TabStripModel* model = tab_handler_->GetTabStripModel(); | 1757 TabStripModel* model = tab_handler_->GetTabStripModel(); |
| 1819 for (int i = 0; i < model->count(); i++) { | 1758 for (int i = 0; i < model->count(); i++) { |
| 1820 TabContents* tc = model->GetTabContentsAt(i); | 1759 TabContents* tc = model->GetTabContentsAt(i); |
| 1821 const GURL& tab_url = tc->GetURL(); | 1760 const GURL& tab_url = tc->GetURL(); |
| 1822 | 1761 |
| 1823 if (tab_url.scheme() == url.scheme() && tab_url.host() == url.host()) { | 1762 if (tab_url.scheme() == url.scheme() && tab_url.host() == url.host()) { |
| 1824 // We found an existing options tab, load the URL in this tab. (Note: | 1763 // We found an existing options tab, load the URL in this tab. (Note: |
| 1825 // this may cause us to unnecessarily reload the same page. We can't | 1764 // this may cause us to unnecessarily reload the same page. We can't |
| 1826 // really detect that unless the options page is permitted to change the | 1765 // really detect that unless the options page is permitted to change the |
| 1827 // URL in the address bar, but security policy doesn't allow that. | 1766 // URL in the address bar, but security policy doesn't allow that. |
| 1828 OpenURLAtIndex(tc, url, GURL(), CURRENT_TAB, PageTransition::GENERATED, | 1767 browser::NavigateParams params(this, url, PageTransition::GENERATED); |
| 1829 -1, -1); | 1768 params.source_contents = tc; |
| 1769 browser::Navigate(¶ms); |
| 1830 model->SelectTabContentsAt(i, false); | 1770 model->SelectTabContentsAt(i, false); |
| 1831 return; | 1771 return; |
| 1832 } | 1772 } |
| 1833 } | 1773 } |
| 1834 | 1774 |
| 1835 // No options tab found, so create a new one. | 1775 // No options tab found, so create a new one. |
| 1836 AddSelectedTabWithURL(url, PageTransition::AUTO_BOOKMARK); | 1776 AddSelectedTabWithURL(url, PageTransition::AUTO_BOOKMARK); |
| 1837 } | 1777 } |
| 1838 | 1778 |
| 1839 void Browser::OpenClearBrowsingDataDialog() { | 1779 void Browser::OpenClearBrowsingDataDialog() { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1909 UserMetrics::RecordAction(UserMetricsAction("UpdateChrome"), profile_); | 1849 UserMetrics::RecordAction(UserMetricsAction("UpdateChrome"), profile_); |
| 1910 window_->ShowUpdateChromeDialog(); | 1850 window_->ShowUpdateChromeDialog(); |
| 1911 } | 1851 } |
| 1912 | 1852 |
| 1913 void Browser::OpenHelpTab() { | 1853 void Browser::OpenHelpTab() { |
| 1914 GURL help_url = google_util::AppendGoogleLocaleParam(GURL(kHelpContentUrl)); | 1854 GURL help_url = google_util::AppendGoogleLocaleParam(GURL(kHelpContentUrl)); |
| 1915 AddSelectedTabWithURL(help_url, PageTransition::AUTO_BOOKMARK); | 1855 AddSelectedTabWithURL(help_url, PageTransition::AUTO_BOOKMARK); |
| 1916 } | 1856 } |
| 1917 | 1857 |
| 1918 void Browser::OpenThemeGalleryTabAndActivate() { | 1858 void Browser::OpenThemeGalleryTabAndActivate() { |
| 1919 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), | 1859 AddSelectedTabWithURL(GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), |
| 1920 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | 1860 PageTransition::LINK); |
| 1921 window_->Activate(); | |
| 1922 } | 1861 } |
| 1923 | 1862 |
| 1924 void Browser::OpenPrivacyDashboardTabAndActivate() { | 1863 void Browser::OpenPrivacyDashboardTabAndActivate() { |
| 1925 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_PRIVACY_DASHBOARD_URL)), | 1864 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_PRIVACY_DASHBOARD_URL)), |
| 1926 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | 1865 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 1927 window_->Activate(); | 1866 window_->Activate(); |
| 1928 } | 1867 } |
| 1929 | 1868 |
| 1930 void Browser::OpenAutoFillHelpTabAndActivate() { | 1869 void Browser::OpenAutoFillHelpTabAndActivate() { |
| 1931 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_AUTOFILL_HELP_URL)), | 1870 AddSelectedTabWithURL(GURL(l10n_util::GetStringUTF8(IDS_AUTOFILL_HELP_URL)), |
| 1932 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | 1871 PageTransition::LINK); |
| 1933 window_->Activate(); | |
| 1934 } | 1872 } |
| 1935 | 1873 |
| 1936 void Browser::OpenSearchEngineOptionsDialog() { | 1874 void Browser::OpenSearchEngineOptionsDialog() { |
| 1937 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1875 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1938 switches::kEnableTabbedOptions)) { | 1876 switches::kEnableTabbedOptions)) { |
| 1939 OpenKeywordEditor(); | 1877 OpenKeywordEditor(); |
| 1940 } else { | 1878 } else { |
| 1941 ShowOptionsWindow(OPTIONS_PAGE_GENERAL, OPTIONS_GROUP_DEFAULT_SEARCH, | 1879 ShowOptionsWindow(OPTIONS_PAGE_GENERAL, OPTIONS_GROUP_DEFAULT_SEARCH, |
| 1942 profile_); | 1880 profile_); |
| 1943 } | 1881 } |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2401 | 2339 |
| 2402 TabContents* Browser::AddBlankTab(bool foreground) { | 2340 TabContents* Browser::AddBlankTab(bool foreground) { |
| 2403 return AddBlankTabAt(-1, foreground); | 2341 return AddBlankTabAt(-1, foreground); |
| 2404 } | 2342 } |
| 2405 | 2343 |
| 2406 TabContents* Browser::AddBlankTabAt(int index, bool foreground) { | 2344 TabContents* Browser::AddBlankTabAt(int index, bool foreground) { |
| 2407 // Time new tab page creation time. We keep track of the timing data in | 2345 // Time new tab page creation time. We keep track of the timing data in |
| 2408 // TabContents, but we want to include the time it takes to create the | 2346 // TabContents, but we want to include the time it takes to create the |
| 2409 // TabContents object too. | 2347 // TabContents object too. |
| 2410 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); | 2348 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); |
| 2411 AddTabWithURLParams params(GURL(chrome::kChromeUINewTabURL), | 2349 browser::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL), |
| 2412 PageTransition::TYPED); | 2350 PageTransition::TYPED); |
| 2413 params.add_types = | 2351 params.tabstrip_add_types = |
| 2414 foreground ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE; | 2352 foreground ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE; |
| 2415 params.index = index; | 2353 params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
| 2416 TabContents* contents = AddTabWithURL(¶ms); | 2354 params.tabstrip_index = index; |
| 2417 contents->set_new_tab_start_time(new_tab_start_time); | 2355 browser::Navigate(¶ms); |
| 2418 return contents; | 2356 params.target_contents->set_new_tab_start_time(new_tab_start_time); |
| 2357 return params.target_contents; |
| 2419 } | 2358 } |
| 2420 | 2359 |
| 2421 Browser* Browser::CreateNewStripWithContents(TabContents* detached_contents, | 2360 Browser* Browser::CreateNewStripWithContents(TabContents* detached_contents, |
| 2422 const gfx::Rect& window_bounds, | 2361 const gfx::Rect& window_bounds, |
| 2423 const DockInfo& dock_info, | 2362 const DockInfo& dock_info, |
| 2424 bool maximize) { | 2363 bool maximize) { |
| 2425 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); | 2364 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); |
| 2426 | 2365 |
| 2427 gfx::Rect new_window_bounds = window_bounds; | 2366 gfx::Rect new_window_bounds = window_bounds; |
| 2428 if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) | 2367 if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2764 } | 2703 } |
| 2765 | 2704 |
| 2766 /////////////////////////////////////////////////////////////////////////////// | 2705 /////////////////////////////////////////////////////////////////////////////// |
| 2767 // Browser, TabContentsDelegate implementation: | 2706 // Browser, TabContentsDelegate implementation: |
| 2768 | 2707 |
| 2769 void Browser::OpenURLFromTab(TabContents* source, | 2708 void Browser::OpenURLFromTab(TabContents* source, |
| 2770 const GURL& url, | 2709 const GURL& url, |
| 2771 const GURL& referrer, | 2710 const GURL& referrer, |
| 2772 WindowOpenDisposition disposition, | 2711 WindowOpenDisposition disposition, |
| 2773 PageTransition::Type transition) { | 2712 PageTransition::Type transition) { |
| 2774 OpenURLAtIndex(source, url, referrer, disposition, transition, -1, | 2713 browser::NavigateParams params(this, url, transition); |
| 2775 TabStripModel::ADD_NONE); | 2714 params.source_contents = source; |
| 2715 params.referrer = referrer; |
| 2716 params.disposition = disposition; |
| 2717 params.tabstrip_add_types = TabStripModel::ADD_NONE; |
| 2718 browser::Navigate(¶ms); |
| 2776 } | 2719 } |
| 2777 | 2720 |
| 2778 void Browser::NavigationStateChanged(const TabContents* source, | 2721 void Browser::NavigationStateChanged(const TabContents* source, |
| 2779 unsigned changed_flags) { | 2722 unsigned changed_flags) { |
| 2780 // Only update the UI when something visible has changed. | 2723 // Only update the UI when something visible has changed. |
| 2781 if (changed_flags) | 2724 if (changed_flags) |
| 2782 ScheduleUIUpdate(source, changed_flags); | 2725 ScheduleUIUpdate(source, changed_flags); |
| 2783 | 2726 |
| 2784 // We don't schedule updates to commands since they will only change once per | 2727 // We don't schedule updates to commands since they will only change once per |
| 2785 // navigation, so we don't have to worry about flickering. | 2728 // navigation, so we don't have to worry about flickering. |
| 2786 if (changed_flags & TabContents::INVALIDATE_URL) | 2729 if (changed_flags & TabContents::INVALIDATE_URL) |
| 2787 UpdateCommandsForTabState(); | 2730 UpdateCommandsForTabState(); |
| 2788 } | 2731 } |
| 2789 | 2732 |
| 2790 void Browser::AddNewContents(TabContents* source, | 2733 void Browser::AddNewContents(TabContents* source, |
| 2791 TabContents* new_contents, | 2734 TabContents* new_contents, |
| 2792 WindowOpenDisposition disposition, | 2735 WindowOpenDisposition disposition, |
| 2793 const gfx::Rect& initial_pos, | 2736 const gfx::Rect& initial_pos, |
| 2794 bool user_gesture) { | 2737 bool user_gesture) { |
| 2795 DCHECK(disposition != SAVE_TO_DISK); // No code for this yet | 2738 // No code for this yet |
| 2796 DCHECK(disposition != CURRENT_TAB); // Can't create a new contents for the | 2739 DCHECK(disposition != SAVE_TO_DISK); |
| 2797 // current tab. | 2740 // Can't create a new contents for the current tab - invalid case. |
| 2741 DCHECK(disposition != CURRENT_TAB); |
| 2798 | 2742 |
| 2743 // TODO(beng): This belongs behind the platform-specific View interface. |
| 2744 // That's why it's there. |
| 2799 #if defined(OS_CHROMEOS) | 2745 #if defined(OS_CHROMEOS) |
| 2800 if (disposition == NEW_POPUP) { | 2746 if (disposition == NEW_POPUP) { |
| 2801 // If the popup is bigger than a given factor of the screen, then | 2747 // If the popup is bigger than a given factor of the screen, then |
| 2802 // turn it into a foreground tab (on chrome os only) | 2748 // turn it into a foreground tab (on chrome os only) |
| 2803 // Also check for width or height == 0, which would otherwise indicate | 2749 // Also check for width or height == 0, which would otherwise indicate |
| 2804 // a tab sized popup window. | 2750 // a tab sized popup window. |
| 2805 GdkScreen* screen = gdk_screen_get_default(); | 2751 GdkScreen* screen = gdk_screen_get_default(); |
| 2806 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor; | 2752 int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor; |
| 2807 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor; | 2753 int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor; |
| 2808 if (initial_pos.width() > max_width || initial_pos.width() == 0 || | 2754 if (initial_pos.width() > max_width || initial_pos.width() == 0 || |
| 2809 initial_pos.height() > max_height || initial_pos.height() == 0) { | 2755 initial_pos.height() > max_height || initial_pos.height() == 0) { |
| 2810 disposition = NEW_FOREGROUND_TAB; | 2756 disposition = NEW_FOREGROUND_TAB; |
| 2811 } | |
| 2812 } | 2757 } |
| 2758 } |
| 2813 #endif | 2759 #endif |
| 2814 | 2760 |
| 2815 // If this is a window with no tabstrip, we can only have one tab so we need | 2761 browser::NavigateParams params(this, new_contents); |
| 2816 // to process this in tabbed browser window. | 2762 params.source_contents = source; |
| 2817 if (!CanSupportWindowFeature(FEATURE_TABSTRIP) && | 2763 params.disposition = disposition; |
| 2818 tab_handler_->GetTabStripModel()->count() > 0 && | 2764 params.window_bounds = initial_pos; |
| 2819 disposition != NEW_WINDOW && | 2765 browser::Navigate(¶ms); |
| 2820 disposition != NEW_POPUP) { | |
| 2821 Browser* b = GetOrCreateTabbedBrowser(profile_); | |
| 2822 DCHECK(b); | |
| 2823 PageTransition::Type transition = PageTransition::LINK; | |
| 2824 // If we were called from an "installed webapp" we want to emulate the code | |
| 2825 // that is run from browser_init.cc for links from external applications. | |
| 2826 // This means we need to open the tab with the START PAGE transition. | |
| 2827 // AddNewContents doesn't support this but the TabStripModel's | |
| 2828 // AddTabContents method does. | |
| 2829 if (type_ & TYPE_APP) | |
| 2830 transition = PageTransition::START_PAGE; | |
| 2831 b->tabstrip_model()->AddTabContents( | |
| 2832 new_contents, -1, transition, TabStripModel::ADD_SELECTED); | |
| 2833 b->window()->Show(); | |
| 2834 return; | |
| 2835 } | |
| 2836 | |
| 2837 if (disposition == NEW_POPUP) { | |
| 2838 Type browser_type; | |
| 2839 if ((type_ & TYPE_APP) || (source && source->is_app())) { | |
| 2840 // New app popup, or an app is creating a popup. | |
| 2841 browser_type = TYPE_APP_POPUP; | |
| 2842 } else { | |
| 2843 browser_type = TYPE_POPUP; | |
| 2844 } | |
| 2845 Browser* browser = Browser::CreateForPopup(browser_type, | |
| 2846 profile_, | |
| 2847 new_contents, | |
| 2848 initial_pos); | |
| 2849 browser->window()->Show(); | |
| 2850 | |
| 2851 } else if (disposition == NEW_WINDOW) { | |
| 2852 Browser* browser = Browser::Create(profile_); | |
| 2853 browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB, | |
| 2854 initial_pos, user_gesture); | |
| 2855 browser->window()->Show(); | |
| 2856 } else if (disposition != SUPPRESS_OPEN) { | |
| 2857 tab_handler_->GetTabStripModel()->AddTabContents( | |
| 2858 new_contents, -1, PageTransition::LINK, | |
| 2859 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED : | |
| 2860 TabStripModel::ADD_NONE); | |
| 2861 } | |
| 2862 } | 2766 } |
| 2863 | 2767 |
| 2864 void Browser::ActivateContents(TabContents* contents) { | 2768 void Browser::ActivateContents(TabContents* contents) { |
| 2865 tab_handler_->GetTabStripModel()->SelectTabContentsAt( | 2769 tab_handler_->GetTabStripModel()->SelectTabContentsAt( |
| 2866 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents), false); | 2770 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents), false); |
| 2867 window_->Activate(); | 2771 window_->Activate(); |
| 2868 } | 2772 } |
| 2869 | 2773 |
| 2870 void Browser::DeactivateContents(TabContents* contents) { | 2774 void Browser::DeactivateContents(TabContents* contents) { |
| 2871 window_->Deactivate(); | 2775 window_->Deactivate(); |
| (...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4062 } | 3966 } |
| 4063 | 3967 |
| 4064 // static | 3968 // static |
| 4065 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { | 3969 Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) { |
| 4066 Browser* browser = GetTabbedBrowser(profile, false); | 3970 Browser* browser = GetTabbedBrowser(profile, false); |
| 4067 if (!browser) | 3971 if (!browser) |
| 4068 browser = Browser::Create(profile); | 3972 browser = Browser::Create(profile); |
| 4069 return browser; | 3973 return browser; |
| 4070 } | 3974 } |
| 4071 | 3975 |
| 4072 void Browser::OpenURLAtIndex(TabContents* source, | |
| 4073 const GURL& url, | |
| 4074 const GURL& referrer, | |
| 4075 WindowOpenDisposition disposition, | |
| 4076 PageTransition::Type transition, | |
| 4077 int index, | |
| 4078 int add_types) { | |
| 4079 // TODO(beng): Move all this code into a separate helper that has unit tests. | |
| 4080 | |
| 4081 // No code for these yet | |
| 4082 DCHECK((disposition != NEW_POPUP) && (disposition != SAVE_TO_DISK)); | |
| 4083 | |
| 4084 TabContents* current_tab = source ? source : GetSelectedTabContents(); | |
| 4085 bool source_tab_was_frontmost = (current_tab == GetSelectedTabContents()); | |
| 4086 TabContents* new_contents = NULL; | |
| 4087 | |
| 4088 // Opening a bookmark counts as a user gesture, so we don't need to avoid | |
| 4089 // carpet-bombing here. | |
| 4090 PageTransition::Type baseTransitionType = | |
| 4091 PageTransition::StripQualifier(transition); | |
| 4092 if ((baseTransitionType == PageTransition::TYPED || | |
| 4093 baseTransitionType == PageTransition::AUTO_BOOKMARK) && | |
| 4094 current_tab != NULL) { | |
| 4095 RenderViewHostDelegate::BrowserIntegration* delegate = current_tab; | |
| 4096 delegate->OnUserGesture(); | |
| 4097 } | |
| 4098 | |
| 4099 // If the URL is part of the same web site, then load it in the same | |
| 4100 // SiteInstance (and thus the same process). This is an optimization to | |
| 4101 // reduce process overhead; it is not necessary for compatibility. (That is, | |
| 4102 // the new tab will not have script connections to the previous tab, so it | |
| 4103 // does not need to be part of the same SiteInstance or BrowsingInstance.) | |
| 4104 // Default to loading in a new SiteInstance and BrowsingInstance. | |
| 4105 // TODO(creis): should this apply to applications? | |
| 4106 SiteInstance* instance = NULL; | |
| 4107 // Don't use this logic when "--process-per-tab" is specified. | |
| 4108 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab)) { | |
| 4109 if (current_tab) { | |
| 4110 const GURL& current_url = current_tab->GetURL(); | |
| 4111 if (SiteInstance::IsSameWebSite(profile_, current_url, url)) | |
| 4112 instance = current_tab->GetSiteInstance(); | |
| 4113 } | |
| 4114 } | |
| 4115 | |
| 4116 // If this browser doeesn't support tabs, we can only have one tab so a new | |
| 4117 // tab always goes into a tabbed browser window. | |
| 4118 if (!CanSupportWindowFeature(FEATURE_TABSTRIP) && | |
| 4119 disposition != CURRENT_TAB && disposition != NEW_WINDOW) { | |
| 4120 // If the disposition is OFF_THE_RECORD we don't want to create a new | |
| 4121 // browser that will itself create another OTR browser. This will result in | |
| 4122 // a browser leak (and crash below because no tab is created or selected). | |
| 4123 if (disposition == OFF_THE_RECORD) { | |
| 4124 OpenURLOffTheRecord(profile_, url); | |
| 4125 return; | |
| 4126 } | |
| 4127 | |
| 4128 Browser* b = GetOrCreateTabbedBrowser(profile_); | |
| 4129 DCHECK(b); | |
| 4130 | |
| 4131 // If we have just created a new browser window, make sure we select the | |
| 4132 // tab. | |
| 4133 if (b->tab_count() == 0 && disposition == NEW_BACKGROUND_TAB) | |
| 4134 disposition = NEW_FOREGROUND_TAB; | |
| 4135 | |
| 4136 b->OpenURL(url, referrer, disposition, transition); | |
| 4137 b->window()->Show(); | |
| 4138 return; | |
| 4139 } | |
| 4140 | |
| 4141 if (profile_->IsOffTheRecord() && disposition == OFF_THE_RECORD) | |
| 4142 disposition = NEW_FOREGROUND_TAB; | |
| 4143 | |
| 4144 if (disposition == SINGLETON_TAB) { | |
| 4145 ShowSingletonTab(url); | |
| 4146 return; | |
| 4147 } else if (disposition == NEW_WINDOW) { | |
| 4148 Browser* browser = Browser::Create(profile_); | |
| 4149 AddTabWithURLParams params(url, transition); | |
| 4150 params.referrer = referrer; | |
| 4151 params.index = index; | |
| 4152 params.add_types = TabStripModel::ADD_SELECTED | add_types; | |
| 4153 params.instance = instance; | |
| 4154 new_contents = browser->AddTabWithURL(¶ms); | |
| 4155 browser->window()->Show(); | |
| 4156 } else if ((disposition == CURRENT_TAB) && current_tab) { | |
| 4157 tab_handler_->GetTabStripModel()->TabNavigating(current_tab, transition); | |
| 4158 | |
| 4159 bool user_initiated = (PageTransition::StripQualifier(transition) == | |
| 4160 PageTransition::AUTO_BOOKMARK); | |
| 4161 | |
| 4162 if (user_initiated && source_tab_was_frontmost && | |
| 4163 window_->GetLocationBar()) { | |
| 4164 // Forcibly reset the location bar if the url is going to change in the | |
| 4165 // current tab, since otherwise it won't discard any ongoing user edits, | |
| 4166 // since it doesn't realize this is a user-initiated action. | |
| 4167 window_->GetLocationBar()->Revert(); | |
| 4168 } | |
| 4169 | |
| 4170 current_tab->controller().LoadURL(url, referrer, transition); | |
| 4171 new_contents = current_tab; | |
| 4172 if (GetStatusBubble()) | |
| 4173 GetStatusBubble()->Hide(); | |
| 4174 | |
| 4175 // Update the location bar. This is synchronous. We specifically don't | |
| 4176 // update the load state since the load hasn't started yet and updating it | |
| 4177 // will put it out of sync with the actual state like whether we're | |
| 4178 // displaying a favicon, which controls the throbber. If we updated it here, | |
| 4179 // the throbber will show the default favicon for a split second when | |
| 4180 // navigating away from the new tab page. | |
| 4181 ScheduleUIUpdate(current_tab, TabContents::INVALIDATE_URL); | |
| 4182 } else if (disposition == OFF_THE_RECORD) { | |
| 4183 OpenURLOffTheRecord(profile_, url); | |
| 4184 return; | |
| 4185 } else if (disposition != SUPPRESS_OPEN) { | |
| 4186 if (disposition != NEW_BACKGROUND_TAB) | |
| 4187 add_types |= TabStripModel::ADD_SELECTED; | |
| 4188 AddTabWithURLParams params(url, transition); | |
| 4189 params.referrer = referrer; | |
| 4190 params.index = index; | |
| 4191 params.add_types = add_types; | |
| 4192 params.instance = instance; | |
| 4193 new_contents = AddTabWithURL(¶ms); | |
| 4194 } | |
| 4195 | |
| 4196 if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost && | |
| 4197 new_contents) { | |
| 4198 // Give the focus to the newly navigated tab, if the source tab was | |
| 4199 // front-most. | |
| 4200 new_contents->Focus(); | |
| 4201 } | |
| 4202 } | |
| 4203 | |
| 4204 void Browser::FindInPage(bool find_next, bool forward_direction) { | 3976 void Browser::FindInPage(bool find_next, bool forward_direction) { |
| 4205 ShowFindBar(); | 3977 ShowFindBar(); |
| 4206 if (find_next) { | 3978 if (find_next) { |
| 4207 string16 find_text; | 3979 string16 find_text; |
| 4208 #if defined(OS_MACOSX) | 3980 #if defined(OS_MACOSX) |
| 4209 // We always want to search for the contents of the find pasteboard on OS X. | 3981 // We always want to search for the contents of the find pasteboard on OS X. |
| 4210 find_text = GetFindPboardText(); | 3982 find_text = GetFindPboardText(); |
| 4211 #endif | 3983 #endif |
| 4212 GetSelectedTabContents()->StartFinding(find_text, | 3984 GetSelectedTabContents()->StartFinding(find_text, |
| 4213 forward_direction, | 3985 forward_direction, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4306 NOTREACHED(); | 4078 NOTREACHED(); |
| 4307 return false; | 4079 return false; |
| 4308 } | 4080 } |
| 4309 | 4081 |
| 4310 void Browser::CreateInstantIfNecessary() { | 4082 void Browser::CreateInstantIfNecessary() { |
| 4311 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && | 4083 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && |
| 4312 !profile()->IsOffTheRecord()) { | 4084 !profile()->IsOffTheRecord()) { |
| 4313 instant_.reset(new InstantController(this)); | 4085 instant_.reset(new InstantController(this)); |
| 4314 } | 4086 } |
| 4315 } | 4087 } |
| OLD | NEW |