Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 10941050: Second try of 157576 https://chromiumcodereview.appspot.com/10780013/ (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chrome_content_browser_client_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 161 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
162 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 162 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
163 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 163 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
164 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 164 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
165 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 165 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
166 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 166 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
167 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 167 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
168 "jdfhpkjeckflbbleddjlpimecpbjdeep" // see crbug.com/142514 168 "jdfhpkjeckflbbleddjlpimecpbjdeep" // see crbug.com/142514
169 }; 169 };
170 170
171 // Returns a copy of the given url with its host set to given host and path set
172 // to given path. Other parts of the url will be the same.
173 GURL ReplaceURLHostAndPath(const GURL& url,
174 const std::string& host,
175 const std::string& path) {
176 url_canon::Replacements<char> replacements;
177 replacements.SetHost(host.c_str(),
178 url_parse::Component(0, host.length()));
179 replacements.SetPath(path.c_str(),
180 url_parse::Component(0, path.length()));
181 return url.ReplaceComponents(replacements);
182 }
183
184 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
185 GURL AddUberHost(const GURL& url) {
186 const std::string uber_host = chrome::kChromeUIUberHost;
187 const std::string new_path = url.host() + url.path();
188
189 return ReplaceURLHostAndPath(url, uber_host, new_path);
190 }
191
192 // If url->host() is "chrome", changes the url from "foo://chrome/bar/" to
193 // "foo://bar/" and returns true. Otherwise returns false.
194 bool RemoveUberHost(GURL* url) {
195 if (url->host() != chrome::kChromeUIUberHost)
196 return false;
197
198 const std::string old_path = url->path();
199
200 const std::string::size_type separator = old_path.find('/', 1);
201 std::string new_host;
202 std::string new_path;
203 if (separator == std::string::npos) {
204 new_host = old_path.empty() ? old_path : old_path.substr(1);
205 } else {
206 new_host = old_path.substr(1, separator - 1);
207 new_path = old_path.substr(separator);
208 }
209
210 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
211
212 return true;
213 }
214
171 // Handles rewriting Web UI URLs. 215 // Handles rewriting Web UI URLs.
172 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { 216 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
217 // Do not handle special URLs such as "about:foo"
218 if (!url->host().empty()) {
219 const GURL chrome_url = AddUberHost(*url);
220
221 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
222 // be called.
223 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
224 browser_context, chrome_url))
225 return true;
226 }
227
173 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 228 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
174 browser_context, *url)) 229 browser_context, *url))
175 return false; 230 return false;
176 231
177 #if defined(OS_CHROMEOS) 232 #if defined(OS_CHROMEOS)
178 // Special case : in ChromeOS in Guest mode bookmarks and history are 233 // Special case : in ChromeOS in Guest mode bookmarks and history are
179 // disabled for security reasons. New tab page explains the reasons, so 234 // disabled for security reasons. New tab page explains the reasons, so
180 // we redirect user to new tab page. 235 // we redirect user to new tab page.
181 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { 236 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
182 if (url->SchemeIs(chrome::kChromeUIScheme) && 237 if (url->SchemeIs(chrome::kChromeUIScheme) &&
(...skipping 10 matching lines...) Expand all
193 // sessions or bookmarks, so we say any URL with that scheme triggers the new 248 // sessions or bookmarks, so we say any URL with that scheme triggers the new
194 // tab page. 249 // tab page.
195 if (url->SchemeIs(chrome::kChromeInternalScheme)) { 250 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
196 // Rewrite it with the proper new tab URL. 251 // Rewrite it with the proper new tab URL.
197 *url = GURL(chrome::kChromeUINewTabURL); 252 *url = GURL(chrome::kChromeUINewTabURL);
198 } 253 }
199 254
200 return true; 255 return true;
201 } 256 }
202 257
258 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
259 // "chrome://foo/".
260 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
261 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
262 return false;
263
264 return RemoveUberHost(url);
265 }
266
203 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions 267 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
204 // below. Extension, and isolated apps require different privileges to be 268 // below. Extension, and isolated apps require different privileges to be
205 // granted to their RenderProcessHosts. This classification allows us to make 269 // granted to their RenderProcessHosts. This classification allows us to make
206 // sure URLs are served by hosts with the right set of privileges. 270 // sure URLs are served by hosts with the right set of privileges.
207 enum RenderProcessHostPrivilege { 271 enum RenderProcessHostPrivilege {
208 PRIV_NORMAL, 272 PRIV_NORMAL,
209 PRIV_HOSTED, 273 PRIV_HOSTED,
210 PRIV_ISOLATED, 274 PRIV_ISOLATED,
211 PRIV_EXTENSION, 275 PRIV_EXTENSION,
212 }; 276 };
(...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 BrowserURLHandler::null_handler()); 1629 BrowserURLHandler::null_handler());
1566 handler->AddHandlerPair(BrowserURLHandler::null_handler(), 1630 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1567 &ExtensionWebUI::HandleChromeURLOverrideReverse); 1631 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1568 1632
1569 // about: handler. Must come before chrome: handler, since it will 1633 // about: handler. Must come before chrome: handler, since it will
1570 // rewrite about: urls to chrome: URLs and then expect chrome: to 1634 // rewrite about: urls to chrome: URLs and then expect chrome: to
1571 // actually handle them. 1635 // actually handle them.
1572 handler->AddHandlerPair(&WillHandleBrowserAboutURL, 1636 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1573 BrowserURLHandler::null_handler()); 1637 BrowserURLHandler::null_handler());
1574 // chrome: & friends. 1638 // chrome: & friends.
1575 handler->AddHandlerPair(&HandleWebUI, 1639 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
1576 BrowserURLHandler::null_handler());
1577 } 1640 }
1578 1641
1579 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { 1642 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
1580 Profile* profile = Profile::FromBrowserContext( 1643 Profile* profile = Profile::FromBrowserContext(
1581 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 1644 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
1582 BrowsingDataRemover* remover = 1645 BrowsingDataRemover* remover =
1583 BrowsingDataRemover::CreateForUnboundedRange(profile); 1646 BrowsingDataRemover::CreateForUnboundedRange(profile);
1584 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 1647 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1585 BrowsingDataHelper::UNPROTECTED_WEB); 1648 BrowsingDataHelper::UNPROTECTED_WEB);
1586 // BrowsingDataRemover takes care of deleting itself when done. 1649 // BrowsingDataRemover takes care of deleting itself when done.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 partition_id = extension->id(); 1787 partition_id = extension->id();
1725 } 1788 }
1726 1789
1727 // Enforce that IsValidStoragePartitionId() implementation stays in sync. 1790 // Enforce that IsValidStoragePartitionId() implementation stays in sync.
1728 DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); 1791 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
1729 return partition_id; 1792 return partition_id;
1730 } 1793 }
1731 1794
1732 1795
1733 } // namespace chrome 1796 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chrome_content_browser_client_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698