Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / browser_about_handler.cc
blob28d1f18390e622e7bfb317baecebfdd34fa5d1c4
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/logging.h"
10 #include "base/strings/string_util.h"
11 #include "chrome/browser/lifetime/application_lifetime.h"
12 #include "chrome/browser/ui/browser_dialogs.h"
13 #include "chrome/common/net/url_fixer_upper.h"
14 #include "chrome/common/url_constants.h"
16 bool WillHandleBrowserAboutURL(GURL* url,
17 content::BrowserContext* browser_context) {
18 // TODO(msw): Eliminate "about:*" constants and literals from code and tests,
19 // then hopefully we can remove this forced fixup.
20 *url = URLFixerUpper::FixupURL(url->possibly_invalid_spec(), std::string());
22 // Check that about: URLs are fixed up to chrome: by URLFixerUpper::FixupURL.
23 DCHECK((*url == GURL(content::kAboutBlankURL)) ||
24 !url->SchemeIs(chrome::kAboutScheme));
26 // Only handle chrome://foo/, URLFixerUpper::FixupURL translates about:foo.
27 if (!url->SchemeIs(chrome::kChromeUIScheme))
28 return false;
30 std::string host(url->host());
31 std::string path;
32 // Replace about with chrome-urls.
33 if (host == chrome::kChromeUIAboutHost)
34 host = chrome::kChromeUIChromeURLsHost;
35 // Replace cache with view-http-cache.
36 if (host == chrome::kChromeUICacheHost) {
37 host = content::kChromeUINetworkViewCacheHost;
38 // Replace sync with sync-internals (for legacy reasons).
39 } else if (host == chrome::kChromeUISyncHost) {
40 host = chrome::kChromeUISyncInternalsHost;
41 // Redirect chrome://extensions.
42 } else if (host == chrome::kChromeUIExtensionsHost) {
43 host = chrome::kChromeUIUberHost;
44 path = chrome::kChromeUIExtensionsHost + url->path();
45 // Redirect chrome://settings/extensions (legacy URL).
46 } else if (host == chrome::kChromeUISettingsHost &&
47 url->path() == std::string("/") + chrome::kExtensionsSubPage) {
48 host = chrome::kChromeUIUberHost;
49 path = chrome::kChromeUIExtensionsHost;
50 // Redirect chrome://history.
51 } else if (host == chrome::kChromeUIHistoryHost) {
52 #if defined(OS_ANDROID)
53 // On Android, redirect directly to chrome://history-frame since
54 // uber page is unsupported.
55 host = chrome::kChromeUIHistoryFrameHost;
56 #else
57 host = chrome::kChromeUIUberHost;
58 path = chrome::kChromeUIHistoryHost + url->path();
59 #endif
60 // Redirect chrome://settings
61 } else if (host == chrome::kChromeUISettingsHost) {
62 host = chrome::kChromeUIUberHost;
63 path = chrome::kChromeUISettingsHost + url->path();
64 // Redirect chrome://help
65 } else if (host == chrome::kChromeUIHelpHost) {
66 host = chrome::kChromeUIUberHost;
67 path = chrome::kChromeUIHelpHost + url->path();
70 GURL::Replacements replacements;
71 replacements.SetHostStr(host);
72 if (!path.empty())
73 replacements.SetPathStr(path);
74 *url = url->ReplaceComponents(replacements);
76 // Having re-written the URL, make the chrome: handler process it.
77 return false;
80 bool HandleNonNavigationAboutURL(const GURL& url) {
81 const std::string host(url.host());
83 if (host == chrome::kChromeUIRestartHost) {
84 // Call AttemptRestart after chrome::Navigate() completes to avoid access of
85 // gtk objects after they are destroyed by BrowserWindowGtk::Close().
86 base::MessageLoop::current()->PostTask(FROM_HERE,
87 base::Bind(&chrome::AttemptRestart));
88 return true;
89 } else if (host == chrome::kChromeUIQuitHost) {
90 base::MessageLoop::current()->PostTask(FROM_HERE,
91 base::Bind(&chrome::AttemptExit));
92 return true;
95 // chrome://ipc/ is currently buggy, so we disable it for official builds.
96 #if !defined(OFFICIAL_BUILD)
98 #if (defined(OS_MACOSX) || defined(OS_WIN)) && defined(IPC_MESSAGE_LOG_ENABLED)
99 if (LowerCaseEqualsASCII(url.spec(), chrome::kChromeUIIPCURL)) {
100 // Run the dialog. This will re-use the existing one if it's already up.
101 chrome::ShowAboutIPCDialog();
102 return true;
104 #endif
106 #endif // OFFICIAL_BUILD
108 return false;