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

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, 10 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 "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(PP_Instance instance, SerializedResource resource)
18 virtual ~URLRequestInfo() {} 18 : PluginResource(instance, resource) {
19 }
20 virtual ~URLRequestInfo() {
21 }
19 22
20 // Resource overrides. 23 // Resource overrides.
21 virtual URLRequestInfo* AsURLRequestInfo() { return this; } 24 virtual URLRequestInfo* AsURLRequestInfo() { return this; }
22 25
23 private: 26 private:
24 DISALLOW_COPY_AND_ASSIGN(URLRequestInfo); 27 DISALLOW_COPY_AND_ASSIGN(URLRequestInfo);
25 }; 28 };
26 29
27 namespace { 30 namespace {
28 31
29 // Returns the dispatcher associated with the given URLRequestInfo, or NULL if 32 // Computes the dispatcher and request object for the given plugin resource,
30 // none exists. 33 // returning true on success.
31 PluginDispatcher* DispatcherFromURLRequestInfo(PP_Resource resource) { 34 bool DispatcherFromURLRequestInfo(PP_Resource resource,
32 URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource); 35 PluginDispatcher** dispatcher,
33 if (!object) 36 URLRequestInfo** request_info) {
34 return NULL; 37 *request_info = PluginResource::GetAs<URLRequestInfo>(resource);
35 return PluginDispatcher::GetForInstance(object->instance()); 38 if (!*request_info)
39 return false;
40 *dispatcher = PluginDispatcher::GetForInstance((*request_info)->instance());
41 return !!*dispatcher;
36 } 42 }
37 43
38 PP_Resource Create(PP_Instance instance) { 44 PP_Resource Create(PP_Instance instance) {
39 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 45 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
40 if (!dispatcher) 46 if (!dispatcher)
41 return 0; 47 return 0;
42 48
43 PP_Resource result; 49 SerializedResource result;
44 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create( 50 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create(
45 INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result)); 51 INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result));
46 if (result) { 52 if (result.is_null())
47 linked_ptr<URLRequestInfo> object(new URLRequestInfo(instance)); 53 return 0;
48 PluginResourceTracker::GetInstance()->AddResource(result, object); 54
49 } 55 linked_ptr<URLRequestInfo> object(new URLRequestInfo(instance, result));
50 return result; 56 return PluginResourceTracker::GetInstance()->AddResource(object);
51 } 57 }
52 58
53 PP_Bool IsURLRequestInfo(PP_Resource resource) { 59 PP_Bool IsURLRequestInfo(PP_Resource resource) {
54 URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource); 60 URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource);
55 return BoolToPPBool(!!object); 61 return BoolToPPBool(!!object);
56 } 62 }
57 63
58 PP_Bool SetProperty(PP_Resource request_id, 64 PP_Bool SetProperty(PP_Resource request_id,
59 PP_URLRequestProperty property, 65 PP_URLRequestProperty property,
60 PP_Var var) { 66 PP_Var var) {
61 PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id); 67 PluginDispatcher* dispatcher;
62 if (!dispatcher) 68 URLRequestInfo* request_info;
69 if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info))
63 return PP_FALSE; 70 return PP_FALSE;
64 71
65 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty( 72 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty(
66 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, 73 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(),
67 static_cast<int32_t>(property), 74 static_cast<int32_t>(property),
68 SerializedVarSendInput(dispatcher, var))); 75 SerializedVarSendInput(dispatcher, var)));
69 76
70 // TODO(brettw) do some validation on the types. We should be able to tell on 77 // 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. 78 // the plugin side whether the request will succeed or fail in the renderer.
72 return PP_TRUE; 79 return PP_TRUE;
73 } 80 }
74 81
75 PP_Bool AppendDataToBody(PP_Resource request_id, 82 PP_Bool AppendDataToBody(PP_Resource request_id,
76 const char* data, uint32_t len) { 83 const char* data, uint32_t len) {
77 PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id); 84 PluginDispatcher* dispatcher;
78 if (!dispatcher) 85 URLRequestInfo* request_info;
86 if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info))
79 return PP_FALSE; 87 return PP_FALSE;
80 88
81 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody( 89 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody(
82 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, std::string(data, len))); 90 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(),
91 std::string(data, len)));
83 92
84 // TODO(brettw) do some validation. We should be able to tell on the plugin 93 // 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. 94 // side whether the request will succeed or fail in the renderer.
86 return PP_TRUE; 95 return PP_TRUE;
87 } 96 }
88 97
89 PP_Bool AppendFileToBody(PP_Resource request_id, 98 PP_Bool AppendFileToBody(PP_Resource request_id,
90 PP_Resource file_ref_id, 99 PP_Resource file_ref_id,
91 int64_t start_offset, 100 int64_t start_offset,
92 int64_t number_of_bytes, 101 int64_t number_of_bytes,
93 PP_Time expected_last_modified_time) { 102 PP_Time expected_last_modified_time) {
94 PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id); 103 PluginDispatcher* dispatcher;
95 if (!dispatcher) 104 URLRequestInfo* request_info;
105 if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info))
106 return PP_FALSE;
107 PluginResource* file_ref_object =
108 PluginResourceTracker::GetInstance()->GetResourceObject(file_ref_id);
109 if (!file_ref_object)
96 return PP_FALSE; 110 return PP_FALSE;
97 111
98 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody( 112 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody(
99 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, file_ref_id, 113 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(),
114 file_ref_object->host_resource(),
100 start_offset, number_of_bytes, expected_last_modified_time)); 115 start_offset, number_of_bytes, expected_last_modified_time));
101 116
102 // TODO(brettw) do some validation. We should be able to tell on the plugin 117 // 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. 118 // side whether the request will succeed or fail in the renderer.
104 return PP_TRUE; 119 return PP_TRUE;
105 } 120 }
106 121
107 const PPB_URLRequestInfo ppb_urlrequestinfo = { 122 const PPB_URLRequestInfo ppb_urlrequestinfo = {
108 &Create, 123 &Create,
109 &IsURLRequestInfo, 124 &IsURLRequestInfo,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody, 157 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody,
143 OnMsgAppendFileToBody) 158 OnMsgAppendFileToBody)
144 IPC_MESSAGE_UNHANDLED(handled = false) 159 IPC_MESSAGE_UNHANDLED(handled = false)
145 IPC_END_MESSAGE_MAP() 160 IPC_END_MESSAGE_MAP()
146 // TODO(brettw): handle bad messages. 161 // TODO(brettw): handle bad messages.
147 return handled; 162 return handled;
148 } 163 }
149 164
150 void PPB_URLRequestInfo_Proxy::OnMsgCreate( 165 void PPB_URLRequestInfo_Proxy::OnMsgCreate(
151 PP_Instance instance, 166 PP_Instance instance,
152 PP_Resource* result) { 167 SerializedResource* result) {
153 *result = ppb_url_request_info_target()->Create(instance); 168 result->set_host_resource(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 SerializedResource 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 SerializedResource 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 SerializedResource request,
174 PP_Resource file_ref, 189 SerializedResource 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

Powered by Google App Engine
This is Rietveld 408576698