diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-10 16:09:01 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-10 16:09:01 +0000 |
commit | c094eaf5de58987d93810e88bd0e1b21b7bcce91 (patch) | |
tree | 346b7873e7330caafb164ba9aa9fd452944d23f9 | |
parent | 7f80fbfe35dfb9aa9d4dba2bbd9e5c799d5fc678 (diff) | |
download | chromium_src-c094eaf5de58987d93810e88bd0e1b21b7bcce91.zip chromium_src-c094eaf5de58987d93810e88bd0e1b21b7bcce91.tar.gz chromium_src-c094eaf5de58987d93810e88bd0e1b21b7bcce91.tar.bz2 |
PPAPI: Add an API for setting a custom user agent for URL requests.
This doesn't hook it up yet.
Pepper Flash needs this for RTMPT.
BUG=134615
TEST=not really (except for trivial URL request test)
Review URL: https://chromiumcodereview.appspot.com/10762017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145885 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ppapi/api/ppb_url_request_info.idl | 14 | ||||
-rw-r--r-- | ppapi/c/ppb_url_request_info.h | 15 | ||||
-rw-r--r-- | ppapi/cpp/url_request_info.h | 22 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 2 | ||||
-rw-r--r-- | ppapi/shared_impl/ppb_url_request_info_shared.cc | 10 | ||||
-rw-r--r-- | ppapi/shared_impl/ppb_url_request_info_shared.h | 4 | ||||
-rw-r--r-- | ppapi/tests/test_url_request.cc | 10 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_url_request_info_impl.cc | 12 |
8 files changed, 77 insertions, 12 deletions
diff --git a/ppapi/api/ppb_url_request_info.idl b/ppapi/api/ppb_url_request_info.idl index c6baedf..06c9edd 100644 --- a/ppapi/api/ppb_url_request_info.idl +++ b/ppapi/api/ppb_url_request_info.idl @@ -140,7 +140,19 @@ enum PP_URLRequestProperty { * <code>PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD</code> must also * be set. Behavior is undefined if the former is >= the latter. */ - PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD = 12 + PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD = 12, + + /** + * This corresponds to a string (<code>PP_VARTYPE_STRING</code>) or may be + * undefined (<code>PP_VARTYPE_UNDEFINED</code>; default). Set it to a string + * to set a custom user-agent header (if empty, that header will be omitted), + * or to undefined to use the default. Only loaders with universal access + * (only available on trusted implementations) will accept + * <code>URLRequestInfo</code> objects that try to set a custom user agent; if + * given to a loader without universal access, <code>PP_ERROR_NOACCESS</code> + * will result. + */ + PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT = 13 }; /** diff --git a/ppapi/c/ppb_url_request_info.h b/ppapi/c/ppb_url_request_info.h index fceda5c..4eaf0db 100644 --- a/ppapi/c/ppb_url_request_info.h +++ b/ppapi/c/ppb_url_request_info.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From ppb_url_request_info.idl modified Mon Nov 14 10:36:01 2011. */ +/* From ppb_url_request_info.idl modified Tue Jul 10 09:05:59 2012. */ #ifndef PPAPI_C_PPB_URL_REQUEST_INFO_H_ #define PPAPI_C_PPB_URL_REQUEST_INFO_H_ @@ -145,7 +145,18 @@ typedef enum { * <code>PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD</code> must also * be set. Behavior is undefined if the former is >= the latter. */ - PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD = 12 + PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD = 12, + /** + * This corresponds to a string (<code>PP_VARTYPE_STRING</code>) or may be + * undefined (<code>PP_VARTYPE_UNDEFINED</code>; default). Set it to a string + * to set a custom user-agent header (if empty, that header will be omitted), + * or to undefined to use the default. Only loaders with universal access + * (only available on trusted implementations) will accept + * <code>URLRequestInfo</code> objects that try to set a custom user agent; if + * given to a loader without universal access, <code>PP_ERROR_NOACCESS</code> + * will result. + */ + PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT = 13 } PP_URLRequestProperty; PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_URLRequestProperty, 4); /** diff --git a/ppapi/cpp/url_request_info.h b/ppapi/cpp/url_request_info.h index 49e47ae..15c1713 100644 --- a/ppapi/cpp/url_request_info.h +++ b/ppapi/cpp/url_request_info.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -245,7 +245,6 @@ class URLRequestInfo : public Resource { return SetProperty(PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, enable); } - /// SetCustomContentTransferEncoding() sets the /// <code>PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING</code> /// (corresponding to a string of type <code>PP_VARTYPE_STRING</code> or @@ -309,6 +308,25 @@ class URLRequestInfo : public Resource { return SetProperty(PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD, size); } + + /// SetCustomUserAgent() sets the + /// <code>PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT</code> (corresponding to a + /// string of type <code>PP_VARTYPE_STRING</code> or might be set to undefined + /// as <code>PP_VARTYPE_UNDEFINED</code>). Set it to a string to set a custom + /// user-agent header (if empty, that header will be omitted), or to undefined + /// to use the default. Only loaders with universal access (only available on + /// trusted implementations) will accept <code>URLRequestInfo</code> objects + /// that try to set a custom user agent; if given to a loader without + /// universal access, <code>PP_ERROR_BADARGUMENT</code> will result. + /// + /// @param[in] user_agent A <code>Var</code> containing the property value. To + /// use the default user agent, set <code>user_agent</code> to an undefined + /// <code>Var</code>. + /// + /// @return true if successful, false if the parameter is invalid. + bool SetCustomUserAgent(const Var& user_agent) { + return SetProperty(PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT, user_agent); + } }; } // namespace pp diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 755d353..e7881a6 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -213,6 +213,8 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::PPB_URLRequestInfo_Data) IPC_STRUCT_TRAITS_MEMBER(custom_content_transfer_encoding) IPC_STRUCT_TRAITS_MEMBER(prefetch_buffer_upper_threshold) IPC_STRUCT_TRAITS_MEMBER(prefetch_buffer_lower_threshold) + IPC_STRUCT_TRAITS_MEMBER(has_custom_user_agent) + IPC_STRUCT_TRAITS_MEMBER(custom_user_agent) IPC_STRUCT_TRAITS_MEMBER(body) IPC_STRUCT_TRAITS_END() diff --git a/ppapi/shared_impl/ppb_url_request_info_shared.cc b/ppapi/shared_impl/ppb_url_request_info_shared.cc index d7a3ea2..058b2be 100644 --- a/ppapi/shared_impl/ppb_url_request_info_shared.cc +++ b/ppapi/shared_impl/ppb_url_request_info_shared.cc @@ -62,6 +62,8 @@ PPB_URLRequestInfo_Data::PPB_URLRequestInfo_Data() allow_credentials(false), has_custom_content_transfer_encoding(false), custom_content_transfer_encoding(), + has_custom_user_agent(false), + custom_user_agent(), prefetch_buffer_upper_threshold(kDefaultPrefetchBufferUpperThreshold), prefetch_buffer_lower_threshold(kDefaultPrefetchBufferLowerThreshold), body() { @@ -181,6 +183,10 @@ bool PPB_URLRequestInfo_Shared::SetUndefinedProperty( 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; } @@ -258,6 +264,10 @@ bool PPB_URLRequestInfo_Shared::SetStringProperty( 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; } diff --git a/ppapi/shared_impl/ppb_url_request_info_shared.h b/ppapi/shared_impl/ppb_url_request_info_shared.h index dbad103..a233708 100644 --- a/ppapi/shared_impl/ppb_url_request_info_shared.h +++ b/ppapi/shared_impl/ppb_url_request_info_shared.h @@ -73,9 +73,11 @@ struct PPAPI_SHARED_EXPORT PPB_URLRequestInfo_Data { bool allow_credentials; // Similar to the custom referrer (above), but for custom content transfer - // encoding. + // encoding and custom user agent, respectively. bool has_custom_content_transfer_encoding; std::string custom_content_transfer_encoding; + bool has_custom_user_agent; + std::string custom_user_agent; int32_t prefetch_buffer_upper_threshold; int32_t prefetch_buffer_lower_threshold; diff --git a/ppapi/tests/test_url_request.cc b/ppapi/tests/test_url_request.cc index e0902f0..00e6d2e 100644 --- a/ppapi/tests/test_url_request.cc +++ b/ppapi/tests/test_url_request.cc @@ -175,6 +175,7 @@ std::string TestURLRequest::TestSetProperty() { TEST_STRING_INVALID(PP_URLREQUESTPROPERTY_HEADERS), TEST_STRING_INVALID(PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL), TEST_STRING_INVALID(PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING), + TEST_STRING_INVALID(PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT), TEST_INT_INVALID(PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD), TEST_INT_INVALID(PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD), PropertyTestData(ID_STR(PP_URLREQUESTPROPERTY_URL), @@ -204,6 +205,15 @@ std::string TestURLRequest::TestSetProperty() { PropertyTestData( ID_STR(PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING), PP_MakeUndefined(), PP_TRUE), + PropertyTestData( + ID_STR(PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT), + PP_MakeString("My Crazy Plugin"), PP_TRUE), + PropertyTestData( + ID_STR(PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT), + PP_MakeString(""), PP_TRUE), + PropertyTestData( + ID_STR(PP_URLREQUESTPROPERTY_CUSTOMUSERAGENT), + PP_MakeUndefined(), PP_TRUE), PropertyTestData(ID_STR(PP_URLREQUESTPROPERTY_URL), PP_MakeUndefined(), PP_FALSE), PropertyTestData(ID_STR(PP_URLREQUESTPROPERTY_METHOD), diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc index 79c09bd..55c6d3a 100644 --- a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc @@ -113,12 +113,11 @@ bool PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame, frame->setReferrerForRequest(*dest, GURL(data().custom_referrer_url)); } - if (data().has_custom_content_transfer_encoding) { - if (!data().custom_content_transfer_encoding.empty()) { - dest->addHTTPHeaderField( - WebString::fromUTF8("Content-Transfer-Encoding"), - WebString::fromUTF8(data().custom_content_transfer_encoding)); - } + if (data().has_custom_content_transfer_encoding && + !data().custom_content_transfer_encoding.empty()) { + dest->addHTTPHeaderField( + WebString::fromUTF8("Content-Transfer-Encoding"), + WebString::fromUTF8(data().custom_content_transfer_encoding)); } return true; @@ -128,6 +127,7 @@ bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { return data().has_custom_referrer_url || data().has_custom_content_transfer_encoding || + data().has_custom_user_agent || url_util::FindAndCompareScheme(data().url, "javascript", NULL); } |