[email protected] | 1640a85 | 2012-01-05 21:05:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/browser/browser_about_handler.h" |
| 6 | |
[email protected] | ec529254 | 2012-09-25 13:10:09 | [diff] [blame] | 7 | #include <algorithm> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include <string> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
[email protected] | f5ec724 | 2012-01-27 07:15:15 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 11 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 12 | #include "base/memory/singleton.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | #include "base/string_util.h" |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 14 | #include "chrome/browser/net/url_fixer_upper.h" |
[email protected] | c96531e8 | 2011-01-26 03:11:14 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_dialogs.h" |
[email protected] | f5ec724 | 2012-01-27 07:15:15 | [diff] [blame] | 16 | #include "chrome/common/chrome_switches.h" |
[email protected] | dcf7d35 | 2009-02-26 01:56:02 | [diff] [blame] | 17 | #include "chrome/common/url_constants.h" |
[email protected] | 18bc42c9 | 2009-02-04 18:59:09 | [diff] [blame] | 18 | |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 19 | namespace { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | |
[email protected] | 62794f46 | 2011-07-19 05:50:16 | [diff] [blame] | 21 | // Add paths here to be included in chrome://chrome-urls (about:about). |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 22 | // These paths will also be suggested by BuiltinProvider. |
[email protected] | ec529254 | 2012-09-25 13:10:09 | [diff] [blame] | 23 | const char* const kPaths[] = { |
[email protected] | f5dae02 | 2011-07-13 21:59:27 | [diff] [blame] | 24 | chrome::kChromeUICacheHost, |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 25 | chrome::kChromeUIChromeURLsHost, |
[email protected] | 4e8655d | 2011-06-16 17:20:17 | [diff] [blame] | 26 | chrome::kChromeUICrashesHost, |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 27 | chrome::kChromeUICreditsHost, |
| 28 | chrome::kChromeUIDNSHost, |
[email protected] | 4052d83 | 2013-01-16 05:31:01 | [diff] [blame] | 29 | chrome::kChromeUIFlagsHost, |
[email protected] | f5dae02 | 2011-07-13 21:59:27 | [diff] [blame] | 30 | chrome::kChromeUIHistoryHost, |
| 31 | chrome::kChromeUIIPCHost, |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 32 | chrome::kChromeUIMemoryHost, |
[email protected] | e4a1cd4 | 2013-02-01 01:11:42 | [diff] [blame] | 33 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 34 | chrome::kChromeUINetExportHost, |
| 35 | #endif |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 36 | chrome::kChromeUINetInternalsHost, |
[email protected] | f5dae02 | 2011-07-13 21:59:27 | [diff] [blame] | 37 | chrome::kChromeUINewTabHost, |
[email protected] | 432954d0 | 2012-01-24 01:18:43 | [diff] [blame] | 38 | chrome::kChromeUIOmniboxHost, |
[email protected] | 9f1b3c0 | 2012-05-02 03:05:58 | [diff] [blame] | 39 | chrome::kChromeUIPredictorsHost, |
[email protected] | 7237980 | 2011-11-18 00:21:54 | [diff] [blame] | 40 | chrome::kChromeUIProfilerHost, |
[email protected] | f5dae02 | 2011-07-13 21:59:27 | [diff] [blame] | 41 | chrome::kChromeUIQuotaInternalsHost, |
[email protected] | df4223a | 2012-11-20 00:43:02 | [diff] [blame] | 42 | chrome::kChromeUISignInInternalsHost, |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 43 | chrome::kChromeUIStatsHost, |
| 44 | chrome::kChromeUISyncInternalsHost, |
[email protected] | 20cd74f | 2012-09-25 14:44:54 | [diff] [blame] | 45 | chrome::kChromeUITermsHost, |
[email protected] | 147408a | 2013-04-23 06:57:51 | [diff] [blame] | 46 | chrome::kChromeUITranslateInternalsHost, |
[email protected] | 77e9e4d | 2012-11-22 00:46:59 | [diff] [blame] | 47 | chrome::kChromeUIUserActionsHost, |
[email protected] | 20cd74f | 2012-09-25 14:44:54 | [diff] [blame] | 48 | chrome::kChromeUIVersionHost, |
[email protected] | fb8f1ca | 2012-09-26 05:17:35 | [diff] [blame] | 49 | #if defined(OS_ANDROID) |
| 50 | chrome::kChromeUIWelcomeHost, |
| 51 | #else |
| 52 | chrome::kChromeUIBookmarksHost, |
| 53 | chrome::kChromeUIDownloadsHost, |
[email protected] | fb8f1ca | 2012-09-26 05:17:35 | [diff] [blame] | 54 | chrome::kChromeUIFlashHost, |
| 55 | chrome::kChromeUIInspectHost, |
| 56 | chrome::kChromeUIPluginsHost, |
| 57 | chrome::kChromeUISettingsHost, |
[email protected] | fb8f1ca | 2012-09-26 05:17:35 | [diff] [blame] | 58 | #endif |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 59 | #if defined(OS_WIN) |
| 60 | chrome::kChromeUIConflictsHost, |
| 61 | #endif |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 62 | #if defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | f5dae02 | 2011-07-13 21:59:27 | [diff] [blame] | 63 | chrome::kChromeUILinuxProxyConfigHost, |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 64 | chrome::kChromeUISandboxHost, |
[email protected] | 0985614 | 2011-06-07 17:20:12 | [diff] [blame] | 65 | #endif |
| 66 | #if defined(OS_CHROMEOS) |
[email protected] | f5dae02 | 2011-07-13 21:59:27 | [diff] [blame] | 67 | chrome::kChromeUIChooseMobileNetworkHost, |
[email protected] | bde493d | 2011-07-13 06:11:57 | [diff] [blame] | 68 | chrome::kChromeUICryptohomeHost, |
[email protected] | 4eceeaa | 2012-08-02 19:40:13 | [diff] [blame] | 69 | chrome::kChromeUIDiagnosticsHost, |
[email protected] | b228ecf1 | 2011-09-08 17:06:59 | [diff] [blame] | 70 | chrome::kChromeUIDiscardsHost, |
[email protected] | 47ff9ff | 2012-08-03 03:20:44 | [diff] [blame] | 71 | chrome::kChromeUIDriveInternalsHost, |
[email protected] | f5dae02 | 2011-07-13 21:59:27 | [diff] [blame] | 72 | chrome::kChromeUIImageBurnerHost, |
| 73 | chrome::kChromeUIKeyboardOverlayHost, |
| 74 | chrome::kChromeUILoginHost, |
| 75 | chrome::kChromeUINetworkHost, |
| 76 | chrome::kChromeUIOobeHost, |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 77 | chrome::kChromeUIOSCreditsHost, |
[email protected] | f5dae02 | 2011-07-13 21:59:27 | [diff] [blame] | 78 | chrome::kChromeUIProxySettingsHost, |
| 79 | chrome::kChromeUISystemInfoHost, |
[email protected] | fb8f1ca | 2012-09-26 05:17:35 | [diff] [blame] | 80 | chrome::kChromeUITaskManagerHost, |
[email protected] | 0985614 | 2011-06-07 17:20:12 | [diff] [blame] | 81 | #endif |
[email protected] | fb8f1ca | 2012-09-26 05:17:35 | [diff] [blame] | 82 | #if !defined(DISABLE_NACL) |
| 83 | chrome::kChromeUINaClHost, |
| 84 | #endif |
| 85 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 86 | chrome::kChromeUIPolicyHost, |
| 87 | #endif |
| 88 | #if defined(ENABLE_EXTENSIONS) |
| 89 | chrome::kChromeUIExtensionsHost, |
| 90 | #endif |
[email protected] | 658677f | 2012-06-09 06:04:02 | [diff] [blame] | 91 | #if defined(ENABLE_PRINTING) |
| 92 | chrome::kChromeUIPrintHost, |
| 93 | #endif |
[email protected] | 46ed086 | 2013-04-14 02:47:56 | [diff] [blame] | 94 | content::kChromeUIAccessibilityHost, |
| 95 | content::kChromeUIAppCacheInternalsHost, |
| 96 | content::kChromeUIBlobInternalsHost, |
| 97 | content::kChromeUIGpuHost, |
[email protected] | d7dece9 | 2013-04-25 23:26:21 | [diff] [blame] | 98 | content::kChromeUIHistogramHost, |
[email protected] | 46ed086 | 2013-04-14 02:47:56 | [diff] [blame] | 99 | content::kChromeUIMediaInternalsHost, |
| 100 | content::kChromeUINetworkViewCacheHost, |
| 101 | content::kChromeUITracingHost, |
| 102 | content::kChromeUIWebRTCInternalsHost, |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 103 | }; |
[email protected] | 13ed8da | 2011-06-07 19:01:45 | [diff] [blame] | 104 | |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 105 | } // namespace |
| 106 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 107 | bool WillHandleBrowserAboutURL(GURL* url, |
| 108 | content::BrowserContext* browser_context) { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 109 | // TODO(msw): Eliminate "about:*" constants and literals from code and tests, |
| 110 | // then hopefully we can remove this forced fixup. |
| 111 | *url = URLFixerUpper::FixupURL(url->possibly_invalid_spec(), std::string()); |
| 112 | |
| 113 | // Check that about: URLs are fixed up to chrome: by URLFixerUpper::FixupURL. |
| 114 | DCHECK((*url == GURL(chrome::kAboutBlankURL)) || |
| 115 | !url->SchemeIs(chrome::kAboutScheme)); |
| 116 | |
| 117 | // Only handle chrome://foo/, URLFixerUpper::FixupURL translates about:foo. |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 118 | if (!url->SchemeIs(chrome::kChromeUIScheme)) |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 119 | return false; |
| 120 | |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 121 | std::string host(url->host()); |
[email protected] | dd86ba30 | 2011-09-19 20:10:37 | [diff] [blame] | 122 | std::string path; |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 123 | // Replace about with chrome-urls. |
| 124 | if (host == chrome::kChromeUIAboutHost) |
| 125 | host = chrome::kChromeUIChromeURLsHost; |
| 126 | // Replace cache with view-http-cache. |
[email protected] | dd86ba30 | 2011-09-19 20:10:37 | [diff] [blame] | 127 | if (host == chrome::kChromeUICacheHost) { |
[email protected] | 46ed086 | 2013-04-14 02:47:56 | [diff] [blame] | 128 | host = content::kChromeUINetworkViewCacheHost; |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 129 | // Replace sync with sync-internals (for legacy reasons). |
[email protected] | dd86ba30 | 2011-09-19 20:10:37 | [diff] [blame] | 130 | } else if (host == chrome::kChromeUISyncHost) { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 131 | host = chrome::kChromeUISyncInternalsHost; |
[email protected] | f5ec724 | 2012-01-27 07:15:15 | [diff] [blame] | 132 | // Redirect chrome://extensions. |
[email protected] | dd86ba30 | 2011-09-19 20:10:37 | [diff] [blame] | 133 | } else if (host == chrome::kChromeUIExtensionsHost) { |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 134 | host = chrome::kChromeUIUberHost; |
| 135 | path = chrome::kChromeUIExtensionsHost + url->path(); |
[email protected] | ba48113 | 2012-02-01 08:18:16 | [diff] [blame] | 136 | // Redirect chrome://settings/extensions. |
[email protected] | 55a6601 | 2012-03-31 00:56:02 | [diff] [blame] | 137 | // TODO(csilv): Remove this URL after M22 (legacy URL). |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 138 | } else if (host == chrome::kChromeUISettingsHost && |
[email protected] | ba48113 | 2012-02-01 08:18:16 | [diff] [blame] | 139 | url->path() == std::string("/") + chrome::kExtensionsSubPage) { |
| 140 | host = chrome::kChromeUIUberHost; |
| 141 | path = chrome::kChromeUIExtensionsHost; |
[email protected] | 55a6601 | 2012-03-31 00:56:02 | [diff] [blame] | 142 | // Redirect chrome://history. |
| 143 | } else if (host == chrome::kChromeUIHistoryHost) { |
[email protected] | 78d4207 | 2012-11-21 23:39:24 | [diff] [blame] | 144 | #if defined(OS_ANDROID) |
| 145 | // On Android, redirect directly to chrome://history-frame since |
| 146 | // uber page is unsupported. |
| 147 | host = chrome::kChromeUIHistoryFrameHost; |
| 148 | #else |
[email protected] | 55a6601 | 2012-03-31 00:56:02 | [diff] [blame] | 149 | host = chrome::kChromeUIUberHost; |
| 150 | path = chrome::kChromeUIHistoryHost + url->path(); |
[email protected] | 78d4207 | 2012-11-21 23:39:24 | [diff] [blame] | 151 | #endif |
[email protected] | f5ec724 | 2012-01-27 07:15:15 | [diff] [blame] | 152 | // Redirect chrome://settings |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 153 | } else if (host == chrome::kChromeUISettingsHost) { |
[email protected] | f5ec724 | 2012-01-27 07:15:15 | [diff] [blame] | 154 | host = chrome::kChromeUIUberHost; |
| 155 | path = chrome::kChromeUISettingsHost + url->path(); |
[email protected] | 56193641 | 2012-10-01 21:15:24 | [diff] [blame] | 156 | // Redirect chrome://help |
| 157 | } else if (host == chrome::kChromeUIHelpHost) { |
| 158 | host = chrome::kChromeUIUberHost; |
| 159 | path = chrome::kChromeUIHelpHost + url->path(); |
[email protected] | dd86ba30 | 2011-09-19 20:10:37 | [diff] [blame] | 160 | } |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 161 | GURL::Replacements replacements; |
| 162 | replacements.SetHostStr(host); |
[email protected] | dd86ba30 | 2011-09-19 20:10:37 | [diff] [blame] | 163 | if (!path.empty()) |
| 164 | replacements.SetPathStr(path); |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 165 | *url = url->ReplaceComponents(replacements); |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 166 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 167 | // Having re-written the URL, make the chrome: handler process it. |
| 168 | return false; |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 171 | bool HandleNonNavigationAboutURL(const GURL& url) { |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 172 | std::string host(url.host()); |
| 173 | |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 174 | // chrome://ipc/ is currently buggy, so we disable it for official builds. |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 175 | #if !defined(OFFICIAL_BUILD) |
| 176 | |
[email protected] | 3984b0c | 2010-06-22 21:11:45 | [diff] [blame] | 177 | #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED) |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 178 | if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) { |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 179 | // Run the dialog. This will re-use the existing one if it's already up. |
[email protected] | 87586fb7 | 2012-07-02 13:15:02 | [diff] [blame] | 180 | chrome::ShowAboutIPCDialog(); |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 181 | return true; |
| 182 | } |
| 183 | #endif |
| 184 | |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 185 | #endif // OFFICIAL_BUILD |
| 186 | |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 187 | return false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 188 | } |
[email protected] | 1b6f6ff | 2011-02-23 01:13:10 | [diff] [blame] | 189 | |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 190 | std::vector<std::string> ChromePaths() { |
[email protected] | ec529254 | 2012-09-25 13:10:09 | [diff] [blame] | 191 | std::vector<std::string> paths(kPaths, kPaths + arraysize(kPaths)); |
| 192 | std::sort(paths.begin(), paths.end()); |
[email protected] | 1b6f6ff | 2011-02-23 01:13:10 | [diff] [blame] | 193 | return paths; |
| 194 | } |