| OLD | NEW |
| 1 // Copyright (c) 2010 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" |
| 11 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 int64_t start_offset; | 185 int64_t start_offset; |
| 186 int64_t number_of_bytes; | 186 int64_t number_of_bytes; |
| 187 PP_Time expected_last_modified_time; | 187 PP_Time expected_last_modified_time; |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PluginInstance* instance) | 190 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PluginInstance* instance) |
| 191 : Resource(instance), | 191 : Resource(instance), |
| 192 stream_to_file_(false), | 192 stream_to_file_(false), |
| 193 follow_redirects_(true), | 193 follow_redirects_(true), |
| 194 record_download_progress_(false), | 194 record_download_progress_(false), |
| 195 record_upload_progress_(false) { | 195 record_upload_progress_(false), |
| 196 use_custom_referrer_(false) { |
| 196 } | 197 } |
| 197 | 198 |
| 198 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() { | 199 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() { |
| 199 } | 200 } |
| 200 | 201 |
| 201 // static | 202 // static |
| 202 const PPB_URLRequestInfo* PPB_URLRequestInfo_Impl::GetInterface() { | 203 const PPB_URLRequestInfo* PPB_URLRequestInfo_Impl::GetInterface() { |
| 203 return &ppb_urlrequestinfo; | 204 return &ppb_urlrequestinfo; |
| 204 } | 205 } |
| 205 | 206 |
| 206 PPB_URLRequestInfo_Impl* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_Impl() { | 207 PPB_URLRequestInfo_Impl* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_Impl() { |
| 207 return this; | 208 return this; |
| 208 } | 209 } |
| 209 | 210 |
| 210 bool PPB_URLRequestInfo_Impl::SetBooleanProperty(PP_URLRequestProperty property, | 211 bool PPB_URLRequestInfo_Impl::SetBooleanProperty(PP_URLRequestProperty property, |
| 211 bool value) { | 212 bool value) { |
| 212 switch (property) { | 213 switch (property) { |
| 213 case PP_URLREQUESTPROPERTY_STREAMTOFILE: | 214 case PP_URLREQUESTPROPERTY_STREAMTOFILE: |
| 214 stream_to_file_ = value; | 215 stream_to_file_ = value; |
| 215 return true; | 216 return true; |
| 216 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS: | 217 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS: |
| 217 follow_redirects_ = value; | 218 follow_redirects_ = value; |
| 218 return true; | 219 return true; |
| 219 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS: | 220 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS: |
| 220 record_download_progress_ = value; | 221 record_download_progress_ = value; |
| 221 return true; | 222 return true; |
| 222 case PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS: | 223 case PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS: |
| 223 record_upload_progress_ = value; | 224 record_upload_progress_ = value; |
| 224 return true; | 225 return true; |
| 226 case PP_URLREQUESTPROPERTY_USECUSTOMREFERRER: |
| 227 use_custom_referrer_ = value; |
| 228 return true; |
| 225 default: | 229 default: |
| 226 return false; | 230 return false; |
| 227 } | 231 } |
| 228 } | 232 } |
| 229 | 233 |
| 230 bool PPB_URLRequestInfo_Impl::SetStringProperty(PP_URLRequestProperty property, | 234 bool PPB_URLRequestInfo_Impl::SetStringProperty(PP_URLRequestProperty property, |
| 231 const std::string& value) { | 235 const std::string& value) { |
| 232 // TODO(darin): Validate input. Perhaps at a different layer? | 236 // TODO(darin): Validate input. Perhaps at a different layer? |
| 233 switch (property) { | 237 switch (property) { |
| 234 case PP_URLREQUESTPROPERTY_URL: | 238 case PP_URLREQUESTPROPERTY_URL: |
| 235 url_ = value; // NOTE: This may be a relative URL. | 239 url_ = value; // NOTE: This may be a relative URL. |
| 236 return true; | 240 return true; |
| 237 case PP_URLREQUESTPROPERTY_METHOD: | 241 case PP_URLREQUESTPROPERTY_METHOD: |
| 238 method_ = value; | 242 method_ = value; |
| 239 return true; | 243 return true; |
| 240 case PP_URLREQUESTPROPERTY_HEADERS: | 244 case PP_URLREQUESTPROPERTY_HEADERS: |
| 241 if (!AreValidHeaders(value)) | 245 if (!AreValidHeaders(value)) |
| 242 return false; | 246 return false; |
| 243 headers_ = value; | 247 headers_ = value; |
| 244 return true; | 248 return true; |
| 249 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: |
| 250 custom_referrer_url_ = value; |
| 251 return true; |
| 245 default: | 252 default: |
| 246 return false; | 253 return false; |
| 247 } | 254 } |
| 248 } | 255 } |
| 249 | 256 |
| 250 bool PPB_URLRequestInfo_Impl::AppendDataToBody(const std::string& data) { | 257 bool PPB_URLRequestInfo_Impl::AppendDataToBody(const std::string& data) { |
| 251 if (!data.empty()) | 258 if (!data.empty()) |
| 252 body_.push_back(BodyItem(data)); | 259 body_.push_back(BodyItem(data)); |
| 253 return true; | 260 return true; |
| 254 } | 261 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 body_[i].number_of_bytes, | 311 body_[i].number_of_bytes, |
| 305 body_[i].expected_last_modified_time); | 312 body_[i].expected_last_modified_time); |
| 306 } else { | 313 } else { |
| 307 DCHECK(!body_[i].data.empty()); | 314 DCHECK(!body_[i].data.empty()); |
| 308 http_body.appendData(WebData(body_[i].data)); | 315 http_body.appendData(WebData(body_[i].data)); |
| 309 } | 316 } |
| 310 } | 317 } |
| 311 web_request.setHTTPBody(http_body); | 318 web_request.setHTTPBody(http_body); |
| 312 } | 319 } |
| 313 | 320 |
| 314 frame->setReferrerForRequest(web_request, WebURL()); // Use default. | 321 if (use_custom_referrer()) { |
| 322 if (!custom_referrer_url_.empty()) |
| 323 frame->setReferrerForRequest(web_request, GURL(custom_referrer_url_)); |
| 324 } else { |
| 325 frame->setReferrerForRequest(web_request, WebURL()); // Use default. |
| 326 } |
| 327 |
| 315 return web_request; | 328 return web_request; |
| 316 } | 329 } |
| 317 | 330 |
| 331 bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { |
| 332 return use_custom_referrer(); |
| 333 } |
| 334 |
| 318 } // namespace ppapi | 335 } // namespace ppapi |
| 319 } // namespace webkit | 336 } // namespace webkit |
| 320 | |
| OLD | NEW |