| OLD | NEW |
| 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 "content/browser/browser_url_handler_impl.h" | 5 #include "content/browser/browser_url_handler_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "content/browser/frame_host/debug_urls.h" | 8 #include "content/browser/frame_host/debug_urls.h" |
| 9 #include "content/browser/webui/web_ui_impl.h" | 9 #include "content/browser/webui/web_ui_impl.h" |
| 10 #include "content/public/browser/content_browser_client.h" | 10 #include "content/public/browser/content_browser_client.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 BrowserURLHandler::URLHandler BrowserURLHandler::null_handler() { | 81 BrowserURLHandler::URLHandler BrowserURLHandler::null_handler() { |
| 82 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det
ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair | 82 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det
ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair |
| 83 return NULL; | 83 return NULL; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // static | 86 // static |
| 87 BrowserURLHandlerImpl* BrowserURLHandlerImpl::GetInstance() { | 87 BrowserURLHandlerImpl* BrowserURLHandlerImpl::GetInstance() { |
| 88 return Singleton<BrowserURLHandlerImpl>::get(); | 88 return Singleton<BrowserURLHandlerImpl>::get(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 BrowserURLHandlerImpl::BrowserURLHandlerImpl() { | 91 BrowserURLHandlerImpl::BrowserURLHandlerImpl() : |
| 92 fixup_handler_(null_handler()) { |
| 92 AddHandlerPair(&DebugURLHandler, BrowserURLHandlerImpl::null_handler()); | 93 AddHandlerPair(&DebugURLHandler, BrowserURLHandlerImpl::null_handler()); |
| 93 | 94 |
| 94 GetContentClient()->browser()->BrowserURLHandlerCreated(this); | 95 GetContentClient()->browser()->BrowserURLHandlerCreated(this); |
| 95 | 96 |
| 96 // view-source: | 97 // view-source: |
| 97 AddHandlerPair(&HandleViewSource, &ReverseViewSource); | 98 AddHandlerPair(&HandleViewSource, &ReverseViewSource); |
| 98 } | 99 } |
| 99 | 100 |
| 100 BrowserURLHandlerImpl::~BrowserURLHandlerImpl() { | 101 BrowserURLHandlerImpl::~BrowserURLHandlerImpl() { |
| 101 } | 102 } |
| 102 | 103 |
| 104 void BrowserURLHandlerImpl::SetFixupHandler(URLHandler handler) { |
| 105 DCHECK_EQ(null_handler(), fixup_handler_); |
| 106 fixup_handler_ = handler; |
| 107 } |
| 108 |
| 103 void BrowserURLHandlerImpl::AddHandlerPair(URLHandler handler, | 109 void BrowserURLHandlerImpl::AddHandlerPair(URLHandler handler, |
| 104 URLHandler reverse_handler) { | 110 URLHandler reverse_handler) { |
| 105 url_handlers_.push_back(HandlerPair(handler, reverse_handler)); | 111 url_handlers_.push_back(HandlerPair(handler, reverse_handler)); |
| 106 } | 112 } |
| 107 | 113 |
| 108 void BrowserURLHandlerImpl::RewriteURLIfNecessary( | 114 void BrowserURLHandlerImpl::RewriteURLIfNecessary( |
| 109 GURL* url, | 115 GURL* url, |
| 110 BrowserContext* browser_context, | 116 BrowserContext* browser_context, |
| 111 bool* reverse_on_redirect) { | 117 bool* reverse_on_redirect) { |
| 112 for (size_t i = 0; i < url_handlers_.size(); ++i) { | 118 for (size_t i = 0; i < url_handlers_.size(); ++i) { |
| 113 URLHandler handler = *url_handlers_[i].first; | 119 URLHandler handler = *url_handlers_[i].first; |
| 114 if (handler && handler(url, browser_context)) { | 120 if (handler && handler(url, browser_context)) { |
| 115 *reverse_on_redirect = (url_handlers_[i].second != NULL); | 121 *reverse_on_redirect = (url_handlers_[i].second != NULL); |
| 116 return; | 122 return; |
| 117 } | 123 } |
| 118 } | 124 } |
| 119 } | 125 } |
| 120 | 126 |
| 127 void BrowserURLHandlerImpl::FixupURLBeforeRewrite( |
| 128 GURL* url, |
| 129 BrowserContext* browser_context) { |
| 130 if (fixup_handler_) |
| 131 fixup_handler_(url, browser_context); |
| 132 } |
| 133 |
| 121 bool BrowserURLHandlerImpl::ReverseURLRewrite( | 134 bool BrowserURLHandlerImpl::ReverseURLRewrite( |
| 122 GURL* url, const GURL& original, BrowserContext* browser_context) { | 135 GURL* url, const GURL& original, BrowserContext* browser_context) { |
| 123 for (size_t i = 0; i < url_handlers_.size(); ++i) { | 136 for (size_t i = 0; i < url_handlers_.size(); ++i) { |
| 124 URLHandler reverse_rewriter = *url_handlers_[i].second; | 137 URLHandler reverse_rewriter = *url_handlers_[i].second; |
| 125 if (reverse_rewriter) { | 138 if (reverse_rewriter) { |
| 126 GURL test_url(original); | 139 GURL test_url(original); |
| 127 URLHandler handler = *url_handlers_[i].first; | 140 URLHandler handler = *url_handlers_[i].first; |
| 128 if (!handler) { | 141 if (!handler) { |
| 129 if (reverse_rewriter(url, browser_context)) | 142 if (reverse_rewriter(url, browser_context)) |
| 130 return true; | 143 return true; |
| 131 } else if (handler(&test_url, browser_context)) { | 144 } else if (handler(&test_url, browser_context)) { |
| 132 return reverse_rewriter(url, browser_context); | 145 return reverse_rewriter(url, browser_context); |
| 133 } | 146 } |
| 134 } | 147 } |
| 135 } | 148 } |
| 136 return false; | 149 return false; |
| 137 } | 150 } |
| 138 | 151 |
| 139 } // namespace content | 152 } // namespace content |
| OLD | NEW |