| 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" |
| 27 #include "webkit/common/resource_response_info.h" | 28 #include "webkit/common/resource_response_info.h" |
| 28 | 29 |
| 29 namespace content { | 30 namespace content { |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // This class handles individual multipart responses. It is instantiated when | 33 // This class handles individual multipart responses. It is instantiated when |
| 33 // we receive HTTP status code 206 in the HTTP response. This indicates | 34 // we receive HTTP status code 206 in the HTTP response. This indicates |
| 34 // that the response could have multiple parts each separated by a boundary | 35 // that the response could have multiple parts each separated by a boundary |
| 35 // specified in the response header. | 36 // specified in the response header. |
| 36 // TODO(jam): this is similar to MultiPartResponseClient in webplugin_impl.cc, | 37 // TODO(jam): this is similar to MultiPartResponseClient in webplugin_impl.cc, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 method_(method), | 96 method_(method), |
| 96 referrer_(referrer), | 97 referrer_(referrer), |
| 97 notify_redirects_(notify_redirects), | 98 notify_redirects_(notify_redirects), |
| 98 is_plugin_src_load_(is_plugin_src_load), | 99 is_plugin_src_load_(is_plugin_src_load), |
| 99 origin_pid_(origin_pid), | 100 origin_pid_(origin_pid), |
| 100 render_frame_id_(render_frame_id), | 101 render_frame_id_(render_frame_id), |
| 101 render_view_id_(render_view_id), | 102 render_view_id_(render_view_id), |
| 102 resource_id_(resource_id), | 103 resource_id_(resource_id), |
| 103 copy_stream_data_(copy_stream_data), | 104 copy_stream_data_(copy_stream_data), |
| 104 data_offset_(0), | 105 data_offset_(0), |
| 105 pending_failure_notification_(false), | 106 pending_failure_notification_(false) { |
| 106 request_id_(-1) { | |
| 107 RequestInfo request_info; | 107 RequestInfo request_info; |
| 108 request_info.method = method; | 108 request_info.method = method; |
| 109 request_info.url = url; | 109 request_info.url = url; |
| 110 request_info.first_party_for_cookies = first_party_for_cookies; | 110 request_info.first_party_for_cookies = first_party_for_cookies; |
| 111 request_info.referrer = referrer; | 111 request_info.referrer = referrer; |
| 112 request_info.load_flags = net::LOAD_NORMAL; | 112 request_info.load_flags = net::LOAD_NORMAL; |
| 113 request_info.requestor_pid = origin_pid; | 113 request_info.requestor_pid = origin_pid; |
| 114 request_info.request_type = ResourceType::OBJECT; | 114 request_info.request_type = ResourceType::OBJECT; |
| 115 request_info.routing_id = render_view_id; | 115 request_info.routing_id = render_view_id; |
| 116 | 116 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 136 if (!content_type_found) { | 136 if (!content_type_found) { |
| 137 if (!request_info.headers.empty()) | 137 if (!request_info.headers.empty()) |
| 138 request_info.headers += "\r\n"; | 138 request_info.headers += "\r\n"; |
| 139 request_info.headers += "Content-Type: application/x-www-form-urlencoded"; | 139 request_info.headers += "Content-Type: application/x-www-form-urlencoded"; |
| 140 } | 140 } |
| 141 } else { | 141 } else { |
| 142 if (!range.empty()) | 142 if (!range.empty()) |
| 143 request_info.headers = std::string("Range: ") + range; | 143 request_info.headers = std::string("Range: ") + range; |
| 144 } | 144 } |
| 145 | 145 |
| 146 ResourceDispatcher* dispatcher = | 146 bridge_.reset(ChildThread::current()->resource_dispatcher()->CreateBridge( |
| 147 ChildThread::current()->resource_dispatcher(); | 147 request_info)); |
| 148 if (!body.empty()) { |
| 149 scoped_refptr<ResourceRequestBody> request_body = |
| 150 new ResourceRequestBody; |
| 151 request_body->AppendBytes(&body[0], body.size()); |
| 152 bridge_->SetRequestBody(request_body.get()); |
| 153 } |
| 148 | 154 |
| 149 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; | 155 bridge_->Start(this); |
| 150 | |
| 151 if (!body.empty()) | |
| 152 request_body->AppendBytes(&body[0], body.size()); | |
| 153 | |
| 154 request_id_ = dispatcher->StartAsync(request_info, request_body, this); | |
| 155 | 156 |
| 156 // TODO(jam): range requests | 157 // TODO(jam): range requests |
| 157 } | 158 } |
| 158 | 159 |
| 159 PluginURLFetcher::~PluginURLFetcher() { | 160 PluginURLFetcher::~PluginURLFetcher() { |
| 160 if (request_id_ >= 0) { | |
| 161 ChildThread::current()->resource_dispatcher()->RemovePendingRequest( | |
| 162 request_id_); | |
| 163 } | |
| 164 } | 161 } |
| 165 | 162 |
| 166 void PluginURLFetcher::Cancel() { | 163 void PluginURLFetcher::Cancel() { |
| 167 ChildThread::current()->resource_dispatcher()->Cancel(request_id_); | 164 bridge_->Cancel(); |
| 168 | 165 |
| 169 // Due to races and nested event loops, PluginURLFetcher may still receive | 166 // Due to races and nested event loops, PluginURLFetcher may still receive |
| 170 // events from the bridge before being destroyed. Do not forward additional | 167 // events from the bridge before being destroyed. Do not forward additional |
| 171 // events back to the plugin, via either |plugin_stream_| or | 168 // events back to the plugin, via either |plugin_stream_| or |
| 172 // |multipart_delegate_| which has its own pointer via | 169 // |multipart_delegate_| which has its own pointer via |
| 173 // MultiPartResponseClient. | 170 // MultiPartResponseClient. |
| 174 if (multipart_delegate_) | 171 if (multipart_delegate_) |
| 175 multipart_delegate_->Cancel(); | 172 multipart_delegate_->Cancel(); |
| 176 plugin_stream_ = NULL; | 173 plugin_stream_ = NULL; |
| 177 } | 174 } |
| 178 | 175 |
| 179 void PluginURLFetcher::URLRedirectResponse(bool allow) { | 176 void PluginURLFetcher::URLRedirectResponse(bool allow) { |
| 180 if (!plugin_stream_) | 177 if (!plugin_stream_) |
| 181 return; | 178 return; |
| 182 | 179 |
| 183 ResourceDispatcher* dispatcher = | |
| 184 ChildThread::current()->resource_dispatcher(); | |
| 185 | |
| 186 if (allow) { | 180 if (allow) { |
| 187 dispatcher->SetDefersLoading(request_id_, false); | 181 bridge_->SetDefersLoading(false); |
| 188 } else { | 182 } else { |
| 189 dispatcher->Cancel(request_id_); | 183 bridge_->Cancel(); |
| 190 plugin_stream_->DidFail(resource_id_); // That will delete |this|. | 184 plugin_stream_->DidFail(resource_id_); // That will delete |this|. |
| 191 } | 185 } |
| 192 } | 186 } |
| 193 | 187 |
| 194 void PluginURLFetcher::OnUploadProgress(uint64 position, uint64 size) { | 188 void PluginURLFetcher::OnUploadProgress(uint64 position, uint64 size) { |
| 195 } | 189 } |
| 196 | 190 |
| 197 bool PluginURLFetcher::OnReceivedRedirect( | 191 bool PluginURLFetcher::OnReceivedRedirect( |
| 198 const GURL& new_url, | 192 const GURL& new_url, |
| 199 const webkit_glue::ResourceResponseInfo& info, | 193 const webkit_glue::ResourceResponseInfo& info, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 230 // If the plugin does not participate in url redirect notifications then just | 224 // If the plugin does not participate in url redirect notifications then just |
| 231 // block cross origin 307 POST redirects. | 225 // block cross origin 307 POST redirects. |
| 232 if (!notify_redirects_) { | 226 if (!notify_redirects_) { |
| 233 if (response_code == 307 && method_ == "POST" && | 227 if (response_code == 307 && method_ == "POST" && |
| 234 old_url.GetOrigin() != new_url.GetOrigin()) { | 228 old_url.GetOrigin() != new_url.GetOrigin()) { |
| 235 plugin_stream_->DidFail(resource_id_); // That will delete |this|. | 229 plugin_stream_->DidFail(resource_id_); // That will delete |this|. |
| 236 return false; | 230 return false; |
| 237 } | 231 } |
| 238 } else { | 232 } else { |
| 239 // Pause the request while we ask the plugin what to do about the redirect. | 233 // Pause the request while we ask the plugin what to do about the redirect. |
| 240 ResourceDispatcher* dispatcher = | 234 bridge_->SetDefersLoading(true); |
| 241 ChildThread::current()->resource_dispatcher(); | |
| 242 dispatcher->SetDefersLoading(request_id_, true); | |
| 243 plugin_stream_->WillSendRequest(url_, response_code); | 235 plugin_stream_->WillSendRequest(url_, response_code); |
| 244 } | 236 } |
| 245 | 237 |
| 246 return true; | 238 return true; |
| 247 } | 239 } |
| 248 | 240 |
| 249 void PluginURLFetcher::OnReceivedResponse( | 241 void PluginURLFetcher::OnReceivedResponse( |
| 250 const webkit_glue::ResourceResponseInfo& info) { | 242 const webkit_glue::ResourceResponseInfo& info) { |
| 251 if (!plugin_stream_) | 243 if (!plugin_stream_) |
| 252 return; | 244 return; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 } | 374 } |
| 383 | 375 |
| 384 if (error_code == net::OK) { | 376 if (error_code == net::OK) { |
| 385 plugin_stream_->DidFinishLoading(resource_id_); | 377 plugin_stream_->DidFinishLoading(resource_id_); |
| 386 } else { | 378 } else { |
| 387 plugin_stream_->DidFail(resource_id_); | 379 plugin_stream_->DidFail(resource_id_); |
| 388 } | 380 } |
| 389 } | 381 } |
| 390 | 382 |
| 391 } // namespace content | 383 } // namespace content |
| OLD | NEW |