Disabling NativeViewAcccessibilityWinTest.RetrieveAllAlerts.
[chromium-blink-merge.git] / chrome / browser / browser_about_handler.cc
blob42a453a8018f8a5f030cbb5a463f1ea1c965b9ca
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
3 // found in the LICENSE file.
5 #include "chrome/browser/browser_about_handler.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/strings/string_util.h"
13 #include "chrome/browser/lifetime/application_lifetime.h"
14 #include "chrome/browser/ui/browser_dialogs.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/url_constants.h"
17 #include "components/url_fixer/url_fixer.h"
19 bool FixupBrowserAboutURL(GURL* url,
20 content::BrowserContext* browser_context) {
21 // Ensure that any cleanup done by FixupURL happens before the rewriting
22 // phase that determines the virtual URL, by including it in an initial
23 // URLHandler. This prevents minor changes from producing a virtual URL,
24 // which could lead to a URL spoof.
25 *url = url_fixer::FixupURL(url->possibly_invalid_spec(), std::string());
26 return true;
29 bool WillHandleBrowserAboutURL(GURL* url,
30 content::BrowserContext* browser_context) {
31 // TODO(msw): Eliminate "about:*" constants and literals from code and tests,
32 // then hopefully we can remove this forced fixup.
33 FixupBrowserAboutURL(url, browser_context);
35 // Check that about: URLs are fixed up to chrome: by url_fixer::FixupURL.
36 DCHECK((*url == GURL(url::kAboutBlankURL)) ||
37 !url->SchemeIs(url::kAboutScheme));
39 // Only handle chrome://foo/, url_fixer::FixupURL translates about:foo.
40 if (!url->SchemeIs(content::kChromeUIScheme))
41 return false;
43 std::string host(url->host());
44 std::string path;
45 // Replace about with chrome-urls.
46 if (host == chrome::kChromeUIAboutHost)
47 host = chrome::kChromeUIChromeURLsHost;
48 // Replace cache with view-http-cache.
49 if (host == chrome::kChromeUICacheHost) {
50 host = content::kChromeUINetworkViewCacheHost;
51 // Replace sync with sync-internals (for legacy reasons).
52 } else if (host == chrome::kChromeUISyncHost) {
53 host = chrome::kChromeUISyncInternalsHost;
54 // Redirect chrome://extensions.
55 } else if (host == chrome::kChromeUIExtensionsHost) {
56 host = chrome::kChromeUIUberHost;
57 path = chrome::kChromeUIExtensionsHost + url->path();
58 // Redirect chrome://settings/extensions (legacy URL).
59 } else if (host == chrome::kChromeUISettingsHost &&
60 url->path() == std::string("/") + chrome::kExtensionsSubPage) {
61 host = chrome::kChromeUIUberHost;
62 path = chrome::kChromeUIExtensionsHost;
63 // Redirect chrome://history.
64 } else if (host == chrome::kChromeUIHistoryHost) {
65 #if defined(OS_ANDROID)
66 // On Android, redirect directly to chrome://history-frame since
67 // uber page is unsupported.
68 host = chrome::kChromeUIHistoryFrameHost;
69 #else
70 host = chrome::kChromeUIUberHost;
71 path = chrome::kChromeUIHistoryHost + url->path();
72 #endif
73 // Redirect chrome://settings
74 } else if (host == chrome::kChromeUISettingsHost) {
75 if (::switches::AboutInSettingsEnabled()) {
76 host = chrome::kChromeUISettingsFrameHost;
77 } else {
78 host = chrome::kChromeUIUberHost;
79 path = chrome::kChromeUISettingsHost + url->path();
81 // Redirect chrome://help
82 } else if (host == chrome::kChromeUIHelpHost) {
83 if (::switches::AboutInSettingsEnabled()) {
84 host = chrome::kChromeUISettingsFrameHost;
85 if (url->path().empty() || url->path() == "/")
86 path = chrome::kChromeUIHelpHost;
87 } else {
88 host = chrome::kChromeUIUberHost;
89 path = chrome::kChromeUIHelpHost + url->path();
93 GURL::Replacements replacements;
94 replacements.SetHostStr(host);
95 if (!path.empty())
96 replacements.SetPathStr(path);
97 *url = url->ReplaceComponents(replacements);
99 // Having re-written the URL, make the chrome: handler process it.
100 return false;
103 bool HandleNonNavigationAboutURL(const GURL& url) {
104 const std::string spec(url.spec());
106 if (LowerCaseEqualsASCII(spec, chrome::kChromeUIRestartURL)) {
107 // Call AttemptRestart after chrome::Navigate() completes to avoid access of
108 // gtk objects after they are destroyed by BrowserWindowGtk::Close().
109 base::MessageLoop::current()->PostTask(FROM_HERE,
110 base::Bind(&chrome::AttemptRestart));
111 return true;
112 } else if (LowerCaseEqualsASCII(spec, chrome::kChromeUIQuitURL)) {
113 base::MessageLoop::current()->PostTask(FROM_HERE,
114 base::Bind(&chrome::AttemptExit));
115 return true;
118 return false;