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

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

Issue 10780013: Add reverse URL handler for shortening uber URLs (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
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 | Annotate | Revision Log
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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 154 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
155 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 155 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
156 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 156 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
157 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 157 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
158 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 158 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
159 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 159 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
160 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 160 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
161 "jdfhpkjeckflbbleddjlpimecpbjdeep" // see crbug.com/142514 161 "jdfhpkjeckflbbleddjlpimecpbjdeep" // see crbug.com/142514
162 }; 162 };
163 163
164 // Returns a copy of the given url with its host set to given host and path set
165 // to given path. Other parts of the url will be the same.
166 GURL ReplaceURLHostAndPath(const GURL& url,
167 const std::string& host,
168 const std::string& path) {
169 url_canon::Replacements<char> replacements;
170 replacements.SetHost(host.c_str(),
171 url_parse::Component(0, host.length()));
172 replacements.SetPath(path.c_str(),
173 url_parse::Component(0, path.length()));
174 return url.ReplaceComponents(replacements);
175 }
176
177 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
178 GURL AddUberHost(const GURL& url) {
179 const std::string uber_host = chrome::kChromeUIUberHost;
180 const std::string old_host = url.host();
181
182 return ReplaceURLHostAndPath(url, uber_host, old_host);
183 }
184
185 // If url->host() is "chrome", changes the url from "foo://chrome/bar/" to
186 // "foo://bar/" and returns true. Otherwise returns false.
187 bool RemoveUberHost(GURL* url) {
188 if (url->host() != chrome::kChromeUIUberHost)
189 return false;
190
191 const std::string old_path = url->path();
192
193 const std::string::size_type separator = old_path.find('/', 1);
194 std::string new_host;
195 std::string new_path;
196 if (separator == std::string::npos) {
197 new_host = old_path.empty() ? old_path : old_path.substr(1);
198 } else {
199 new_host = old_path.substr(1, separator - 1);
200 new_path = old_path.substr(separator);
201 }
202
203 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
204
205 return true;
206 }
207
164 // Handles rewriting Web UI URLs. 208 // Handles rewriting Web UI URLs.
165 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { 209 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
210 // Do not handle special URLs such as "about:foo"
211 if (url->host() != "") {
Alexei Svitkine (slow) 2012/09/14 14:15:27 Nit: Check !url->host().empty() instead.
Cem Kocagil 2012/09/17 18:28:40 Done.
212 const GURL chrome_url = AddUberHost(*url);
213
214 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
215 // be called.
216 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
217 browser_context, chrome_url))
218 return true;
219 }
220
166 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 221 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
167 browser_context, *url)) 222 browser_context, *url))
168 return false; 223 return false;
169 224
170 #if defined(OS_CHROMEOS) 225 #if defined(OS_CHROMEOS)
171 // Special case : in ChromeOS in Guest mode bookmarks and history are 226 // Special case : in ChromeOS in Guest mode bookmarks and history are
172 // disabled for security reasons. New tab page explains the reasons, so 227 // disabled for security reasons. New tab page explains the reasons, so
173 // we redirect user to new tab page. 228 // we redirect user to new tab page.
174 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { 229 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
175 if (url->SchemeIs(chrome::kChromeUIScheme) && 230 if (url->SchemeIs(chrome::kChromeUIScheme) &&
(...skipping 10 matching lines...) Expand all
186 // sessions or bookmarks, so we say any URL with that scheme triggers the new 241 // sessions or bookmarks, so we say any URL with that scheme triggers the new
187 // tab page. 242 // tab page.
188 if (url->SchemeIs(chrome::kChromeInternalScheme)) { 243 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
189 // Rewrite it with the proper new tab URL. 244 // Rewrite it with the proper new tab URL.
190 *url = GURL(chrome::kChromeUINewTabURL); 245 *url = GURL(chrome::kChromeUINewTabURL);
191 } 246 }
192 247
193 return true; 248 return true;
194 } 249 }
195 250
251 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
252 // "chrome://foo/".
253 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
254 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
255 return false;
256
257 return RemoveUberHost(url);
258 }
259
196 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions 260 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
197 // below. Extension, and isolated apps require different privileges to be 261 // below. Extension, and isolated apps require different privileges to be
198 // granted to their RenderProcessHosts. This classification allows us to make 262 // granted to their RenderProcessHosts. This classification allows us to make
199 // sure URLs are served by hosts with the right set of privileges. 263 // sure URLs are served by hosts with the right set of privileges.
200 enum RenderProcessHostPrivilege { 264 enum RenderProcessHostPrivilege {
201 PRIV_NORMAL, 265 PRIV_NORMAL,
202 PRIV_HOSTED, 266 PRIV_HOSTED,
203 PRIV_ISOLATED, 267 PRIV_ISOLATED,
204 PRIV_EXTENSION, 268 PRIV_EXTENSION,
205 }; 269 };
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 BrowserURLHandler::null_handler()); 1616 BrowserURLHandler::null_handler());
1553 handler->AddHandlerPair(BrowserURLHandler::null_handler(), 1617 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1554 &ExtensionWebUI::HandleChromeURLOverrideReverse); 1618 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1555 1619
1556 // about: handler. Must come before chrome: handler, since it will 1620 // about: handler. Must come before chrome: handler, since it will
1557 // rewrite about: urls to chrome: URLs and then expect chrome: to 1621 // rewrite about: urls to chrome: URLs and then expect chrome: to
1558 // actually handle them. 1622 // actually handle them.
1559 handler->AddHandlerPair(&WillHandleBrowserAboutURL, 1623 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1560 BrowserURLHandler::null_handler()); 1624 BrowserURLHandler::null_handler());
1561 // chrome: & friends. 1625 // chrome: & friends.
1562 handler->AddHandlerPair(&HandleWebUI, 1626 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
1563 BrowserURLHandler::null_handler());
1564 } 1627 }
1565 1628
1566 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { 1629 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
1567 Profile* profile = Profile::FromBrowserContext( 1630 Profile* profile = Profile::FromBrowserContext(
1568 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 1631 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
1569 BrowsingDataRemover* remover = 1632 BrowsingDataRemover* remover =
1570 BrowsingDataRemover::CreateForUnboundedRange(profile); 1633 BrowsingDataRemover::CreateForUnboundedRange(profile);
1571 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 1634 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1572 BrowsingDataHelper::UNPROTECTED_WEB); 1635 BrowsingDataHelper::UNPROTECTED_WEB);
1573 // BrowsingDataRemover takes care of deleting itself when done. 1636 // BrowsingDataRemover takes care of deleting itself when done.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 partition_id = extension->id(); 1767 partition_id = extension->id();
1705 } 1768 }
1706 1769
1707 // Enforce that IsValidStoragePartitionId() implementation stays in sync. 1770 // Enforce that IsValidStoragePartitionId() implementation stays in sync.
1708 DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); 1771 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
1709 return partition_id; 1772 return partition_id;
1710 } 1773 }
1711 1774
1712 1775
1713 } // namespace chrome 1776 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698