| Index: chrome/browser/chrome_content_browser_client.cc
|
| diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
|
| index 6cd498bc826fc1d16924eeb66143aea99ae9848f..e3b335301ed8afcc22a57cc872a3c80d1d83290e 100644
|
| --- a/chrome/browser/chrome_content_browser_client.cc
|
| +++ b/chrome/browser/chrome_content_browser_client.cc
|
| @@ -158,8 +158,60 @@ const char* kPredefinedAllowedSocketOrigins[] = {
|
| "ghbfeebgmiidnnmeobbbaiamklmpbpii" // see crbug.com/134099
|
| };
|
|
|
| +// Returns a copy of the given url with its host set to given host and path set
|
| +// to given path. Other parts of the url will be the same.
|
| +GURL ReplaceURLHostAndPath(const GURL& url,
|
| + const std::string& host,
|
| + const std::string& path) {
|
| + url_canon::Replacements<char> replacements;
|
| + replacements.SetHost(host.c_str(),
|
| + url_parse::Component(0, host.length()));
|
| + replacements.SetPath(path.c_str(),
|
| + url_parse::Component(0, path.length()));
|
| + return url.ReplaceComponents(replacements);
|
| +}
|
| +
|
| +// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
|
| +GURL AddUberHost(const GURL& url) {
|
| + const std::string uber_host = chrome::kChromeUIUberHost;
|
| + const std::string old_host = url.host();
|
| +
|
| + return ReplaceURLHostAndPath(url, uber_host, old_host);
|
| +}
|
| +
|
| +// If url->host() is "chrome", changes the url from "foo://chrome/bar/" to
|
| +// "foo://bar/" and returns true. Otherwise returns false.
|
| +bool RemoveUberHost(GURL* url) {
|
| + if (url->host() != chrome::kChromeUIUberHost)
|
| + return false;
|
| +
|
| + const std::string old_path = url->path();
|
| +
|
| + const int separator = old_path.find('/', 1);
|
| + std::string new_host;
|
| + std::string new_path;
|
| + if (separator == std::string::npos) {
|
| + new_host = old_path.empty() ? old_path : old_path.substr(1);
|
| + } else {
|
| + new_host = old_path.substr(1, separator - 1);
|
| + new_path = old_path.substr(separator);
|
| + }
|
| +
|
| + *url = ReplaceURLHostAndPath(*url, new_host, new_path);
|
| +
|
| + return true;
|
| +}
|
| +
|
| // Handles rewriting Web UI URLs.
|
| bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
|
| + const GURL chrome_url = AddUberHost(*url);
|
| +
|
| + // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
|
| + // be called.
|
| + if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
|
| + browser_context, chrome_url))
|
| + return true;
|
| +
|
| if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
|
| browser_context, *url))
|
| return false;
|
| @@ -190,6 +242,15 @@ bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
|
| return true;
|
| }
|
|
|
| +// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
|
| +// "chrome://foo/".
|
| +bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
|
| + if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
|
| + return false;
|
| +
|
| + return RemoveUberHost(url);
|
| +}
|
| +
|
| // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
|
| // below. Extension, and isolated apps require different privileges to be
|
| // granted to their RenderProcessHosts. This classification allows us to make
|
| @@ -1538,8 +1599,7 @@ void ChromeContentBrowserClient::BrowserURLHandlerCreated(
|
| handler->AddHandlerPair(&WillHandleBrowserAboutURL,
|
| BrowserURLHandler::null_handler());
|
| // chrome: & friends.
|
| - handler->AddHandlerPair(&HandleWebUI,
|
| - BrowserURLHandler::null_handler());
|
| + handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
|
| }
|
|
|
| void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
|
|
|