[Storage] Blob Storage Refactoring pt 1:
[chromium-blink-merge.git] / chrome / browser / browser_about_handler.cc
blob7d1958577adfd67905f0e0217cb3c44b65a7c799
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 WillHandleBrowserAboutURL(GURL* url,
20 content::BrowserContext* browser_context) {
21 // TODO(msw): Eliminate "about:*" constants and literals from code and tests,
22 // then hopefully we can remove this forced fixup.
23 *url = url_fixer::FixupURL(url->possibly_invalid_spec(), std::string());
25 // Check that about: URLs are fixed up to chrome: by url_fixer::FixupURL.
26 DCHECK((*url == GURL(url::kAboutBlankURL)) ||
27 !url->SchemeIs(url::kAboutScheme));
29 // Only handle chrome://foo/, url_fixer::FixupURL translates about:foo.
30 if (!url->SchemeIs(content::kChromeUIScheme))
31 return false;
33 std::string host(url->host());
34 std::string path;
35 // Replace about with chrome-urls.
36 if (host == chrome::kChromeUIAboutHost)
37 host = chrome::kChromeUIChromeURLsHost;
38 // Replace cache with view-http-cache.
39 if (host == chrome::kChromeUICacheHost) {
40 host = content::kChromeUINetworkViewCacheHost;
41 // Replace sync with sync-internals (for legacy reasons).
42 } else if (host == chrome::kChromeUISyncHost) {
43 host = chrome::kChromeUISyncInternalsHost;
44 // Redirect chrome://extensions.
45 } else if (host == chrome::kChromeUIExtensionsHost) {
46 host = chrome::kChromeUIUberHost;
47 path = chrome::kChromeUIExtensionsHost + url->path();
48 // Redirect chrome://settings/extensions (legacy URL).
49 } else if (host == chrome::kChromeUISettingsHost &&
50 url->path() == std::string("/") + chrome::kExtensionsSubPage) {
51 host = chrome::kChromeUIUberHost;
52 path = chrome::kChromeUIExtensionsHost;
53 // Redirect chrome://history.
54 } else if (host == chrome::kChromeUIHistoryHost) {
55 #if defined(OS_ANDROID)
56 // On Android, redirect directly to chrome://history-frame since
57 // uber page is unsupported.
58 host = chrome::kChromeUIHistoryFrameHost;
59 #else
60 host = chrome::kChromeUIUberHost;
61 path = chrome::kChromeUIHistoryHost + url->path();
62 #endif
63 // Redirect chrome://settings
64 } else if (host == chrome::kChromeUISettingsHost) {
65 if (::switches::AboutInSettingsEnabled()) {
66 host = chrome::kChromeUISettingsFrameHost;
67 } else {
68 host = chrome::kChromeUIUberHost;
69 path = chrome::kChromeUISettingsHost + url->path();
71 // Redirect chrome://help
72 } else if (host == chrome::kChromeUIHelpHost) {
73 if (::switches::AboutInSettingsEnabled()) {
74 host = chrome::kChromeUISettingsFrameHost;
75 if (url->path().empty() || url->path() == "/")
76 path = chrome::kChromeUIHelpHost;
77 } else {
78 host = chrome::kChromeUIUberHost;
79 path = chrome::kChromeUIHelpHost + url->path();
83 GURL::Replacements replacements;
84 replacements.SetHostStr(host);
85 if (!path.empty())
86 replacements.SetPathStr(path);
87 *url = url->ReplaceComponents(replacements);
89 // Having re-written the URL, make the chrome: handler process it.
90 return false;
93 bool HandleNonNavigationAboutURL(const GURL& url) {
94 const std::string spec(url.spec());
96 if (LowerCaseEqualsASCII(spec, chrome::kChromeUIRestartURL)) {
97 // Call AttemptRestart after chrome::Navigate() completes to avoid access of
98 // gtk objects after they are destroyed by BrowserWindowGtk::Close().
99 base::MessageLoop::current()->PostTask(FROM_HERE,
100 base::Bind(&chrome::AttemptRestart));
101 return true;
102 } else if (LowerCaseEqualsASCII(spec, chrome::kChromeUIQuitURL)) {
103 base::MessageLoop::current()->PostTask(FROM_HERE,
104 base::Bind(&chrome::AttemptExit));
105 return true;
108 return false;