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..ccdd477b2d2ab9fc6839fd6038860e33124ec419 100644 |
| --- a/chrome/browser/chrome_content_browser_client.cc |
| +++ b/chrome/browser/chrome_content_browser_client.cc |
| @@ -160,6 +160,18 @@ 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)); |
|
Alexei Svitkine (slow)
2012/08/07 14:59:33
Nit: Make a const std::string in the local scope a
|
| + std::string host = url->host(); |
|
Alexei Svitkine (slow)
2012/08/07 14:59:33
Nit: Should be const.
|
| + replacements.SetPath(host.c_str(), url_parse::Component(0, host.length())); |
| + GURL chrome_url = url->ReplaceComponents(replacements); |
|
Alexei Svitkine (slow)
2012/08/07 14:59:33
Nit: Maybe extract the above block to a separate f
Cem Kocagil
2012/08/07 20:56:22
Good idea. I went further and added two functions:
|
| + |
| + // Handle valid "chrome://chrome/foo" URLs so the reverse handler will |
| + // be called. |
| + if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| + browser_context, chrome_url)) |
| + return true; |
|
Alexei Svitkine (slow)
2012/08/07 14:59:33
Add a comment why this doesn't need to set *url ev
Cem Kocagil
2012/08/07 20:56:22
The comment right above that block explains why it
|
| + |
| if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| browser_context, *url)) |
| return false; |
| @@ -190,6 +202,35 @@ 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) || |
| + url->host() != chrome::kChromeUIUberHost) |
| + return false; |
| + |
| + std::string old_path = url->path(); |
|
Alexei Svitkine (slow)
2012/08/07 14:59:33
Nit: Should be const.
|
| + |
| + int separator = old_path.find('/', 1); |
|
Alexei Svitkine (slow)
2012/08/07 14:59:33
Nit: Should be const.
|
| + std::string new_host; |
| + std::string new_path; |
| + if (separator == std::string::npos) { |
| + new_host = old_path.substr(1); |
|
Alexei Svitkine (slow)
2012/08/07 14:59:33
What if old_path is an empty string? (Also, does f
Cem Kocagil
2012/08/07 20:56:22
It should work when old_path is empty. I checked t
|
| + } else { |
| + new_host = old_path.substr(1, separator - 1); |
| + new_path = old_path.substr(separator); |
| + } |
| + |
| + url_canon::Replacements<char> replacements; |
| + replacements.ClearHost(); |
|
Alexei Svitkine (slow)
2012/08/07 14:59:33
Is this needed given that you set it immediately a
|
| + 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 +1580,7 @@ void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| BrowserURLHandler::null_handler()); |
| // chrome: & friends. |
| handler->AddHandlerPair(&HandleWebUI, |
| - BrowserURLHandler::null_handler()); |
| + &HandleWebUIReverse); |
| } |
| void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |