diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-14 20:51:04 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-14 20:51:04 +0000 |
commit | 13c34d1395636e081be2318e8ae12bc8fa71ca57 (patch) | |
tree | 4a719a69338f1cc14fe23db88e061c513cf122db /chrome | |
parent | 1364d8b89dd74afd35a5d9fe4bb4f3c66d09c3c4 (diff) | |
download | chromium_src-13c34d1395636e081be2318e8ae12bc8fa71ca57.zip chromium_src-13c34d1395636e081be2318e8ae12bc8fa71ca57.tar.gz chromium_src-13c34d1395636e081be2318e8ae12bc8fa71ca57.tar.bz2 |
Change the URLs used to access "view-cache:" and "view-net-internals:".
"net-internal:*" ==> "chrome://net-internals/*"
"view-cache:*" ==> "chrome://net-internals/view-cache/*"
"view-cache:stats" ==> "chrome://net-internals/httpcache.stats"
As before, there are also aliases from the "about:*" page:
"about:net-internal[/*]" aliases "chrome://net-internals/*"
"about:cache[/*]" aliases "chrome://net-internals/view-cache"
BUG=http://crbug.com/21551
Review URL: http://codereview.chromium.org/202067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26158 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_about_handler.cc | 38 | ||||
-rw-r--r-- | chrome/browser/child_process_security_policy_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/chrome_url_data_manager.cc | 35 | ||||
-rw-r--r-- | chrome/common/url_constants.cc | 7 | ||||
-rw-r--r-- | chrome/common/url_constants.h | 8 |
5 files changed, 68 insertions, 22 deletions
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 047ca97..3e4baf3 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -759,6 +759,23 @@ void ChromeOSAboutVersionHandler::OnVersion( #endif +// Returns true if |url|'s spec starts with |about_specifier|, and is +// terminated by the start of a path. +bool StartsWithAboutSpecifier(const GURL& url, const char* about_specifier) { + return StartsWithASCII(url.spec(), about_specifier, true) && + (url.spec().size() == strlen(about_specifier) || + url.spec()[strlen(about_specifier)] == '/'); +} + +// Transforms a URL of the form "about:foo/XXX" to <url_prefix> + "XXX". +GURL RemapAboutURL(const std::string& url_prefix, const GURL& url) { + std::string path; + size_t split = url.spec().find('/'); + if (split != std::string::npos) + path = url.spec().substr(split + 1); + return GURL(url_prefix + path); +} + } // namespace // ----------------------------------------------------------------------------- @@ -774,23 +791,16 @@ bool WillHandleBrowserAboutURL(GURL* url, Profile* profile) { if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutBlankURL)) return false; - // Handle rewriting view-cache URLs. This allows us to load about:cache. - if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutCacheURL)) { - // Create an mapping from about:cache to the view-cache: internal URL. - *url = GURL(std::string(chrome::kViewCacheScheme) + ":"); + // Rewrite about:cache/* URLs to chrome://net-internals/view-cache/* + if (StartsWithAboutSpecifier(*url, chrome::kAboutCacheURL)) { + *url = RemapAboutURL(chrome::kNetworkViewCacheURL + std::string("/"), + *url); return true; } - // Handle rewriting net-internal URLs. This allows us to load - // about:net-internal. - if (StartsWithASCII(url->spec(), chrome::kAboutNetInternalURL, true)) { - // Create a mapping from about:net-internal to the view-net-internal: - // internal URL. - std::string path; - size_t split = url->spec().find('/'); - if (split != std::string::npos) - path = url->spec().substr(split + 1); - *url = GURL(std::string(chrome::kViewNetInternalScheme) + ":" + path); + // Rewrite about:net-internals/* URLs to chrome://net-internals/* + if (StartsWithAboutSpecifier(*url, chrome::kAboutNetInternalsURL)) { + *url = RemapAboutURL(chrome::kNetworkViewInternalsURL, *url); return true; } diff --git a/chrome/browser/child_process_security_policy_unittest.cc b/chrome/browser/child_process_security_policy_unittest.cc index 1cdccc9..87fd0dc 100644 --- a/chrome/browser/child_process_security_policy_unittest.cc +++ b/chrome/browser/child_process_security_policy_unittest.cc @@ -72,8 +72,6 @@ TEST_F(ChildProcessSecurityPolicyTest, StandardSchemesTest) { EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("file:///etc/passwd"))); EXPECT_FALSE(p->CanRequestURL(kRendererID, - GURL("view-cache:http://www.google.com/"))); - EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("chrome://foo/bar"))); p->Remove(kRendererID); diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc index c3ef325..fccb406 100644 --- a/chrome/browser/dom_ui/chrome_url_data_manager.cc +++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc @@ -22,6 +22,7 @@ #include "net/url_request/url_request.h" #include "net/url_request/url_request_file_job.h" #include "net/url_request/url_request_job.h" +#include "net/url_request/url_request_view_net_internals_job.h" #include "grit/locale_settings.h" @@ -296,6 +297,34 @@ void ChromeURLDataManager::DataSource::SetFontAndTextDirection( L"rtl" : L"ltr"); } +// This class describes how to form chrome://net-internals/DESCRIPTION +// URLs, and conversely how to extract DESCRIPTION. +// +// This needs to be passed to URLRequestViewNetInternalsJob, which lives +// in the network module and doesn't know anything about what URL protocol +// it has been registered with. +class NetInternalsURLFormat : public URLRequestViewNetInternalsJob::URLFormat { + public: + virtual std::string GetDetails(const GURL& url) { + DCHECK(IsSupportedURL(url)); + size_t start = strlen(chrome::kNetworkViewInternalsURL); + if (start >= url.spec().size()) + return std::string(); + return url.spec().substr(start); + } + + virtual GURL MakeURL(const std::string& details) { + return GURL(std::string(chrome::kNetworkViewInternalsURL) + details); + } + + static bool IsSupportedURL(const GURL& url) { + // Note that kNetworkViewInternalsURL is terminated by a '/'. + return StartsWithASCII(url.spec(), + chrome::kNetworkViewInternalsURL, + true /*case_sensitive*/); + } +}; + URLRequestJob* ChromeURLDataManager::Factory(URLRequest* request, const std::string& scheme) { // Try first with a file handler @@ -304,6 +333,12 @@ URLRequestJob* ChromeURLDataManager::Factory(URLRequest* request, return new URLRequestChromeFileJob(request, FilePath::FromWStringHack(path)); + // Next check for chrome://net-internals/, which uses its own job type. + if (NetInternalsURLFormat::IsSupportedURL(request->url())) { + static NetInternalsURLFormat url_format; + return new URLRequestViewNetInternalsJob(request, &url_format); + } + // Fall back to using a custom handler return new URLRequestChromeJob(request); } diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index ed128cd..aad1747 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -20,15 +20,13 @@ const char kJavaScriptScheme[] = "javascript"; const char kMailToScheme[] = "mailto"; const char kPrintScheme[] = "print"; const char kUserScriptScheme[] = "chrome-user-script"; -const char kViewCacheScheme[] = "view-cache"; -const char kViewNetInternalScheme[] = "view-net-internal"; const char kViewSourceScheme[] = "view-source"; const char kStandardSchemeSeparator[] = "://"; const char kAboutBlankURL[] = "about:blank"; const char kAboutCacheURL[] = "about:cache"; -const char kAboutNetInternalURL[] = "about:net-internal"; +const char kAboutNetInternalsURL[] = "about:net-internals"; const char kAboutCrashURL[] = "about:crash"; const char kAboutHangURL[] = "about:hang"; const char kAboutMemoryURL[] = "about:memory"; @@ -63,4 +61,7 @@ const char kSyncMergeAndSyncPath[] = "mergeandsync"; const char kSyncThrobberPath[] = "throbber.png"; const char kSyncSetupFlowPath[] = "setup"; +const char kNetworkViewInternalsURL[] = "chrome://net-internals/"; +const char kNetworkViewCacheURL[] = "chrome://net-internals/view-cache"; + } // namespace chrome diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index c647339..8526642 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -24,8 +24,6 @@ extern const char kJavaScriptScheme[]; extern const char kMailToScheme[]; extern const char kPrintScheme[]; extern const char kUserScriptScheme[]; -extern const char kViewCacheScheme[]; -extern const char kViewNetInternalScheme[]; extern const char kViewSourceScheme[]; // Used to separate a standard scheme and the hostname: "://". @@ -35,7 +33,7 @@ extern const char kStandardSchemeSeparator[]; extern const char kAboutBlankURL[]; extern const char kAboutBrowserCrash[]; extern const char kAboutCacheURL[]; -extern const char kAboutNetInternalURL[]; +extern const char kAboutNetInternalsURL[]; extern const char kAboutCrashURL[]; extern const char kAboutHangURL[]; extern const char kAboutMemoryURL[]; @@ -71,6 +69,10 @@ extern const char kSyncMergeAndSyncPath[]; extern const char kSyncThrobberPath[]; extern const char kSyncSetupFlowPath[]; +// Network related URLs. +extern const char kNetworkViewCacheURL[]; +extern const char kNetworkViewInternalsURL[]; + } // namespace chrome #endif // CHROME_COMMON_URL_CONSTANTS_H_ |