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

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

Issue 7706021: Convert FileRefImpl and URLRequestInfo to shared_impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests fixed Created 9 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) 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"
8 #include "ppapi/proxy/enter_proxy.h"
9 #include "ppapi/proxy/plugin_dispatcher.h" 7 #include "ppapi/proxy/plugin_dispatcher.h"
10 #include "ppapi/proxy/ppapi_messages.h" 8 #include "ppapi/shared_impl/url_request_info_impl.h"
11 #include "ppapi/thunk/ppb_url_request_info_api.h"
12 #include "ppapi/thunk/resource_creation_api.h"
13 #include "ppapi/thunk/thunk.h" 9 #include "ppapi/thunk/thunk.h"
14 10
15 using ppapi::thunk::EnterFunctionNoLock;
16 using ppapi::thunk::PPB_URLRequestInfo_API;
17 using ppapi::thunk::ResourceCreationAPI;
18
19 namespace ppapi { 11 namespace ppapi {
20 namespace proxy { 12 namespace proxy {
21 13
22 namespace { 14 namespace {
23 15
24 InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher, 16 InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher,
25 const void* target_interface) { 17 const void* target_interface) {
26 return new PPB_URLRequestInfo_Proxy(dispatcher, target_interface); 18 return new PPB_URLRequestInfo_Proxy(dispatcher, target_interface);
27 } 19 }
28 20
29 } // namespace 21 } // namespace
30 22
31 class URLRequestInfo : public Resource,
32 public PPB_URLRequestInfo_API {
33 public:
34 URLRequestInfo(const HostResource& resource);
35 virtual ~URLRequestInfo();
36
37 virtual PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE;
38
39 // PPB_URLRequestInfo_API implementation.
40 virtual PP_Bool SetProperty(PP_URLRequestProperty property,
41 PP_Var var) OVERRIDE;
42 virtual PP_Bool AppendDataToBody(const void* data, uint32_t len) OVERRIDE;
43 virtual PP_Bool AppendFileToBody(
44 PP_Resource file_ref,
45 int64_t start_offset,
46 int64_t number_of_bytes,
47 PP_Time expected_last_modified_time) OVERRIDE;
48
49 private:
50 PluginDispatcher* GetDispatcher() const {
51 return PluginDispatcher::GetForResource(this);
52 }
53
54 DISALLOW_COPY_AND_ASSIGN(URLRequestInfo);
55 };
56
57 URLRequestInfo::URLRequestInfo(const HostResource& resource)
58 : Resource(resource) {
59 }
60
61 URLRequestInfo::~URLRequestInfo() {
62 }
63
64 PPB_URLRequestInfo_API* URLRequestInfo::AsPPB_URLRequestInfo_API() {
65 return this;
66 }
67
68 PP_Bool URLRequestInfo::SetProperty(PP_URLRequestProperty property,
69 PP_Var var) {
70 GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty(
71 INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(),
72 static_cast<int32_t>(property),
73 SerializedVarSendInput(GetDispatcher(), var)));
74
75 // TODO(brettw) do some validation on the types. We should be able to tell on
76 // the plugin side whether the request will succeed or fail in the renderer.
77 return PP_TRUE;
78 }
79
80 PP_Bool URLRequestInfo::AppendDataToBody(const void* data, uint32_t len) {
81 GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody(
82 INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(),
83 std::string(static_cast<const char*>(data), len)));
84
85 // TODO(brettw) do some validation. We should be able to tell on the plugin
86 // side whether the request will succeed or fail in the renderer.
87 return PP_TRUE;
88 }
89
90 PP_Bool URLRequestInfo::AppendFileToBody(PP_Resource file_ref,
91 int64_t start_offset,
92 int64_t number_of_bytes,
93 PP_Time expected_last_modified_time) {
94 Resource* file_ref_object =
95 PluginResourceTracker::GetInstance()->GetResource(file_ref);
96 if (!file_ref_object)
97 return PP_FALSE;
98
99 GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody(
100 INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(),
101 file_ref_object->host_resource(),
102 start_offset, number_of_bytes, expected_last_modified_time));
103
104 // TODO(brettw) do some validation. We should be able to tell on the plugin
105 // side whether the request will succeed or fail in the renderer.
106 return PP_TRUE;
107 }
108
109 // PPB_URLRequestInfo_Proxy ----------------------------------------------------
110
111 PPB_URLRequestInfo_Proxy::PPB_URLRequestInfo_Proxy( 23 PPB_URLRequestInfo_Proxy::PPB_URLRequestInfo_Proxy(
112 Dispatcher* dispatcher, 24 Dispatcher* dispatcher,
113 const void* target_interface) 25 const void* target_interface)
114 : InterfaceProxy(dispatcher, target_interface) { 26 : InterfaceProxy(dispatcher, target_interface) {
115 } 27 }
116 28
117 PPB_URLRequestInfo_Proxy::~PPB_URLRequestInfo_Proxy() { 29 PPB_URLRequestInfo_Proxy::~PPB_URLRequestInfo_Proxy() {
118 } 30 }
119 31
120 // static 32 // static
121 const InterfaceProxy::Info* PPB_URLRequestInfo_Proxy::GetInfo() { 33 const InterfaceProxy::Info* PPB_URLRequestInfo_Proxy::GetInfo() {
122 static const Info info = { 34 static const Info info = {
123 thunk::GetPPB_URLRequestInfo_Thunk(), 35 thunk::GetPPB_URLRequestInfo_Thunk(),
124 PPB_URLREQUESTINFO_INTERFACE, 36 PPB_URLREQUESTINFO_INTERFACE,
125 INTERFACE_ID_PPB_URL_REQUEST_INFO, 37 INTERFACE_ID_PPB_URL_REQUEST_INFO,
126 false, 38 false,
127 &CreateURLRequestInfoProxy, 39 &CreateURLRequestInfoProxy,
128 }; 40 };
129 return &info; 41 return &info;
130 } 42 }
131 43
132 // static
133 PP_Resource PPB_URLRequestInfo_Proxy::CreateProxyResource(
134 PP_Instance instance) {
135 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
136 if (!dispatcher)
137 return 0;
138
139 HostResource result;
140 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create(
141 INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result));
142 if (result.is_null())
143 return 0;
144 return (new URLRequestInfo(result))->GetReference();
145 }
146
147 bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { 44 bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) {
148 bool handled = true; 45 // No messages to handle.
149 IPC_BEGIN_MESSAGE_MAP(PPB_URLRequestInfo_Proxy, msg) 46 return false;
150 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_Create, OnMsgCreate)
151 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_SetProperty,
152 OnMsgSetProperty)
153 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody,
154 OnMsgAppendDataToBody)
155 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody,
156 OnMsgAppendFileToBody)
157 IPC_MESSAGE_UNHANDLED(handled = false)
158 IPC_END_MESSAGE_MAP()
159 // TODO(brettw): handle bad messages.
160 return handled;
161 }
162
163 void PPB_URLRequestInfo_Proxy::OnMsgCreate(
164 PP_Instance instance,
165 HostResource* result) {
166 EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true);
167 if (enter.succeeded()) {
168 result->SetHostResource(instance,
169 enter.functions()->CreateURLRequestInfo(instance));
170 }
171 }
172
173 void PPB_URLRequestInfo_Proxy::OnMsgSetProperty(
174 HostResource request,
175 int32_t property,
176 SerializedVarReceiveInput value) {
177 EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request);
178 if (enter.succeeded()) {
179 enter.object()->SetProperty(static_cast<PP_URLRequestProperty>(property),
180 value.Get(dispatcher()));
181 }
182 }
183
184 void PPB_URLRequestInfo_Proxy::OnMsgAppendDataToBody(
185 HostResource request,
186 const std::string& data) {
187 EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request);
188 if (enter.succeeded())
189 enter.object()->AppendDataToBody(data.c_str(), data.size());
190 }
191
192 void PPB_URLRequestInfo_Proxy::OnMsgAppendFileToBody(
193 HostResource request,
194 HostResource file_ref,
195 int64_t start_offset,
196 int64_t number_of_bytes,
197 double expected_last_modified_time) {
198 EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request);
199 if (enter.succeeded()) {
200 enter.object()->AppendFileToBody(
201 file_ref.host_resource(), start_offset, number_of_bytes,
202 expected_last_modified_time);
203 }
204 } 47 }
205 48
206 } // namespace proxy 49 } // namespace proxy
207 } // namespace ppapi 50 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698