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

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

Powered by Google App Engine
This is Rietveld 408576698