Chromium Code Reviews| 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/multipart_response_delegate.h" | 9 #include "content/child/multipart_response_delegate.h" |
| 10 #include "content/child/npapi/plugin_host.h" | 10 #include "content/child/npapi/plugin_host.h" |
| 11 #include "content/child/npapi/plugin_instance.h" | 11 #include "content/child/npapi/plugin_instance.h" |
| 12 #include "content/child/npapi/plugin_stream_url.h" | 12 #include "content/child/npapi/plugin_stream_url.h" |
| 13 #include "content/child/npapi/webplugin.h" | 13 #include "content/child/npapi/webplugin.h" |
| 14 #include "content/child/npapi/webplugin_resource_client.h" | 14 #include "content/child/npapi/webplugin_resource_client.h" |
| 15 #include "content/child/plugin_messages.h" | 15 #include "content/child/plugin_messages.h" |
| 16 #include "content/child/request_extra_data.h" | 16 #include "content/child/request_extra_data.h" |
| 17 #include "content/child/request_info.h" | 17 #include "content/child/request_info.h" |
| 18 #include "content/child/resource_dispatcher.h" | 18 #include "content/child/resource_dispatcher.h" |
| 19 #include "content/child/web_url_loader_impl.h" | 19 #include "content/child/web_url_loader_impl.h" |
| 20 #include "content/common/resource_request_body.h" | 20 #include "content/common/resource_request_body.h" |
| 21 #include "content/common/service_worker/service_worker_types.h" | 21 #include "content/common/service_worker/service_worker_types.h" |
| 22 #include "content/public/common/resource_response_info.h" | 22 #include "content/public/common/resource_response_info.h" |
| 23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
| 26 #include "net/url_request/url_request.h" | 26 #include "net/url_request/redirect_info.h" |
| 27 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 27 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 28 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 28 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 29 #include "webkit/child/resource_loader_bridge.h" | 29 #include "webkit/child/resource_loader_bridge.h" |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // This class handles individual multipart responses. It is instantiated when | 34 // This class handles individual multipart responses. It is instantiated when |
| 35 // we receive HTTP status code 206 in the HTTP response. This indicates | 35 // we receive HTTP status code 206 in the HTTP response. This indicates |
| 36 // that the response could have multiple parts each separated by a boundary | 36 // that the response could have multiple parts each separated by a boundary |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 } else { | 184 } else { |
| 185 bridge_->Cancel(); | 185 bridge_->Cancel(); |
| 186 plugin_stream_->DidFail(resource_id_); // That will delete |this|. | 186 plugin_stream_->DidFail(resource_id_); // That will delete |this|. |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 void PluginURLFetcher::OnUploadProgress(uint64 position, uint64 size) { | 190 void PluginURLFetcher::OnUploadProgress(uint64 position, uint64 size) { |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool PluginURLFetcher::OnReceivedRedirect( | 193 bool PluginURLFetcher::OnReceivedRedirect( |
| 194 const GURL& new_url, | 194 const net::RedirectInfo& redirect_info, |
| 195 const GURL& new_first_party_for_cookies, | |
| 196 const ResourceResponseInfo& info) { | 195 const ResourceResponseInfo& info) { |
| 197 if (!plugin_stream_) | 196 if (!plugin_stream_) |
| 198 return false; | 197 return false; |
| 199 | 198 |
| 200 // TODO(jam): THIS LOGIC IS COPIED FROM WebPluginImpl::willSendRequest until | 199 // TODO(jam): THIS LOGIC IS COPIED FROM WebPluginImpl::willSendRequest until |
| 201 // kDirectNPAPIRequests is the default and we can remove the old path there. | 200 // kDirectNPAPIRequests is the default and we can remove the old path there. |
| 202 | 201 |
| 203 // Currently this check is just to catch an https -> http redirect when | 202 // Currently this check is just to catch an https -> http redirect when |
| 204 // loading the main plugin src URL. Longer term, we could investigate | 203 // loading the main plugin src URL. Longer term, we could investigate |
| 205 // firing mixed diplay or scripting issues for subresource loads | 204 // firing mixed diplay or scripting issues for subresource loads |
| 206 // initiated by plug-ins. | 205 // initiated by plug-ins. |
| 207 if (is_plugin_src_load_ && | 206 if (is_plugin_src_load_ && |
| 208 !plugin_stream_->instance()->webplugin()->CheckIfRunInsecureContent( | 207 !plugin_stream_->instance()->webplugin()->CheckIfRunInsecureContent( |
| 209 new_url)) { | 208 redirect_info.url)) { |
| 210 plugin_stream_->DidFail(resource_id_); // That will delete |this|. | 209 plugin_stream_->DidFail(resource_id_); // That will delete |this|. |
| 211 return false; | 210 return false; |
| 212 } | 211 } |
| 213 | 212 |
| 214 // It's unfortunate that this logic of when a redirect's method changes is | |
| 215 // in url_request.cc, but weburlloader_impl.cc and this file have to duplicate | |
| 216 // it instead of passing that information. | |
| 217 int response_code; | |
| 218 if (info.headers) { | |
| 219 response_code = info.headers->response_code(); | |
| 220 } else { | |
| 221 // A redirect may have NULL headers if it came from URLRequestRedirectJob. | |
| 222 // | |
| 223 // TODO(davidben): Get the actual response code from the browser. Either | |
| 224 // fake enough of headers to have a response code or pass it down as part of | |
| 225 // https://crbug.com/384609. | |
| 226 response_code = 307; | |
| 227 } | |
| 228 method_ = net::URLRequest::ComputeMethodForRedirect(method_, response_code); | |
| 229 GURL old_url = url_; | 213 GURL old_url = url_; |
| 230 url_ = new_url; | 214 url_ = redirect_info.url; |
| 231 first_party_for_cookies_ = new_first_party_for_cookies; | 215 method_ = redirect_info.method; |
|
mmenke
2014/07/17 16:55:09
I don't think we need method_ any more - we only n
davidben
2014/07/17 22:03:54
Done.
| |
| 216 first_party_for_cookies_ = redirect_info.first_party_for_cookies; | |
| 232 | 217 |
| 233 // If the plugin does not participate in url redirect notifications then just | 218 // If the plugin does not participate in url redirect notifications then just |
| 234 // block cross origin 307 POST redirects. | 219 // block cross origin 307 POST redirects. |
|
mmenke
2014/07/17 16:55:09
Hrm...Should we be allowing other cross origin red
davidben
2014/07/17 22:03:54
I'm not sure. I suspect that actually should inclu
| |
| 235 if (!notify_redirects_) { | 220 if (!notify_redirects_) { |
| 236 if (response_code == 307 && method_ == "POST" && | 221 if (redirect_info.status_code == 307 && method_ == "POST" && |
| 237 old_url.GetOrigin() != new_url.GetOrigin()) { | 222 old_url.GetOrigin() != url_.GetOrigin()) { |
| 238 plugin_stream_->DidFail(resource_id_); // That will delete |this|. | 223 plugin_stream_->DidFail(resource_id_); // That will delete |this|. |
| 239 return false; | 224 return false; |
| 240 } | 225 } |
| 241 } else { | 226 } else { |
| 242 // Pause the request while we ask the plugin what to do about the redirect. | 227 // Pause the request while we ask the plugin what to do about the redirect. |
| 243 bridge_->SetDefersLoading(true); | 228 bridge_->SetDefersLoading(true); |
| 244 plugin_stream_->WillSendRequest(url_, response_code); | 229 plugin_stream_->WillSendRequest(url_, redirect_info.status_code); |
| 245 } | 230 } |
| 246 | 231 |
| 247 return true; | 232 return true; |
| 248 } | 233 } |
| 249 | 234 |
| 250 void PluginURLFetcher::OnReceivedResponse(const ResourceResponseInfo& info) { | 235 void PluginURLFetcher::OnReceivedResponse(const ResourceResponseInfo& info) { |
| 251 if (!plugin_stream_) | 236 if (!plugin_stream_) |
| 252 return; | 237 return; |
| 253 | 238 |
| 254 // TODO(jam): THIS LOGIC IS COPIED FROM WebPluginImpl::didReceiveResponse | 239 // TODO(jam): THIS LOGIC IS COPIED FROM WebPluginImpl::didReceiveResponse |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 } | 367 } |
| 383 | 368 |
| 384 if (error_code == net::OK) { | 369 if (error_code == net::OK) { |
| 385 plugin_stream_->DidFinishLoading(resource_id_); | 370 plugin_stream_->DidFinishLoading(resource_id_); |
| 386 } else { | 371 } else { |
| 387 plugin_stream_->DidFail(resource_id_); | 372 plugin_stream_->DidFail(resource_id_); |
| 388 } | 373 } |
| 389 } | 374 } |
| 390 | 375 |
| 391 } // namespace content | 376 } // namespace content |
| OLD | NEW |