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/renderer/pepper/pepper_url_loader_host.h" | 5 #include "content/renderer/pepper/pepper_url_loader_host.h" |
6 | 6 |
7 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 7 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
8 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 8 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
9 #include "content/renderer/pepper/url_request_info_util.h" | 9 #include "content/renderer/pepper/url_request_info_util.h" |
10 #include "content/renderer/pepper/url_response_info_util.h" | 10 #include "content/renderer/pepper/url_response_info_util.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // re-entering the scoped_ptr destructor with the same scoped_ptr object | 97 // re-entering the scoped_ptr destructor with the same scoped_ptr object |
98 // via loader_.reset(). Be sure that loader_ is first NULL then destroy | 98 // via loader_.reset(). Be sure that loader_ is first NULL then destroy |
99 // the scoped_ptr. See http://crbug.com/159429. | 99 // the scoped_ptr. See http://crbug.com/159429. |
100 scoped_ptr<blink::WebURLLoader> for_destruction_only(loader_.release()); | 100 scoped_ptr<blink::WebURLLoader> for_destruction_only(loader_.release()); |
101 } | 101 } |
102 | 102 |
103 int32_t PepperURLLoaderHost::OnResourceMessageReceived( | 103 int32_t PepperURLLoaderHost::OnResourceMessageReceived( |
104 const IPC::Message& msg, | 104 const IPC::Message& msg, |
105 ppapi::host::HostMessageContext* context) { | 105 ppapi::host::HostMessageContext* context) { |
106 IPC_BEGIN_MESSAGE_MAP(PepperURLLoaderHost, msg) | 106 IPC_BEGIN_MESSAGE_MAP(PepperURLLoaderHost, msg) |
107 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 107 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_URLLoader_Open, OnHostMsgOpen) |
108 PpapiHostMsg_URLLoader_Open, | 108 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_URLLoader_SetDeferLoading, |
109 OnHostMsgOpen) | 109 OnHostMsgSetDeferLoading) |
110 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 110 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_URLLoader_Close, |
111 PpapiHostMsg_URLLoader_SetDeferLoading, | 111 OnHostMsgClose); |
112 OnHostMsgSetDeferLoading) | 112 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
113 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | 113 PpapiHostMsg_URLLoader_GrantUniversalAccess, |
114 PpapiHostMsg_URLLoader_Close, | 114 OnHostMsgGrantUniversalAccess) |
115 OnHostMsgClose); | |
116 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | |
117 PpapiHostMsg_URLLoader_GrantUniversalAccess, | |
118 OnHostMsgGrantUniversalAccess) | |
119 IPC_END_MESSAGE_MAP() | 115 IPC_END_MESSAGE_MAP() |
120 return PP_ERROR_FAILED; | 116 return PP_ERROR_FAILED; |
121 } | 117 } |
122 | 118 |
123 void PepperURLLoaderHost::willSendRequest( | 119 void PepperURLLoaderHost::willSendRequest( |
124 WebURLLoader* loader, | 120 WebURLLoader* loader, |
125 WebURLRequest& new_request, | 121 WebURLRequest& new_request, |
126 const WebURLResponse& redirect_response) { | 122 const WebURLResponse& redirect_response) { |
127 DCHECK(out_of_order_replies_.empty()); | 123 DCHECK(out_of_order_replies_.empty()); |
128 if (!request_data_.follow_redirects) { | 124 if (!request_data_.follow_redirects) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 168 } |
173 | 169 |
174 void PepperURLLoaderHost::didFinishLoading(WebURLLoader* loader, | 170 void PepperURLLoaderHost::didFinishLoading(WebURLLoader* loader, |
175 double finish_time, | 171 double finish_time, |
176 int64_t total_encoded_data_length) { | 172 int64_t total_encoded_data_length) { |
177 // Note that |loader| will be NULL for document loads. | 173 // Note that |loader| will be NULL for document loads. |
178 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_FinishedLoading(PP_OK)); | 174 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_FinishedLoading(PP_OK)); |
179 } | 175 } |
180 | 176 |
181 void PepperURLLoaderHost::didFail(WebURLLoader* loader, | 177 void PepperURLLoaderHost::didFail(WebURLLoader* loader, |
182 const WebURLError& error) { | 178 const WebURLError& error) { |
183 // Note that |loader| will be NULL for document loads. | 179 // Note that |loader| will be NULL for document loads. |
184 int32_t pp_error = PP_ERROR_FAILED; | 180 int32_t pp_error = PP_ERROR_FAILED; |
185 if (error.domain.equals(WebString::fromUTF8(net::kErrorDomain))) { | 181 if (error.domain.equals(WebString::fromUTF8(net::kErrorDomain))) { |
186 // TODO(bbudge): Extend pp_errors.h to cover interesting network errors | 182 // TODO(bbudge): Extend pp_errors.h to cover interesting network errors |
187 // from the net error domain. | 183 // from the net error domain. |
188 switch (error.reason) { | 184 switch (error.reason) { |
189 case net::ERR_ACCESS_DENIED: | 185 case net::ERR_ACCESS_DENIED: |
190 case net::ERR_NETWORK_ACCESS_DENIED: | 186 case net::ERR_NETWORK_ACCESS_DENIED: |
191 pp_error = PP_ERROR_NOACCESS; | 187 pp_error = PP_ERROR_NOACCESS; |
192 break; | 188 break; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 if (main_document_loader_) | 225 if (main_document_loader_) |
230 return PP_ERROR_INPROGRESS; | 226 return PP_ERROR_INPROGRESS; |
231 | 227 |
232 // Create a copy of the request data since CreateWebURLRequest will populate | 228 // Create a copy of the request data since CreateWebURLRequest will populate |
233 // the file refs. | 229 // the file refs. |
234 ppapi::URLRequestInfoData filled_in_request_data = request_data; | 230 ppapi::URLRequestInfoData filled_in_request_data = request_data; |
235 | 231 |
236 if (URLRequestRequiresUniversalAccess(filled_in_request_data) && | 232 if (URLRequestRequiresUniversalAccess(filled_in_request_data) && |
237 !has_universal_access_) { | 233 !has_universal_access_) { |
238 ppapi::PpapiGlobals::Get()->LogWithSource( | 234 ppapi::PpapiGlobals::Get()->LogWithSource( |
239 pp_instance(), PP_LOGLEVEL_ERROR, std::string(), | 235 pp_instance(), |
| 236 PP_LOGLEVEL_ERROR, |
| 237 std::string(), |
240 "PPB_URLLoader.Open: The URL you're requesting is " | 238 "PPB_URLLoader.Open: The URL you're requesting is " |
241 " on a different security origin than your plugin. To request " | 239 " on a different security origin than your plugin. To request " |
242 " cross-origin resources, see " | 240 " cross-origin resources, see " |
243 " PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS."); | 241 " PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS."); |
244 return PP_ERROR_NOACCESS; | 242 return PP_ERROR_NOACCESS; |
245 } | 243 } |
246 | 244 |
247 if (loader_.get()) | 245 if (loader_.get()) |
248 return PP_ERROR_INPROGRESS; | 246 return PP_ERROR_INPROGRESS; |
249 | 247 |
250 WebLocalFrame* frame = GetFrame(); | 248 WebLocalFrame* frame = GetFrame(); |
251 if (!frame) | 249 if (!frame) |
252 return PP_ERROR_FAILED; | 250 return PP_ERROR_FAILED; |
253 | 251 |
254 WebURLRequest web_request; | 252 WebURLRequest web_request; |
255 if (!CreateWebURLRequest(pp_instance(), | 253 if (!CreateWebURLRequest( |
256 &filled_in_request_data, | 254 pp_instance(), &filled_in_request_data, frame, &web_request)) { |
257 frame, | |
258 &web_request)) { | |
259 return PP_ERROR_FAILED; | 255 return PP_ERROR_FAILED; |
260 } | 256 } |
261 | 257 |
262 web_request.setTargetType(WebURLRequest::TargetIsObject); | 258 web_request.setTargetType(WebURLRequest::TargetIsObject); |
263 web_request.setRequestorProcessID(renderer_ppapi_host_->GetPluginPID()); | 259 web_request.setRequestorProcessID(renderer_ppapi_host_->GetPluginPID()); |
264 | 260 |
265 WebURLLoaderOptions options; | 261 WebURLLoaderOptions options; |
266 if (has_universal_access_) { | 262 if (has_universal_access_) { |
267 options.allowCredentials = true; | 263 options.allowCredentials = true; |
268 options.crossOriginRequestPolicy = | 264 options.crossOriginRequestPolicy = |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // messages we send to the plugin are not sent out of order. See | 390 // messages we send to the plugin are not sent out of order. See |
395 // SendUpdateToPlugin() for more details. | 391 // SendUpdateToPlugin() for more details. |
396 DCHECK(!pending_response_); | 392 DCHECK(!pending_response_); |
397 pending_response_ = true; | 393 pending_response_ = true; |
398 | 394 |
399 DataFromWebURLResponse( | 395 DataFromWebURLResponse( |
400 renderer_ppapi_host_, | 396 renderer_ppapi_host_, |
401 pp_instance(), | 397 pp_instance(), |
402 response, | 398 response, |
403 base::Bind(&PepperURLLoaderHost::DidDataFromWebURLResponse, | 399 base::Bind(&PepperURLLoaderHost::DidDataFromWebURLResponse, |
404 weak_factory_.GetWeakPtr())); | 400 weak_factory_.GetWeakPtr())); |
405 } | 401 } |
406 } | 402 } |
407 | 403 |
408 void PepperURLLoaderHost::DidDataFromWebURLResponse( | 404 void PepperURLLoaderHost::DidDataFromWebURLResponse( |
409 const ppapi::URLResponseInfoData& data) { | 405 const ppapi::URLResponseInfoData& data) { |
410 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_ReceivedResponse(data)); | 406 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_ReceivedResponse(data)); |
411 } | 407 } |
412 | 408 |
413 void PepperURLLoaderHost::UpdateProgress() { | 409 void PepperURLLoaderHost::UpdateProgress() { |
414 bool record_download = request_data_.record_download_progress; | 410 bool record_download = request_data_.record_download_progress; |
415 bool record_upload = request_data_.record_upload_progress; | 411 bool record_upload = request_data_.record_upload_progress; |
416 if (record_download || record_upload) { | 412 if (record_download || record_upload) { |
417 // Here we go through some effort to only send the exact information that | 413 // Here we go through some effort to only send the exact information that |
418 // the requestor wanted in the request flags. It would be just as | 414 // the requestor wanted in the request flags. It would be just as |
419 // efficient to send all of it, but we don't want people to rely on | 415 // efficient to send all of it, but we don't want people to rely on |
420 // getting download progress when they happen to set the upload progress | 416 // getting download progress when they happen to set the upload progress |
421 // flag. | 417 // flag. |
422 ppapi::proxy::ResourceMessageReplyParams params; | 418 ppapi::proxy::ResourceMessageReplyParams params; |
423 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_UpdateProgress( | 419 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_UpdateProgress( |
424 record_upload ? bytes_sent_ : -1, | 420 record_upload ? bytes_sent_ : -1, |
425 record_upload ? total_bytes_to_be_sent_ : -1, | 421 record_upload ? total_bytes_to_be_sent_ : -1, |
426 record_download ? bytes_received_ : -1, | 422 record_download ? bytes_received_ : -1, |
427 record_download ? total_bytes_to_be_received_ : -1)); | 423 record_download ? total_bytes_to_be_received_ : -1)); |
428 } | 424 } |
429 } | 425 } |
430 | 426 |
431 } // namespace content | 427 } // namespace content |
OLD | NEW |