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

Side by Side Diff: ppapi/shared_impl/ppb_url_request_info_shared.cc

Issue 10913257: Convert url request info to new proxy API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/shared_impl/ppb_url_request_info_shared.h"
6
7 #include "base/string_util.h"
8 #include "ppapi/shared_impl/var.h"
9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/ppb_file_ref_api.h"
11
12 using ppapi::thunk::EnterResourceNoLock;
13
14 namespace ppapi {
15
16 namespace {
17
18 const int32_t kDefaultPrefetchBufferUpperThreshold = 100 * 1000 * 1000;
19 const int32_t kDefaultPrefetchBufferLowerThreshold = 50 * 1000 * 1000;
20
21 } // namespace
22
23 PPB_URLRequestInfo_Data::BodyItem::BodyItem()
24 : is_file(false),
25 start_offset(0),
26 number_of_bytes(-1),
27 expected_last_modified_time(0.0) {
28 }
29
30 PPB_URLRequestInfo_Data::BodyItem::BodyItem(const std::string& data)
31 : is_file(false),
32 data(data),
33 start_offset(0),
34 number_of_bytes(-1),
35 expected_last_modified_time(0.0) {
36 }
37
38 PPB_URLRequestInfo_Data::BodyItem::BodyItem(
39 Resource* file_ref,
40 int64_t start_offset,
41 int64_t number_of_bytes,
42 PP_Time expected_last_modified_time)
43 : is_file(true),
44 file_ref(file_ref),
45 file_ref_host_resource(file_ref->host_resource()),
46 start_offset(start_offset),
47 number_of_bytes(number_of_bytes),
48 expected_last_modified_time(expected_last_modified_time) {
49 }
50
51 PPB_URLRequestInfo_Data::PPB_URLRequestInfo_Data()
52 : url(),
53 method(),
54 headers(),
55 stream_to_file(false),
56 follow_redirects(true),
57 record_download_progress(false),
58 record_upload_progress(false),
59 has_custom_referrer_url(false),
60 custom_referrer_url(),
61 allow_cross_origin_requests(false),
62 allow_credentials(false),
63 has_custom_content_transfer_encoding(false),
64 custom_content_transfer_encoding(),
65 has_custom_user_agent(false),
66 custom_user_agent(),
67 prefetch_buffer_upper_threshold(kDefaultPrefetchBufferUpperThreshold),
68 prefetch_buffer_lower_threshold(kDefaultPrefetchBufferLowerThreshold),
69 body() {
70 }
71
72 PPB_URLRequestInfo_Data::~PPB_URLRequestInfo_Data() {
73 }
74
75 PPB_URLRequestInfo_Shared::PPB_URLRequestInfo_Shared(
76 ResourceObjectType type,
77 PP_Instance instance,
78 const PPB_URLRequestInfo_Data& data)
79 : Resource(type, instance),
80 data_(data) {
81 }
82
83 PPB_URLRequestInfo_Shared::~PPB_URLRequestInfo_Shared() {
84 }
85
86 thunk::PPB_URLRequestInfo_API*
87 PPB_URLRequestInfo_Shared::AsPPB_URLRequestInfo_API() {
88 return this;
89 }
90
91 PP_Bool PPB_URLRequestInfo_Shared::SetProperty(PP_URLRequestProperty property,
92 PP_Var var) {
93 // IMPORTANT: Do not do security validation of parameters at this level
94 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. This
95 // code is used both in the plugin (which we don't trust) and in the renderer
96 // (which we trust more). When running out-of-process, the plugin calls this
97 // function to configure the PPB_URLRequestInfo_Data, which is then sent to
98 // the renderer and *not* run through SetProperty again.
99 //
100 // This means that anything in the PPB_URLRequestInfo_Data needs to be
101 // validated at the time the URL is requested (which is what ValidateData
102 // does). If your feature requires security checks, it should be in the
103 // implementation in the renderer when the WebKit request is actually
104 // constructed.
105 //
106 // It is legal to do some validation here if you want to report failure to
107 // the plugin as a convenience, as long as you also do it in the renderer
108 // later.
109 PP_Bool result = PP_FALSE;
110 switch (var.type) {
111 case PP_VARTYPE_UNDEFINED:
112 result = PP_FromBool(SetUndefinedProperty(property));
113 break;
114 case PP_VARTYPE_BOOL:
115 result = PP_FromBool(
116 SetBooleanProperty(property, PP_ToBool(var.value.as_bool)));
117 break;
118 case PP_VARTYPE_INT32:
119 result = PP_FromBool(
120 SetIntegerProperty(property, var.value.as_int));
121 break;
122 case PP_VARTYPE_STRING: {
123 StringVar* string = StringVar::FromPPVar(var);
124 if (string)
125 result = PP_FromBool(SetStringProperty(property, string->value()));
126 break;
127 }
128 default:
129 break;
130 }
131 return result;
132 }
133
134 PP_Bool PPB_URLRequestInfo_Shared::AppendDataToBody(const void* data,
135 uint32_t len) {
136 if (len > 0) {
137 data_.body.push_back(PPB_URLRequestInfo_Data::BodyItem(
138 std::string(static_cast<const char*>(data), len)));
139 }
140 return PP_TRUE;
141 }
142
143 PP_Bool PPB_URLRequestInfo_Shared::AppendFileToBody(
144 PP_Resource file_ref,
145 int64_t start_offset,
146 int64_t number_of_bytes,
147 PP_Time expected_last_modified_time) {
148 EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref, true);
149 if (enter.failed())
150 return PP_FALSE;
151
152 // Ignore a call to append nothing.
153 if (number_of_bytes == 0)
154 return PP_TRUE;
155
156 // Check for bad values. (-1 means read until end of file.)
157 if (start_offset < 0 || number_of_bytes < -1)
158 return PP_FALSE;
159
160 data_.body.push_back(PPB_URLRequestInfo_Data::BodyItem(
161 enter.resource(),
162 start_offset,
163 number_of_bytes,
164 expected_last_modified_time));
165 return PP_TRUE;
166 }
167
168 const PPB_URLRequestInfo_Data& PPB_URLRequestInfo_Shared::GetData() const {
169 return data_;
170 }
171
172 bool PPB_URLRequestInfo_Shared::SetUndefinedProperty(
173 PP_URLRequestProperty property) {
174 // IMPORTANT: Do not do security validation of parameters at this level
175 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See
176 // SetProperty() above for why.
177 switch (property) {
178 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL:
179 data_.has_custom_referrer_url = false;
180 data_.custom_referrer_url = std::string();
181 return true;
182 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING:
183 data_.has_custom_content_transfer_encoding = false;
184 data_.custom_content_transfer_encoding = std::string();
185 return true;
186 case PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT:
187 data_.has_custom_user_agent = false;
188 data_.custom_user_agent = std::string();
189 return true;
190 default:
191 return false;
192 }
193 }
194
195 bool PPB_URLRequestInfo_Shared::SetBooleanProperty(
196 PP_URLRequestProperty property,
197 bool value) {
198 // IMPORTANT: Do not do security validation of parameters at this level
199 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See
200 // SetProperty() above for why.
201 switch (property) {
202 case PP_URLREQUESTPROPERTY_STREAMTOFILE:
203 data_.stream_to_file = value;
204 return true;
205 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS:
206 data_.follow_redirects = value;
207 return true;
208 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS:
209 data_.record_download_progress = value;
210 return true;
211 case PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS:
212 data_.record_upload_progress = value;
213 return true;
214 case PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS:
215 data_.allow_cross_origin_requests = value;
216 return true;
217 case PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS:
218 data_.allow_credentials = value;
219 return true;
220 default:
221 return false;
222 }
223 }
224
225 bool PPB_URLRequestInfo_Shared::SetIntegerProperty(
226 PP_URLRequestProperty property,
227 int32_t value) {
228 // IMPORTANT: Do not do security validation of parameters at this level
229 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See
230 // SetProperty() above for why.
231 switch (property) {
232 case PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD:
233 data_.prefetch_buffer_upper_threshold = value;
234 return true;
235 case PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD:
236 data_.prefetch_buffer_lower_threshold = value;
237 return true;
238 default:
239 return false;
240 }
241 }
242
243 bool PPB_URLRequestInfo_Shared::SetStringProperty(
244 PP_URLRequestProperty property,
245 const std::string& value) {
246 // IMPORTANT: Do not do security validation of parameters at this level
247 // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See
248 // SetProperty() above for why.
249 switch (property) {
250 case PP_URLREQUESTPROPERTY_URL:
251 data_.url = value; // NOTE: This may be a relative URL.
252 return true;
253 case PP_URLREQUESTPROPERTY_METHOD:
254 data_.method = value;
255 return true;
256 case PP_URLREQUESTPROPERTY_HEADERS:
257 data_.headers = value;
258 return true;
259 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL:
260 data_.has_custom_referrer_url = true;
261 data_.custom_referrer_url = value;
262 return true;
263 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING:
264 data_.has_custom_content_transfer_encoding = true;
265 data_.custom_content_transfer_encoding = value;
266 return true;
267 case PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT:
268 data_.has_custom_user_agent = true;
269 data_.custom_user_agent = value;
270 return true;
271 default:
272 return false;
273 }
274 }
275
276 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_url_request_info_shared.h ('k') | ppapi/shared_impl/url_request_info_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698