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

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

Issue 6899055: PPAPI: Force async callback invocation option. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 "ppapi/c/pp_completion_callback.h" 8 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_core.h"
10 #include "ppapi/c/ppb_url_loader.h" 11 #include "ppapi/c/ppb_url_loader.h"
11 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" 12 #include "ppapi/c/trusted/ppb_url_loader_trusted.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 PP_Bool IsURLLoader(PP_Resource resource) { 60 PP_Bool IsURLLoader(PP_Resource resource) {
60 return BoolToPPBool(!!Resource::GetAs<PPB_URLLoader_Impl>(resource)); 61 return BoolToPPBool(!!Resource::GetAs<PPB_URLLoader_Impl>(resource));
61 } 62 }
62 63
63 int32_t Open(PP_Resource loader_id, 64 int32_t Open(PP_Resource loader_id,
64 PP_Resource request_id, 65 PP_Resource request_id,
65 PP_CompletionCallback callback) { 66 PP_CompletionCallback callback) {
66 scoped_refptr<PPB_URLLoader_Impl> loader( 67 scoped_refptr<PPB_URLLoader_Impl> loader(
67 Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); 68 Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
68 if (!loader) 69 if (!loader)
69 return PP_ERROR_BADRESOURCE; 70 return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
70 71
71 scoped_refptr<PPB_URLRequestInfo_Impl> request( 72 scoped_refptr<PPB_URLRequestInfo_Impl> request(
72 Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id)); 73 Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id));
73 if (!request) 74 if (!request)
74 return PP_ERROR_BADRESOURCE; 75 return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
75 76
76 return loader->Open(request, callback); 77 int32_t result = loader->Open(request, callback);
78 return MayForceCallback(callback, result);
77 } 79 }
78 80
79 int32_t FollowRedirect(PP_Resource loader_id, 81 int32_t FollowRedirect(PP_Resource loader_id,
80 PP_CompletionCallback callback) { 82 PP_CompletionCallback callback) {
81 scoped_refptr<PPB_URLLoader_Impl> loader( 83 scoped_refptr<PPB_URLLoader_Impl> loader(
82 Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); 84 Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
83 if (!loader) 85 if (!loader)
84 return PP_ERROR_BADRESOURCE; 86 return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
85 87
86 return loader->FollowRedirect(callback); 88 int32_t result = loader->FollowRedirect(callback);
89 return MayForceCallback(callback, result);
87 } 90 }
88 91
89 PP_Bool GetUploadProgress(PP_Resource loader_id, 92 PP_Bool GetUploadProgress(PP_Resource loader_id,
90 int64_t* bytes_sent, 93 int64_t* bytes_sent,
91 int64_t* total_bytes_to_be_sent) { 94 int64_t* total_bytes_to_be_sent) {
92 scoped_refptr<PPB_URLLoader_Impl> loader( 95 scoped_refptr<PPB_URLLoader_Impl> loader(
93 Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); 96 Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
94 if (!loader) 97 if (!loader)
95 return PP_FALSE; 98 return PP_FALSE;
96 99
(...skipping 26 matching lines...) Expand all
123 return response_info->GetReference(); 126 return response_info->GetReference();
124 } 127 }
125 128
126 int32_t ReadResponseBody(PP_Resource loader_id, 129 int32_t ReadResponseBody(PP_Resource loader_id,
127 void* buffer, 130 void* buffer,
128 int32_t bytes_to_read, 131 int32_t bytes_to_read,
129 PP_CompletionCallback callback) { 132 PP_CompletionCallback callback) {
130 scoped_refptr<PPB_URLLoader_Impl> loader( 133 scoped_refptr<PPB_URLLoader_Impl> loader(
131 Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); 134 Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
132 if (!loader) 135 if (!loader)
133 return PP_ERROR_BADRESOURCE; 136 return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
134 137
135 return loader->ReadResponseBody(buffer, bytes_to_read, callback); 138 int32_t result = loader->ReadResponseBody(buffer, bytes_to_read, callback);
139 return MayForceCallback(callback, result);
136 } 140 }
137 141
138 int32_t FinishStreamingToFile(PP_Resource loader_id, 142 int32_t FinishStreamingToFile(PP_Resource loader_id,
139 PP_CompletionCallback callback) { 143 PP_CompletionCallback callback) {
140 scoped_refptr<PPB_URLLoader_Impl> loader( 144 scoped_refptr<PPB_URLLoader_Impl> loader(
141 Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); 145 Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
142 if (!loader) 146 if (!loader)
143 return PP_ERROR_BADRESOURCE; 147 return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
144 148
145 return loader->FinishStreamingToFile(callback); 149 int32_t result = loader->FinishStreamingToFile(callback);
150 return MayForceCallback(callback, result);
146 } 151 }
147 152
148 void Close(PP_Resource loader_id) { 153 void Close(PP_Resource loader_id) {
149 scoped_refptr<PPB_URLLoader_Impl> loader( 154 scoped_refptr<PPB_URLLoader_Impl> loader(
150 Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); 155 Resource::GetAs<PPB_URLLoader_Impl>(loader_id));
151 if (!loader) 156 if (!loader)
152 return; 157 return;
153 158
154 loader->Close(); 159 loader->Close();
155 } 160 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 245 }
241 } 246 }
242 247
243 int32_t PPB_URLLoader_Impl::Open(PPB_URLRequestInfo_Impl* request, 248 int32_t PPB_URLLoader_Impl::Open(PPB_URLRequestInfo_Impl* request,
244 PP_CompletionCallback callback) { 249 PP_CompletionCallback callback) {
245 int32_t rv = ValidateCallback(callback); 250 int32_t rv = ValidateCallback(callback);
246 if (rv != PP_OK) 251 if (rv != PP_OK)
247 return rv; 252 return rv;
248 253
249 if (request->RequiresUniversalAccess() && !has_universal_access_) 254 if (request->RequiresUniversalAccess() && !has_universal_access_)
250 return PP_ERROR_BADARGUMENT; 255 return PP_ERROR_NOACCESS;
251 256
252 if (loader_.get()) 257 if (loader_.get())
253 return PP_ERROR_INPROGRESS; 258 return PP_ERROR_INPROGRESS;
254 259
255 WebFrame* frame = GetFrame(instance()); 260 WebFrame* frame = GetFrame(instance());
256 if (!frame) 261 if (!frame)
257 return PP_ERROR_FAILED; 262 return PP_ERROR_FAILED;
258 WebURLRequest web_request(request->ToWebURLRequest(frame));
259 263
260 WebURLLoaderOptions options; 264 WebURLLoaderOptions options;
261 if (has_universal_access_) { 265 if (has_universal_access_) {
262 // Universal access allows cross-origin requests and sends credentials. 266 // Universal access allows cross-origin requests and sends credentials.
263 options.crossOriginRequestPolicy = 267 options.crossOriginRequestPolicy =
264 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; 268 WebURLLoaderOptions::CrossOriginRequestPolicyAllow;
265 options.allowCredentials = true; 269 options.allowCredentials = true;
266 } else if (request->allow_cross_origin_requests()) { 270 } else if (request->allow_cross_origin_requests()) {
267 // Otherwise, allow cross-origin requests with access control. 271 // Otherwise, allow cross-origin requests with access control.
268 options.crossOriginRequestPolicy = 272 options.crossOriginRequestPolicy =
269 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; 273 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl;
270 options.allowCredentials = request->allow_credentials(); 274 options.allowCredentials = request->allow_credentials();
271 } 275 }
272 276
273 is_asynchronous_load_suspended_ = false; 277 is_asynchronous_load_suspended_ = false;
274 loader_.reset(frame->createAssociatedURLLoader(options)); 278 loader_.reset(frame->createAssociatedURLLoader(options));
275 if (!loader_.get()) 279 if (!loader_.get())
276 return PP_ERROR_FAILED; 280 return PP_ERROR_FAILED;
277 281
282 WebURLRequest web_request(request->ToWebURLRequest(frame));
278 loader_->loadAsynchronously(web_request, this); 283 loader_->loadAsynchronously(web_request, this);
279 // Check for immediate failure; The AssociatedURLLoader will call our 284 // Check for immediate failure; The AssociatedURLLoader will call our
280 // didFail method synchronously for certain kinds of access violations 285 // didFail method synchronously for certain kinds of access violations
281 // so we must return an error to the caller. 286 // so we must return an error to the caller.
282 // TODO(bbudge) Modify the underlying AssociatedURLLoader to only call 287 // TODO(bbudge) Modify the underlying AssociatedURLLoader to only call
283 // back asynchronously. 288 // back asynchronously.
284 if (done_status_ == PP_ERROR_FAILED) 289 if (done_status_ == PP_ERROR_FAILED)
285 return PP_ERROR_NOACCESS; 290 return PP_ERROR_NOACCESS;
286 291
287 request_info_ = scoped_refptr<PPB_URLRequestInfo_Impl>(request); 292 request_info_ = scoped_refptr<PPB_URLRequestInfo_Impl>(request);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { 578 bool PPB_URLLoader_Impl::RecordDownloadProgress() const {
574 return request_info_ && request_info_->record_download_progress(); 579 return request_info_ && request_info_->record_download_progress();
575 } 580 }
576 581
577 bool PPB_URLLoader_Impl::RecordUploadProgress() const { 582 bool PPB_URLLoader_Impl::RecordUploadProgress() const {
578 return request_info_ && request_info_->record_upload_progress(); 583 return request_info_ && request_info_->record_upload_progress();
579 } 584 }
580 585
581 } // namespace ppapi 586 } // namespace ppapi
582 } // namespace webkit 587 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698