OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/child/npapi/plugin_url_fetcher.h" | 5 #include "content/child/npapi/plugin_url_fetcher.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "content/child/child_thread.h" | 8 #include "content/child/child_thread.h" |
9 #include "content/child/npapi/plugin_host.h" | 9 #include "content/child/npapi/plugin_host.h" |
10 #include "content/child/npapi/plugin_instance.h" | 10 #include "content/child/npapi/plugin_instance.h" |
11 #include "content/child/npapi/plugin_stream_url.h" | 11 #include "content/child/npapi/plugin_stream_url.h" |
12 #include "content/child/npapi/webplugin.h" | 12 #include "content/child/npapi/webplugin.h" |
13 #include "content/child/npapi/webplugin_resource_client.h" | 13 #include "content/child/npapi/webplugin_resource_client.h" |
14 #include "content/child/plugin_messages.h" | 14 #include "content/child/plugin_messages.h" |
15 #include "content/child/request_extra_data.h" | 15 #include "content/child/request_extra_data.h" |
16 #include "content/child/request_info.h" | 16 #include "content/child/request_info.h" |
17 #include "content/child/resource_dispatcher.h" | 17 #include "content/child/resource_dispatcher.h" |
18 #include "content/child/web_url_loader_impl.h" | 18 #include "content/child/web_url_loader_impl.h" |
19 #include "content/common/resource_request_body.h" | 19 #include "content/common/resource_request_body.h" |
20 #include "content/common/service_worker/service_worker_types.h" | 20 #include "content/common/service_worker/service_worker_types.h" |
21 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
24 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 24 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
25 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 25 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
26 #include "webkit/child/multipart_response_delegate.h" | 26 #include "webkit/child/multipart_response_delegate.h" |
27 #include "webkit/child/resource_loader_bridge.h" | |
28 #include "webkit/common/resource_response_info.h" | 27 #include "webkit/common/resource_response_info.h" |
29 | 28 |
30 namespace content { | 29 namespace content { |
31 namespace { | 30 namespace { |
32 | 31 |
33 // This class handles individual multipart responses. It is instantiated when | 32 // This class handles individual multipart responses. It is instantiated when |
34 // we receive HTTP status code 206 in the HTTP response. This indicates | 33 // we receive HTTP status code 206 in the HTTP response. This indicates |
35 // that the response could have multiple parts each separated by a boundary | 34 // that the response could have multiple parts each separated by a boundary |
36 // specified in the response header. | 35 // specified in the response header. |
37 // TODO(jam): this is similar to MultiPartResponseClient in webplugin_impl.cc, | 36 // TODO(jam): this is similar to MultiPartResponseClient in webplugin_impl.cc, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 if (!content_type_found) { | 135 if (!content_type_found) { |
137 if (!request_info.headers.empty()) | 136 if (!request_info.headers.empty()) |
138 request_info.headers += "\r\n"; | 137 request_info.headers += "\r\n"; |
139 request_info.headers += "Content-Type: application/x-www-form-urlencoded"; | 138 request_info.headers += "Content-Type: application/x-www-form-urlencoded"; |
140 } | 139 } |
141 } else { | 140 } else { |
142 if (!range.empty()) | 141 if (!range.empty()) |
143 request_info.headers = std::string("Range: ") + range; | 142 request_info.headers = std::string("Range: ") + range; |
144 } | 143 } |
145 | 144 |
146 bridge_.reset(ChildThread::current()->resource_dispatcher()->CreateBridge( | 145 ResourceDispatcher* dispatcher = |
147 request_info)); | 146 ChildThread::current()->resource_dispatcher(); |
| 147 dispatcher->CreateBridge(request_info); |
| 148 |
148 if (!body.empty()) { | 149 if (!body.empty()) { |
149 scoped_refptr<ResourceRequestBody> request_body = | 150 scoped_refptr<ResourceRequestBody> request_body = |
150 new ResourceRequestBody; | 151 new ResourceRequestBody; |
151 request_body->AppendBytes(&body[0], body.size()); | 152 request_body->AppendBytes(&body[0], body.size()); |
152 bridge_->SetRequestBody(request_body.get()); | 153 dispatcher->SetRequestBody(request_body.get()); |
153 } | 154 } |
154 | 155 |
155 bridge_->Start(this); | 156 dispatcher->Start(this); |
156 | 157 |
157 // TODO(jam): range requests | 158 // TODO(jam): range requests |
158 } | 159 } |
159 | 160 |
160 PluginURLFetcher::~PluginURLFetcher() { | 161 PluginURLFetcher::~PluginURLFetcher() { |
161 } | 162 } |
162 | 163 |
163 void PluginURLFetcher::Cancel() { | 164 void PluginURLFetcher::Cancel() { |
164 bridge_->Cancel(); | 165 ChildThread::current()->resource_dispatcher()->Cancel(); |
165 | 166 |
166 // Due to races and nested event loops, PluginURLFetcher may still receive | 167 // Due to races and nested event loops, PluginURLFetcher may still receive |
167 // events from the bridge before being destroyed. Do not forward additional | 168 // events from the bridge before being destroyed. Do not forward additional |
168 // events back to the plugin, via either |plugin_stream_| or | 169 // events back to the plugin, via either |plugin_stream_| or |
169 // |multipart_delegate_| which has its own pointer via | 170 // |multipart_delegate_| which has its own pointer via |
170 // MultiPartResponseClient. | 171 // MultiPartResponseClient. |
171 if (multipart_delegate_) | 172 if (multipart_delegate_) |
172 multipart_delegate_->Cancel(); | 173 multipart_delegate_->Cancel(); |
173 plugin_stream_ = NULL; | 174 plugin_stream_ = NULL; |
174 } | 175 } |
175 | 176 |
176 void PluginURLFetcher::URLRedirectResponse(bool allow) { | 177 void PluginURLFetcher::URLRedirectResponse(bool allow) { |
177 if (!plugin_stream_) | 178 if (!plugin_stream_) |
178 return; | 179 return; |
179 | 180 |
| 181 ResourceDispatcher* dispatcher = |
| 182 ChildThread::current()->resource_dispatcher(); |
| 183 |
180 if (allow) { | 184 if (allow) { |
181 bridge_->SetDefersLoading(false); | 185 dispatcher->SetDefersLoading(false); |
182 } else { | 186 } else { |
183 bridge_->Cancel(); | 187 dispatcher->Cancel(); |
184 plugin_stream_->DidFail(resource_id_); // That will delete |this|. | 188 plugin_stream_->DidFail(resource_id_); // That will delete |this|. |
185 } | 189 } |
186 } | 190 } |
187 | 191 |
188 void PluginURLFetcher::OnUploadProgress(uint64 position, uint64 size) { | 192 void PluginURLFetcher::OnUploadProgress(uint64 position, uint64 size) { |
189 } | 193 } |
190 | 194 |
191 bool PluginURLFetcher::OnReceivedRedirect( | 195 bool PluginURLFetcher::OnReceivedRedirect( |
192 const GURL& new_url, | 196 const GURL& new_url, |
193 const webkit_glue::ResourceResponseInfo& info, | 197 const webkit_glue::ResourceResponseInfo& info, |
(...skipping 30 matching lines...) Expand all Loading... |
224 // If the plugin does not participate in url redirect notifications then just | 228 // If the plugin does not participate in url redirect notifications then just |
225 // block cross origin 307 POST redirects. | 229 // block cross origin 307 POST redirects. |
226 if (!notify_redirects_) { | 230 if (!notify_redirects_) { |
227 if (response_code == 307 && method_ == "POST" && | 231 if (response_code == 307 && method_ == "POST" && |
228 old_url.GetOrigin() != new_url.GetOrigin()) { | 232 old_url.GetOrigin() != new_url.GetOrigin()) { |
229 plugin_stream_->DidFail(resource_id_); // That will delete |this|. | 233 plugin_stream_->DidFail(resource_id_); // That will delete |this|. |
230 return false; | 234 return false; |
231 } | 235 } |
232 } else { | 236 } else { |
233 // Pause the request while we ask the plugin what to do about the redirect. | 237 // Pause the request while we ask the plugin what to do about the redirect. |
234 bridge_->SetDefersLoading(true); | 238 ResourceDispatcher* dispatcher = |
| 239 ChildThread::current()->resource_dispatcher(); |
| 240 dispatcher->SetDefersLoading(true); |
235 plugin_stream_->WillSendRequest(url_, response_code); | 241 plugin_stream_->WillSendRequest(url_, response_code); |
236 } | 242 } |
237 | 243 |
238 return true; | 244 return true; |
239 } | 245 } |
240 | 246 |
241 void PluginURLFetcher::OnReceivedResponse( | 247 void PluginURLFetcher::OnReceivedResponse( |
242 const webkit_glue::ResourceResponseInfo& info) { | 248 const webkit_glue::ResourceResponseInfo& info) { |
243 if (!plugin_stream_) | 249 if (!plugin_stream_) |
244 return; | 250 return; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 } | 380 } |
375 | 381 |
376 if (error_code == net::OK) { | 382 if (error_code == net::OK) { |
377 plugin_stream_->DidFinishLoading(resource_id_); | 383 plugin_stream_->DidFinishLoading(resource_id_); |
378 } else { | 384 } else { |
379 plugin_stream_->DidFail(resource_id_); | 385 plugin_stream_->DidFail(resource_id_); |
380 } | 386 } |
381 } | 387 } |
382 | 388 |
383 } // namespace content | 389 } // namespace content |
OLD | NEW |