Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: webkit/plugins/ppapi/ppb_url_loader_impl.cc

Issue 7669055: Remove webkit::ppapi::Resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nulls auditeed Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_url_loader_impl.h" 5 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "ppapi/c/pp_completion_callback.h" 9 #include "ppapi/c/pp_completion_callback.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 11 matching lines...) Expand all
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h " 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h "
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
26 #include "webkit/appcache/web_application_cache_host_impl.h" 26 #include "webkit/appcache/web_application_cache_host_impl.h"
27 #include "webkit/plugins/ppapi/common.h" 27 #include "webkit/plugins/ppapi/common.h"
28 #include "webkit/plugins/ppapi/plugin_module.h" 28 #include "webkit/plugins/ppapi/plugin_module.h"
29 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 29 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
30 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" 30 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
31 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" 31 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h"
32 #include "webkit/plugins/ppapi/resource_helper.h"
32 33
33 using appcache::WebApplicationCacheHostImpl; 34 using appcache::WebApplicationCacheHostImpl;
35 using ppapi::Resource;
34 using ppapi::thunk::EnterResourceNoLock; 36 using ppapi::thunk::EnterResourceNoLock;
35 using ppapi::thunk::PPB_URLLoader_API; 37 using ppapi::thunk::PPB_URLLoader_API;
36 using ppapi::thunk::PPB_URLRequestInfo_API; 38 using ppapi::thunk::PPB_URLRequestInfo_API;
37 using WebKit::WebFrame; 39 using WebKit::WebFrame;
38 using WebKit::WebString; 40 using WebKit::WebString;
39 using WebKit::WebURL; 41 using WebKit::WebURL;
40 using WebKit::WebURLError; 42 using WebKit::WebURLError;
41 using WebKit::WebURLLoader; 43 using WebKit::WebURLLoader;
42 using WebKit::WebURLLoaderOptions; 44 using WebKit::WebURLLoaderOptions;
43 using WebKit::WebURLRequest; 45 using WebKit::WebURLRequest;
44 using WebKit::WebURLResponse; 46 using WebKit::WebURLResponse;
45 47
46 #ifdef _MSC_VER 48 #ifdef _MSC_VER
47 // Do not warn about use of std::copy with raw pointers. 49 // Do not warn about use of std::copy with raw pointers.
48 #pragma warning(disable : 4996) 50 #pragma warning(disable : 4996)
49 #endif 51 #endif
50 52
51 namespace webkit { 53 namespace webkit {
52 namespace ppapi { 54 namespace ppapi {
53 55
54 PPB_URLLoader_Impl::PPB_URLLoader_Impl(PluginInstance* instance, 56 namespace {
57
58 WebFrame* GetFrameForResource(const Resource* resource) {
59 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(resource);
60 if (!plugin_instance)
61 return NULL;
62 return plugin_instance->container()->element().document().frame();
63 }
64
65 } // namespace
66
67 PPB_URLLoader_Impl::PPB_URLLoader_Impl(PP_Instance instance,
55 bool main_document_loader) 68 bool main_document_loader)
56 : Resource(instance), 69 : Resource(instance),
57 main_document_loader_(main_document_loader), 70 main_document_loader_(main_document_loader),
58 pending_callback_(), 71 pending_callback_(),
59 bytes_sent_(0), 72 bytes_sent_(0),
60 total_bytes_to_be_sent_(-1), 73 total_bytes_to_be_sent_(-1),
61 bytes_received_(0), 74 bytes_received_(0),
62 total_bytes_to_be_received_(-1), 75 total_bytes_to_be_received_(-1),
63 user_buffer_(NULL), 76 user_buffer_(NULL),
64 user_buffer_size_(0), 77 user_buffer_size_(0),
(...skipping 27 matching lines...) Expand all
92 int32_t rv = ValidateCallback(callback); 105 int32_t rv = ValidateCallback(callback);
93 if (rv != PP_OK) 106 if (rv != PP_OK)
94 return rv; 107 return rv;
95 108
96 if (request->RequiresUniversalAccess() && !has_universal_access_) 109 if (request->RequiresUniversalAccess() && !has_universal_access_)
97 return PP_ERROR_NOACCESS; 110 return PP_ERROR_NOACCESS;
98 111
99 if (loader_.get()) 112 if (loader_.get())
100 return PP_ERROR_INPROGRESS; 113 return PP_ERROR_INPROGRESS;
101 114
102 WebFrame* frame = instance()->container()->element().document().frame(); 115 WebFrame* frame = GetFrameForResource(this);
103 if (!frame) 116 if (!frame)
104 return PP_ERROR_FAILED; 117 return PP_ERROR_FAILED;
105 WebURLRequest web_request(request->ToWebURLRequest(frame)); 118 WebURLRequest web_request(request->ToWebURLRequest(frame));
106 119
107 WebURLLoaderOptions options; 120 WebURLLoaderOptions options;
108 if (has_universal_access_) { 121 if (has_universal_access_) {
109 // Universal access allows cross-origin requests and sends credentials. 122 // Universal access allows cross-origin requests and sends credentials.
110 options.crossOriginRequestPolicy = 123 options.crossOriginRequestPolicy =
111 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; 124 WebURLLoaderOptions::CrossOriginRequestPolicyAllow;
112 options.allowCredentials = true; 125 options.allowCredentials = true;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 loader_->setDefersLoading(false); 232 loader_->setDefersLoading(false);
220 is_asynchronous_load_suspended_ = false; 233 is_asynchronous_load_suspended_ = false;
221 } 234 }
222 235
223 // Wait for didFinishLoading / didFail. 236 // Wait for didFinishLoading / didFail.
224 RegisterCallback(callback); 237 RegisterCallback(callback);
225 return PP_OK_COMPLETIONPENDING; 238 return PP_OK_COMPLETIONPENDING;
226 } 239 }
227 240
228 void PPB_URLLoader_Impl::Close() { 241 void PPB_URLLoader_Impl::Close() {
229 if (loader_.get()) { 242 if (loader_.get())
230 loader_->cancel(); 243 loader_->cancel();
231 } else if (main_document_loader_) { 244 else if (main_document_loader_)
232 WebFrame* frame = instance()->container()->element().document().frame(); 245 GetFrameForResource(this)->stopLoading();
233 frame->stopLoading();
234 }
235 // TODO(viettrungluu): Check what happens to the callback (probably the 246 // TODO(viettrungluu): Check what happens to the callback (probably the
236 // wrong thing). May need to post abort here. crbug.com/69457 247 // wrong thing). May need to post abort here. crbug.com/69457
237 } 248 }
238 249
239 void PPB_URLLoader_Impl::GrantUniversalAccess() { 250 void PPB_URLLoader_Impl::GrantUniversalAccess() {
240 has_universal_access_ = true; 251 has_universal_access_ = true;
241 } 252 }
242 253
243 void PPB_URLLoader_Impl::SetStatusCallback( 254 void PPB_URLLoader_Impl::SetStatusCallback(
244 PP_URLLoaderTrusted_StatusCallback cb) { 255 PP_URLLoaderTrusted_StatusCallback cb) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 if (pending_callback_.get() && !pending_callback_->completed()) 366 if (pending_callback_.get() && !pending_callback_->completed())
356 return PP_ERROR_INPROGRESS; 367 return PP_ERROR_INPROGRESS;
357 368
358 return PP_OK; 369 return PP_OK;
359 } 370 }
360 371
361 void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) { 372 void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) {
362 DCHECK(callback.func); 373 DCHECK(callback.func);
363 DCHECK(!pending_callback_.get() || pending_callback_->completed()); 374 DCHECK(!pending_callback_.get() || pending_callback_->completed());
364 375
376 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
377 if (!plugin_module)
378 return;
379
365 pending_callback_ = new TrackedCompletionCallback( 380 pending_callback_ = new TrackedCompletionCallback(
366 instance()->module()->GetCallbackTracker(), pp_resource(), callback); 381 plugin_module->GetCallbackTracker(), pp_resource(), callback);
367 } 382 }
368 383
369 void PPB_URLLoader_Impl::RunCallback(int32_t result) { 384 void PPB_URLLoader_Impl::RunCallback(int32_t result) {
370 // This may be null only when this is a main document loader. 385 // This may be null only when this is a main document loader.
371 if (!pending_callback_.get()) { 386 if (!pending_callback_.get()) {
372 CHECK(main_document_loader_); 387 CHECK(main_document_loader_);
373 return; 388 return;
374 } 389 }
375 390
376 scoped_refptr<TrackedCompletionCallback> callback; 391 scoped_refptr<TrackedCompletionCallback> callback;
(...skipping 20 matching lines...) Expand all
397 } 412 }
398 413
399 // Reset for next time. 414 // Reset for next time.
400 user_buffer_ = NULL; 415 user_buffer_ = NULL;
401 user_buffer_size_ = 0; 416 user_buffer_size_ = 0;
402 return bytes_to_copy; 417 return bytes_to_copy;
403 } 418 }
404 419
405 void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) { 420 void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) {
406 scoped_refptr<PPB_URLResponseInfo_Impl> response_info( 421 scoped_refptr<PPB_URLResponseInfo_Impl> response_info(
407 new PPB_URLResponseInfo_Impl(instance())); 422 new PPB_URLResponseInfo_Impl(pp_instance()));
408 if (response_info->Initialize(response)) 423 if (response_info->Initialize(response))
409 response_info_ = response_info; 424 response_info_ = response_info;
410 } 425 }
411 426
412 void PPB_URLLoader_Impl::UpdateStatus() { 427 void PPB_URLLoader_Impl::UpdateStatus() {
413 if (status_callback_ && 428 if (status_callback_ &&
414 (RecordDownloadProgress() || RecordUploadProgress())) { 429 (RecordDownloadProgress() || RecordUploadProgress())) {
415 // Here we go through some effort to only send the exact information that 430 // Here we go through some effort to only send the exact information that
416 // the requestor wanted in the request flags. It would be just as 431 // the requestor wanted in the request flags. It would be just as
417 // efficient to send all of it, but we don't want people to rely on 432 // efficient to send all of it, but we don't want people to rely on
418 // getting download progress when they happen to set the upload progress 433 // getting download progress when they happen to set the upload progress
419 // flag. 434 // flag.
420 status_callback_( 435 status_callback_(
421 instance()->pp_instance(), pp_resource(), 436 pp_instance(), pp_resource(),
422 RecordUploadProgress() ? bytes_sent_ : -1, 437 RecordUploadProgress() ? bytes_sent_ : -1,
423 RecordUploadProgress() ? total_bytes_to_be_sent_ : -1, 438 RecordUploadProgress() ? total_bytes_to_be_sent_ : -1,
424 RecordDownloadProgress() ? bytes_received_ : -1, 439 RecordDownloadProgress() ? bytes_received_ : -1,
425 RecordDownloadProgress() ? total_bytes_to_be_received_ : -1); 440 RecordDownloadProgress() ? total_bytes_to_be_received_ : -1);
426 } 441 }
427 } 442 }
428 443
429 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { 444 bool PPB_URLLoader_Impl::RecordDownloadProgress() const {
430 return request_info_ && request_info_->record_download_progress(); 445 return request_info_ && request_info_->record_download_progress();
431 } 446 }
432 447
433 bool PPB_URLLoader_Impl::RecordUploadProgress() const { 448 bool PPB_URLLoader_Impl::RecordUploadProgress() const {
434 return request_info_ && request_info_->record_upload_progress(); 449 return request_info_ && request_info_->record_upload_progress();
435 } 450 }
436 451
437 } // namespace ppapi 452 } // namespace ppapi
438 } // namespace webkit 453 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_url_loader_impl.h ('k') | webkit/plugins/ppapi/ppb_url_request_info_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698