1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/proxy/ppb_url_request_info_proxy.h"
#include "ppapi/c/ppb_url_request_info.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace pp {
namespace proxy {
class URLRequestInfo : public PluginResource {
public:
URLRequestInfo(const HostResource& resource) : PluginResource(resource) {
}
virtual ~URLRequestInfo() {
}
// Resource overrides.
virtual URLRequestInfo* AsURLRequestInfo() { return this; }
private:
DISALLOW_COPY_AND_ASSIGN(URLRequestInfo);
};
namespace {
// Computes the dispatcher and request object for the given plugin resource,
// returning true on success.
bool DispatcherFromURLRequestInfo(PP_Resource resource,
PluginDispatcher** dispatcher,
URLRequestInfo** request_info) {
*request_info = PluginResource::GetAs<URLRequestInfo>(resource);
if (!*request_info)
return false;
*dispatcher = PluginDispatcher::GetForInstance((*request_info)->instance());
return !!*dispatcher;
}
PP_Resource Create(PP_Instance instance) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return 0;
HostResource result;
dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create(
INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result));
if (result.is_null())
return 0;
linked_ptr<URLRequestInfo> object(new URLRequestInfo(result));
return PluginResourceTracker::GetInstance()->AddResource(object);
}
PP_Bool IsURLRequestInfo(PP_Resource resource) {
URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource);
return BoolToPPBool(!!object);
}
PP_Bool SetProperty(PP_Resource request_id,
PP_URLRequestProperty property,
PP_Var var) {
PluginDispatcher* dispatcher;
URLRequestInfo* request_info;
if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info))
return PP_FALSE;
dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty(
INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(),
static_cast<int32_t>(property),
SerializedVarSendInput(dispatcher, var)));
// TODO(brettw) do some validation on the types. We should be able to tell on
// the plugin side whether the request will succeed or fail in the renderer.
return PP_TRUE;
}
PP_Bool AppendDataToBody(PP_Resource request_id,
const char* data, uint32_t len) {
PluginDispatcher* dispatcher;
URLRequestInfo* request_info;
if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info))
return PP_FALSE;
dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody(
INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(),
std::string(data, len)));
// TODO(brettw) do some validation. We should be able to tell on the plugin
// side whether the request will succeed or fail in the renderer.
return PP_TRUE;
}
PP_Bool AppendFileToBody(PP_Resource request_id,
PP_Resource file_ref_id,
int64_t start_offset,
int64_t number_of_bytes,
PP_Time expected_last_modified_time) {
PluginDispatcher* dispatcher;
URLRequestInfo* request_info;
if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info))
return PP_FALSE;
PluginResource* file_ref_object =
PluginResourceTracker::GetInstance()->GetResourceObject(file_ref_id);
if (!file_ref_object)
return PP_FALSE;
dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody(
INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(),
file_ref_object->host_resource(),
start_offset, number_of_bytes, expected_last_modified_time));
// TODO(brettw) do some validation. We should be able to tell on the plugin
// side whether the request will succeed or fail in the renderer.
return PP_TRUE;
}
const PPB_URLRequestInfo urlrequestinfo_interface = {
&Create,
&IsURLRequestInfo,
&SetProperty,
&AppendDataToBody,
&AppendFileToBody
};
InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher,
const void* target_interface) {
return new PPB_URLRequestInfo_Proxy(dispatcher, target_interface);
}
} // namespace
PPB_URLRequestInfo_Proxy::PPB_URLRequestInfo_Proxy(
Dispatcher* dispatcher,
const void* target_interface)
: InterfaceProxy(dispatcher, target_interface) {
}
PPB_URLRequestInfo_Proxy::~PPB_URLRequestInfo_Proxy() {
}
// static
const InterfaceProxy::Info* PPB_URLRequestInfo_Proxy::GetInfo() {
static const Info info = {
&urlrequestinfo_interface,
PPB_URLREQUESTINFO_INTERFACE,
INTERFACE_ID_PPB_URL_REQUEST_INFO,
false,
&CreateURLRequestInfoProxy,
};
return &info;
}
bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_URLRequestInfo_Proxy, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_Create, OnMsgCreate)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_SetProperty,
OnMsgSetProperty)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody,
OnMsgAppendDataToBody)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody,
OnMsgAppendFileToBody)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
// TODO(brettw): handle bad messages.
return handled;
}
void PPB_URLRequestInfo_Proxy::OnMsgCreate(
PP_Instance instance,
HostResource* result) {
result->SetHostResource(instance,
ppb_url_request_info_target()->Create(instance));
}
void PPB_URLRequestInfo_Proxy::OnMsgSetProperty(
HostResource request,
int32_t property,
SerializedVarReceiveInput value) {
ppb_url_request_info_target()->SetProperty(request.host_resource(),
static_cast<PP_URLRequestProperty>(property),
value.Get(dispatcher()));
}
void PPB_URLRequestInfo_Proxy::OnMsgAppendDataToBody(
HostResource request,
const std::string& data) {
ppb_url_request_info_target()->AppendDataToBody(request.host_resource(),
data.c_str(), data.size());
}
void PPB_URLRequestInfo_Proxy::OnMsgAppendFileToBody(
HostResource request,
HostResource file_ref,
int64_t start_offset,
int64_t number_of_bytes,
double expected_last_modified_time) {
ppb_url_request_info_target()->AppendFileToBody(
request.host_resource(), file_ref.host_resource(),
start_offset, number_of_bytes, expected_last_modified_time);
}
} // namespace proxy
} // namespace pp
|