blob: 8d5d320073e2c34c7e46d67eb16d8341e07d03bf [file] [log] [blame]
[email protected]1640a852012-01-05 21:05:381// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/browser_about_handler.h"
6
[email protected]ec5292542012-09-25 13:10:097#include <algorithm>
initial.commit09911bf2008-07-26 23:55:298#include <string>
initial.commit09911bf2008-07-26 23:55:299
[email protected]f5ec7242012-01-27 07:15:1510#include "base/command_line.h"
[email protected]b3adbd02011-11-30 22:23:2711#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/singleton.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/string_util.h"
[email protected]89f550b2011-06-08 18:34:0314#include "chrome/browser/net/url_fixer_upper.h"
[email protected]c96531e82011-01-26 03:11:1415#include "chrome/browser/ui/browser_dialogs.h"
[email protected]f5ec7242012-01-27 07:15:1516#include "chrome/common/chrome_switches.h"
[email protected]dcf7d352009-02-26 01:56:0217#include "chrome/common/url_constants.h"
[email protected]18bc42c92009-02-04 18:59:0918
[email protected]cd3d7892009-03-04 23:55:0619namespace {
initial.commit09911bf2008-07-26 23:55:2920
[email protected]62794f462011-07-19 05:50:1621// Add paths here to be included in chrome://chrome-urls (about:about).
[email protected]89f550b2011-06-08 18:34:0322// These paths will also be suggested by BuiltinProvider.
[email protected]ec5292542012-09-25 13:10:0923const char* const kPaths[] = {
[email protected]f5dae022011-07-13 21:59:2724 chrome::kChromeUICacheHost,
[email protected]89f550b2011-06-08 18:34:0325 chrome::kChromeUIChromeURLsHost,
[email protected]4e8655d2011-06-16 17:20:1726 chrome::kChromeUICrashesHost,
[email protected]89f550b2011-06-08 18:34:0327 chrome::kChromeUICreditsHost,
28 chrome::kChromeUIDNSHost,
[email protected]4052d832013-01-16 05:31:0129 chrome::kChromeUIFlagsHost,
[email protected]f5dae022011-07-13 21:59:2730 chrome::kChromeUIHistoryHost,
31 chrome::kChromeUIIPCHost,
[email protected]89f550b2011-06-08 18:34:0332 chrome::kChromeUIMemoryHost,
[email protected]e4a1cd42013-02-01 01:11:4233#if defined(OS_ANDROID) || defined(OS_IOS)
34 chrome::kChromeUINetExportHost,
35#endif
[email protected]89f550b2011-06-08 18:34:0336 chrome::kChromeUINetInternalsHost,
[email protected]f5dae022011-07-13 21:59:2737 chrome::kChromeUINewTabHost,
[email protected]432954d02012-01-24 01:18:4338 chrome::kChromeUIOmniboxHost,
[email protected]9f1b3c02012-05-02 03:05:5839 chrome::kChromeUIPredictorsHost,
[email protected]72379802011-11-18 00:21:5440 chrome::kChromeUIProfilerHost,
[email protected]f5dae022011-07-13 21:59:2741 chrome::kChromeUIQuotaInternalsHost,
[email protected]df4223a2012-11-20 00:43:0242 chrome::kChromeUISignInInternalsHost,
[email protected]89f550b2011-06-08 18:34:0343 chrome::kChromeUIStatsHost,
44 chrome::kChromeUISyncInternalsHost,
[email protected]20cd74f2012-09-25 14:44:5445 chrome::kChromeUITermsHost,
[email protected]147408a2013-04-23 06:57:5146 chrome::kChromeUITranslateInternalsHost,
[email protected]77e9e4d2012-11-22 00:46:5947 chrome::kChromeUIUserActionsHost,
[email protected]20cd74f2012-09-25 14:44:5448 chrome::kChromeUIVersionHost,
[email protected]fb8f1ca2012-09-26 05:17:3549#if defined(OS_ANDROID)
50 chrome::kChromeUIWelcomeHost,
51#else
52 chrome::kChromeUIBookmarksHost,
53 chrome::kChromeUIDownloadsHost,
[email protected]fb8f1ca2012-09-26 05:17:3554 chrome::kChromeUIFlashHost,
55 chrome::kChromeUIInspectHost,
56 chrome::kChromeUIPluginsHost,
57 chrome::kChromeUISettingsHost,
[email protected]fb8f1ca2012-09-26 05:17:3558#endif
[email protected]89f550b2011-06-08 18:34:0359#if defined(OS_WIN)
60 chrome::kChromeUIConflictsHost,
61#endif
[email protected]e60c0232011-11-11 19:56:3562#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f5dae022011-07-13 21:59:2763 chrome::kChromeUILinuxProxyConfigHost,
[email protected]89f550b2011-06-08 18:34:0364 chrome::kChromeUISandboxHost,
[email protected]09856142011-06-07 17:20:1265#endif
66#if defined(OS_CHROMEOS)
[email protected]f5dae022011-07-13 21:59:2767 chrome::kChromeUIChooseMobileNetworkHost,
[email protected]bde493d2011-07-13 06:11:5768 chrome::kChromeUICryptohomeHost,
[email protected]4eceeaa2012-08-02 19:40:1369 chrome::kChromeUIDiagnosticsHost,
[email protected]b228ecf12011-09-08 17:06:5970 chrome::kChromeUIDiscardsHost,
[email protected]47ff9ff2012-08-03 03:20:4471 chrome::kChromeUIDriveInternalsHost,
[email protected]f5dae022011-07-13 21:59:2772 chrome::kChromeUIImageBurnerHost,
73 chrome::kChromeUIKeyboardOverlayHost,
74 chrome::kChromeUILoginHost,
75 chrome::kChromeUINetworkHost,
76 chrome::kChromeUIOobeHost,
[email protected]89f550b2011-06-08 18:34:0377 chrome::kChromeUIOSCreditsHost,
[email protected]f5dae022011-07-13 21:59:2778 chrome::kChromeUIProxySettingsHost,
79 chrome::kChromeUISystemInfoHost,
[email protected]fb8f1ca2012-09-26 05:17:3580 chrome::kChromeUITaskManagerHost,
[email protected]09856142011-06-07 17:20:1281#endif
[email protected]fb8f1ca2012-09-26 05:17:3582#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]658677f2012-06-09 06:04:0291#if defined(ENABLE_PRINTING)
92 chrome::kChromeUIPrintHost,
93#endif
[email protected]46ed0862013-04-14 02:47:5694 content::kChromeUIAccessibilityHost,
95 content::kChromeUIAppCacheInternalsHost,
96 content::kChromeUIBlobInternalsHost,
97 content::kChromeUIGpuHost,
[email protected]d7dece92013-04-25 23:26:2198 content::kChromeUIHistogramHost,
[email protected]46ed0862013-04-14 02:47:5699 content::kChromeUIMediaInternalsHost,
100 content::kChromeUINetworkViewCacheHost,
101 content::kChromeUITracingHost,
102 content::kChromeUIWebRTCInternalsHost,
[email protected]89f550b2011-06-08 18:34:03103};
[email protected]13ed8da2011-06-07 19:01:45104
[email protected]cd3d7892009-03-04 23:55:06105} // namespace
106
[email protected]3d7474ff2011-07-27 17:47:37107bool WillHandleBrowserAboutURL(GURL* url,
108 content::BrowserContext* browser_context) {
[email protected]89f550b2011-06-08 18:34:03109 // 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]89f550b2011-06-08 18:34:03118 if (!url->SchemeIs(chrome::kChromeUIScheme))
[email protected]cd3d7892009-03-04 23:55:06119 return false;
120
[email protected]89f550b2011-06-08 18:34:03121 std::string host(url->host());
[email protected]dd86ba302011-09-19 20:10:37122 std::string path;
[email protected]89f550b2011-06-08 18:34:03123 // Replace about with chrome-urls.
124 if (host == chrome::kChromeUIAboutHost)
125 host = chrome::kChromeUIChromeURLsHost;
126 // Replace cache with view-http-cache.
[email protected]dd86ba302011-09-19 20:10:37127 if (host == chrome::kChromeUICacheHost) {
[email protected]46ed0862013-04-14 02:47:56128 host = content::kChromeUINetworkViewCacheHost;
[email protected]89f550b2011-06-08 18:34:03129 // Replace sync with sync-internals (for legacy reasons).
[email protected]dd86ba302011-09-19 20:10:37130 } else if (host == chrome::kChromeUISyncHost) {
[email protected]89f550b2011-06-08 18:34:03131 host = chrome::kChromeUISyncInternalsHost;
[email protected]f5ec7242012-01-27 07:15:15132 // Redirect chrome://extensions.
[email protected]dd86ba302011-09-19 20:10:37133 } else if (host == chrome::kChromeUIExtensionsHost) {
[email protected]a048ad22012-03-23 04:26:56134 host = chrome::kChromeUIUberHost;
135 path = chrome::kChromeUIExtensionsHost + url->path();
[email protected]ba481132012-02-01 08:18:16136 // Redirect chrome://settings/extensions.
[email protected]55a66012012-03-31 00:56:02137 // TODO(csilv): Remove this URL after M22 (legacy URL).
[email protected]a048ad22012-03-23 04:26:56138 } else if (host == chrome::kChromeUISettingsHost &&
[email protected]ba481132012-02-01 08:18:16139 url->path() == std::string("/") + chrome::kExtensionsSubPage) {
140 host = chrome::kChromeUIUberHost;
141 path = chrome::kChromeUIExtensionsHost;
[email protected]55a66012012-03-31 00:56:02142 // Redirect chrome://history.
143 } else if (host == chrome::kChromeUIHistoryHost) {
[email protected]78d42072012-11-21 23:39:24144#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]55a66012012-03-31 00:56:02149 host = chrome::kChromeUIUberHost;
150 path = chrome::kChromeUIHistoryHost + url->path();
[email protected]78d42072012-11-21 23:39:24151#endif
[email protected]f5ec7242012-01-27 07:15:15152 // Redirect chrome://settings
[email protected]a048ad22012-03-23 04:26:56153 } else if (host == chrome::kChromeUISettingsHost) {
[email protected]f5ec7242012-01-27 07:15:15154 host = chrome::kChromeUIUberHost;
155 path = chrome::kChromeUISettingsHost + url->path();
[email protected]561936412012-10-01 21:15:24156 // Redirect chrome://help
157 } else if (host == chrome::kChromeUIHelpHost) {
158 host = chrome::kChromeUIUberHost;
159 path = chrome::kChromeUIHelpHost + url->path();
[email protected]dd86ba302011-09-19 20:10:37160 }
[email protected]89f550b2011-06-08 18:34:03161 GURL::Replacements replacements;
162 replacements.SetHostStr(host);
[email protected]dd86ba302011-09-19 20:10:37163 if (!path.empty())
164 replacements.SetPathStr(path);
[email protected]89f550b2011-06-08 18:34:03165 *url = url->ReplaceComponents(replacements);
[email protected]cd3d7892009-03-04 23:55:06166
[email protected]b3adbd02011-11-30 22:23:27167 // Having re-written the URL, make the chrome: handler process it.
168 return false;
[email protected]cd3d7892009-03-04 23:55:06169}
170
[email protected]cd3d7892009-03-04 23:55:06171bool HandleNonNavigationAboutURL(const GURL& url) {
[email protected]b3adbd02011-11-30 22:23:27172 std::string host(url.host());
173
[email protected]89f550b2011-06-08 18:34:03174 // chrome://ipc/ is currently buggy, so we disable it for official builds.
[email protected]d55aaa132009-09-28 21:08:04175#if !defined(OFFICIAL_BUILD)
176
[email protected]3984b0c2010-06-22 21:11:45177#if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED)
[email protected]89f550b2011-06-08 18:34:03178 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) {
[email protected]cd3d7892009-03-04 23:55:06179 // Run the dialog. This will re-use the existing one if it's already up.
[email protected]87586fb72012-07-02 13:15:02180 chrome::ShowAboutIPCDialog();
[email protected]cd3d7892009-03-04 23:55:06181 return true;
182 }
183#endif
184
[email protected]d55aaa132009-09-28 21:08:04185#endif // OFFICIAL_BUILD
186
[email protected]cd3d7892009-03-04 23:55:06187 return false;
initial.commit09911bf2008-07-26 23:55:29188}
[email protected]1b6f6ff2011-02-23 01:13:10189
[email protected]89f550b2011-06-08 18:34:03190std::vector<std::string> ChromePaths() {
[email protected]ec5292542012-09-25 13:10:09191 std::vector<std::string> paths(kPaths, kPaths + arraysize(kPaths));
192 std::sort(paths.begin(), paths.end());
[email protected]1b6f6ff2011-02-23 01:13:10193 return paths;
194}