Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chrome_content_browser_client.h" | 5 #include "chrome/browser/chrome_content_browser_client.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary | 151 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary |
| 152 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 | 152 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 |
| 153 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 | 153 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 |
| 154 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 | 154 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 |
| 155 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 | 155 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 |
| 156 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 | 156 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 |
| 157 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 | 157 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 |
| 158 "ghbfeebgmiidnnmeobbbaiamklmpbpii" // see crbug.com/134099 | 158 "ghbfeebgmiidnnmeobbbaiamklmpbpii" // see crbug.com/134099 |
| 159 }; | 159 }; |
| 160 | 160 |
| 161 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/" | |
| 162 GURL AddUberHost(const GURL& url) { | |
| 163 const std::string uber_host = chrome::kChromeUIUberHost; | |
| 164 const std::string old_host = url.host(); | |
| 165 | |
| 166 url_canon::Replacements<char> replacements; | |
| 167 replacements.SetHost(uber_host.c_str(), | |
| 168 url_parse::Component(0, uber_host.length())); | |
| 169 replacements.SetPath(old_host.c_str(), | |
| 170 url_parse::Component(0, old_host.length())); | |
| 171 | |
| 172 return url.ReplaceComponents(replacements); | |
| 173 } | |
| 174 | |
| 175 // If url->host() is "chrome", it maps "foo://chrome/bar/" to "foo://bar/" | |
| 176 bool RemoveUberHost(GURL* url) { | |
| 177 if (url->host() != chrome::kChromeUIUberHost) | |
| 178 return false; | |
| 179 | |
| 180 const std::string old_path = url->path(); | |
| 181 | |
| 182 const int separator = old_path.find('/', 1); | |
| 183 std::string new_host; | |
| 184 std::string new_path; | |
| 185 if (separator == std::string::npos) { | |
| 186 new_host = old_path.substr(1); | |
|
Alexei Svitkine (slow)
2012/08/08 15:07:40
Even if find() is okay when |old_path| is empty, t
| |
| 187 } else { | |
| 188 new_host = old_path.substr(1, separator - 1); | |
| 189 new_path = old_path.substr(separator); | |
| 190 } | |
| 191 | |
| 192 url_canon::Replacements<char> replacements; | |
| 193 replacements.SetHost(new_host.c_str(), | |
| 194 url_parse::Component(0, new_host.length())); | |
| 195 replacements.SetPath(new_path.c_str(), | |
| 196 url_parse::Component(0, new_path.length())); | |
| 197 *url = url->ReplaceComponents(replacements); | |
|
Alexei Svitkine (slow)
2012/08/08 15:07:40
Can you extract this block into a helper function,
| |
| 198 | |
| 199 return true; | |
| 200 } | |
| 201 | |
| 161 // Handles rewriting Web UI URLs. | 202 // Handles rewriting Web UI URLs. |
| 162 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { | 203 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
| 204 const GURL chrome_url = AddUberHost(*url); | |
| 205 | |
| 206 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will | |
| 207 // be called. | |
| 208 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( | |
| 209 browser_context, chrome_url)) | |
| 210 return true; | |
| 211 | |
| 163 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( | 212 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 164 browser_context, *url)) | 213 browser_context, *url)) |
| 165 return false; | 214 return false; |
| 166 | 215 |
| 167 #if defined(OS_CHROMEOS) | 216 #if defined(OS_CHROMEOS) |
| 168 // Special case : in ChromeOS in Guest mode bookmarks and history are | 217 // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 169 // disabled for security reasons. New tab page explains the reasons, so | 218 // disabled for security reasons. New tab page explains the reasons, so |
| 170 // we redirect user to new tab page. | 219 // we redirect user to new tab page. |
| 171 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { | 220 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { |
| 172 if (url->SchemeIs(chrome::kChromeUIScheme) && | 221 if (url->SchemeIs(chrome::kChromeUIScheme) && |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 183 // sessions or bookmarks, so we say any URL with that scheme triggers the new | 232 // sessions or bookmarks, so we say any URL with that scheme triggers the new |
| 184 // tab page. | 233 // tab page. |
| 185 if (url->SchemeIs(chrome::kChromeInternalScheme)) { | 234 if (url->SchemeIs(chrome::kChromeInternalScheme)) { |
| 186 // Rewrite it with the proper new tab URL. | 235 // Rewrite it with the proper new tab URL. |
| 187 *url = GURL(chrome::kChromeUINewTabURL); | 236 *url = GURL(chrome::kChromeUINewTabURL); |
| 188 } | 237 } |
| 189 | 238 |
| 190 return true; | 239 return true; |
| 191 } | 240 } |
| 192 | 241 |
| 242 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to | |
| 243 // "chrome://foo/". | |
| 244 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) { | |
| 245 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme)) | |
| 246 return false; | |
| 247 | |
| 248 return RemoveUberHost(url); | |
| 249 } | |
| 250 | |
| 193 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions | 251 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions |
| 194 // below. Extension, and isolated apps require different privileges to be | 252 // below. Extension, and isolated apps require different privileges to be |
| 195 // granted to their RenderProcessHosts. This classification allows us to make | 253 // granted to their RenderProcessHosts. This classification allows us to make |
| 196 // sure URLs are served by hosts with the right set of privileges. | 254 // sure URLs are served by hosts with the right set of privileges. |
| 197 enum RenderProcessHostPrivilege { | 255 enum RenderProcessHostPrivilege { |
| 198 PRIV_NORMAL, | 256 PRIV_NORMAL, |
| 199 PRIV_HOSTED, | 257 PRIV_HOSTED, |
| 200 PRIV_ISOLATED, | 258 PRIV_ISOLATED, |
| 201 PRIV_EXTENSION, | 259 PRIV_EXTENSION, |
| 202 }; | 260 }; |
| (...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1532 handler->AddHandlerPair(BrowserURLHandler::null_handler(), | 1590 handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
| 1533 &ExtensionWebUI::HandleChromeURLOverrideReverse); | 1591 &ExtensionWebUI::HandleChromeURLOverrideReverse); |
| 1534 | 1592 |
| 1535 // about: handler. Must come before chrome: handler, since it will | 1593 // about: handler. Must come before chrome: handler, since it will |
| 1536 // rewrite about: urls to chrome: URLs and then expect chrome: to | 1594 // rewrite about: urls to chrome: URLs and then expect chrome: to |
| 1537 // actually handle them. | 1595 // actually handle them. |
| 1538 handler->AddHandlerPair(&WillHandleBrowserAboutURL, | 1596 handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 1539 BrowserURLHandler::null_handler()); | 1597 BrowserURLHandler::null_handler()); |
| 1540 // chrome: & friends. | 1598 // chrome: & friends. |
| 1541 handler->AddHandlerPair(&HandleWebUI, | 1599 handler->AddHandlerPair(&HandleWebUI, |
| 1542 BrowserURLHandler::null_handler()); | 1600 &HandleWebUIReverse); |
| 1543 } | 1601 } |
| 1544 | 1602 |
| 1545 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { | 1603 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |
| 1546 Profile* profile = Profile::FromBrowserContext( | 1604 Profile* profile = Profile::FromBrowserContext( |
| 1547 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); | 1605 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); |
| 1548 BrowsingDataRemover* remover = new BrowsingDataRemover(profile, | 1606 BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 1549 BrowsingDataRemover::EVERYTHING, | 1607 BrowsingDataRemover::EVERYTHING, |
| 1550 base::Time()); | 1608 base::Time()); |
| 1551 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, | 1609 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
| 1552 BrowsingDataHelper::UNPROTECTED_WEB); | 1610 BrowsingDataHelper::UNPROTECTED_WEB); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1666 io_thread_application_locale_ = locale; | 1724 io_thread_application_locale_ = locale; |
| 1667 } | 1725 } |
| 1668 | 1726 |
| 1669 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( | 1727 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( |
| 1670 const std::string& locale) { | 1728 const std::string& locale) { |
| 1671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1672 io_thread_application_locale_ = locale; | 1730 io_thread_application_locale_ = locale; |
| 1673 } | 1731 } |
| 1674 | 1732 |
| 1675 } // namespace chrome | 1733 } // namespace chrome |
| OLD | NEW |