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

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: comments 3 Created 8 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/chrome_content_browser_client_unittest.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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 GURL ReplaceURLHostAndPath(const GURL url, const std::string host,
Alexei Svitkine (slow) 2012/08/08 18:55:55 Pass these args by ref. Put the 2nd and 3rd args o
162 const std::string path) {
163 url_canon::Replacements<char> replacements;
164 replacements.SetHost(host.c_str(),
165 url_parse::Component(0, host.length()));
166 replacements.SetPath(path.c_str(),
167 url_parse::Component(0, path.length()));
168 return url.ReplaceComponents(replacements);
169 }
170
171 // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/"
172 GURL AddUberHost(const GURL& url) {
173 const std::string uber_host = chrome::kChromeUIUberHost;
174 const std::string old_host = url.host();
175
176 return ReplaceURLHostAndPath(url, uber_host, old_host);
177 }
178
179 // If url->host() is "chrome", it maps "foo://chrome/bar/" to "foo://bar/"
Alexei Svitkine (slow) 2012/08/08 18:55:55 Explain the return value in the comment. End the s
180 bool RemoveUberHost(GURL* url) {
181 if (url->host() != chrome::kChromeUIUberHost)
182 return false;
183
184 const std::string old_path = url->path();
185
186 const int separator = old_path.find('/', 1);
187 std::string new_host;
188 std::string new_path;
189 if (separator == std::string::npos) {
190 new_host = old_path.empty() ? old_path : old_path.substr(1);
191 } else {
192 new_host = old_path.substr(1, separator - 1);
193 new_path = old_path.substr(separator);
194 }
195
196 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
197
198 return true;
199 }
200
161 // Handles rewriting Web UI URLs. 201 // Handles rewriting Web UI URLs.
162 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { 202 bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
203 const GURL chrome_url = AddUberHost(*url);
204
205 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
206 // be called.
207 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
208 browser_context, chrome_url))
209 return true;
210
163 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 211 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
164 browser_context, *url)) 212 browser_context, *url))
165 return false; 213 return false;
166 214
167 #if defined(OS_CHROMEOS) 215 #if defined(OS_CHROMEOS)
168 // Special case : in ChromeOS in Guest mode bookmarks and history are 216 // Special case : in ChromeOS in Guest mode bookmarks and history are
169 // disabled for security reasons. New tab page explains the reasons, so 217 // disabled for security reasons. New tab page explains the reasons, so
170 // we redirect user to new tab page. 218 // we redirect user to new tab page.
171 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { 219 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
172 if (url->SchemeIs(chrome::kChromeUIScheme) && 220 if (url->SchemeIs(chrome::kChromeUIScheme) &&
(...skipping 10 matching lines...) Expand all
183 // sessions or bookmarks, so we say any URL with that scheme triggers the new 231 // sessions or bookmarks, so we say any URL with that scheme triggers the new
184 // tab page. 232 // tab page.
185 if (url->SchemeIs(chrome::kChromeInternalScheme)) { 233 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
186 // Rewrite it with the proper new tab URL. 234 // Rewrite it with the proper new tab URL.
187 *url = GURL(chrome::kChromeUINewTabURL); 235 *url = GURL(chrome::kChromeUINewTabURL);
188 } 236 }
189 237
190 return true; 238 return true;
191 } 239 }
192 240
241 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
242 // "chrome://foo/".
243 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
244 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
245 return false;
246
247 return RemoveUberHost(url);
248 }
249
193 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions 250 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
194 // below. Extension, and isolated apps require different privileges to be 251 // below. Extension, and isolated apps require different privileges to be
195 // granted to their RenderProcessHosts. This classification allows us to make 252 // granted to their RenderProcessHosts. This classification allows us to make
196 // sure URLs are served by hosts with the right set of privileges. 253 // sure URLs are served by hosts with the right set of privileges.
197 enum RenderProcessHostPrivilege { 254 enum RenderProcessHostPrivilege {
198 PRIV_NORMAL, 255 PRIV_NORMAL,
199 PRIV_HOSTED, 256 PRIV_HOSTED,
200 PRIV_ISOLATED, 257 PRIV_ISOLATED,
201 PRIV_EXTENSION, 258 PRIV_EXTENSION,
202 }; 259 };
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 handler->AddHandlerPair(BrowserURLHandler::null_handler(), 1589 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1533 &ExtensionWebUI::HandleChromeURLOverrideReverse); 1590 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1534 1591
1535 // about: handler. Must come before chrome: handler, since it will 1592 // about: handler. Must come before chrome: handler, since it will
1536 // rewrite about: urls to chrome: URLs and then expect chrome: to 1593 // rewrite about: urls to chrome: URLs and then expect chrome: to
1537 // actually handle them. 1594 // actually handle them.
1538 handler->AddHandlerPair(&WillHandleBrowserAboutURL, 1595 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1539 BrowserURLHandler::null_handler()); 1596 BrowserURLHandler::null_handler());
1540 // chrome: & friends. 1597 // chrome: & friends.
1541 handler->AddHandlerPair(&HandleWebUI, 1598 handler->AddHandlerPair(&HandleWebUI,
1542 BrowserURLHandler::null_handler()); 1599 &HandleWebUIReverse);
Alexei Svitkine (slow) 2012/08/08 18:55:55 Nit: This can now fit on the previous line.
1543 } 1600 }
1544 1601
1545 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { 1602 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
1546 Profile* profile = Profile::FromBrowserContext( 1603 Profile* profile = Profile::FromBrowserContext(
1547 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 1604 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
1548 BrowsingDataRemover* remover = new BrowsingDataRemover(profile, 1605 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1549 BrowsingDataRemover::EVERYTHING, 1606 BrowsingDataRemover::EVERYTHING,
1550 base::Time()); 1607 base::Time());
1551 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 1608 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1552 BrowsingDataHelper::UNPROTECTED_WEB); 1609 BrowsingDataHelper::UNPROTECTED_WEB);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 io_thread_application_locale_ = locale; 1723 io_thread_application_locale_ = locale;
1667 } 1724 }
1668 1725
1669 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( 1726 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1670 const std::string& locale) { 1727 const std::string& locale) {
1671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1672 io_thread_application_locale_ = locale; 1729 io_thread_application_locale_ = locale;
1673 } 1730 }
1674 1731
1675 } // namespace chrome 1732 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chrome_content_browser_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698