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