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_impl.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "content/browser/webui/web_ui_impl.h" | 8 #include "content/browser/webui/web_ui_impl.h" |
9 #include "content/public/browser/content_browser_client.h" | 9 #include "content/public/browser/content_browser_client.h" |
10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 | 12 |
| 13 using content::BrowserURLHandler; |
| 14 |
13 // Handles rewriting view-source URLs for what we'll actually load. | 15 // Handles rewriting view-source URLs for what we'll actually load. |
14 static bool HandleViewSource(GURL* url, | 16 static bool HandleViewSource(GURL* url, |
15 content::BrowserContext* browser_context) { | 17 content::BrowserContext* browser_context) { |
16 if (url->SchemeIs(chrome::kViewSourceScheme)) { | 18 if (url->SchemeIs(chrome::kViewSourceScheme)) { |
17 // Load the inner URL instead. | 19 // Load the inner URL instead. |
18 *url = GURL(url->path()); | 20 *url = GURL(url->path()); |
19 | 21 |
20 // Bug 26129: limit view-source to view the content and not any | 22 // Bug 26129: limit view-source to view the content and not any |
21 // other kind of 'active' url scheme like 'javascript' or 'data'. | 23 // other kind of 'active' url scheme like 'javascript' or 'data'. |
22 static const char* const allowed_sub_schemes[] = { | 24 static const char* const allowed_sub_schemes[] = { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 content::BrowserContext* browser_context) { | 65 content::BrowserContext* browser_context) { |
64 // Circumvent processing URLs that the renderer process will handle. | 66 // Circumvent processing URLs that the renderer process will handle. |
65 return *url == GURL(chrome::kChromeUICrashURL) || | 67 return *url == GURL(chrome::kChromeUICrashURL) || |
66 *url == GURL(chrome::kChromeUIHangURL) || | 68 *url == GURL(chrome::kChromeUIHangURL) || |
67 *url == GURL(chrome::kChromeUIKillURL) || | 69 *url == GURL(chrome::kChromeUIKillURL) || |
68 *url == GURL(chrome::kChromeUIShorthangURL); | 70 *url == GURL(chrome::kChromeUIShorthangURL); |
69 } | 71 } |
70 | 72 |
71 // static | 73 // static |
72 BrowserURLHandler* BrowserURLHandler::GetInstance() { | 74 BrowserURLHandler* BrowserURLHandler::GetInstance() { |
73 return Singleton<BrowserURLHandler>::get(); | 75 return BrowserURLHandlerImpl::GetInstance(); |
74 } | 76 } |
75 | 77 |
76 // static | 78 // static |
77 BrowserURLHandler::URLHandler BrowserURLHandler::null_handler() { | 79 BrowserURLHandler::URLHandler BrowserURLHandler::null_handler() { |
78 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det
ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair | 80 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det
ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair |
79 return NULL; | 81 return NULL; |
80 } | 82 } |
81 | 83 |
82 BrowserURLHandler::BrowserURLHandler() { | 84 // static |
83 AddHandlerPair(&HandleDebugUrl, BrowserURLHandler::null_handler()); | 85 BrowserURLHandlerImpl* BrowserURLHandlerImpl::GetInstance() { |
| 86 return Singleton<BrowserURLHandlerImpl>::get(); |
| 87 } |
| 88 |
| 89 BrowserURLHandlerImpl::BrowserURLHandlerImpl() { |
| 90 AddHandlerPair(&HandleDebugUrl, BrowserURLHandlerImpl::null_handler()); |
84 | 91 |
85 content::GetContentClient()->browser()->BrowserURLHandlerCreated(this); | 92 content::GetContentClient()->browser()->BrowserURLHandlerCreated(this); |
86 | 93 |
87 // view-source: | 94 // view-source: |
88 AddHandlerPair(&HandleViewSource, &ReverseViewSource); | 95 AddHandlerPair(&HandleViewSource, &ReverseViewSource); |
89 } | 96 } |
90 | 97 |
91 BrowserURLHandler::~BrowserURLHandler() { | 98 BrowserURLHandlerImpl::~BrowserURLHandlerImpl() { |
92 } | 99 } |
93 | 100 |
94 void BrowserURLHandler::AddHandlerPair(URLHandler handler, | 101 void BrowserURLHandlerImpl::AddHandlerPair(URLHandler handler, |
95 URLHandler reverse_handler) { | 102 URLHandler reverse_handler) { |
96 url_handlers_.push_back(HandlerPair(handler, reverse_handler)); | 103 url_handlers_.push_back(HandlerPair(handler, reverse_handler)); |
97 } | 104 } |
98 | 105 |
99 void BrowserURLHandler::RewriteURLIfNecessary( | 106 void BrowserURLHandlerImpl::RewriteURLIfNecessary( |
100 GURL* url, | 107 GURL* url, |
101 content::BrowserContext* browser_context, | 108 content::BrowserContext* browser_context, |
102 bool* reverse_on_redirect) { | 109 bool* reverse_on_redirect) { |
103 for (size_t i = 0; i < url_handlers_.size(); ++i) { | 110 for (size_t i = 0; i < url_handlers_.size(); ++i) { |
104 URLHandler handler = *url_handlers_[i].first; | 111 URLHandler handler = *url_handlers_[i].first; |
105 if (handler && handler(url, browser_context)) { | 112 if (handler && handler(url, browser_context)) { |
106 *reverse_on_redirect = (url_handlers_[i].second != NULL); | 113 *reverse_on_redirect = (url_handlers_[i].second != NULL); |
107 return; | 114 return; |
108 } | 115 } |
109 } | 116 } |
110 } | 117 } |
111 | 118 |
112 bool BrowserURLHandler::ReverseURLRewrite( | 119 bool BrowserURLHandlerImpl::ReverseURLRewrite( |
113 GURL* url, const GURL& original, content::BrowserContext* browser_context) { | 120 GURL* url, const GURL& original, content::BrowserContext* browser_context) { |
114 for (size_t i = 0; i < url_handlers_.size(); ++i) { | 121 for (size_t i = 0; i < url_handlers_.size(); ++i) { |
115 URLHandler reverse_rewriter = *url_handlers_[i].second; | 122 URLHandler reverse_rewriter = *url_handlers_[i].second; |
116 if (reverse_rewriter) { | 123 if (reverse_rewriter) { |
117 GURL test_url(original); | 124 GURL test_url(original); |
118 URLHandler handler = *url_handlers_[i].first; | 125 URLHandler handler = *url_handlers_[i].first; |
119 if (!handler) { | 126 if (!handler) { |
120 if (reverse_rewriter(url, browser_context)) | 127 if (reverse_rewriter(url, browser_context)) |
121 return true; | 128 return true; |
122 } else if (handler(&test_url, browser_context)) { | 129 } else if (handler(&test_url, browser_context)) { |
123 return reverse_rewriter(url, browser_context); | 130 return reverse_rewriter(url, browser_context); |
124 } | 131 } |
125 } | 132 } |
126 } | 133 } |
127 return false; | 134 return false; |
128 } | 135 } |
OLD | NEW |