diff options
author | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 18:58:32 +0000 |
---|---|---|
committer | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 18:58:32 +0000 |
commit | 38178a40098824ecafd6d81e9f19631acaf37c75 (patch) | |
tree | 7f051b0d8d818cca8766919f43b91796a5f5e27f /chrome/browser/browser_url_handler.cc | |
parent | 501ebf0409b21006e224116a324f18ad94edc725 (diff) | |
download | chromium_src-38178a40098824ecafd6d81e9f19631acaf37c75.zip chromium_src-38178a40098824ecafd6d81e9f19631acaf37c75.tar.gz chromium_src-38178a40098824ecafd6d81e9f19631acaf37c75.tar.bz2 |
Allow rewriting of URLs to be reversed in some cases, so that if the underlying renderer URL changes, the virtual URL displayed in the address bar can be updated to reflect that. Currently apply that technique only to view-source rewrites, so it will follow redirects.
BUG=19444
TEST=go to view-source:http://crbug.com
Review URL: http://codereview.chromium.org/493001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34851 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_url_handler.cc')
-rw-r--r-- | chrome/browser/browser_url_handler.cc | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/chrome/browser/browser_url_handler.cc b/chrome/browser/browser_url_handler.cc index 0cd1e2f..b209e04 100644 --- a/chrome/browser/browser_url_handler.cc +++ b/chrome/browser/browser_url_handler.cc @@ -43,6 +43,21 @@ static bool HandleViewSource(GURL* url, Profile* profile) { return false; } +// Turns a non view-source URL into the corresponding view-source URL. +static bool ReverseViewSource(GURL* url, Profile* profile) { + // No action necessary if the URL is already view-source: + if (url->SchemeIs(chrome::kViewSourceScheme)) + return false; + + url_canon::Replacements<char> repl; + repl.SetScheme(chrome::kViewSourceScheme, + url_parse::Component(0, strlen(chrome::kViewSourceScheme))); + repl.SetPath(url->spec().c_str(), + url_parse::Component(0, url->spec().size())); + *url = url->ReplaceComponents(repl); + return true; +} + // Handles rewriting DOM UI URLs. static bool HandleDOMUI(GURL* url, Profile* profile) { if (!DOMUIFactory::UseDOMUIForURL(*url)) @@ -60,7 +75,7 @@ static bool HandleDOMUI(GURL* url, Profile* profile) { return true; } -std::vector<BrowserURLHandler::URLHandler> BrowserURLHandler::url_handlers_; +std::vector<BrowserURLHandler::HandlerPair> BrowserURLHandler::url_handlers_; // static void BrowserURLHandler::InitURLHandlers() { @@ -68,18 +83,40 @@ void BrowserURLHandler::InitURLHandlers() { return; // Add the default URL handlers. - url_handlers_.push_back(&ExtensionDOMUI::HandleChromeURLOverride); - url_handlers_.push_back(&WillHandleBrowserAboutURL); // about: - url_handlers_.push_back(&HandleDOMUI); // chrome: & friends. - url_handlers_.push_back(&HandleViewSource); // view-source: + url_handlers_.push_back( + HandlerPair(&ExtensionDOMUI::HandleChromeURLOverride, NULL)); + // about: + url_handlers_.push_back(HandlerPair(&WillHandleBrowserAboutURL, NULL)); + // chrome: & friends. + url_handlers_.push_back(HandlerPair(&HandleDOMUI, NULL)); + // view-source: + url_handlers_.push_back(HandlerPair(&HandleViewSource, &ReverseViewSource)); } // static -void BrowserURLHandler::RewriteURLIfNecessary(GURL* url, Profile* profile) { +void BrowserURLHandler::RewriteURLIfNecessary(GURL* url, Profile* profile, + bool* reverse_on_redirect) { if (url_handlers_.empty()) InitURLHandlers(); for (size_t i = 0; i < url_handlers_.size(); ++i) { - if ((*url_handlers_[i])(url, profile)) + if ((*url_handlers_[i].first)(url, profile)) { + *reverse_on_redirect = (url_handlers_[i].second != NULL); return; + } } } + +// static +bool BrowserURLHandler::ReverseURLRewrite( + GURL* url, const GURL& original, Profile* profile) { + for (size_t i = 0; i < url_handlers_.size(); ++i) { + GURL test_url(original); + if ((*url_handlers_[i].first)(&test_url, profile)) { + if (url_handlers_[i].second) + return (*url_handlers_[i].second)(url, profile); + else + return false; + } + } + return false; +} |