• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/browser_about_handler.h"
6 
7 #include <string>
8 
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/url_constants.h"
14 #include "components/url_fixer/url_fixer.h"
15 
WillHandleBrowserAboutURL(GURL * url,content::BrowserContext * browser_context)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 = url_fixer::FixupURL(url->possibly_invalid_spec(), std::string());
21 
22   // Check that about: URLs are fixed up to chrome: by url_fixer::FixupURL.
23   DCHECK((*url == GURL(url::kAboutBlankURL)) ||
24          !url->SchemeIs(url::kAboutScheme));
25 
26   // Only handle chrome://foo/, url_fixer::FixupURL translates about:foo.
27   if (!url->SchemeIs(content::kChromeUIScheme))
28     return false;
29 
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();
68   }
69 
70   GURL::Replacements replacements;
71   replacements.SetHostStr(host);
72   if (!path.empty())
73     replacements.SetPathStr(path);
74   *url = url->ReplaceComponents(replacements);
75 
76   // Having re-written the URL, make the chrome: handler process it.
77   return false;
78 }
79 
HandleNonNavigationAboutURL(const GURL & url)80 bool HandleNonNavigationAboutURL(const GURL& url) {
81   const std::string host(url.host());
82 
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;
93   }
94 
95   // chrome://ipc/ is currently buggy, so we disable it for official builds.
96 #if !defined(OFFICIAL_BUILD)
97 
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;
103   }
104 #endif
105 
106 #endif  // OFFICIAL_BUILD
107 
108   return false;
109 }
110