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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Handles rewriting Web UI URLs. | 161 // Handles rewriting Web UI URLs. |
| 162 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { | 162 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
| 163 url_canon::Replacements<char> replacements; | |
|
Cem Kocagil
2012/07/25 23:02:34
This addition here is to ensure that the reverse h
| |
| 164 replacements.SetHost("chrome", url_parse::Component(0, 6)); | |
| 165 std::string host = url->host(); | |
| 166 replacements.SetPath(host.c_str(), url_parse::Component(0, host.length())); | |
| 167 GURL chrome_url = url->ReplaceComponents(replacements); | |
| 168 | |
| 169 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( | |
| 170 browser_context, chrome_url)) | |
| 171 return true; | |
| 172 | |
| 163 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( | 173 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 164 browser_context, *url)) | 174 browser_context, *url)) |
| 165 return false; | 175 return false; |
| 166 | 176 |
| 167 #if defined(OS_CHROMEOS) | 177 #if defined(OS_CHROMEOS) |
| 168 // Special case : in ChromeOS in Guest mode bookmarks and history are | 178 // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 169 // disabled for security reasons. New tab page explains the reasons, so | 179 // disabled for security reasons. New tab page explains the reasons, so |
| 170 // we redirect user to new tab page. | 180 // we redirect user to new tab page. |
| 171 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { | 181 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { |
| 172 if (url->SchemeIs(chrome::kChromeUIScheme) && | 182 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 | 193 // sessions or bookmarks, so we say any URL with that scheme triggers the new |
| 184 // tab page. | 194 // tab page. |
| 185 if (url->SchemeIs(chrome::kChromeInternalScheme)) { | 195 if (url->SchemeIs(chrome::kChromeInternalScheme)) { |
| 186 // Rewrite it with the proper new tab URL. | 196 // Rewrite it with the proper new tab URL. |
| 187 *url = GURL(chrome::kChromeUINewTabURL); | 197 *url = GURL(chrome::kChromeUINewTabURL); |
| 188 } | 198 } |
| 189 | 199 |
| 190 return true; | 200 return true; |
| 191 } | 201 } |
| 192 | 202 |
| 203 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) { | |
| 204 if (!url | |
|
Cem Kocagil
2012/07/25 23:02:34
Some of these checks are probably not necessary, I
| |
| 205 || !url->is_valid() | |
| 206 || !url->SchemeIs(chrome::kChromeUIScheme) | |
| 207 || url->host() != chrome::kChromeUIUberHost) | |
|
Alexei Svitkine (slow)
2012/07/26 15:12:31
This doesn't follow the Chromium coding style. See
| |
| 208 return false; | |
| 209 | |
| 210 std::string old_path = url->path(); | |
| 211 | |
| 212 int separator = old_path.find('/', 1); | |
| 213 std::string new_host; | |
| 214 std::string new_path; | |
| 215 if (separator == std::string::npos) { | |
| 216 new_host = old_path.substr(1); | |
| 217 } else { | |
| 218 new_host = old_path.substr(1, separator - 1); | |
| 219 new_path = old_path.substr(separator); | |
| 220 } | |
| 221 | |
| 222 url_canon::Replacements<char> replacements; | |
| 223 replacements.ClearHost(); | |
| 224 replacements.SetHost(new_host.c_str(), | |
| 225 url_parse::Component(0, new_host.length())); | |
| 226 replacements.SetPath(new_path.c_str(), | |
| 227 url_parse::Component(0, new_path.length())); | |
| 228 *url = url->ReplaceComponents(replacements); | |
| 229 return true; | |
| 230 } | |
| 231 | |
| 193 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions | 232 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions |
| 194 // below. Extension, and isolated apps require different privileges to be | 233 // below. Extension, and isolated apps require different privileges to be |
| 195 // granted to their RenderProcessHosts. This classification allows us to make | 234 // granted to their RenderProcessHosts. This classification allows us to make |
| 196 // sure URLs are served by hosts with the right set of privileges. | 235 // sure URLs are served by hosts with the right set of privileges. |
| 197 enum RenderProcessHostPrivilege { | 236 enum RenderProcessHostPrivilege { |
| 198 PRIV_NORMAL, | 237 PRIV_NORMAL, |
| 199 PRIV_HOSTED, | 238 PRIV_HOSTED, |
| 200 PRIV_ISOLATED, | 239 PRIV_ISOLATED, |
| 201 PRIV_EXTENSION, | 240 PRIV_EXTENSION, |
| 202 }; | 241 }; |
| (...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1532 handler->AddHandlerPair(BrowserURLHandler::null_handler(), | 1571 handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
| 1533 &ExtensionWebUI::HandleChromeURLOverrideReverse); | 1572 &ExtensionWebUI::HandleChromeURLOverrideReverse); |
| 1534 | 1573 |
| 1535 // about: handler. Must come before chrome: handler, since it will | 1574 // about: handler. Must come before chrome: handler, since it will |
| 1536 // rewrite about: urls to chrome: URLs and then expect chrome: to | 1575 // rewrite about: urls to chrome: URLs and then expect chrome: to |
| 1537 // actually handle them. | 1576 // actually handle them. |
| 1538 handler->AddHandlerPair(&WillHandleBrowserAboutURL, | 1577 handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 1539 BrowserURLHandler::null_handler()); | 1578 BrowserURLHandler::null_handler()); |
| 1540 // chrome: & friends. | 1579 // chrome: & friends. |
| 1541 handler->AddHandlerPair(&HandleWebUI, | 1580 handler->AddHandlerPair(&HandleWebUI, |
| 1542 BrowserURLHandler::null_handler()); | 1581 &HandleWebUIReverse); |
| 1543 } | 1582 } |
| 1544 | 1583 |
| 1545 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { | 1584 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |
| 1546 Profile* profile = Profile::FromBrowserContext( | 1585 Profile* profile = Profile::FromBrowserContext( |
| 1547 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); | 1586 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); |
| 1548 BrowsingDataRemover* remover = new BrowsingDataRemover(profile, | 1587 BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 1549 BrowsingDataRemover::EVERYTHING, | 1588 BrowsingDataRemover::EVERYTHING, |
| 1550 base::Time()); | 1589 base::Time()); |
| 1551 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, | 1590 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
| 1552 BrowsingDataHelper::UNPROTECTED_WEB); | 1591 BrowsingDataHelper::UNPROTECTED_WEB); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1666 io_thread_application_locale_ = locale; | 1705 io_thread_application_locale_ = locale; |
| 1667 } | 1706 } |
| 1668 | 1707 |
| 1669 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( | 1708 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( |
| 1670 const std::string& locale) { | 1709 const std::string& locale) { |
| 1671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1672 io_thread_application_locale_ = locale; | 1711 io_thread_application_locale_ = locale; |
| 1673 } | 1712 } |
| 1674 | 1713 |
| 1675 } // namespace chrome | 1714 } // namespace chrome |
| OLD | NEW |