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