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 "chrome/browser/custom_handlers/protocol_handler_registry.h" | 5 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // Clears the default for the provided protocol. | 83 // Clears the default for the provided protocol. |
84 // Should be called only from the IO thread. | 84 // Should be called only from the IO thread. |
85 void ClearDefault(const std::string& scheme); | 85 void ClearDefault(const std::string& scheme); |
86 | 86 |
87 // Makes this ProtocolHandler the default handler for its protocol. | 87 // Makes this ProtocolHandler the default handler for its protocol. |
88 // Should be called only from the IO thread. | 88 // Should be called only from the IO thread. |
89 void SetDefault(const ProtocolHandler& handler); | 89 void SetDefault(const ProtocolHandler& handler); |
90 | 90 |
91 // Creates a URL request job for the given request if there is a matching | 91 // Creates a URL request job for the given request if there is a matching |
92 // protocol handler, returns NULL otherwise. | 92 // protocol handler, returns NULL otherwise. |
93 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const; | 93 net::URLRequestJob* MaybeCreateJob( |
| 94 net::URLRequest* request, net::NetworkDelegate* network_delegate) const; |
94 | 95 |
95 // Indicate that the registry has been enabled in the IO thread's | 96 // Indicate that the registry has been enabled in the IO thread's |
96 // copy of the data. | 97 // copy of the data. |
97 void Enable() { enabled_ = true; } | 98 void Enable() { enabled_ = true; } |
98 | 99 |
99 // Indicate that the registry has been disabled in the IO thread's copy of | 100 // Indicate that the registry has been disabled in the IO thread's copy of |
100 // the data. | 101 // the data. |
101 void Disable() { enabled_ = false; } | 102 void Disable() { enabled_ = false; } |
102 | 103 |
103 private: | 104 private: |
(...skipping 26 matching lines...) Expand all Loading... |
130 void ProtocolHandlerRegistry::Core::SetDefault(const ProtocolHandler& handler) { | 131 void ProtocolHandlerRegistry::Core::SetDefault(const ProtocolHandler& handler) { |
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
132 ClearDefault(handler.protocol()); | 133 ClearDefault(handler.protocol()); |
133 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); | 134 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); |
134 } | 135 } |
135 | 136 |
136 // Create a new job for the supplied |URLRequest| if a default handler | 137 // Create a new job for the supplied |URLRequest| if a default handler |
137 // is registered and the associated handler is able to interpret | 138 // is registered and the associated handler is able to interpret |
138 // the url from |request|. | 139 // the url from |request|. |
139 net::URLRequestJob* ProtocolHandlerRegistry::Core::MaybeCreateJob( | 140 net::URLRequestJob* ProtocolHandlerRegistry::Core::MaybeCreateJob( |
140 net::URLRequest* request) const { | 141 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
142 | 143 |
143 ProtocolHandler handler = LookupHandler(default_handlers_, | 144 ProtocolHandler handler = LookupHandler(default_handlers_, |
144 request->url().scheme()); | 145 request->url().scheme()); |
145 if (handler.IsEmpty()) | 146 if (handler.IsEmpty()) |
146 return NULL; | 147 return NULL; |
147 | 148 |
148 GURL translated_url(handler.TranslateUrl(request->url())); | 149 GURL translated_url(handler.TranslateUrl(request->url())); |
149 if (!translated_url.is_valid()) | 150 if (!translated_url.is_valid()) |
150 return NULL; | 151 return NULL; |
151 | 152 |
152 return new net::URLRequestRedirectJob(request, translated_url); | 153 return new net::URLRequestRedirectJob( |
| 154 request, network_delegate, translated_url); |
153 } | 155 } |
154 | 156 |
155 // URLInterceptor ------------------------------------------------------------ | 157 // URLInterceptor ------------------------------------------------------------ |
156 | 158 |
157 // Instances of this class are produced for ownership by the IO | 159 // Instances of this class are produced for ownership by the IO |
158 // thread where it handler URL requests. We should never hold | 160 // thread where it handler URL requests. We should never hold |
159 // any pointers on this class, only produce them in response to | 161 // any pointers on this class, only produce them in response to |
160 // requests via |ProtocolHandlerRegistry::CreateURLInterceptor|. | 162 // requests via |ProtocolHandlerRegistry::CreateURLInterceptor|. |
161 class ProtocolHandlerRegistry::URLInterceptor | 163 class ProtocolHandlerRegistry::URLInterceptor |
162 : public net::URLRequestJobFactory::Interceptor { | 164 : public net::URLRequestJobFactory::Interceptor { |
163 public: | 165 public: |
164 explicit URLInterceptor(Core* core); | 166 explicit URLInterceptor(Core* core); |
165 virtual ~URLInterceptor(); | 167 virtual ~URLInterceptor(); |
166 | 168 |
167 virtual net::URLRequestJob* MaybeIntercept( | 169 virtual net::URLRequestJob* MaybeIntercept( |
168 net::URLRequest* request) const OVERRIDE; | 170 net::URLRequest* request, |
| 171 net::NetworkDelegate* network_delegate) const OVERRIDE; |
169 | 172 |
170 virtual bool WillHandleProtocol(const std::string& protocol) const OVERRIDE; | 173 virtual bool WillHandleProtocol(const std::string& protocol) const OVERRIDE; |
171 | 174 |
172 virtual net::URLRequestJob* MaybeInterceptRedirect( | 175 virtual net::URLRequestJob* MaybeInterceptRedirect( |
173 const GURL& url, net::URLRequest* request) const OVERRIDE { | 176 const GURL& url, |
| 177 net::URLRequest* request, |
| 178 net::NetworkDelegate* network_delegate) const OVERRIDE { |
174 return NULL; | 179 return NULL; |
175 } | 180 } |
176 | 181 |
177 virtual net::URLRequestJob* MaybeInterceptResponse( | 182 virtual net::URLRequestJob* MaybeInterceptResponse( |
178 net::URLRequest* request) const OVERRIDE { | 183 net::URLRequest* request, |
| 184 net::NetworkDelegate* network_delegate) const OVERRIDE { |
179 return NULL; | 185 return NULL; |
180 } | 186 } |
181 | 187 |
182 private: | 188 private: |
183 scoped_refptr<Core> core_; | 189 scoped_refptr<Core> core_; |
184 DISALLOW_COPY_AND_ASSIGN(URLInterceptor); | 190 DISALLOW_COPY_AND_ASSIGN(URLInterceptor); |
185 }; | 191 }; |
186 | 192 |
187 ProtocolHandlerRegistry::URLInterceptor::URLInterceptor(Core* core) | 193 ProtocolHandlerRegistry::URLInterceptor::URLInterceptor(Core* core) |
188 : core_(core) { | 194 : core_(core) { |
189 DCHECK(core_); | 195 DCHECK(core_); |
190 } | 196 } |
191 | 197 |
192 ProtocolHandlerRegistry::URLInterceptor::~URLInterceptor() { | 198 ProtocolHandlerRegistry::URLInterceptor::~URLInterceptor() { |
193 } | 199 } |
194 | 200 |
195 net::URLRequestJob* ProtocolHandlerRegistry::URLInterceptor::MaybeIntercept( | 201 net::URLRequestJob* ProtocolHandlerRegistry::URLInterceptor::MaybeIntercept( |
196 net::URLRequest* request) const { | 202 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
198 | 204 |
199 return core_->MaybeCreateJob(request); | 205 return core_->MaybeCreateJob(request, network_delegate); |
200 } | 206 } |
201 | 207 |
202 bool ProtocolHandlerRegistry::URLInterceptor::WillHandleProtocol( | 208 bool ProtocolHandlerRegistry::URLInterceptor::WillHandleProtocol( |
203 const std::string& protocol) const { | 209 const std::string& protocol) const { |
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
205 | 211 |
206 return core_->IsHandledProtocol(protocol); | 212 return core_->IsHandledProtocol(protocol); |
207 } | 213 } |
208 | 214 |
209 // DefaultClientObserver ------------------------------------------------------ | 215 // DefaultClientObserver ------------------------------------------------------ |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 } | 869 } |
864 | 870 |
865 net::URLRequestJobFactory::Interceptor* | 871 net::URLRequestJobFactory::Interceptor* |
866 ProtocolHandlerRegistry::CreateURLInterceptor() { | 872 ProtocolHandlerRegistry::CreateURLInterceptor() { |
867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 873 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
868 // this is always created on the UI thread (in profile_io's | 874 // this is always created on the UI thread (in profile_io's |
869 // InitializeOnUIThread. Any method calls must be done | 875 // InitializeOnUIThread. Any method calls must be done |
870 // on the IO thread (this is checked). | 876 // on the IO thread (this is checked). |
871 return new URLInterceptor(core_); | 877 return new URLInterceptor(core_); |
872 } | 878 } |
OLD | NEW |