| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/browser_url_handler.h" | 5 #include "content/browser/browser_url_handler.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "content/browser/content_browser_client.h" | 8 #include "content/browser/content_browser_client.h" |
| 9 #include "content/browser/webui/web_ui.h" | 9 #include "content/browser/webui/web_ui.h" |
| 10 #include "content/common/url_constants.h" | 10 #include "content/common/url_constants.h" |
| 11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 12 | 12 |
| 13 // Handles rewriting view-source URLs for what we'll actually load. | 13 // Handles rewriting view-source URLs for what we'll actually load. |
| 14 static bool HandleViewSource(GURL* url, Profile* profile) { | 14 static bool HandleViewSource(GURL* url, |
| 15 content::BrowserContext* browser_context) { |
| 15 if (url->SchemeIs(chrome::kViewSourceScheme)) { | 16 if (url->SchemeIs(chrome::kViewSourceScheme)) { |
| 16 // Load the inner URL instead. | 17 // Load the inner URL instead. |
| 17 *url = GURL(url->path()); | 18 *url = GURL(url->path()); |
| 18 | 19 |
| 19 // Bug 26129: limit view-source to view the content and not any | 20 // Bug 26129: limit view-source to view the content and not any |
| 20 // other kind of 'active' url scheme like 'javascript' or 'data'. | 21 // other kind of 'active' url scheme like 'javascript' or 'data'. |
| 21 static const char* const allowed_sub_schemes[] = { | 22 static const char* const allowed_sub_schemes[] = { |
| 22 chrome::kHttpScheme, chrome::kHttpsScheme, chrome::kFtpScheme, | 23 chrome::kHttpScheme, chrome::kHttpsScheme, chrome::kFtpScheme, |
| 23 chrome::kChromeDevToolsScheme, chrome::kChromeUIScheme, | 24 chrome::kChromeDevToolsScheme, chrome::kChromeUIScheme, |
| 24 chrome::kFileScheme | 25 chrome::kFileScheme |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 *url = GURL(chrome::kAboutBlankURL); | 37 *url = GURL(chrome::kAboutBlankURL); |
| 37 return false; | 38 return false; |
| 38 } | 39 } |
| 39 | 40 |
| 40 return true; | 41 return true; |
| 41 } | 42 } |
| 42 return false; | 43 return false; |
| 43 } | 44 } |
| 44 | 45 |
| 45 // Turns a non view-source URL into the corresponding view-source URL. | 46 // Turns a non view-source URL into the corresponding view-source URL. |
| 46 static bool ReverseViewSource(GURL* url, Profile* profile) { | 47 static bool ReverseViewSource(GURL* url, |
| 48 content::BrowserContext* browser_context) { |
| 47 // No action necessary if the URL is already view-source: | 49 // No action necessary if the URL is already view-source: |
| 48 if (url->SchemeIs(chrome::kViewSourceScheme)) | 50 if (url->SchemeIs(chrome::kViewSourceScheme)) |
| 49 return false; | 51 return false; |
| 50 | 52 |
| 51 url_canon::Replacements<char> repl; | 53 url_canon::Replacements<char> repl; |
| 52 repl.SetScheme(chrome::kViewSourceScheme, | 54 repl.SetScheme(chrome::kViewSourceScheme, |
| 53 url_parse::Component(0, strlen(chrome::kViewSourceScheme))); | 55 url_parse::Component(0, strlen(chrome::kViewSourceScheme))); |
| 54 repl.SetPath(url->spec().c_str(), | 56 repl.SetPath(url->spec().c_str(), |
| 55 url_parse::Component(0, url->spec().size())); | 57 url_parse::Component(0, url->spec().size())); |
| 56 *url = url->ReplaceComponents(repl); | 58 *url = url->ReplaceComponents(repl); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 82 } | 84 } |
| 83 | 85 |
| 84 BrowserURLHandler::~BrowserURLHandler() { | 86 BrowserURLHandler::~BrowserURLHandler() { |
| 85 } | 87 } |
| 86 | 88 |
| 87 void BrowserURLHandler::AddHandlerPair(URLHandler handler, | 89 void BrowserURLHandler::AddHandlerPair(URLHandler handler, |
| 88 URLHandler reverse_handler) { | 90 URLHandler reverse_handler) { |
| 89 url_handlers_.push_back(HandlerPair(handler, reverse_handler)); | 91 url_handlers_.push_back(HandlerPair(handler, reverse_handler)); |
| 90 } | 92 } |
| 91 | 93 |
| 92 void BrowserURLHandler::RewriteURLIfNecessary(GURL* url, Profile* profile, | 94 void BrowserURLHandler::RewriteURLIfNecessary( |
| 93 bool* reverse_on_redirect) { | 95 GURL* url, |
| 96 content::BrowserContext* browser_context, |
| 97 bool* reverse_on_redirect) { |
| 94 for (size_t i = 0; i < url_handlers_.size(); ++i) { | 98 for (size_t i = 0; i < url_handlers_.size(); ++i) { |
| 95 URLHandler handler = *url_handlers_[i].first; | 99 URLHandler handler = *url_handlers_[i].first; |
| 96 if (handler && handler(url, profile)) { | 100 if (handler && handler(url, browser_context)) { |
| 97 *reverse_on_redirect = (url_handlers_[i].second != NULL); | 101 *reverse_on_redirect = (url_handlers_[i].second != NULL); |
| 98 return; | 102 return; |
| 99 } | 103 } |
| 100 } | 104 } |
| 101 } | 105 } |
| 102 | 106 |
| 103 bool BrowserURLHandler::ReverseURLRewrite( | 107 bool BrowserURLHandler::ReverseURLRewrite( |
| 104 GURL* url, const GURL& original, Profile* profile) { | 108 GURL* url, const GURL& original, content::BrowserContext* browser_context) { |
| 105 for (size_t i = 0; i < url_handlers_.size(); ++i) { | 109 for (size_t i = 0; i < url_handlers_.size(); ++i) { |
| 106 URLHandler reverse_rewriter = *url_handlers_[i].second; | 110 URLHandler reverse_rewriter = *url_handlers_[i].second; |
| 107 if (reverse_rewriter) { | 111 if (reverse_rewriter) { |
| 108 GURL test_url(original); | 112 GURL test_url(original); |
| 109 URLHandler handler = *url_handlers_[i].first; | 113 URLHandler handler = *url_handlers_[i].first; |
| 110 if (!handler) { | 114 if (!handler) { |
| 111 if (reverse_rewriter(url, profile)) | 115 if (reverse_rewriter(url, browser_context)) |
| 112 return true; | 116 return true; |
| 113 } else if (handler(&test_url, profile)) { | 117 } else if (handler(&test_url, browser_context)) { |
| 114 return reverse_rewriter(url, profile); | 118 return reverse_rewriter(url, browser_context); |
| 115 } | 119 } |
| 116 } | 120 } |
| 117 } | 121 } |
| 118 return false; | 122 return false; |
| 119 } | 123 } |
| OLD | NEW |