| 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 "net/http/http_util.h" | 10 #include "net/http/http_util.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PluginInstance* instance) | 197 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PluginInstance* instance) |
| 198 : Resource(instance), | 198 : Resource(instance), |
| 199 stream_to_file_(false), | 199 stream_to_file_(false), |
| 200 follow_redirects_(true), | 200 follow_redirects_(true), |
| 201 record_download_progress_(false), | 201 record_download_progress_(false), |
| 202 record_upload_progress_(false), | 202 record_upload_progress_(false), |
| 203 has_custom_referrer_url_(false), | 203 has_custom_referrer_url_(false), |
| 204 allow_cross_origin_requests_(false), | 204 allow_cross_origin_requests_(false), |
| 205 allow_credentials_(false) { | 205 allow_credentials_(false), |
| 206 has_custom_content_transfer_encoding_(false) { |
| 206 } | 207 } |
| 207 | 208 |
| 208 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() { | 209 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() { |
| 209 } | 210 } |
| 210 | 211 |
| 211 // static | 212 // static |
| 212 const PPB_URLRequestInfo* PPB_URLRequestInfo_Impl::GetInterface() { | 213 const PPB_URLRequestInfo* PPB_URLRequestInfo_Impl::GetInterface() { |
| 213 return &ppb_urlrequestinfo; | 214 return &ppb_urlrequestinfo; |
| 214 } | 215 } |
| 215 | 216 |
| 216 PPB_URLRequestInfo_Impl* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_Impl() { | 217 PPB_URLRequestInfo_Impl* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_Impl() { |
| 217 return this; | 218 return this; |
| 218 } | 219 } |
| 219 | 220 |
| 220 bool PPB_URLRequestInfo_Impl::SetUndefinedProperty( | 221 bool PPB_URLRequestInfo_Impl::SetUndefinedProperty( |
| 221 PP_URLRequestProperty property) { | 222 PP_URLRequestProperty property) { |
| 222 switch (property) { | 223 switch (property) { |
| 223 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: | 224 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: |
| 224 has_custom_referrer_url_ = false; | 225 has_custom_referrer_url_ = false; |
| 225 custom_referrer_url_ = std::string(); | 226 custom_referrer_url_ = std::string(); |
| 226 return true; | 227 return true; |
| 228 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING: |
| 229 has_custom_content_transfer_encoding_ = false; |
| 230 custom_content_transfer_encoding_ = std::string(); |
| 231 return true; |
| 227 default: | 232 default: |
| 228 return false; | 233 return false; |
| 229 } | 234 } |
| 230 } | 235 } |
| 231 | 236 |
| 232 bool PPB_URLRequestInfo_Impl::SetBooleanProperty(PP_URLRequestProperty property, | 237 bool PPB_URLRequestInfo_Impl::SetBooleanProperty(PP_URLRequestProperty property, |
| 233 bool value) { | 238 bool value) { |
| 234 switch (property) { | 239 switch (property) { |
| 235 case PP_URLREQUESTPROPERTY_STREAMTOFILE: | 240 case PP_URLREQUESTPROPERTY_STREAMTOFILE: |
| 236 stream_to_file_ = value; | 241 stream_to_file_ = value; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 267 return true; | 272 return true; |
| 268 case PP_URLREQUESTPROPERTY_HEADERS: | 273 case PP_URLREQUESTPROPERTY_HEADERS: |
| 269 if (!AreValidHeaders(value)) | 274 if (!AreValidHeaders(value)) |
| 270 return false; | 275 return false; |
| 271 headers_ = value; | 276 headers_ = value; |
| 272 return true; | 277 return true; |
| 273 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: | 278 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: |
| 274 has_custom_referrer_url_ = true; | 279 has_custom_referrer_url_ = true; |
| 275 custom_referrer_url_ = value; | 280 custom_referrer_url_ = value; |
| 276 return true; | 281 return true; |
| 282 case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING: |
| 283 has_custom_content_transfer_encoding_ = true; |
| 284 custom_content_transfer_encoding_ = value; |
| 285 return true; |
| 277 default: | 286 default: |
| 278 return false; | 287 return false; |
| 279 } | 288 } |
| 280 } | 289 } |
| 281 | 290 |
| 282 bool PPB_URLRequestInfo_Impl::AppendDataToBody(const std::string& data) { | 291 bool PPB_URLRequestInfo_Impl::AppendDataToBody(const std::string& data) { |
| 283 if (!data.empty()) | 292 if (!data.empty()) |
| 284 body_.push_back(BodyItem(data)); | 293 body_.push_back(BodyItem(data)); |
| 285 return true; | 294 return true; |
| 286 } | 295 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 web_request.setHTTPBody(http_body); | 352 web_request.setHTTPBody(http_body); |
| 344 } | 353 } |
| 345 | 354 |
| 346 if (has_custom_referrer_url_) { | 355 if (has_custom_referrer_url_) { |
| 347 if (!custom_referrer_url_.empty()) | 356 if (!custom_referrer_url_.empty()) |
| 348 frame->setReferrerForRequest(web_request, GURL(custom_referrer_url_)); | 357 frame->setReferrerForRequest(web_request, GURL(custom_referrer_url_)); |
| 349 } else { | 358 } else { |
| 350 frame->setReferrerForRequest(web_request, WebURL()); // Use default. | 359 frame->setReferrerForRequest(web_request, WebURL()); // Use default. |
| 351 } | 360 } |
| 352 | 361 |
| 362 if (has_custom_content_transfer_encoding_) { |
| 363 if (!custom_content_transfer_encoding_.empty()) { |
| 364 web_request.addHTTPHeaderField( |
| 365 WebString::fromUTF8("Content-Transfer-Encoding"), |
| 366 WebString::fromUTF8(custom_content_transfer_encoding_)); |
| 367 } |
| 368 } |
| 369 |
| 353 return web_request; | 370 return web_request; |
| 354 } | 371 } |
| 355 | 372 |
| 356 bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { | 373 bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { |
| 357 return has_custom_referrer_url_; | 374 return has_custom_referrer_url_ || has_custom_content_transfer_encoding_; |
| 358 } | 375 } |
| 359 | 376 |
| 360 } // namespace ppapi | 377 } // namespace ppapi |
| 361 } // namespace webkit | 378 } // namespace webkit |
| OLD | NEW |