summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/url_request_info_resource.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-19 19:52:12 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-19 19:52:12 +0000
commit7b2f7297010c777f5adaa4b6131828a20496447a (patch)
tree67d307b8e93dd8f2f33d2268079ef33f403e104e /ppapi/proxy/url_request_info_resource.cc
parent060088c510e263ed73ed3be8d6c5a55292f9ff91 (diff)
downloadchromium_src-7b2f7297010c777f5adaa4b6131828a20496447a.zip
chromium_src-7b2f7297010c777f5adaa4b6131828a20496447a.tar.gz
chromium_src-7b2f7297010c777f5adaa4b6131828a20496447a.tar.bz2
Convert url request info to new proxy API.
This splits out the helper functions in the in-process version to a new file: url_request_info_util. This will be moved to content/renderer when we move the url_loader. The unit test was moved from webkit/plugins/ppapi to content/renderer/ppapi. I made it a browsertest which allowed the removal of a little boilerplate. I had to add "internal" functions for loading stuff with just the data struct rather than a resource so the proxy doesn't have to create an in-process URLRequestInfo resource (which can't be created now when running out-of-process) just to create a request. This should be a little more efficient now anyway, and these duplicates will go away when such code moves to the new proxy design. BUG= Review URL: https://codereview.chromium.org/10913257 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157588 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/url_request_info_resource.cc')
-rw-r--r--ppapi/proxy/url_request_info_resource.cc215
1 files changed, 215 insertions, 0 deletions
diff --git a/ppapi/proxy/url_request_info_resource.cc b/ppapi/proxy/url_request_info_resource.cc
new file mode 100644
index 0000000..19d02d7
--- /dev/null
+++ b/ppapi/proxy/url_request_info_resource.cc
@@ -0,0 +1,215 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/url_request_info_resource.h"
+
+#include "ppapi/shared_impl/var.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_file_ref_api.h"
+
+namespace ppapi {
+namespace proxy {
+
+URLRequestInfoResource::URLRequestInfoResource(Connection connection,
+ PP_Instance instance,
+ const URLRequestInfoData& data)
+ : PluginResource(connection, instance),
+ data_(data) {
+}
+
+URLRequestInfoResource::~URLRequestInfoResource() {
+}
+
+thunk::PPB_URLRequestInfo_API*
+URLRequestInfoResource::AsPPB_URLRequestInfo_API() {
+ return this;
+}
+
+PP_Bool URLRequestInfoResource::SetProperty(PP_URLRequestProperty property,
+ PP_Var var) {
+ // IMPORTANT: Do not do security validation of parameters at this level
+ // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. This
+ // code is used both in the plugin (which we don't trust) and in the renderer
+ // (which we trust more). When running out-of-process, the plugin calls this
+ // function to configure the URLRequestInfoData, which is then sent to
+ // the renderer and *not* run through SetProperty again.
+ //
+ // This means that anything in the PPB_URLRequestInfo_Data needs to be
+ // validated at the time the URL is requested (which is what ValidateData
+ // does). If your feature requires security checks, it should be in the
+ // implementation in the renderer when the WebKit request is actually
+ // constructed.
+ //
+ // It is legal to do some validation here if you want to report failure to
+ // the plugin as a convenience, as long as you also do it in the renderer
+ // later.
+ PP_Bool result = PP_FALSE;
+ switch (var.type) {
+ case PP_VARTYPE_UNDEFINED:
+ result = PP_FromBool(SetUndefinedProperty(property));
+ break;
+ case PP_VARTYPE_BOOL:
+ result = PP_FromBool(
+ SetBooleanProperty(property, PP_ToBool(var.value.as_bool)));
+ break;
+ case PP_VARTYPE_INT32:
+ result = PP_FromBool(
+ SetIntegerProperty(property, var.value.as_int));
+ break;
+ case PP_VARTYPE_STRING: {
+ StringVar* string = StringVar::FromPPVar(var);
+ if (string)
+ result = PP_FromBool(SetStringProperty(property, string->value()));
+ break;
+ }
+ default:
+ break;
+ }
+ return result;
+}
+
+PP_Bool URLRequestInfoResource::AppendDataToBody(const void* data,
+ uint32_t len) {
+ if (len > 0) {
+ data_.body.push_back(URLRequestInfoData::BodyItem(
+ std::string(static_cast<const char*>(data), len)));
+ }
+ return PP_TRUE;
+}
+
+PP_Bool URLRequestInfoResource::AppendFileToBody(
+ PP_Resource file_ref,
+ int64_t start_offset,
+ int64_t number_of_bytes,
+ PP_Time expected_last_modified_time) {
+ thunk::EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref, true);
+ if (enter.failed())
+ return PP_FALSE;
+
+ // Ignore a call to append nothing.
+ if (number_of_bytes == 0)
+ return PP_TRUE;
+
+ // Check for bad values. (-1 means read until end of file.)
+ if (start_offset < 0 || number_of_bytes < -1)
+ return PP_FALSE;
+
+ data_.body.push_back(URLRequestInfoData::BodyItem(
+ enter.resource(),
+ start_offset,
+ number_of_bytes,
+ expected_last_modified_time));
+ return PP_TRUE;
+}
+
+const URLRequestInfoData& URLRequestInfoResource::GetData() const {
+ return data_;
+}
+
+bool URLRequestInfoResource::SetUndefinedProperty(
+ PP_URLRequestProperty property) {
+ // IMPORTANT: Do not do security validation of parameters at this level
+ // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See
+ // SetProperty() above for why.
+ switch (property) {
+ case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL:
+ data_.has_custom_referrer_url = false;
+ data_.custom_referrer_url = std::string();
+ return true;
+ case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING:
+ data_.has_custom_content_transfer_encoding = false;
+ data_.custom_content_transfer_encoding = std::string();
+ return true;
+ case PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT:
+ data_.has_custom_user_agent = false;
+ data_.custom_user_agent = std::string();
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool URLRequestInfoResource::SetBooleanProperty(
+ PP_URLRequestProperty property,
+ bool value) {
+ // IMPORTANT: Do not do security validation of parameters at this level
+ // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See
+ // SetProperty() above for why.
+ switch (property) {
+ case PP_URLREQUESTPROPERTY_STREAMTOFILE:
+ data_.stream_to_file = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS:
+ data_.follow_redirects = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS:
+ data_.record_download_progress = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS:
+ data_.record_upload_progress = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS:
+ data_.allow_cross_origin_requests = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS:
+ data_.allow_credentials = value;
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool URLRequestInfoResource::SetIntegerProperty(
+ PP_URLRequestProperty property,
+ int32_t value) {
+ // IMPORTANT: Do not do security validation of parameters at this level
+ // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See
+ // SetProperty() above for why.
+ switch (property) {
+ case PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD:
+ data_.prefetch_buffer_upper_threshold = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD:
+ data_.prefetch_buffer_lower_threshold = value;
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool URLRequestInfoResource::SetStringProperty(
+ PP_URLRequestProperty property,
+ const std::string& value) {
+ // IMPORTANT: Do not do security validation of parameters at this level
+ // without also adding them to PPB_URLRequestInfo_Impl::ValidateData. See
+ // SetProperty() above for why.
+ switch (property) {
+ case PP_URLREQUESTPROPERTY_URL:
+ data_.url = value; // NOTE: This may be a relative URL.
+ return true;
+ case PP_URLREQUESTPROPERTY_METHOD:
+ data_.method = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_HEADERS:
+ data_.headers = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL:
+ data_.has_custom_referrer_url = true;
+ data_.custom_referrer_url = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING:
+ data_.has_custom_content_transfer_encoding = true;
+ data_.custom_content_transfer_encoding = value;
+ return true;
+ case PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT:
+ data_.has_custom_user_agent = true;
+ data_.custom_user_agent = value;
+ return true;
+ default:
+ return false;
+ }
+}
+
+} // namespace proxy
+} // namespace ppapi