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..239bb4178b5da5bbb8731ca3906133b073b3f305 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; |
|
Cem Kocagil
2012/07/25 23:02:34
This addition here is to ensure that the reverse h
|
| + 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,35 @@ bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
| return true; |
| } |
| +bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) { |
| + if (!url |
|
Cem Kocagil
2012/07/25 23:02:34
Some of these checks are probably not necessary, I
|
| + || !url->is_valid() |
| + || !url->SchemeIs(chrome::kChromeUIScheme) |
| + || url->host() != chrome::kChromeUIUberHost) |
|
Alexei Svitkine (slow)
2012/07/26 15:12:31
This doesn't follow the Chromium coding style. See
|
| + 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 +1578,7 @@ void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| BrowserURLHandler::null_handler()); |
| // chrome: & friends. |
| handler->AddHandlerPair(&HandleWebUI, |
| - BrowserURLHandler::null_handler()); |
| + &HandleWebUIReverse); |
| } |
| void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |