| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/chrome_pages.h" | 5 #include "chrome/browser/ui/chrome_pages.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/download/download_shelf.h" | 11 #include "chrome/browser/download/download_shelf.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/signin/signin_manager.h" | 15 #include "chrome/browser/signin/signin_manager.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" |
| 18 #include "chrome/browser/ui/browser_navigator.h" | 19 #include "chrome/browser/ui/browser_navigator.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/browser/ui/extensions/application_launch.h" | 21 #include "chrome/browser/ui/extensions/application_launch.h" |
| 21 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 23 #include "chrome/browser/ui/settings_window_manager.h" |
| 22 #include "chrome/browser/ui/singleton_tabs.h" | 24 #include "chrome/browser/ui/singleton_tabs.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/browser/ui/webui/options/content_settings_handler.h" | 26 #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
| 27 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 26 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/common/url_constants.h" |
| 27 #include "google_apis/gaia/gaia_urls.h" | 32 #include "google_apis/gaia/gaia_urls.h" |
| 28 #include "net/base/url_util.h" | 33 #include "net/base/url_util.h" |
| 29 #include "url/gurl.h" | |
| 30 | 34 |
| 31 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 32 #include "chrome/browser/enumerate_modules_model_win.h" | 36 #include "chrome/browser/enumerate_modules_model_win.h" |
| 33 #endif | 37 #endif |
| 34 | 38 |
| 35 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 36 #include "chrome/browser/chromeos/genius_app/app_id.h" | 40 #include "chrome/browser/chromeos/genius_app/app_id.h" |
| 37 #include "chromeos/chromeos_switches.h" | 41 #include "chromeos/chromeos_switches.h" |
| 38 #endif | 42 #endif |
| 39 | 43 |
| 40 using base::UserMetricsAction; | 44 using base::UserMetricsAction; |
| 41 | 45 |
| 42 namespace chrome { | 46 namespace chrome { |
| 43 namespace { | 47 namespace { |
| 44 | 48 |
| 45 const char kHashMark[] = "#"; | 49 const char kHashMark[] = "#"; |
| 46 | 50 |
| 47 void OpenBookmarkManagerWithHash(Browser* browser, | 51 void OpenBookmarkManagerWithHash(Browser* browser, |
| 48 const std::string& action, | 52 const std::string& action, |
| 49 int64 node_id) { | 53 int64 node_id) { |
| 50 content::RecordAction(UserMetricsAction("ShowBookmarkManager")); | 54 content::RecordAction(UserMetricsAction("ShowBookmarkManager")); |
| 51 content::RecordAction(UserMetricsAction("ShowBookmarks")); | 55 content::RecordAction(UserMetricsAction("ShowBookmarks")); |
| 52 NavigateParams params(GetSingletonTabNavigateParams( | 56 NavigateParams params(GetSingletonTabNavigateParams( |
| 53 browser, | 57 browser, |
| 54 GURL(kChromeUIBookmarksURL).Resolve( | 58 GURL(kChromeUIBookmarksURL).Resolve(base::StringPrintf( |
| 55 base::StringPrintf("/#%s%s", action.c_str(), | 59 "/#%s%s", action.c_str(), base::Int64ToString(node_id).c_str())))); |
| 56 base::Int64ToString(node_id).c_str())))); | |
| 57 params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; | 60 params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; |
| 58 ShowSingletonTabOverwritingNTP(browser, params); | 61 ShowSingletonTabOverwritingNTP(browser, params); |
| 59 } | 62 } |
| 60 | 63 |
| 61 void NavigateToSingletonTab(Browser* browser, const GURL& url) { | 64 void NavigateToSingletonTab(Browser* browser, const GURL& url) { |
| 62 NavigateParams params(GetSingletonTabNavigateParams(browser, url)); | 65 NavigateParams params(GetSingletonTabNavigateParams(browser, url)); |
| 63 params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; | 66 params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; |
| 64 ShowSingletonTabOverwritingNTP(browser, params); | 67 ShowSingletonTabOverwritingNTP(browser, params); |
| 65 } | 68 } |
| 66 | 69 |
| 67 // Shows either the help app or the appropriate help page for |source|. If | 70 // Shows either the help app or the appropriate help page for |source|. If |
| 68 // |browser| is NULL and the help page is used (vs the app), the help page is | 71 // |browser| is NULL and the help page is used (vs the app), the help page is |
| 69 // shown in the last active browser. If there is no such browser, a new browser | 72 // shown in the last active browser. If there is no such browser, a new browser |
| 70 // is created. | 73 // is created. |
| 71 void ShowHelpImpl(Browser* browser, | 74 void ShowHelpImpl(Browser* browser, |
| 72 Profile* profile, | 75 Profile* profile, |
| 73 HostDesktopType host_desktop_type, | 76 HostDesktopType host_desktop_type, |
| 74 HelpSource source) { | 77 HelpSource source) { |
| 75 content::RecordAction(UserMetricsAction("ShowHelpTab")); | 78 content::RecordAction(UserMetricsAction("ShowHelpTab")); |
| 76 #if defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD) | 79 #if defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD) |
| 77 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 80 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 78 if (!command_line->HasSwitch(chromeos::switches::kDisableGeniusApp)) { | 81 if (!command_line->HasSwitch(chromeos::switches::kDisableGeniusApp)) { |
| 79 const extensions::Extension* extension = profile->GetExtensionService()-> | 82 const extensions::Extension* extension = |
| 80 GetInstalledExtension(genius_app::kGeniusAppId); | 83 profile->GetExtensionService()->GetInstalledExtension( |
| 81 OpenApplication( | 84 genius_app::kGeniusAppId); |
| 82 AppLaunchParams(profile, extension, 0, host_desktop_type)); | 85 OpenApplication(AppLaunchParams(profile, extension, 0, host_desktop_type)); |
| 83 return; | 86 return; |
| 84 } | 87 } |
| 85 #endif | 88 #endif |
| 86 GURL url; | 89 GURL url; |
| 87 switch (source) { | 90 switch (source) { |
| 88 case HELP_SOURCE_KEYBOARD: | 91 case HELP_SOURCE_KEYBOARD: |
| 89 url = GURL(kChromeHelpViaKeyboardURL); | 92 url = GURL(kChromeHelpViaKeyboardURL); |
| 90 break; | 93 break; |
| 91 case HELP_SOURCE_MENU: | 94 case HELP_SOURCE_MENU: |
| 92 url = GURL(kChromeHelpViaMenuURL); | 95 url = GURL(kChromeHelpViaMenuURL); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 return; | 172 return; |
| 170 } | 173 } |
| 171 } | 174 } |
| 172 #endif | 175 #endif |
| 173 | 176 |
| 174 content::RecordAction(UserMetricsAction("AboutConflicts")); | 177 content::RecordAction(UserMetricsAction("AboutConflicts")); |
| 175 ShowSingletonTab(browser, GURL(kChromeUIConflictsURL)); | 178 ShowSingletonTab(browser, GURL(kChromeUIConflictsURL)); |
| 176 } | 179 } |
| 177 | 180 |
| 178 void ShowHelp(Browser* browser, HelpSource source) { | 181 void ShowHelp(Browser* browser, HelpSource source) { |
| 179 ShowHelpImpl(browser, browser->profile(), browser->host_desktop_type(), | 182 ShowHelpImpl( |
| 180 source); | 183 browser, browser->profile(), browser->host_desktop_type(), source); |
| 181 } | 184 } |
| 182 | 185 |
| 183 void ShowHelpForProfile(Profile* profile, | 186 void ShowHelpForProfile(Profile* profile, |
| 184 HostDesktopType host_desktop_type, | 187 HostDesktopType host_desktop_type, |
| 185 HelpSource source) { | 188 HelpSource source) { |
| 186 ShowHelpImpl(NULL, profile, host_desktop_type, source); | 189 ShowHelpImpl(NULL, profile, host_desktop_type, source); |
| 187 } | 190 } |
| 188 | 191 |
| 189 void ShowPolicy(Browser* browser) { | 192 void ShowPolicy(Browser* browser) { |
| 190 ShowSingletonTab(browser, GURL(kChromeUIPolicyURL)); | 193 ShowSingletonTab(browser, GURL(kChromeUIPolicyURL)); |
| 191 } | 194 } |
| 192 | 195 |
| 193 void ShowSlow(Browser* browser) { | 196 void ShowSlow(Browser* browser) { |
| 194 #if defined(OS_CHROMEOS) | 197 #if defined(OS_CHROMEOS) |
| 195 ShowSingletonTab(browser, GURL(kChromeUISlowURL)); | 198 ShowSingletonTab(browser, GURL(kChromeUISlowURL)); |
| 196 #endif | 199 #endif |
| 197 } | 200 } |
| 198 | 201 |
| 202 GURL GetSettingsUrl(const std::string& sub_page) { |
| 203 std::string url = std::string(kChromeUISettingsURL) + sub_page; |
| 204 #if defined(OS_CHROMEOS) |
| 205 if (sub_page.find(kInternetOptionsSubPage, 0) != std::string::npos) { |
| 206 std::string::size_type loc = sub_page.find("?", 0); |
| 207 std::string network_page = |
| 208 loc != std::string::npos ? sub_page.substr(loc) : std::string(); |
| 209 url = std::string(kChromeUISettingsURL) + network_page; |
| 210 } |
| 211 #endif |
| 212 return GURL(url); |
| 213 } |
| 214 |
| 215 bool IsSettingsWindow(const Browser* browser) { |
| 216 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 217 switches::kEnableSettingsWindow)) |
| 218 return false; |
| 219 if (browser->is_type_tabbed()) |
| 220 return false; |
| 221 const content::WebContents* web_contents = |
| 222 browser->tab_strip_model()->GetWebContentsAt(0); |
| 223 if (!web_contents) |
| 224 return false; |
| 225 GURL url(web_contents->GetURL()); |
| 226 return (url.SchemeIs(content::kChromeUIScheme) && |
| 227 url.spec().find(chrome::kChromeUISettingsURL) == 0); |
| 228 } |
| 229 |
| 199 void ShowSettings(Browser* browser) { | 230 void ShowSettings(Browser* browser) { |
| 200 content::RecordAction(UserMetricsAction("ShowOptions")); | |
| 201 ShowSettingsSubPage(browser, std::string()); | 231 ShowSettingsSubPage(browser, std::string()); |
| 202 } | 232 } |
| 203 | 233 |
| 204 void ShowSettingsSubPage(Browser* browser, const std::string& sub_page) { | 234 void ShowSettingsSubPage(Browser* browser, const std::string& sub_page) { |
| 205 std::string url = std::string(kChromeUISettingsURL) + sub_page; | 235 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 206 #if defined(OS_CHROMEOS) | 236 ::switches::kEnableSettingsWindow)) { |
| 207 if (sub_page.find(kInternetOptionsSubPage, 0) != std::string::npos) { | 237 SettingsWindowManager::GetInstance()->ShowForProfile(browser->profile(), |
| 208 std::string::size_type loc = sub_page.find("?", 0); | 238 sub_page); |
| 209 std::string network_page = loc != std::string::npos ? | 239 return; |
| 210 sub_page.substr(loc) : std::string(); | |
| 211 url = std::string(kChromeUISettingsURL) + network_page; | |
| 212 } | 240 } |
| 213 #endif | 241 ShowSettingsSubPageInTabbedBrowser(browser, sub_page); |
| 214 NavigateParams params(GetSingletonTabNavigateParams(browser, GURL(url))); | 242 } |
| 243 |
| 244 void ShowSettingsSubPageForProfile(Profile* profile, |
| 245 const std::string& sub_page) { |
| 246 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 247 ::switches::kEnableSettingsWindow)) { |
| 248 SettingsWindowManager::GetInstance()->ShowForProfile(profile, sub_page); |
| 249 return; |
| 250 } |
| 251 Browser* browser = |
| 252 chrome::FindTabbedBrowser(profile, false, HOST_DESKTOP_TYPE_NATIVE); |
| 253 if (!browser) { |
| 254 browser = new Browser( |
| 255 Browser::CreateParams(profile, chrome::HOST_DESKTOP_TYPE_NATIVE)); |
| 256 } |
| 257 ShowSettingsSubPageInTabbedBrowser(browser, sub_page); |
| 258 } |
| 259 |
| 260 void ShowSettingsSubPageInTabbedBrowser(Browser* browser, |
| 261 const std::string& sub_page) { |
| 262 content::RecordAction(UserMetricsAction("ShowOptions")); |
| 263 GURL gurl = GetSettingsUrl(sub_page); |
| 264 NavigateParams params(GetSingletonTabNavigateParams(browser, gurl)); |
| 215 params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; | 265 params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE; |
| 216 ShowSingletonTabOverwritingNTP(browser, params); | 266 ShowSingletonTabOverwritingNTP(browser, params); |
| 217 } | 267 } |
| 218 | 268 |
| 219 void ShowContentSettings(Browser* browser, | 269 void ShowContentSettings(Browser* browser, |
| 220 ContentSettingsType content_settings_type) { | 270 ContentSettingsType content_settings_type) { |
| 221 ShowSettingsSubPage( | 271 ShowSettingsSubPage( |
| 222 browser, | 272 browser, |
| 223 kContentSettingsExceptionsSubPage + std::string(kHashMark) + | 273 kContentSettingsExceptionsSubPage + std::string(kHashMark) + |
| 224 options::ContentSettingsHandler::ContentSettingsTypeToGroupName( | 274 options::ContentSettingsHandler::ContentSettingsTypeToGroupName( |
| 225 content_settings_type)); | 275 content_settings_type)); |
| 226 } | 276 } |
| 227 | 277 |
| 228 void ShowClearBrowsingDataDialog(Browser* browser) { | 278 void ShowClearBrowsingDataDialog(Browser* browser) { |
| 229 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShowDlg")); | 279 content::RecordAction(UserMetricsAction("ClearBrowsingData_ShowDlg")); |
| 230 ShowSettingsSubPage(browser, kClearBrowserDataSubPage); | 280 ShowSettingsSubPage(browser, kClearBrowserDataSubPage); |
| 231 } | 281 } |
| 232 | 282 |
| 233 void ShowPasswordManager(Browser* browser) { | 283 void ShowPasswordManager(Browser* browser) { |
| 234 content::RecordAction(UserMetricsAction("Options_ShowPasswordManager")); | 284 content::RecordAction(UserMetricsAction("Options_ShowPasswordManager")); |
| 235 ShowSettingsSubPage(browser, kPasswordManagerSubPage); | 285 ShowSettingsSubPage(browser, kPasswordManagerSubPage); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 265 // If the browser's profile is an incognito profile, make sure to use | 315 // If the browser's profile is an incognito profile, make sure to use |
| 266 // a browser window from the original profile. The user cannot sign in | 316 // a browser window from the original profile. The user cannot sign in |
| 267 // from an incognito window. | 317 // from an incognito window. |
| 268 scoped_ptr<ScopedTabbedBrowserDisplayer> displayer; | 318 scoped_ptr<ScopedTabbedBrowserDisplayer> displayer; |
| 269 if (browser->profile()->IsOffTheRecord()) { | 319 if (browser->profile()->IsOffTheRecord()) { |
| 270 displayer.reset(new ScopedTabbedBrowserDisplayer( | 320 displayer.reset(new ScopedTabbedBrowserDisplayer( |
| 271 original_profile, chrome::HOST_DESKTOP_TYPE_NATIVE)); | 321 original_profile, chrome::HOST_DESKTOP_TYPE_NATIVE)); |
| 272 browser = displayer->browser(); | 322 browser = displayer->browser(); |
| 273 } | 323 } |
| 274 | 324 |
| 275 NavigateToSingletonTab(browser, | 325 NavigateToSingletonTab(browser, GURL(signin::GetPromoURL(source, false))); |
| 276 GURL(signin::GetPromoURL(source, false))); | |
| 277 DCHECK_GT(browser->tab_strip_model()->count(), 0); | 326 DCHECK_GT(browser->tab_strip_model()->count(), 0); |
| 278 } | 327 } |
| 279 } | 328 } |
| 280 | 329 |
| 281 } // namespace chrome | 330 } // namespace chrome |
| OLD | NEW |