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

Side by Side Diff: ppapi/proxy/ppb_url_loader_proxy.cc

Issue 10913257: Convert url request info to new proxy API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ppapi/proxy/ppb_url_loader_proxy.h" 5 #include "ppapi/proxy/ppb_url_loader_proxy.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "ppapi/c/pp_completion_callback.h" 14 #include "ppapi/c/pp_completion_callback.h"
15 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
16 #include "ppapi/c/pp_resource.h" 16 #include "ppapi/c/pp_resource.h"
17 #include "ppapi/c/ppb_url_loader.h" 17 #include "ppapi/c/ppb_url_loader.h"
18 #include "ppapi/c/private/ppb_proxy_private.h" 18 #include "ppapi/c/private/ppb_proxy_private.h"
19 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" 19 #include "ppapi/c/trusted/ppb_url_loader_trusted.h"
20 #include "ppapi/proxy/enter_proxy.h" 20 #include "ppapi/proxy/enter_proxy.h"
21 #include "ppapi/proxy/host_dispatcher.h" 21 #include "ppapi/proxy/host_dispatcher.h"
22 #include "ppapi/proxy/plugin_dispatcher.h" 22 #include "ppapi/proxy/plugin_dispatcher.h"
23 #include "ppapi/proxy/plugin_resource_tracker.h" 23 #include "ppapi/proxy/plugin_resource_tracker.h"
24 #include "ppapi/proxy/ppapi_messages.h" 24 #include "ppapi/proxy/ppapi_messages.h"
25 #include "ppapi/proxy/ppb_url_response_info_proxy.h" 25 #include "ppapi/proxy/ppb_url_response_info_proxy.h"
26 #include "ppapi/shared_impl/scoped_pp_resource.h" 26 #include "ppapi/shared_impl/scoped_pp_resource.h"
27 #include "ppapi/shared_impl/tracked_callback.h" 27 #include "ppapi/shared_impl/tracked_callback.h"
28 #include "ppapi/thunk/enter.h" 28 #include "ppapi/thunk/enter.h"
29 #include "ppapi/thunk/ppb_url_loader_api.h" 29 #include "ppapi/thunk/ppb_url_loader_api.h"
30 #include "ppapi/thunk/ppb_url_request_info_api.h"
30 #include "ppapi/thunk/resource_creation_api.h" 31 #include "ppapi/thunk/resource_creation_api.h"
31 #include "ppapi/thunk/thunk.h" 32 #include "ppapi/thunk/thunk.h"
32 33
33 #if defined(OS_LINUX) 34 #if defined(OS_LINUX)
34 #include <sys/shm.h> 35 #include <sys/shm.h>
35 #endif 36 #endif
36 37
37 using ppapi::thunk::EnterResourceNoLock; 38 using ppapi::thunk::EnterResourceNoLock;
38 using ppapi::thunk::PPB_URLLoader_API; 39 using ppapi::thunk::PPB_URLLoader_API;
39 using ppapi::thunk::ResourceCreationAPI; 40 using ppapi::thunk::ResourceCreationAPI;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 public: 86 public:
86 URLLoader(const HostResource& resource); 87 URLLoader(const HostResource& resource);
87 virtual ~URLLoader(); 88 virtual ~URLLoader();
88 89
89 // Resource overrides. 90 // Resource overrides.
90 virtual PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE; 91 virtual PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE;
91 92
92 // PPB_URLLoader_API implementation. 93 // PPB_URLLoader_API implementation.
93 virtual int32_t Open(PP_Resource request_id, 94 virtual int32_t Open(PP_Resource request_id,
94 scoped_refptr<TrackedCallback> callback) OVERRIDE; 95 scoped_refptr<TrackedCallback> callback) OVERRIDE;
96 virtual int32_t Open(const URLRequestInfoData& data,
97 scoped_refptr<TrackedCallback> callback) OVERRIDE;
95 virtual int32_t FollowRedirect( 98 virtual int32_t FollowRedirect(
96 scoped_refptr<TrackedCallback> callback) OVERRIDE; 99 scoped_refptr<TrackedCallback> callback) OVERRIDE;
97 virtual PP_Bool GetUploadProgress(int64_t* bytes_sent, 100 virtual PP_Bool GetUploadProgress(int64_t* bytes_sent,
98 int64_t* total_bytes_to_be_sent) OVERRIDE; 101 int64_t* total_bytes_to_be_sent) OVERRIDE;
99 virtual PP_Bool GetDownloadProgress( 102 virtual PP_Bool GetDownloadProgress(
100 int64_t* bytes_received, 103 int64_t* bytes_received,
101 int64_t* total_bytes_to_be_received) OVERRIDE; 104 int64_t* total_bytes_to_be_received) OVERRIDE;
102 virtual PP_Resource GetResponseInfo() OVERRIDE; 105 virtual PP_Resource GetResponseInfo() OVERRIDE;
103 virtual int32_t ReadResponseBody( 106 virtual int32_t ReadResponseBody(
104 void* buffer, 107 void* buffer,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 int32_t URLLoader::Open(PP_Resource request_id, 185 int32_t URLLoader::Open(PP_Resource request_id,
183 scoped_refptr<TrackedCallback> callback) { 186 scoped_refptr<TrackedCallback> callback) {
184 EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(request_id, true); 187 EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(request_id, true);
185 if (enter.failed()) { 188 if (enter.failed()) {
186 Log(PP_LOGLEVEL_ERROR, "PPB_URLLoader.Open: The URL you're requesting is " 189 Log(PP_LOGLEVEL_ERROR, "PPB_URLLoader.Open: The URL you're requesting is "
187 " on a different security origin than your plugin. To request " 190 " on a different security origin than your plugin. To request "
188 " cross-origin resources, see " 191 " cross-origin resources, see "
189 " PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS."); 192 " PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS.");
190 return PP_ERROR_BADRESOURCE; 193 return PP_ERROR_BADRESOURCE;
191 } 194 }
195 return Open(enter.object()->GetData(), callback);
196 }
192 197
198 int32_t URLLoader::Open(const URLRequestInfoData& data,
199 scoped_refptr<TrackedCallback> callback) {
193 if (TrackedCallback::IsPending(current_callback_)) 200 if (TrackedCallback::IsPending(current_callback_))
194 return PP_ERROR_INPROGRESS; 201 return PP_ERROR_INPROGRESS;
195 202
196 current_callback_ = callback; 203 current_callback_ = callback;
197 204
198 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( 205 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open(
199 API_ID_PPB_URL_LOADER, host_resource(), enter.object()->GetData())); 206 API_ID_PPB_URL_LOADER, host_resource(), data));
200 return PP_OK_COMPLETIONPENDING; 207 return PP_OK_COMPLETIONPENDING;
201 } 208 }
202 209
203 int32_t URLLoader::FollowRedirect(scoped_refptr<TrackedCallback> callback) { 210 int32_t URLLoader::FollowRedirect(scoped_refptr<TrackedCallback> callback) {
204 if (TrackedCallback::IsPending(current_callback_)) 211 if (TrackedCallback::IsPending(current_callback_))
205 return PP_ERROR_INPROGRESS; 212 return PP_ERROR_INPROGRESS;
206 213
207 current_callback_ = callback; 214 current_callback_ = callback;
208 215
209 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( 216 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect(
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 HostResource* result) { 452 HostResource* result) {
446 thunk::EnterResourceCreation enter(instance); 453 thunk::EnterResourceCreation enter(instance);
447 if (enter.succeeded()) { 454 if (enter.succeeded()) {
448 result->SetHostResource(instance, 455 result->SetHostResource(instance,
449 enter.functions()->CreateURLLoader(instance)); 456 enter.functions()->CreateURLLoader(instance));
450 PrepareURLLoaderForSendingToPlugin(result->host_resource()); 457 PrepareURLLoaderForSendingToPlugin(result->host_resource());
451 } 458 }
452 } 459 }
453 460
454 void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, 461 void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader,
455 const PPB_URLRequestInfo_Data& data) { 462 const URLRequestInfoData& data) {
456 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( 463 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter(
457 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader); 464 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader);
458 thunk::EnterResourceCreation enter_creation(loader.instance()); 465 enter.SetResult(enter.object()->Open(data, enter.callback()));
459 if (enter.failed() || enter_creation.failed())
460 return;
461
462 ScopedPPResource request_resource(
463 ScopedPPResource::PassRef(),
464 enter_creation.functions()->CreateURLRequestInfo(loader.instance(),
465 data));
466 enter.SetResult(enter.object()->Open(request_resource, enter.callback()));
467 // TODO(brettw) bug 73236 register for the status callbacks. 466 // TODO(brettw) bug 73236 register for the status callbacks.
468 } 467 }
469 468
470 void PPB_URLLoader_Proxy::OnMsgFollowRedirect( 469 void PPB_URLLoader_Proxy::OnMsgFollowRedirect(
471 const HostResource& loader) { 470 const HostResource& loader) {
472 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( 471 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter(
473 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader); 472 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader);
474 if (enter.succeeded()) 473 if (enter.succeeded())
475 enter.SetResult(enter.object()->FollowRedirect(enter.callback())); 474 enter.SetResult(enter.object()->FollowRedirect(enter.callback()));
476 } 475 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 587 }
589 588
590 void PPB_URLLoader_Proxy::OnCallback(int32_t result, 589 void PPB_URLLoader_Proxy::OnCallback(int32_t result,
591 const HostResource& resource) { 590 const HostResource& resource) {
592 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( 591 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete(
593 API_ID_PPB_URL_LOADER, resource, result)); 592 API_ID_PPB_URL_LOADER, resource, result));
594 } 593 }
595 594
596 } // namespace proxy 595 } // namespace proxy
597 } // namespace ppapi 596 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698