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

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

Issue 6334016: Refactor PPAPI proxy resource handling to maintain which host they came from,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « ppapi/proxy/ppb_url_request_info_proxy.h ('k') | ppapi/proxy/ppb_url_response_info_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ppapi/proxy/ppb_url_request_info_proxy.h" 5 #include "ppapi/proxy/ppb_url_request_info_proxy.h"
6 6
7 #include "ppapi/c/ppb_url_request_info.h" 7 #include "ppapi/c/ppb_url_request_info.h"
8 #include "ppapi/proxy/plugin_dispatcher.h" 8 #include "ppapi/proxy/plugin_dispatcher.h"
9 #include "ppapi/proxy/plugin_resource.h" 9 #include "ppapi/proxy/plugin_resource.h"
10 #include "ppapi/proxy/ppapi_messages.h" 10 #include "ppapi/proxy/ppapi_messages.h"
11 11
12 namespace pp { 12 namespace pp {
13 namespace proxy { 13 namespace proxy {
14 14
15 class URLRequestInfo : public PluginResource { 15 class URLRequestInfo : public PluginResource {
16 public: 16 public:
17 URLRequestInfo(PP_Instance instance) : PluginResource(instance) {} 17 URLRequestInfo(const HostResource& resource) : PluginResource(resource) {
18 virtual ~URLRequestInfo() {} 18 }
19 virtual ~URLRequestInfo() {
20 }
19 21
20 // Resource overrides. 22 // Resource overrides.
21 virtual URLRequestInfo* AsURLRequestInfo() { return this; } 23 virtual URLRequestInfo* AsURLRequestInfo() { return this; }
22 24
23 private: 25 private:
24 DISALLOW_COPY_AND_ASSIGN(URLRequestInfo); 26 DISALLOW_COPY_AND_ASSIGN(URLRequestInfo);
25 }; 27 };
26 28
27 namespace { 29 namespace {
28 30
29 // Returns the dispatcher associated with the given URLRequestInfo, or NULL if 31 // Computes the dispatcher and request object for the given plugin resource,
30 // none exists. 32 // returning true on success.
31 PluginDispatcher* DispatcherFromURLRequestInfo(PP_Resource resource) { 33 bool DispatcherFromURLRequestInfo(PP_Resource resource,
32 URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource); 34 PluginDispatcher** dispatcher,
33 if (!object) 35 URLRequestInfo** request_info) {
34 return NULL; 36 *request_info = PluginResource::GetAs<URLRequestInfo>(resource);
35 return PluginDispatcher::GetForInstance(object->instance()); 37 if (!*request_info)
38 return false;
39 *dispatcher = PluginDispatcher::GetForInstance((*request_info)->instance());
40 return !!*dispatcher;
36 } 41 }
37 42
38 PP_Resource Create(PP_Instance instance) { 43 PP_Resource Create(PP_Instance instance) {
39 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 44 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
40 if (!dispatcher) 45 if (!dispatcher)
41 return 0; 46 return 0;
42 47
43 PP_Resource result; 48 HostResource result;
44 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create( 49 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create(
45 INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result)); 50 INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result));
46 if (result) { 51 if (result.is_null())
47 linked_ptr<URLRequestInfo> object(new URLRequestInfo(instance)); 52 return 0;
48 PluginResourceTracker::GetInstance()->AddResource(result, object); 53
49 } 54 linked_ptr<URLRequestInfo> object(new URLRequestInfo(result));
50 return result; 55 return PluginResourceTracker::GetInstance()->AddResource(object);
51 } 56 }
52 57
53 PP_Bool IsURLRequestInfo(PP_Resource resource) { 58 PP_Bool IsURLRequestInfo(PP_Resource resource) {
54 URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource); 59 URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource);
55 return BoolToPPBool(!!object); 60 return BoolToPPBool(!!object);
56 } 61 }
57 62
58 PP_Bool SetProperty(PP_Resource request_id, 63 PP_Bool SetProperty(PP_Resource request_id,
59 PP_URLRequestProperty property, 64 PP_URLRequestProperty property,
60 PP_Var var) { 65 PP_Var var) {
61 PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id); 66 PluginDispatcher* dispatcher;
62 if (!dispatcher) 67 URLRequestInfo* request_info;
68 if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info))
63 return PP_FALSE; 69 return PP_FALSE;
64 70
65 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty( 71 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty(
66 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, 72 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(),
67 static_cast<int32_t>(property), 73 static_cast<int32_t>(property),
68 SerializedVarSendInput(dispatcher, var))); 74 SerializedVarSendInput(dispatcher, var)));
69 75
70 // TODO(brettw) do some validation on the types. We should be able to tell on 76 // TODO(brettw) do some validation on the types. We should be able to tell on
71 // the plugin side whether the request will succeed or fail in the renderer. 77 // the plugin side whether the request will succeed or fail in the renderer.
72 return PP_TRUE; 78 return PP_TRUE;
73 } 79 }
74 80
75 PP_Bool AppendDataToBody(PP_Resource request_id, 81 PP_Bool AppendDataToBody(PP_Resource request_id,
76 const char* data, uint32_t len) { 82 const char* data, uint32_t len) {
77 PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id); 83 PluginDispatcher* dispatcher;
78 if (!dispatcher) 84 URLRequestInfo* request_info;
85 if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info))
79 return PP_FALSE; 86 return PP_FALSE;
80 87
81 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody( 88 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody(
82 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, std::string(data, len))); 89 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(),
90 std::string(data, len)));
83 91
84 // TODO(brettw) do some validation. We should be able to tell on the plugin 92 // TODO(brettw) do some validation. We should be able to tell on the plugin
85 // side whether the request will succeed or fail in the renderer. 93 // side whether the request will succeed or fail in the renderer.
86 return PP_TRUE; 94 return PP_TRUE;
87 } 95 }
88 96
89 PP_Bool AppendFileToBody(PP_Resource request_id, 97 PP_Bool AppendFileToBody(PP_Resource request_id,
90 PP_Resource file_ref_id, 98 PP_Resource file_ref_id,
91 int64_t start_offset, 99 int64_t start_offset,
92 int64_t number_of_bytes, 100 int64_t number_of_bytes,
93 PP_Time expected_last_modified_time) { 101 PP_Time expected_last_modified_time) {
94 PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id); 102 PluginDispatcher* dispatcher;
95 if (!dispatcher) 103 URLRequestInfo* request_info;
104 if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info))
105 return PP_FALSE;
106 PluginResource* file_ref_object =
107 PluginResourceTracker::GetInstance()->GetResourceObject(file_ref_id);
108 if (!file_ref_object)
96 return PP_FALSE; 109 return PP_FALSE;
97 110
98 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody( 111 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody(
99 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, file_ref_id, 112 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(),
113 file_ref_object->host_resource(),
100 start_offset, number_of_bytes, expected_last_modified_time)); 114 start_offset, number_of_bytes, expected_last_modified_time));
101 115
102 // TODO(brettw) do some validation. We should be able to tell on the plugin 116 // TODO(brettw) do some validation. We should be able to tell on the plugin
103 // side whether the request will succeed or fail in the renderer. 117 // side whether the request will succeed or fail in the renderer.
104 return PP_TRUE; 118 return PP_TRUE;
105 } 119 }
106 120
107 const PPB_URLRequestInfo ppb_urlrequestinfo = { 121 const PPB_URLRequestInfo ppb_urlrequestinfo = {
108 &Create, 122 &Create,
109 &IsURLRequestInfo, 123 &IsURLRequestInfo,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody, 156 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody,
143 OnMsgAppendFileToBody) 157 OnMsgAppendFileToBody)
144 IPC_MESSAGE_UNHANDLED(handled = false) 158 IPC_MESSAGE_UNHANDLED(handled = false)
145 IPC_END_MESSAGE_MAP() 159 IPC_END_MESSAGE_MAP()
146 // TODO(brettw): handle bad messages. 160 // TODO(brettw): handle bad messages.
147 return handled; 161 return handled;
148 } 162 }
149 163
150 void PPB_URLRequestInfo_Proxy::OnMsgCreate( 164 void PPB_URLRequestInfo_Proxy::OnMsgCreate(
151 PP_Instance instance, 165 PP_Instance instance,
152 PP_Resource* result) { 166 HostResource* result) {
153 *result = ppb_url_request_info_target()->Create(instance); 167 result->SetHostResource(instance,
168 ppb_url_request_info_target()->Create(instance));
154 } 169 }
155 170
156 void PPB_URLRequestInfo_Proxy::OnMsgSetProperty( 171 void PPB_URLRequestInfo_Proxy::OnMsgSetProperty(
157 PP_Resource request, 172 HostResource request,
158 int32_t property, 173 int32_t property,
159 SerializedVarReceiveInput value) { 174 SerializedVarReceiveInput value) {
160 ppb_url_request_info_target()->SetProperty(request, 175 ppb_url_request_info_target()->SetProperty(request.host_resource(),
161 static_cast<PP_URLRequestProperty>(property), 176 static_cast<PP_URLRequestProperty>(property),
162 value.Get(dispatcher())); 177 value.Get(dispatcher()));
163 } 178 }
164 179
165 void PPB_URLRequestInfo_Proxy::OnMsgAppendDataToBody( 180 void PPB_URLRequestInfo_Proxy::OnMsgAppendDataToBody(
166 PP_Resource request, 181 HostResource request,
167 const std::string& data) { 182 const std::string& data) {
168 ppb_url_request_info_target()->AppendDataToBody(request, data.c_str(), 183 ppb_url_request_info_target()->AppendDataToBody(request.host_resource(),
169 data.size()); 184 data.c_str(), data.size());
170 } 185 }
171 186
172 void PPB_URLRequestInfo_Proxy::OnMsgAppendFileToBody( 187 void PPB_URLRequestInfo_Proxy::OnMsgAppendFileToBody(
173 PP_Resource request, 188 HostResource request,
174 PP_Resource file_ref, 189 HostResource file_ref,
175 int64_t start_offset, 190 int64_t start_offset,
176 int64_t number_of_bytes, 191 int64_t number_of_bytes,
177 double expected_last_modified_time) { 192 double expected_last_modified_time) {
178 ppb_url_request_info_target()->AppendFileToBody( 193 ppb_url_request_info_target()->AppendFileToBody(
179 request, file_ref, start_offset, number_of_bytes, 194 request.host_resource(), file_ref.host_resource(),
180 expected_last_modified_time); 195 start_offset, number_of_bytes, expected_last_modified_time);
181 } 196 }
182 197
183 } // namespace proxy 198 } // namespace proxy
184 } // namespace pp 199 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_url_request_info_proxy.h ('k') | ppapi/proxy/ppb_url_response_info_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698