Chromium Code Reviews| 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..66135f1f89b129d502ca46747809665db77b6020 100644 |
| --- a/chrome/browser/chrome_content_browser_client.cc |
| +++ b/chrome/browser/chrome_content_browser_client.cc |
| @@ -160,6 +160,16 @@ const char* kPredefinedAllowedSocketOrigins[] = { |
| // Handles rewriting Web UI URLs. |
| bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
| + url_canon::Replacements<char> replacements; |
| + replacements.SetHost("chrome", url_parse::Component(0, 6)); |
| + std::string host = url->host(); |
| + replacements.SetPath(host.c_str(), url_parse::Component(0, host.length())); |
| + GURL chrome_url = url->ReplaceComponents(replacements); |
| + |
| + if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| + browser_context, chrome_url)) |
| + return true; |
| + |
| if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| browser_context, *url)) |
| return false; |
| @@ -190,6 +200,33 @@ bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
| return true; |
| } |
| +bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) { |
|
Alexei Svitkine (slow)
2012/08/02 22:00:11
This needs a comment explaining what it does, incl
|
| + if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme) |
| + || url->host() != chrome::kChromeUIUberHost) |
|
Alexei Svitkine (slow)
2012/08/02 22:00:11
This doesn't follow Chromium style. Put the || on
|
| + return false; |
| + |
| + std::string old_path = url->path(); |
| + |
| + int separator = old_path.find('/', 1); |
| + std::string new_host; |
| + std::string new_path; |
| + if (separator == std::string::npos) { |
| + new_host = old_path.substr(1); |
| + } else { |
| + new_host = old_path.substr(1, separator - 1); |
| + new_path = old_path.substr(separator); |
| + } |
| + |
| + url_canon::Replacements<char> replacements; |
| + replacements.ClearHost(); |
| + replacements.SetHost(new_host.c_str(), |
| + url_parse::Component(0, new_host.length())); |
| + replacements.SetPath(new_path.c_str(), |
| + url_parse::Component(0, new_path.length())); |
| + *url = url->ReplaceComponents(replacements); |
| + return true; |
| +} |
| + |
| // 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 |
| @@ -1539,7 +1576,7 @@ void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| BrowserURLHandler::null_handler()); |
| // chrome: & friends. |
| handler->AddHandlerPair(&HandleWebUI, |
| - BrowserURLHandler::null_handler()); |
| + &HandleWebUIReverse); |
| } |
| void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |