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

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

Powered by Google App Engine
This is Rietveld 408576698