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

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 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
164 replacements.SetHost("chrome", url_parse::Component(0, 6));
Alexei Svitkine (slow) 2012/08/07 14:59:33 Nit: Make a const std::string in the local scope a
165 std::string host = url->host();
Alexei Svitkine (slow) 2012/08/07 14:59:33 Nit: Should be const.
166 replacements.SetPath(host.c_str(), url_parse::Component(0, host.length()));
167 GURL chrome_url = url->ReplaceComponents(replacements);
Alexei Svitkine (slow) 2012/08/07 14:59:33 Nit: Maybe extract the above block to a separate f
Cem Kocagil 2012/08/07 20:56:22 Good idea. I went further and added two functions:
168
169 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
170 // be called.
171 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
172 browser_context, chrome_url))
173 return true;
Alexei Svitkine (slow) 2012/08/07 14:59:33 Add a comment why this doesn't need to set *url ev
Cem Kocagil 2012/08/07 20:56:22 The comment right above that block explains why it
174
163 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 175 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
164 browser_context, *url)) 176 browser_context, *url))
165 return false; 177 return false;
166 178
167 #if defined(OS_CHROMEOS) 179 #if defined(OS_CHROMEOS)
168 // Special case : in ChromeOS in Guest mode bookmarks and history are 180 // Special case : in ChromeOS in Guest mode bookmarks and history are
169 // disabled for security reasons. New tab page explains the reasons, so 181 // disabled for security reasons. New tab page explains the reasons, so
170 // we redirect user to new tab page. 182 // we redirect user to new tab page.
171 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { 183 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
172 if (url->SchemeIs(chrome::kChromeUIScheme) && 184 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 195 // sessions or bookmarks, so we say any URL with that scheme triggers the new
184 // tab page. 196 // tab page.
185 if (url->SchemeIs(chrome::kChromeInternalScheme)) { 197 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
186 // Rewrite it with the proper new tab URL. 198 // Rewrite it with the proper new tab URL.
187 *url = GURL(chrome::kChromeUINewTabURL); 199 *url = GURL(chrome::kChromeUINewTabURL);
188 } 200 }
189 201
190 return true; 202 return true;
191 } 203 }
192 204
205 // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
206 // "chrome://foo/".
207 bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
208 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme) ||
209 url->host() != chrome::kChromeUIUberHost)
210 return false;
211
212 std::string old_path = url->path();
Alexei Svitkine (slow) 2012/08/07 14:59:33 Nit: Should be const.
213
214 int separator = old_path.find('/', 1);
Alexei Svitkine (slow) 2012/08/07 14:59:33 Nit: Should be const.
215 std::string new_host;
216 std::string new_path;
217 if (separator == std::string::npos) {
218 new_host = old_path.substr(1);
Alexei Svitkine (slow) 2012/08/07 14:59:33 What if old_path is an empty string? (Also, does f
Cem Kocagil 2012/08/07 20:56:22 It should work when old_path is empty. I checked t
219 } else {
220 new_host = old_path.substr(1, separator - 1);
221 new_path = old_path.substr(separator);
222 }
223
224 url_canon::Replacements<char> replacements;
225 replacements.ClearHost();
Alexei Svitkine (slow) 2012/08/07 14:59:33 Is this needed given that you set it immediately a
226 replacements.SetHost(new_host.c_str(),
227 url_parse::Component(0, new_host.length()));
228 replacements.SetPath(new_path.c_str(),
229 url_parse::Component(0, new_path.length()));
230 *url = url->ReplaceComponents(replacements);
231 return true;
232 }
233
193 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions 234 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
194 // below. Extension, and isolated apps require different privileges to be 235 // below. Extension, and isolated apps require different privileges to be
195 // granted to their RenderProcessHosts. This classification allows us to make 236 // granted to their RenderProcessHosts. This classification allows us to make
196 // sure URLs are served by hosts with the right set of privileges. 237 // sure URLs are served by hosts with the right set of privileges.
197 enum RenderProcessHostPrivilege { 238 enum RenderProcessHostPrivilege {
198 PRIV_NORMAL, 239 PRIV_NORMAL,
199 PRIV_HOSTED, 240 PRIV_HOSTED,
200 PRIV_ISOLATED, 241 PRIV_ISOLATED,
201 PRIV_EXTENSION, 242 PRIV_EXTENSION,
202 }; 243 };
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 handler->AddHandlerPair(BrowserURLHandler::null_handler(), 1573 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1533 &ExtensionWebUI::HandleChromeURLOverrideReverse); 1574 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1534 1575
1535 // about: handler. Must come before chrome: handler, since it will 1576 // about: handler. Must come before chrome: handler, since it will
1536 // rewrite about: urls to chrome: URLs and then expect chrome: to 1577 // rewrite about: urls to chrome: URLs and then expect chrome: to
1537 // actually handle them. 1578 // actually handle them.
1538 handler->AddHandlerPair(&WillHandleBrowserAboutURL, 1579 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1539 BrowserURLHandler::null_handler()); 1580 BrowserURLHandler::null_handler());
1540 // chrome: & friends. 1581 // chrome: & friends.
1541 handler->AddHandlerPair(&HandleWebUI, 1582 handler->AddHandlerPair(&HandleWebUI,
1542 BrowserURLHandler::null_handler()); 1583 &HandleWebUIReverse);
1543 } 1584 }
1544 1585
1545 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { 1586 void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
1546 Profile* profile = Profile::FromBrowserContext( 1587 Profile* profile = Profile::FromBrowserContext(
1547 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 1588 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
1548 BrowsingDataRemover* remover = new BrowsingDataRemover(profile, 1589 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1549 BrowsingDataRemover::EVERYTHING, 1590 BrowsingDataRemover::EVERYTHING,
1550 base::Time()); 1591 base::Time());
1551 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 1592 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1552 BrowsingDataHelper::UNPROTECTED_WEB); 1593 BrowsingDataHelper::UNPROTECTED_WEB);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 io_thread_application_locale_ = locale; 1707 io_thread_application_locale_ = locale;
1667 } 1708 }
1668 1709
1669 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( 1710 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1670 const std::string& locale) { 1711 const std::string& locale) {
1671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1672 io_thread_application_locale_ = locale; 1713 io_thread_application_locale_ = locale;
1673 } 1714 }
1674 1715
1675 } // namespace chrome 1716 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698