| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 PP_Bool SetProperty(PP_Resource request_id, | 98 PP_Bool SetProperty(PP_Resource request_id, |
| 99 PP_URLRequestProperty property, | 99 PP_URLRequestProperty property, |
| 100 PP_Var var) { | 100 PP_Var var) { |
| 101 scoped_refptr<PPB_URLRequestInfo_Impl> request( | 101 scoped_refptr<PPB_URLRequestInfo_Impl> request( |
| 102 Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id)); | 102 Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id)); |
| 103 if (!request) | 103 if (!request) |
| 104 return PP_FALSE; | 104 return PP_FALSE; |
| 105 | 105 |
| 106 if (var.type == PP_VARTYPE_BOOL) { | 106 PP_Bool result = PP_FALSE; |
| 107 return BoolToPPBool( | 107 switch (var.type) { |
| 108 request->SetBooleanProperty(property, | 108 case PP_VARTYPE_UNDEFINED: |
| 109 PPBoolToBool(var.value.as_bool))); | 109 result = BoolToPPBool(request->SetUndefinedProperty(property)); |
| 110 break; |
| 111 case PP_VARTYPE_BOOL: |
| 112 result = BoolToPPBool( |
| 113 request->SetBooleanProperty(property, |
| 114 PPBoolToBool(var.value.as_bool))); |
| 115 break; |
| 116 case PP_VARTYPE_STRING: { |
| 117 scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); |
| 118 if (string) |
| 119 result = BoolToPPBool(request->SetStringProperty(property, |
| 120 string->value())); |
| 121 break; |
| 122 } |
| 123 default: |
| 124 break; |
| 110 } | 125 } |
| 111 | 126 return result; |
| 112 if (var.type == PP_VARTYPE_STRING) { | |
| 113 scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); | |
| 114 if (string) { | |
| 115 return BoolToPPBool(request->SetStringProperty(property, | |
| 116 string->value())); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 return PP_FALSE; | |
| 121 } | 127 } |
| 122 | 128 |
| 123 PP_Bool AppendDataToBody(PP_Resource request_id, | 129 PP_Bool AppendDataToBody(PP_Resource request_id, |
| 124 const char* data, | 130 const char* data, |
| 125 uint32_t len) { | 131 uint32_t len) { |
| 126 scoped_refptr<PPB_URLRequestInfo_Impl> request( | 132 scoped_refptr<PPB_URLRequestInfo_Impl> request( |
| 127 Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id)); | 133 Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id)); |
| 128 if (!request) | 134 if (!request) |
| 129 return PP_FALSE; | 135 return PP_FALSE; |
| 130 | 136 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 int64_t start_offset; | 191 int64_t start_offset; |
| 186 int64_t number_of_bytes; | 192 int64_t number_of_bytes; |
| 187 PP_Time expected_last_modified_time; | 193 PP_Time expected_last_modified_time; |
| 188 }; | 194 }; |
| 189 | 195 |
| 190 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PluginInstance* instance) | 196 PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PluginInstance* instance) |
| 191 : Resource(instance), | 197 : Resource(instance), |
| 192 stream_to_file_(false), | 198 stream_to_file_(false), |
| 193 follow_redirects_(true), | 199 follow_redirects_(true), |
| 194 record_download_progress_(false), | 200 record_download_progress_(false), |
| 195 record_upload_progress_(false) { | 201 record_upload_progress_(false), |
| 202 has_custom_referrer_url_(false) { |
| 196 } | 203 } |
| 197 | 204 |
| 198 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() { | 205 PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() { |
| 199 } | 206 } |
| 200 | 207 |
| 201 // static | 208 // static |
| 202 const PPB_URLRequestInfo* PPB_URLRequestInfo_Impl::GetInterface() { | 209 const PPB_URLRequestInfo* PPB_URLRequestInfo_Impl::GetInterface() { |
| 203 return &ppb_urlrequestinfo; | 210 return &ppb_urlrequestinfo; |
| 204 } | 211 } |
| 205 | 212 |
| 206 PPB_URLRequestInfo_Impl* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_Impl() { | 213 PPB_URLRequestInfo_Impl* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_Impl() { |
| 207 return this; | 214 return this; |
| 208 } | 215 } |
| 209 | 216 |
| 217 bool PPB_URLRequestInfo_Impl::SetUndefinedProperty( |
| 218 PP_URLRequestProperty property) { |
| 219 switch (property) { |
| 220 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: |
| 221 has_custom_referrer_url_ = false; |
| 222 custom_referrer_url_ = std::string(); |
| 223 return true; |
| 224 default: |
| 225 return false; |
| 226 } |
| 227 } |
| 228 |
| 210 bool PPB_URLRequestInfo_Impl::SetBooleanProperty(PP_URLRequestProperty property, | 229 bool PPB_URLRequestInfo_Impl::SetBooleanProperty(PP_URLRequestProperty property, |
| 211 bool value) { | 230 bool value) { |
| 212 switch (property) { | 231 switch (property) { |
| 213 case PP_URLREQUESTPROPERTY_STREAMTOFILE: | 232 case PP_URLREQUESTPROPERTY_STREAMTOFILE: |
| 214 stream_to_file_ = value; | 233 stream_to_file_ = value; |
| 215 return true; | 234 return true; |
| 216 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS: | 235 case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS: |
| 217 follow_redirects_ = value; | 236 follow_redirects_ = value; |
| 218 return true; | 237 return true; |
| 219 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS: | 238 case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 235 url_ = value; // NOTE: This may be a relative URL. | 254 url_ = value; // NOTE: This may be a relative URL. |
| 236 return true; | 255 return true; |
| 237 case PP_URLREQUESTPROPERTY_METHOD: | 256 case PP_URLREQUESTPROPERTY_METHOD: |
| 238 method_ = value; | 257 method_ = value; |
| 239 return true; | 258 return true; |
| 240 case PP_URLREQUESTPROPERTY_HEADERS: | 259 case PP_URLREQUESTPROPERTY_HEADERS: |
| 241 if (!AreValidHeaders(value)) | 260 if (!AreValidHeaders(value)) |
| 242 return false; | 261 return false; |
| 243 headers_ = value; | 262 headers_ = value; |
| 244 return true; | 263 return true; |
| 264 case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL: |
| 265 has_custom_referrer_url_ = true; |
| 266 custom_referrer_url_ = value; |
| 267 return true; |
| 245 default: | 268 default: |
| 246 return false; | 269 return false; |
| 247 } | 270 } |
| 248 } | 271 } |
| 249 | 272 |
| 250 bool PPB_URLRequestInfo_Impl::AppendDataToBody(const std::string& data) { | 273 bool PPB_URLRequestInfo_Impl::AppendDataToBody(const std::string& data) { |
| 251 if (!data.empty()) | 274 if (!data.empty()) |
| 252 body_.push_back(BodyItem(data)); | 275 body_.push_back(BodyItem(data)); |
| 253 return true; | 276 return true; |
| 254 } | 277 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 body_[i].number_of_bytes, | 327 body_[i].number_of_bytes, |
| 305 body_[i].expected_last_modified_time); | 328 body_[i].expected_last_modified_time); |
| 306 } else { | 329 } else { |
| 307 DCHECK(!body_[i].data.empty()); | 330 DCHECK(!body_[i].data.empty()); |
| 308 http_body.appendData(WebData(body_[i].data)); | 331 http_body.appendData(WebData(body_[i].data)); |
| 309 } | 332 } |
| 310 } | 333 } |
| 311 web_request.setHTTPBody(http_body); | 334 web_request.setHTTPBody(http_body); |
| 312 } | 335 } |
| 313 | 336 |
| 314 frame->setReferrerForRequest(web_request, WebURL()); // Use default. | 337 if (has_custom_referrer_url_) { |
| 338 if (!custom_referrer_url_.empty()) |
| 339 frame->setReferrerForRequest(web_request, GURL(custom_referrer_url_)); |
| 340 } else { |
| 341 frame->setReferrerForRequest(web_request, WebURL()); // Use default. |
| 342 } |
| 343 |
| 315 return web_request; | 344 return web_request; |
| 316 } | 345 } |
| 317 | 346 |
| 347 bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { |
| 348 return has_custom_referrer_url_; |
| 349 } |
| 350 |
| 318 } // namespace ppapi | 351 } // namespace ppapi |
| 319 } // namespace webkit | 352 } // namespace webkit |
| 320 | |
| OLD | NEW |