| OLD | NEW |
| 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 "webkit/plugins/ppapi/ppb_url_request_info_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "googleurl/src/url_util.h" | 10 #include "googleurl/src/url_util.h" |
| 11 #include "net/http/http_util.h" | 11 #include "net/http/http_util.h" |
| 12 #include "ppapi/c/pp_var.h" | |
| 13 #include "ppapi/shared_impl/var.h" | 12 #include "ppapi/shared_impl/var.h" |
| 14 #include "ppapi/thunk/enter.h" | 13 #include "ppapi/thunk/enter.h" |
| 15 #include "ppapi/thunk/ppb_file_ref_api.h" | |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHTTPBody.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHTTPBody.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 22 #include "webkit/glue/webkit_glue.h" | 20 #include "webkit/glue/webkit_glue.h" |
| 23 #include "webkit/plugins/ppapi/common.h" | 21 #include "webkit/plugins/ppapi/common.h" |
| 24 #include "webkit/plugins/ppapi/plugin_module.h" | 22 #include "webkit/plugins/ppapi/plugin_module.h" |
| 25 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 23 //#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 26 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 24 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 27 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" | 25 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" |
| 28 #include "webkit/plugins/ppapi/resource_helper.h" | 26 #include "webkit/plugins/ppapi/resource_helper.h" |
| 29 #include "webkit/plugins/ppapi/string.h" | |
| 30 | 27 |
| 31 using ppapi::StringVar; | 28 using ppapi::PPB_URLRequestInfo_Data; |
| 29 using ppapi::Resource; |
| 32 using ppapi::thunk::EnterResourceNoLock; | 30 using ppapi::thunk::EnterResourceNoLock; |
| 33 using ppapi::thunk::PPB_FileRef_API; | 31 using ppapi::thunk::PPB_FileRef_API; |
| 34 using ppapi::thunk::PPB_URLRequestInfo_API; | |
| 35 using WebKit::WebData; | 32 using WebKit::WebData; |
| 36 using WebKit::WebHTTPBody; | 33 using WebKit::WebHTTPBody; |
| 37 using WebKit::WebString; | 34 using WebKit::WebString; |
| 38 using WebKit::WebFrame; | 35 using WebKit::WebFrame; |
| 39 using WebKit::WebURL; | 36 using WebKit::WebURL; |
| 40 using WebKit::WebURLRequest; | 37 using WebKit::WebURLRequest; |
| 41 | 38 |
| 42 namespace webkit { | 39 namespace webkit { |
| 43 namespace ppapi { | 40 namespace ppapi { |
| 44 | 41 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 58 return false; | 55 return false; |
| 59 if (c == '(' || c == ')' || c == '<' || c == '>' || c == '@' || | 56 if (c == '(' || c == ')' || c == '<' || c == '>' || c == '@' || |
| 60 c == ',' || c == ';' || c == ':' || c == '\\' || c == '\"' || | 57 c == ',' || c == ';' || c == ':' || c == '\\' || c == '\"' || |
| 61 c == '/' || c == '[' || c == ']' || c == '?' || c == '=' || | 58 c == '/' || c == '[' || c == ']' || c == '?' || c == '=' || |
| 62 c == '{' || c == '}') | 59 c == '{' || c == '}') |
| 63 return false; | 60 return false; |
| 64 } | 61 } |
| 65 return true; | 62 return true; |
| 66 } | 63 } |
| 67 | 64 |
| 68 // These methods are not allowed by the XMLHttpRequest standard. | |
| 69 // http://www.w3.org/TR/XMLHttpRequest/#the-open-method | |
| 70 const char* const kForbiddenHttpMethods[] = { | |
| 71 "connect", | |
| 72 "trace", | |
| 73 "track", | |
| 74 }; | |
| 75 | |
| 76 // These are the "known" methods in the Webkit XHR implementation. Also see | |
| 77 // the XMLHttpRequest standard. | |
| 78 // http://www.w3.org/TR/XMLHttpRequest/#the-open-method | |
| 79 const char* const kKnownHttpMethods[] = { | |
| 80 "get", | |
| 81 "post", | |
| 82 "put", | |
| 83 "head", | |
| 84 "copy", | |
| 85 "delete", | |
| 86 "index", | |
| 87 "lock", | |
| 88 "m-post", | |
| 89 "mkcol", | |
| 90 "move", | |
| 91 "options", | |
| 92 "propfind", | |
| 93 "proppatch", | |
| 94 "unlock", | |
| 95 }; | |
| 96 | |
| 97 std::string ValidateMethod(const std::string& method) { | |
| 98 for (size_t i = 0; i < arraysize(kForbiddenHttpMethods); ++i) { | |
| 99 if (LowerCaseEqualsASCII(method, kForbiddenHttpMethods[i])) | |
| 100 return std::string(); | |
| 101 } | |
| 102 for (size_t i = 0; i < arraysize(kKnownHttpMethods); ++i) { | |
| 103 if (LowerCaseEqualsASCII(method, kKnownHttpMethods[i])) { | |
| 104 // Convert the method name to upper case to match Webkit and Firefox's | |
| 105 // XHR implementation. | |
| 106 return StringToUpperASCII(std::string(kKnownHttpMethods[i])); | |
| 107 } | |
| 108 } | |
| 109 // Pass through unknown methods that are not forbidden. | |
| 110 return method; | |
| 111 } | |
| 112 | |
| 113 // A header string containing any of the following fields will cause | 65 // A header string containing any of the following fields will cause |
| 114 // an error. The list comes from the XMLHttpRequest standard. | 66 // an error. The list comes from the XMLHttpRequest standard. |
| 115 // http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method | 67 // http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method |
| 116 const char* const kForbiddenHeaderFields[] = { | 68 const char* const kForbiddenHeaderFields[] = { |
| 117 "accept-charset", | 69 "accept-charset", |
| 118 "accept-encoding", | 70 "accept-encoding", |
| 119 "connection", | 71 "connection", |
| 120 "content-length", | 72 "content-length", |
| 121 "cookie", | 73 "cookie", |
| 122 "cookie2", | 74 "cookie2", |
| (...skipping 29 matching lines...) Expand all Loading... |
| 152 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); | 104 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); |
| 153 while (it.GetNext()) { | 105 while (it.GetNext()) { |
| 154 if (!IsValidHeaderField(it.name())) | 106 if (!IsValidHeaderField(it.name())) |
| 155 return false; | 107 return false; |
| 156 } | 108 } |
| 157 return true; | 109 return true; |
| 158 } | 110 } |
| 159 | 111 |
| 160 } // namespace | 112 } // namespace |
| 161 | 113 |
| 162 struct PPB_URLRequestInfo_Impl::BodyItem { | |
| 163 explicit BodyItem(const std::string& data) | |
| 164 : data(data), | |
| 165 start_offset(0), | |
| 166 number_of_bytes(-1), | |
| 167 expected_last_modified_time(0.0) { | |
| 168 } | |
| 169 | 114 |
| 170 BodyItem(PPB_FileRef_Impl* file_ref, | 115 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl( |
| 171 int64_t start_offset, | 116 PP_Instance instance, |
| 172 int64_t number_of_bytes, | 117 const PPB_URLRequestInfo_Data& data) |
| 173 PP_Time expected_last_modified_time) | 118 : URLRequestInfoImpl(instance, data) { |
| 174 : file_ref(file_ref), | |
| 175 start_offset(start_offset), | |
| 176 number_of_bytes(number_of_bytes), | |
| 177 expected_last_modified_time(expected_last_modified_time) { | |
| 178 } | |
| 179 | |
| 180 std::string data; | |
| 181 scoped_refptr<PPB_FileRef_Impl> file_ref; | |
| 182 int64_t start_offset; | |
| 183 int64_t number_of_bytes; | |
| 184 PP_Time expected_last_modified_time; | |
| 185 }; | |
| 186 | |
| 187 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PP_Instance instance) | |
| 188 : Resource(instance), | |
| 189 stream_to_file_(false), | |
| 190 follow_redirects_(true), | |
| 191 record_download_progress_(false), | |
| 192 record_upload_progress_(false), | |
| 193 has_custom_referrer_url_(false), | |
| 194 allow_cross_origin_requests_(false), | |
| 195 allow_credentials_(false), | |
| 196 has_custom_content_transfer_encoding_(false), | |
| 197 prefetch_buffer_upper_threshold_(kDefaultPrefetchBufferUpperThreshold), | |
| 198 prefetch_buffer_lower_threshold_(kDefaultPrefetchBufferLowerThreshold) { | |
| 199 } | 119 } |
| 200 | 120 |
| 201 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() { | 121 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() { |
| 202 } | 122 } |
| 203 | 123 |
| 204 PPB_URLRequestInfo_API* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_API() { | 124 bool PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame, |
| 205 return this; | 125 WebURLRequest* dest) { |
| 206 } | 126 // In the out-of-process case, we've received the PPB_URLRequestInfo_Data |
| 127 // from the untrusted plugin and done no validation on it. We need to be |
| 128 // sure it's not being malicious by checking everything for consistency. |
| 129 if (!ValidateData()) |
| 130 return false; |
| 207 | 131 |
| 208 PP_Bool PPB_URLRequestInfo_Impl::SetProperty(PP_URLRequestProperty property, | 132 dest->initialize(); |
| 209 PP_Var var) { | 133 dest->setURL(frame->document().completeURL(WebString::fromUTF8( |
| 210 PP_Bool result = PP_FALSE; | 134 data().url))); |
| 211 switch (var.type) { | 135 dest->setDownloadToFile(data().stream_to_file); |
| 212 case PP_VARTYPE_UNDEFINED: | 136 dest->setReportUploadProgress(data().record_upload_progress); |
| 213 result = PP_FromBool(SetUndefinedProperty(property)); | |
| 214 break; | |
| 215 case PP_VARTYPE_BOOL: | |
| 216 result = PP_FromBool( | |
| 217 SetBooleanProperty(property, PP_ToBool(var.value.as_bool))); | |
| 218 break; | |
| 219 case PP_VARTYPE_INT32: | |
| 220 result = PP_FromBool( | |
| 221 SetIntegerProperty(property, var.value.as_int)); | |
| 222 break; | |
| 223 case PP_VARTYPE_STRING: { | |
| 224 StringVar* string = StringVar::FromPPVar(var); | |
| 225 if (string) | |
| 226 result = PP_FromBool(SetStringProperty(property, string->value())); | |
| 227 break; | |
| 228 } | |
| 229 default: | |
| 230 break; | |
| 231 } | |
| 232 return result; | |
| 233 } | |
| 234 | 137 |
| 235 PP_Bool PPB_URLRequestInfo_Impl::AppendDataToBody(const void* data, | 138 if (!data().method.empty()) |
| 236 uint32_t len) { | 139 dest->setHTTPMethod(WebString::fromUTF8(data().method)); |
| 237 if (len > 0) | |
| 238 body_.push_back(BodyItem(std::string(static_cast<const char*>(data), len))); | |
| 239 return PP_TRUE; | |
| 240 } | |
| 241 | 140 |
| 242 PP_Bool PPB_URLRequestInfo_Impl::AppendFileToBody( | 141 dest->setFirstPartyForCookies( |
| 243 PP_Resource file_ref, | |
| 244 int64_t start_offset, | |
| 245 int64_t number_of_bytes, | |
| 246 PP_Time expected_last_modified_time) { | |
| 247 // Ignore a call to append nothing. | |
| 248 if (number_of_bytes == 0) | |
| 249 return PP_TRUE; | |
| 250 | |
| 251 // Check for bad values. (-1 means read until end of file.) | |
| 252 if (start_offset < 0 || number_of_bytes < -1) | |
| 253 return PP_FALSE; | |
| 254 | |
| 255 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true); | |
| 256 if (enter.failed()) | |
| 257 return PP_FALSE; | |
| 258 | |
| 259 body_.push_back(BodyItem(static_cast<PPB_FileRef_Impl*>(enter.object()), | |
| 260 start_offset, | |
| 261 number_of_bytes, | |
| 262 expected_last_modified_time)); | |
| 263 return PP_TRUE; | |
| 264 } | |
| 265 | |
| 266 WebURLRequest PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame) const { | |
| 267 WebURLRequest web_request; | |
| 268 web_request.initialize(); | |
| 269 web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_))); | |
| 270 web_request.setDownloadToFile(stream_to_file_); | |
| 271 web_request.setReportUploadProgress(record_upload_progress()); | |
| 272 | |
| 273 if (!method_.empty()) | |
| 274 web_request.setHTTPMethod(WebString::fromUTF8(method_)); | |
| 275 | |
| 276 web_request.setFirstPartyForCookies( | |
| 277 frame->document().firstPartyForCookies()); | 142 frame->document().firstPartyForCookies()); |
| 278 | 143 |
| 279 if (!headers_.empty()) { | 144 const std::string& headers = data().headers; |
| 280 net::HttpUtil::HeadersIterator it(headers_.begin(), headers_.end(), "\n"); | 145 if (!headers.empty()) { |
| 146 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); |
| 281 while (it.GetNext()) { | 147 while (it.GetNext()) { |
| 282 web_request.addHTTPHeaderField( | 148 dest->addHTTPHeaderField( |
| 283 WebString::fromUTF8(it.name()), | 149 WebString::fromUTF8(it.name()), |
| 284 WebString::fromUTF8(it.values())); | 150 WebString::fromUTF8(it.values())); |
| 285 } | 151 } |
| 286 } | 152 } |
| 287 | 153 |
| 288 if (!body_.empty()) { | 154 // Append the upload data. |
| 155 if (!data().body.empty()) { |
| 289 WebHTTPBody http_body; | 156 WebHTTPBody http_body; |
| 290 http_body.initialize(); | 157 http_body.initialize(); |
| 291 for (size_t i = 0; i < body_.size(); ++i) { | 158 for (size_t i = 0; i < data().body.size(); ++i) { |
| 292 if (body_[i].file_ref) { | 159 const PPB_URLRequestInfo_Data::BodyItem& item = data().body[i]; |
| 293 FilePath platform_path; | 160 if (item.is_file) { |
| 294 switch (body_[i].file_ref->file_system()->type()) { | 161 if (!AppendFileRefToBody(item.file_ref, |
| 295 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: | 162 item.start_offset, |
| 296 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: | 163 item.number_of_bytes, |
| 297 // TODO(kinuko): remove this sync IPC when we add more generic | 164 item.expected_last_modified_time, |
| 298 // AppendURLRange solution that works for both Blob/FileSystem URL. | 165 &http_body)) |
| 299 ResourceHelper::GetPluginDelegate(this)-> | 166 return false; |
| 300 SyncGetFileSystemPlatformPath( | |
| 301 body_[i].file_ref->GetFileSystemURL(), &platform_path); | |
| 302 break; | |
| 303 case PP_FILESYSTEMTYPE_EXTERNAL: | |
| 304 platform_path = body_[i].file_ref->GetSystemPath(); | |
| 305 break; | |
| 306 default: | |
| 307 NOTREACHED(); | |
| 308 } | |
| 309 http_body.appendFileRange( | |
| 310 webkit_glue::FilePathToWebString(platform_path), | |
| 311 body_[i].start_offset, | |
| 312 body_[i].number_of_bytes, | |
| 313 body_[i].expected_last_modified_time); | |
| 314 } else { | 167 } else { |
| 315 DCHECK(!body_[i].data.empty()); | 168 DCHECK(!item.data.empty()); |
| 316 http_body.appendData(WebData(body_[i].data)); | 169 http_body.appendData(WebData(item.data)); |
| 317 } | 170 } |
| 318 } | 171 } |
| 319 web_request.setHTTPBody(http_body); | 172 dest->setHTTPBody(http_body); |
| 320 } | 173 } |
| 321 | 174 |
| 322 if (has_custom_referrer_url_) { | 175 if (data().has_custom_referrer_url) { |
| 323 if (!custom_referrer_url_.empty()) | 176 if (!data().custom_referrer_url.empty()) |
| 324 frame->setReferrerForRequest(web_request, GURL(custom_referrer_url_)); | 177 frame->setReferrerForRequest(*dest, GURL(data().custom_referrer_url)); |
| 325 } else if (!allow_cross_origin_requests_) { | 178 } else if (!data().allow_cross_origin_requests) { |
| 326 // Use default, except for cross-origin requests, since 'referer' is not | 179 // Use default, except for cross-origin requests, since 'referer' is not |
| 327 // whitelisted and will cause the request to fail. | 180 // whitelisted and will cause the request to fail. |
| 328 frame->setReferrerForRequest(web_request, WebURL()); | 181 frame->setReferrerForRequest(*dest, WebURL()); |
| 329 } | 182 } |
| 330 | 183 |
| 331 if (has_custom_content_transfer_encoding_) { | 184 if (data().has_custom_content_transfer_encoding) { |
| 332 if (!custom_content_transfer_encoding_.empty()) { | 185 if (!data().custom_content_transfer_encoding.empty()) { |
| 333 web_request.addHTTPHeaderField( | 186 dest->addHTTPHeaderField( |
| 334 WebString::fromUTF8("Content-Transfer-Encoding"), | 187 WebString::fromUTF8("Content-Transfer-Encoding"), |
| 335 WebString::fromUTF8(custom_content_transfer_encoding_)); | 188 WebString::fromUTF8(data().custom_content_transfer_encoding)); |
| 336 } | 189 } |
| 337 } | 190 } |
| 338 | 191 |
| 339 return web_request; | 192 return true; |
| 340 } | 193 } |
| 341 | 194 |
| 342 bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { | 195 bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { |
| 343 return | 196 return |
| 344 has_custom_referrer_url_ || | 197 data().has_custom_referrer_url || |
| 345 has_custom_content_transfer_encoding_ || | 198 data().has_custom_content_transfer_encoding || |
| 346 url_util::FindAndCompareScheme(url_, "javascript", NULL); | 199 url_util::FindAndCompareScheme(data().url, "javascript", NULL); |
| 347 } | 200 } |
| 348 | 201 |
| 349 bool PPB_URLRequestInfo_Impl::SetUndefinedProperty( | 202 bool PPB_URLRequestInfo_Impl::ValidateData() { |
| 350 PP_URLRequestProperty property) { | 203 // Method should either be empty or a valid one. |
| 351 switch (property) { | 204 if (!data().method.empty()) { |
| 352 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: | 205 std::string canonicalized = ValidateMethod(data().method); |
| 353 has_custom_referrer_url_ = false; | 206 if (canonicalized.empty()) |
| 354 custom_referrer_url_ = std::string(); | |
| 355 return true; | |
| 356 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING: | |
| 357 has_custom_content_transfer_encoding_ = false; | |
| 358 custom_content_transfer_encoding_ = std::string(); | |
| 359 return true; | |
| 360 default: | |
| 361 return false; | 207 return false; |
| 208 data().method = canonicalized; |
| 362 } | 209 } |
| 210 |
| 211 if (!AreValidHeaders(data().headers)) |
| 212 return false; |
| 213 |
| 214 // Get the Resource objects for any file refs with only host resource (this |
| 215 // is the state of the request as it comes off IPC). |
| 216 for (size_t i = 0; i < data().body.size(); ++i) { |
| 217 PPB_URLRequestInfo_Data::BodyItem& item = data().body[i]; |
| 218 if (item.is_file && !item.file_ref) { |
| 219 EnterResourceNoLock<PPB_FileRef_API> enter( |
| 220 item.file_ref_host_resource.host_resource(), false); |
| 221 if (!enter.succeeded()) |
| 222 return false; |
| 223 item.file_ref = enter.resource(); |
| 224 } |
| 225 } |
| 226 return true; |
| 363 } | 227 } |
| 364 | 228 |
| 365 bool PPB_URLRequestInfo_Impl::SetBooleanProperty(PP_URLRequestProperty property, | 229 bool PPB_URLRequestInfo_Impl::AppendFileRefToBody( |
| 366 bool value) { | 230 Resource* file_ref_resource, |
| 367 switch (property) { | 231 int64_t start_offset, |
| 368 case PP_URLREQUESTPROPERTY_STREAMTOFILE: | 232 int64_t number_of_bytes, |
| 369 stream_to_file_ = value; | 233 PP_Time expected_last_modified_time, |
| 370 return true; | 234 WebHTTPBody *http_body) { |
| 371 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS: | 235 // Get the underlying file ref impl. |
| 372 follow_redirects_ = value; | 236 if (!file_ref_resource) |
| 373 return true; | 237 return false; |
| 374 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS: | 238 PPB_FileRef_API* file_ref_api = file_ref_resource->AsPPB_FileRef_API(); |
| 375 record_download_progress_ = value; | 239 if (!file_ref_api) |
| 376 return true; | 240 return false; |
| 377 case PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS: | 241 const PPB_FileRef_Impl* file_ref = |
| 378 record_upload_progress_ = value; | 242 static_cast<PPB_FileRef_Impl*>(file_ref_api); |
| 379 return true; | 243 |
| 380 case PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS: | 244 FilePath platform_path; |
| 381 allow_cross_origin_requests_ = value; | 245 switch (file_ref->file_system()->type()) { |
| 382 return true; | 246 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: |
| 383 case PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS: | 247 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: |
| 384 allow_credentials_ = value; | 248 // TODO(kinuko): remove this sync IPC when we add more generic |
| 385 return true; | 249 // AppendURLRange solution that works for both Blob/FileSystem URL. |
| 250 ResourceHelper::GetPluginDelegate(this)-> |
| 251 SyncGetFileSystemPlatformPath( |
| 252 file_ref->GetFileSystemURL(), &platform_path); |
| 253 break; |
| 254 case PP_FILESYSTEMTYPE_EXTERNAL: |
| 255 platform_path = file_ref->GetSystemPath(); |
| 256 break; |
| 386 default: | 257 default: |
| 387 return false; | 258 NOTREACHED(); |
| 388 } | 259 } |
| 260 http_body->appendFileRange( |
| 261 webkit_glue::FilePathToWebString(platform_path), |
| 262 start_offset, |
| 263 number_of_bytes, |
| 264 expected_last_modified_time); |
| 265 return true; |
| 389 } | 266 } |
| 390 | 267 |
| 391 bool PPB_URLRequestInfo_Impl::SetIntegerProperty(PP_URLRequestProperty property, | |
| 392 int32_t value) { | |
| 393 switch (property) { | |
| 394 case PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD: | |
| 395 prefetch_buffer_upper_threshold_ = value; | |
| 396 return true; | |
| 397 case PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD: | |
| 398 prefetch_buffer_lower_threshold_ = value; | |
| 399 return true; | |
| 400 default: | |
| 401 return false; | |
| 402 } | |
| 403 } | |
| 404 | |
| 405 bool PPB_URLRequestInfo_Impl::SetStringProperty(PP_URLRequestProperty property, | |
| 406 const std::string& value) { | |
| 407 // TODO(darin): Validate input. Perhaps at a different layer? | |
| 408 switch (property) { | |
| 409 case PP_URLREQUESTPROPERTY_URL: | |
| 410 url_ = value; // NOTE: This may be a relative URL. | |
| 411 return true; | |
| 412 case PP_URLREQUESTPROPERTY_METHOD: | |
| 413 if (!IsValidToken(value)) | |
| 414 return false; | |
| 415 method_ = ValidateMethod(value); | |
| 416 return !method_.empty(); | |
| 417 case PP_URLREQUESTPROPERTY_HEADERS: | |
| 418 if (!AreValidHeaders(value)) | |
| 419 return false; | |
| 420 headers_ = value; | |
| 421 return true; | |
| 422 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: | |
| 423 has_custom_referrer_url_ = true; | |
| 424 custom_referrer_url_ = value; | |
| 425 return true; | |
| 426 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING: | |
| 427 has_custom_content_transfer_encoding_ = true; | |
| 428 custom_content_transfer_encoding_ = value; | |
| 429 return true; | |
| 430 default: | |
| 431 return false; | |
| 432 } | |
| 433 } | |
| 434 | 268 |
| 435 } // namespace ppapi | 269 } // namespace ppapi |
| 436 } // namespace webkit | 270 } // namespace webkit |
| OLD | NEW |