summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-26 04:51:07 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-26 04:51:07 +0000
commit6f75c95235c7ea357e180ddfb6d1cba143d87645 (patch)
treee5440672cfbe6bac4d28f6790ab1c5b4ee8b3f93 /ppapi
parentecba6c3763755a5c617972d74f0d798939183260 (diff)
downloadchromium_src-6f75c95235c7ea357e180ddfb6d1cba143d87645.zip
chromium_src-6f75c95235c7ea357e180ddfb6d1cba143d87645.tar.gz
chromium_src-6f75c95235c7ea357e180ddfb6d1cba143d87645.tar.bz2
Convert FileRefImpl and URLRequestInfo to shared_impl.
One nice side effect of this change is that there are no longer any IPCs associated with the request info. Instead, we just send the parameters to the host when we open a url loader. Review URL: http://codereview.chromium.org/7706021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98391 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/ppapi_shared.gypi4
-rw-r--r--ppapi/proxy/ppapi_messages.h63
-rw-r--r--ppapi/proxy/ppapi_param_traits.cc34
-rw-r--r--ppapi/proxy/ppapi_param_traits.h11
-rw-r--r--ppapi/proxy/ppb_file_chooser_proxy.cc10
-rw-r--r--ppapi/proxy/ppb_file_chooser_proxy.h4
-rw-r--r--ppapi/proxy/ppb_file_ref_proxy.cc88
-rw-r--r--ppapi/proxy/ppb_file_ref_proxy.h11
-rw-r--r--ppapi/proxy/ppb_flash_proxy.cc43
-rw-r--r--ppapi/proxy/ppb_flash_proxy.h6
-rw-r--r--ppapi/proxy/ppb_url_loader_proxy.cc27
-rw-r--r--ppapi/proxy/ppb_url_loader_proxy.h5
-rw-r--r--ppapi/proxy/ppb_url_request_info_proxy.cc163
-rw-r--r--ppapi/proxy/ppb_url_request_info_proxy.h24
-rw-r--r--ppapi/proxy/ppb_url_response_info_proxy.cc4
-rw-r--r--ppapi/proxy/ppb_url_response_info_proxy.h6
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc9
-rw-r--r--ppapi/proxy/resource_creation_proxy.h4
-rw-r--r--ppapi/proxy/serialized_structs.cc4
-rw-r--r--ppapi/proxy/serialized_structs.h11
-rw-r--r--ppapi/shared_impl/file_ref_impl.cc65
-rw-r--r--ppapi/shared_impl/file_ref_impl.h63
-rw-r--r--ppapi/shared_impl/scoped_pp_resource.cc4
-rw-r--r--ppapi/shared_impl/scoped_pp_resource.h5
-rw-r--r--ppapi/shared_impl/url_request_info_impl.cc337
-rw-r--r--ppapi/shared_impl/url_request_info_impl.h143
-rw-r--r--ppapi/shared_impl/var.cc5
-rw-r--r--ppapi/shared_impl/var.h1
-rw-r--r--ppapi/tests/test_url_loader.cc17
-rw-r--r--ppapi/tests/test_url_loader.h2
-rw-r--r--ppapi/thunk/enter.h9
-rw-r--r--ppapi/thunk/ppb_file_ref_api.h7
-rw-r--r--ppapi/thunk/ppb_url_request_info_api.h6
-rw-r--r--ppapi/thunk/ppb_url_request_info_thunk.cc4
-rw-r--r--ppapi/thunk/resource_creation_api.h7
35 files changed, 838 insertions, 368 deletions
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index b4ab027..51fa35b 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -32,6 +32,8 @@
'shared_impl/char_set_impl.h',
'shared_impl/crypto_impl.cc',
'shared_impl/crypto_impl.h',
+ 'shared_impl/file_ref_impl.cc',
+ 'shared_impl/file_ref_impl.h',
'shared_impl/font_impl.cc',
'shared_impl/font_impl.h',
'shared_impl/function_group_base.cc',
@@ -63,6 +65,8 @@
'shared_impl/time_conversion.h',
'shared_impl/tracker_base.cc',
'shared_impl/tracker_base.h',
+ 'shared_impl/url_request_info_impl.cc',
+ 'shared_impl/url_request_info_impl.h',
'shared_impl/url_util_impl.cc',
'shared_impl/url_util_impl.h',
'shared_impl/var.cc',
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index cd1efe1..f786163 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -34,6 +34,7 @@
#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/shared_impl/input_event_impl.h"
#include "ppapi/shared_impl/ppapi_preferences.h"
+#include "ppapi/shared_impl/url_request_info_impl.h"
#define IPC_MESSAGE_START PpapiMsgStart
@@ -108,6 +109,35 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::InputEventData)
IPC_STRUCT_TRAITS_MEMBER(character_text)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(ppapi::PPB_URLRequestInfo_Data)
+ IPC_STRUCT_TRAITS_MEMBER(url)
+ IPC_STRUCT_TRAITS_MEMBER(method)
+ IPC_STRUCT_TRAITS_MEMBER(headers)
+ IPC_STRUCT_TRAITS_MEMBER(stream_to_file)
+ IPC_STRUCT_TRAITS_MEMBER(follow_redirects)
+ IPC_STRUCT_TRAITS_MEMBER(record_download_progress)
+ IPC_STRUCT_TRAITS_MEMBER(record_upload_progress)
+ IPC_STRUCT_TRAITS_MEMBER(has_custom_referrer_url)
+ IPC_STRUCT_TRAITS_MEMBER(custom_referrer_url)
+ IPC_STRUCT_TRAITS_MEMBER(allow_cross_origin_requests)
+ IPC_STRUCT_TRAITS_MEMBER(allow_credentials)
+ IPC_STRUCT_TRAITS_MEMBER(has_custom_content_transfer_encoding)
+ 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(body)
+IPC_STRUCT_TRAITS_END()
+
+IPC_STRUCT_TRAITS_BEGIN(ppapi::PPB_URLRequestInfo_Data::BodyItem)
+ IPC_STRUCT_TRAITS_MEMBER(is_file)
+ IPC_STRUCT_TRAITS_MEMBER(data)
+ // Note: we don't serialize file_ref.
+ IPC_STRUCT_TRAITS_MEMBER(file_ref_host_resource)
+ IPC_STRUCT_TRAITS_MEMBER(start_offset)
+ IPC_STRUCT_TRAITS_MEMBER(number_of_bytes)
+ IPC_STRUCT_TRAITS_MEMBER(expected_last_modified_time)
+IPC_STRUCT_TRAITS_END()
+
// These are from the browser to the plugin.
// Loads the given plugin.
IPC_MESSAGE_CONTROL1(PpapiMsg_LoadPlugin, FilePath /* path */)
@@ -189,7 +219,7 @@ IPC_MESSAGE_ROUTED3(
PpapiMsg_PPBFileChooser_ChooseComplete,
ppapi::HostResource /* chooser */,
int32_t /* result_code (will be != PP_OK on failure */,
- std::vector<ppapi::proxy::PPBFileRef_CreateInfo> /* chosen_files */)
+ std::vector<ppapi::PPB_FileRef_CreateInfo> /* chosen_files */)
// PPB_FileSystem.
IPC_MESSAGE_ROUTED2(
@@ -531,10 +561,10 @@ IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBFileChooser_Show,
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFileRef_Create,
ppapi::HostResource /* file_system */,
std::string /* path */,
- ppapi::proxy::PPBFileRef_CreateInfo /* result */)
+ ppapi::PPB_FileRef_CreateInfo /* result */)
IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFileRef_GetParent,
ppapi::HostResource /* file_ref */,
- ppapi::proxy::PPBFileRef_CreateInfo /* result */)
+ ppapi::PPB_FileRef_CreateInfo /* result */)
IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileRef_MakeDirectory,
ppapi::HostResource /* file_ref */,
PP_Bool /* make_ancestors */,
@@ -575,8 +605,9 @@ IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_GetProxyForURL,
PP_Instance /* instance */,
std::string /* url */,
ppapi::proxy::SerializedVar /* result */)
-IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_Navigate,
- ppapi::HostResource /* request_info */,
+IPC_SYNC_MESSAGE_ROUTED4_1(PpapiHostMsg_PPBFlash_Navigate,
+ PP_Instance /* instance */,
+ ppapi::PPB_URLRequestInfo_Data /* request_data */,
std::string /* target */,
bool /* from_user_action */,
int32_t /* result */)
@@ -840,7 +871,7 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBURLLoader_Create,
ppapi::HostResource /* result */)
IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBURLLoader_Open,
ppapi::HostResource /* loader */,
- ppapi::HostResource /*request_info */,
+ ppapi::PPB_URLRequestInfo_Data /* request_data */,
uint32_t /* serialized_callback */)
IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBURLLoader_FollowRedirect,
ppapi::HostResource /* loader */,
@@ -860,24 +891,6 @@ IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBURLLoader_Close,
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBURLLoader_GrantUniversalAccess,
ppapi::HostResource /* loader */)
-// PPB_URLRequestInfo.
-IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBURLRequestInfo_Create,
- PP_Instance /* instance */,
- ppapi::HostResource /* result */)
-IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBURLRequestInfo_SetProperty,
- ppapi::HostResource /* request */,
- int32_t /* property */,
- ppapi::proxy::SerializedVar /* value */)
-IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody,
- ppapi::HostResource /* request */,
- std::string /* data */)
-IPC_MESSAGE_ROUTED5(PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody,
- ppapi::HostResource /* request */,
- ppapi::HostResource /* file_ref */,
- int64_t /* start_offset */,
- int64_t /* number_of_bytes */,
- double /* expected_last_modified_time */)
-
// PPB_URLResponseInfo.
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBURLResponseInfo_GetProperty,
ppapi::HostResource /* response */,
@@ -885,7 +898,7 @@ IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBURLResponseInfo_GetProperty,
ppapi::proxy::SerializedVar /* result */)
IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef,
ppapi::HostResource /* response */,
- ppapi::proxy::PPBFileRef_CreateInfo /* result */)
+ ppapi::PPB_FileRef_CreateInfo /* result */)
// PPB_URLUtil.
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBURLUtil_ResolveRelativeToDocument,
diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc
index 0e3c6de..b80df34 100644
--- a/ppapi/proxy/ppapi_param_traits.cc
+++ b/ppapi/proxy/ppapi_param_traits.cc
@@ -248,33 +248,31 @@ void ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Log(
std::string* l) {
}
-// PPBFileRef_CreateInfo -------------------------------------------------------
+// PPB_FileRef_CreateInfo ------------------------------------------------------
// static
-void ParamTraits<ppapi::proxy::PPBFileRef_CreateInfo>::Write(
- Message* m,
- const param_type& p) {
+void ParamTraits<ppapi::PPB_FileRef_CreateInfo>::Write(Message* m,
+ const param_type& p) {
ParamTraits<ppapi::HostResource>::Write(m, p.resource);
ParamTraits<int>::Write(m, p.file_system_type);
- ParamTraits<ppapi::proxy::SerializedVar>::Write(m, p.path);
- ParamTraits<ppapi::proxy::SerializedVar>::Write(m, p.name);
+ ParamTraits<std::string>::Write(m, p.path);
+ ParamTraits<std::string>::Write(m, p.name);
}
// static
-bool ParamTraits<ppapi::proxy::PPBFileRef_CreateInfo>::Read(const Message* m,
- void** iter,
- param_type* r) {
+bool ParamTraits<ppapi::PPB_FileRef_CreateInfo>::Read(const Message* m,
+ void** iter,
+ param_type* r) {
return
ParamTraits<ppapi::HostResource>::Read(m, iter, &r->resource) &&
ParamTraits<int>::Read(m, iter, &r->file_system_type) &&
- ParamTraits<ppapi::proxy::SerializedVar>::Read(m, iter, &r->path) &&
- ParamTraits<ppapi::proxy::SerializedVar>::Read(m, iter, &r->name);
+ ParamTraits<std::string>::Read(m, iter, &r->path) &&
+ ParamTraits<std::string>::Read(m, iter, &r->name);
}
// static
-void ParamTraits<ppapi::proxy::PPBFileRef_CreateInfo>::Log(
- const param_type& p,
- std::string* l) {
+void ParamTraits<ppapi::PPB_FileRef_CreateInfo>::Log(const param_type& p,
+ std::string* l) {
}
// PPBURLLoader_UpdateProgress_Params ------------------------------------------
@@ -440,16 +438,16 @@ void ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Log(
std::string* l) {
}
-// std::vector<PPBFileRef_CreateInfo> ------------------------------------------
+// std::vector<PPB_FileRef_CreateInfo> -----------------------------------------
-void ParamTraits< std::vector<ppapi::proxy::PPBFileRef_CreateInfo> >::Write(
+void ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Write(
Message* m,
const param_type& p) {
WriteVectorWithoutCopy(m, p);
}
// static
-bool ParamTraits< std::vector<ppapi::proxy::PPBFileRef_CreateInfo> >::Read(
+bool ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Read(
const Message* m,
void** iter,
param_type* r) {
@@ -457,7 +455,7 @@ bool ParamTraits< std::vector<ppapi::proxy::PPBFileRef_CreateInfo> >::Read(
}
// static
-void ParamTraits< std::vector<ppapi::proxy::PPBFileRef_CreateInfo> >::Log(
+void ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Log(
const param_type& p,
std::string* l) {
}
diff --git a/ppapi/proxy/ppapi_param_traits.h b/ppapi/proxy/ppapi_param_traits.h
index b53d5f5..71fa9cb 100644
--- a/ppapi/proxy/ppapi_param_traits.h
+++ b/ppapi/proxy/ppapi_param_traits.h
@@ -13,6 +13,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/pp_var.h"
+#include "ppapi/shared_impl/file_ref_impl.h"
struct PP_FileInfo;
struct PP_ObjectProperty;
@@ -22,10 +23,10 @@ struct PP_Flash_NetAddress;
namespace ppapi {
class HostResource;
+//struct PPB_FileRef_CreateInfo;
namespace proxy {
-struct PPBFileRef_CreateInfo;
struct PPBFlash_DrawGlyphs_Params;
struct PPBURLLoader_UpdateProgress_Params;
struct SerializedDirEntry;
@@ -79,8 +80,8 @@ struct ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params> {
};
template<>
-struct ParamTraits<ppapi::proxy::PPBFileRef_CreateInfo> {
- typedef ppapi::proxy::PPBFileRef_CreateInfo param_type;
+struct ParamTraits<ppapi::PPB_FileRef_CreateInfo> {
+ typedef ppapi::PPB_FileRef_CreateInfo param_type;
static void Write(Message* m, const param_type& p);
static bool Read(const Message* m, void** iter, param_type* r);
static void Log(const param_type& p, std::string* l);
@@ -135,8 +136,8 @@ struct ParamTraits< std::vector<ppapi::proxy::SerializedVar> > {
};
template<>
-struct ParamTraits< std::vector<ppapi::proxy::PPBFileRef_CreateInfo> > {
- typedef std::vector<ppapi::proxy::PPBFileRef_CreateInfo> param_type;
+struct ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> > {
+ typedef std::vector<ppapi::PPB_FileRef_CreateInfo> param_type;
static void Write(Message* m, const param_type& p);
static bool Read(const Message* m, void** iter, param_type* r);
static void Log(const param_type& p, std::string* l);
diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc
index 10ed0d9..f13ea86 100644
--- a/ppapi/proxy/ppb_file_chooser_proxy.cc
+++ b/ppapi/proxy/ppb_file_chooser_proxy.cc
@@ -39,7 +39,7 @@ class FileChooser : public Resource,
// Handles the choose complete notification from the host.
void ChooseComplete(
int32_t result_code,
- const std::vector<PPBFileRef_CreateInfo>& chosen_files);
+ const std::vector<PPB_FileRef_CreateInfo>& chosen_files);
private:
PP_CompletionCallback current_show_callback_;
@@ -106,7 +106,7 @@ PP_Resource FileChooser::GetNextChosenFile() {
void FileChooser::ChooseComplete(
int32_t result_code,
- const std::vector<PPBFileRef_CreateInfo>& chosen_files) {
+ const std::vector<PPB_FileRef_CreateInfo>& chosen_files) {
// Convert each of the passed in file infos to resources. These will be owned
// by the FileChooser object until they're passed to the plugin.
DCHECK(file_queue_.empty());
@@ -245,7 +245,7 @@ void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) {
void PPB_FileChooser_Proxy::OnMsgChooseComplete(
const HostResource& chooser,
int32_t result_code,
- const std::vector<PPBFileRef_CreateInfo>& chosen_files) {
+ const std::vector<PPB_FileRef_CreateInfo>& chosen_files) {
EnterPluginFromHostResource<PPB_FileChooser_API> enter(chooser);
if (enter.succeeded()) {
static_cast<FileChooser*>(enter.object())->ChooseComplete(
@@ -255,7 +255,7 @@ void PPB_FileChooser_Proxy::OnMsgChooseComplete(
void PPB_FileChooser_Proxy::OnShowCallback(int32_t result,
const HostResource& chooser) {
- std::vector<PPBFileRef_CreateInfo> files;
+ std::vector<PPB_FileRef_CreateInfo> files;
if (result == PP_OK) {
// Jump through some hoops to get the FileRef proxy. Since we know we're
// in the host at this point, we can ask the host dispatcher for it.
@@ -268,7 +268,7 @@ void PPB_FileChooser_Proxy::OnShowCallback(int32_t result,
while (PP_Resource cur_file_resource =
ppb_file_chooser_target()->GetNextChosenFile(
chooser.host_resource())) {
- PPBFileRef_CreateInfo cur_create_info;
+ PPB_FileRef_CreateInfo cur_create_info;
file_ref_proxy->SerializeFileRef(cur_file_resource, &cur_create_info);
files.push_back(cur_create_info);
}
diff --git a/ppapi/proxy/ppb_file_chooser_proxy.h b/ppapi/proxy/ppb_file_chooser_proxy.h
index 322edc2..4f3bc84 100644
--- a/ppapi/proxy/ppb_file_chooser_proxy.h
+++ b/ppapi/proxy/ppb_file_chooser_proxy.h
@@ -20,10 +20,10 @@ struct PPB_FileChooser_Dev;
namespace ppapi {
class HostResource;
+struct PPB_FileRef_CreateInfo;
namespace proxy {
-struct PPBFileRef_CreateInfo;
class SerializedVarReceiveInput;
class PPB_FileChooser_Proxy : public InterfaceProxy {
@@ -58,7 +58,7 @@ class PPB_FileChooser_Proxy : public InterfaceProxy {
void OnMsgChooseComplete(
const ppapi::HostResource& chooser,
int32_t result_code,
- const std::vector<PPBFileRef_CreateInfo>& chosen_files);
+ const std::vector<PPB_FileRef_CreateInfo>& chosen_files);
// Called when the show is complete in the host. This will notify the plugin
// via IPC and OnMsgChooseComplete will be called there.
diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc
index 9ad0635..0cf26bd 100644
--- a/ppapi/proxy/ppb_file_ref_proxy.cc
+++ b/ppapi/proxy/ppb_file_ref_proxy.cc
@@ -12,7 +12,7 @@
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"
-#include "ppapi/thunk/ppb_file_ref_api.h"
+#include "ppapi/shared_impl/file_ref_impl.h"
#include "ppapi/thunk/resource_creation_api.h"
#include "ppapi/thunk/thunk.h"
@@ -33,18 +33,12 @@ InterfaceProxy* CreateFileRefProxy(Dispatcher* dispatcher,
} // namespace
-class FileRef : public Resource, public PPB_FileRef_API {
+class FileRef : public FileRefImpl {
public:
- explicit FileRef(const PPBFileRef_CreateInfo& info);
+ explicit FileRef(const PPB_FileRef_CreateInfo& info);
virtual ~FileRef();
- // Resource overrides.
- virtual PPB_FileRef_API* AsPPB_FileRef_API() OVERRIDE;
-
- // PPB_FileRef_API implementation.
- virtual PP_FileSystemType GetFileSystemType() const OVERRIDE;
- virtual PP_Var GetName() const OVERRIDE;
- virtual PP_Var GetPath() const OVERRIDE;
+ // PPB_FileRef_API implementation (not provided by FileRefImpl).
virtual PP_Resource GetParent() OVERRIDE;
virtual int32_t MakeDirectory(PP_Bool make_ancestors,
PP_CompletionCallback callback) OVERRIDE;
@@ -60,50 +54,18 @@ class FileRef : public Resource, public PPB_FileRef_API {
return PluginDispatcher::GetForResource(this);
}
- PP_FileSystemType file_system_type_;
- PP_Var path_;
- PP_Var name_;
-
- DISALLOW_COPY_AND_ASSIGN(FileRef);
+ DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef);
};
-FileRef::FileRef(const PPBFileRef_CreateInfo& info)
- : Resource(info.resource) {
- Dispatcher* dispatcher = PluginDispatcher::GetForResource(this);
-
- file_system_type_ = static_cast<PP_FileSystemType>(info.file_system_type);
-
- name_ = ReceiveSerializedVarReturnValue(info.name).Return(dispatcher);
- path_ = ReceiveSerializedVarReturnValue(info.path).Return(dispatcher);
+FileRef::FileRef(const PPB_FileRef_CreateInfo& info)
+ : FileRefImpl(FileRefImpl::InitAsProxy(), info) {
}
FileRef::~FileRef() {
- PluginVarTracker& var_tracker =
- PluginResourceTracker::GetInstance()->var_tracker();
- var_tracker.ReleaseVar(path_);
- var_tracker.ReleaseVar(name_);
-}
-
-PPB_FileRef_API* FileRef::AsPPB_FileRef_API() {
- return this;
-}
-
-PP_FileSystemType FileRef::GetFileSystemType() const {
- return file_system_type_;
-}
-
-PP_Var FileRef::GetName() const {
- PluginResourceTracker::GetInstance()->var_tracker().AddRefVar(name_);
- return name_;
-}
-
-PP_Var FileRef::GetPath() const {
- PluginResourceTracker::GetInstance()->var_tracker().AddRefVar(path_);
- return path_;
}
PP_Resource FileRef::GetParent() {
- PPBFileRef_CreateInfo create_info;
+ PPB_FileRef_CreateInfo create_info;
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent(
INTERFACE_ID_PPB_FILE_REF, host_resource(), &create_info));
return PPB_FileRef_Proxy::DeserializeFileRef(create_info);
@@ -176,7 +138,7 @@ PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Resource file_system,
if (!file_system_object)
return 0;
- PPBFileRef_CreateInfo create_info;
+ PPB_FileRef_CreateInfo create_info;
PluginDispatcher::GetForResource(file_system_object)->Send(
new PpapiHostMsg_PPBFileRef_Create(
INTERFACE_ID_PPB_FILE_REF, file_system_object->host_resource(),
@@ -200,35 +162,15 @@ bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) {
}
void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref,
- PPBFileRef_CreateInfo* result) {
+ PPB_FileRef_CreateInfo* result) {
EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false);
- if (enter.failed()) {
- NOTREACHED();
- return;
- }
-
- // We need the instance out of the resource for serializing back to the
- // plugin. This code can only run in the host.
- if (dispatcher()->IsPlugin()) {
- NOTREACHED();
- return;
- }
- HostDispatcher* host_dispatcher = static_cast<HostDispatcher*>(dispatcher());
- PP_Instance instance =
- host_dispatcher->ppb_proxy()->GetInstanceForResource(file_ref);
-
- result->resource.SetHostResource(instance, file_ref);
- result->file_system_type =
- static_cast<int>(enter.object()->GetFileSystemType());
- result->path = SerializedVarReturnValue::Convert(dispatcher(),
- enter.object()->GetPath());
- result->name = SerializedVarReturnValue::Convert(dispatcher(),
- enter.object()->GetName());
+ if (enter.succeeded())
+ *result = enter.object()->GetCreateInfo();
}
// static
PP_Resource PPB_FileRef_Proxy::DeserializeFileRef(
- const PPBFileRef_CreateInfo& serialized) {
+ const PPB_FileRef_CreateInfo& serialized) {
if (serialized.resource.is_null())
return 0; // Resource invalid.
return (new FileRef(serialized))->GetReference();
@@ -236,7 +178,7 @@ PP_Resource PPB_FileRef_Proxy::DeserializeFileRef(
void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system,
const std::string& path,
- PPBFileRef_CreateInfo* result) {
+ PPB_FileRef_CreateInfo* result) {
EnterFunctionNoLock<ResourceCreationAPI> enter(file_system.instance(), true);
if (enter.failed())
return;
@@ -248,7 +190,7 @@ void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system,
}
void PPB_FileRef_Proxy::OnMsgGetParent(const HostResource& host_resource,
- PPBFileRef_CreateInfo* result) {
+ PPB_FileRef_CreateInfo* result) {
EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource);
if (enter.succeeded())
SerializeFileRef(enter.object()->GetParent(), result);
diff --git a/ppapi/proxy/ppb_file_ref_proxy.h b/ppapi/proxy/ppb_file_ref_proxy.h
index 3ae502d..1241343 100644
--- a/ppapi/proxy/ppb_file_ref_proxy.h
+++ b/ppapi/proxy/ppb_file_ref_proxy.h
@@ -18,11 +18,10 @@ struct PPB_FileRef_Dev;
namespace ppapi {
class HostResource;
+struct PPB_FileRef_CreateInfo;
namespace proxy {
-struct PPBFileRef_CreateInfo;
-
class PPB_FileRef_Proxy : public InterfaceProxy {
public:
PPB_FileRef_Proxy(Dispatcher* dispatcher, const void* target_interface);
@@ -46,7 +45,7 @@ class PPB_FileRef_Proxy : public InterfaceProxy {
// Various PPAPI functions return file refs from various interfaces, so this
// function is public so anybody can send a file ref.
void SerializeFileRef(PP_Resource file_ref,
- PPBFileRef_CreateInfo* result);
+ PPB_FileRef_CreateInfo* result);
// Creates a plugin resource from the given CreateInfo sent from the host.
// The value will be the result of calling SerializeFileRef on the host.
@@ -56,15 +55,15 @@ class PPB_FileRef_Proxy : public InterfaceProxy {
// Various PPAPI functions return file refs from various interfaces, so this
// function is public so anybody can receive a file ref.
static PP_Resource DeserializeFileRef(
- const PPBFileRef_CreateInfo& serialized);
+ const PPB_FileRef_CreateInfo& serialized);
private:
// Message handlers.
void OnMsgCreate(const ppapi::HostResource& file_system,
const std::string& path,
- PPBFileRef_CreateInfo* result);
+ PPB_FileRef_CreateInfo* result);
void OnMsgGetParent(const ppapi::HostResource& host_resource,
- PPBFileRef_CreateInfo* result);
+ PPB_FileRef_CreateInfo* result);
void OnMsgMakeDirectory(const ppapi::HostResource& host_resource,
PP_Bool make_ancestors,
uint32_t serialized_callback);
diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc
index 725af5f..c551ace 100644
--- a/ppapi/proxy/ppb_flash_proxy.cc
+++ b/ppapi/proxy/ppb_flash_proxy.cc
@@ -19,6 +19,10 @@
#include "ppapi/proxy/proxy_module.h"
#include "ppapi/proxy/serialized_var.h"
#include "ppapi/shared_impl/resource.h"
+#include "ppapi/shared_impl/scoped_pp_resource.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_url_request_info_api.h"
+#include "ppapi/thunk/resource_creation_api.h"
namespace ppapi {
namespace proxy {
@@ -95,20 +99,19 @@ PP_Var GetProxyForURL(PP_Instance instance, const char* url) {
int32_t Navigate(PP_Resource request_id,
const char* target,
bool from_user_action) {
- Resource* request_object =
- PluginResourceTracker::GetInstance()->GetResource(request_id);
- if (!request_object)
+ thunk::EnterResource<thunk::PPB_URLRequestInfo_API> enter(request_id, true);
+ if (enter.failed())
return PP_ERROR_BADRESOURCE;
+ PP_Instance instance = enter.resource()->pp_instance();
- PluginDispatcher* dispatcher =
- PluginDispatcher::GetForInstance(request_object->pp_instance());
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_FAILED;
int32_t result = PP_ERROR_FAILED;
dispatcher->Send(new PpapiHostMsg_PPBFlash_Navigate(
INTERFACE_ID_PPB_FLASH,
- request_object->host_resource(), target, from_user_action,
+ instance, enter.object()->GetData(), target, from_user_action,
&result));
return result;
}
@@ -256,18 +259,40 @@ void PPB_Flash_Proxy::OnMsgGetProxyForURL(PP_Instance instance,
instance, url.c_str()));
}
-void PPB_Flash_Proxy::OnMsgNavigate(const HostResource& request_info,
+void PPB_Flash_Proxy::OnMsgNavigate(PP_Instance instance,
+ const PPB_URLRequestInfo_Data& data,
const std::string& target,
bool from_user_action,
int32_t* result) {
DCHECK(!dispatcher()->IsPlugin());
+
+ // Validate the PP_Instance since we'll be constructing resources on its
+ // behalf.
+ HostDispatcher* host_dispatcher = static_cast<HostDispatcher*>(dispatcher());
+ if (HostDispatcher::GetForInstance(instance) != host_dispatcher) {
+ NOTREACHED();
+ *result = PP_ERROR_BADARGUMENT;
+ return;
+ }
+
// We need to allow re-entrancy here, because this may call into Javascript
// (e.g. with a "javascript:" URL), or do things like navigate away from the
// page, either one of which will need to re-enter into the plugin.
// It is safe, because it is essentially equivalent to NPN_GetURL, where Flash
// would expect re-entrancy. When running in-process, it does re-enter here.
- static_cast<HostDispatcher*>(dispatcher())->set_allow_plugin_reentrancy();
- *result = ppb_flash_target()->Navigate(request_info.host_resource(),
+ host_dispatcher->set_allow_plugin_reentrancy();
+
+ // Make a temporary request resource.
+ thunk::EnterFunctionNoLock<thunk::ResourceCreationAPI> enter(instance, true);
+ if (enter.failed()) {
+ *result = PP_ERROR_FAILED;
+ return;
+ }
+ ScopedPPResource request_resource(
+ ScopedPPResource::PassRef(),
+ enter.functions()->CreateURLRequestInfo(instance, data));
+
+ *result = ppb_flash_target()->Navigate(request_resource,
target.c_str(),
from_user_action);
}
diff --git a/ppapi/proxy/ppb_flash_proxy.h b/ppapi/proxy/ppb_flash_proxy.h
index faf4222..f893ce2 100644
--- a/ppapi/proxy/ppb_flash_proxy.h
+++ b/ppapi/proxy/ppb_flash_proxy.h
@@ -19,6 +19,9 @@ struct PP_FileInfo;
struct PPB_Flash;
namespace ppapi {
+
+struct PPB_URLRequestInfo_Data;
+
namespace proxy {
struct PPBFlash_DrawGlyphs_Params;
@@ -47,7 +50,8 @@ class PPB_Flash_Proxy : public InterfaceProxy {
void OnMsgGetProxyForURL(PP_Instance instance,
const std::string& url,
SerializedVarReturnValue result);
- void OnMsgNavigate(const HostResource& request_info,
+ void OnMsgNavigate(PP_Instance instance,
+ const PPB_URLRequestInfo_Data& data,
const std::string& target,
bool from_user_action,
int32_t* result);
diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc
index 3f6cd10..e6ef68e 100644
--- a/ppapi/proxy/ppb_url_loader_proxy.cc
+++ b/ppapi/proxy/ppb_url_loader_proxy.cc
@@ -22,6 +22,7 @@
#include "ppapi/proxy/plugin_resource_tracker.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/ppb_url_response_info_proxy.h"
+#include "ppapi/shared_impl/scoped_pp_resource.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_url_loader_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -180,16 +181,14 @@ PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() {
int32_t URLLoader::Open(PP_Resource request_id,
PP_CompletionCallback callback) {
- Resource* request_object =
- PluginResourceTracker::GetInstance()->GetResource(request_id);
- if (!request_object)
- return PP_ERROR_BADARGUMENT;
+ EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(request_id, true);
+ if (enter.failed())
+ return PP_ERROR_BADRESOURCE;
// TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that
// the proper callback semantics happen if the object is deleted.
GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open(
- INTERFACE_ID_PPB_URL_LOADER, host_resource(),
- request_object->host_resource(),
+ INTERFACE_ID_PPB_URL_LOADER, host_resource(), enter.object()->GetData(),
GetDispatcher()->callback_tracker().SendCallback(callback)));
return PP_OK_COMPLETIONPENDING;
}
@@ -453,13 +452,23 @@ void PPB_URLLoader_Proxy::OnMsgCreate(PP_Instance instance,
}
void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader,
- const HostResource& request_info,
+ const PPB_URLRequestInfo_Data& data,
uint32_t serialized_callback) {
+ // Have to be careful to always issue the callback, so don't return early.
EnterHostFromHostResource<PPB_URLLoader_API> enter(loader);
+ EnterFunctionNoLock<ResourceCreationAPI> enter_creation(
+ loader.instance(), true);
+
PP_CompletionCallback callback = ReceiveCallback(serialized_callback);
+
int32_t result = PP_ERROR_BADRESOURCE;
- if (enter.succeeded())
- result = enter.object()->Open(request_info.host_resource(), callback);
+ if (enter.succeeded() && enter_creation.succeeded()) {
+ ScopedPPResource request_resource(
+ ScopedPPResource::PassRef(),
+ enter_creation.functions()->CreateURLRequestInfo(loader.instance(),
+ data));
+ result = enter.object()->Open(request_resource, callback);
+ }
if (result != PP_OK_COMPLETIONPENDING)
PP_RunCompletionCallback(&callback, result);
// TODO(brettw) bug 73236 register for the status callbacks.
diff --git a/ppapi/proxy/ppb_url_loader_proxy.h b/ppapi/proxy/ppb_url_loader_proxy.h
index 7f2ec40..17825f1 100644
--- a/ppapi/proxy/ppb_url_loader_proxy.h
+++ b/ppapi/proxy/ppb_url_loader_proxy.h
@@ -20,6 +20,9 @@ struct PPB_URLLoader;
struct PPB_URLLoaderTrusted;
namespace ppapi {
+
+struct PPB_URLRequestInfo_Data;
+
namespace proxy {
struct PPBURLLoader_UpdateProgress_Params;
@@ -62,7 +65,7 @@ class PPB_URLLoader_Proxy : public InterfaceProxy {
void OnMsgCreate(PP_Instance instance,
ppapi::HostResource* result);
void OnMsgOpen(const ppapi::HostResource& loader,
- const ppapi::HostResource& request_info,
+ const PPB_URLRequestInfo_Data& data,
uint32_t serialized_callback);
void OnMsgFollowRedirect(const ppapi::HostResource& loader,
uint32_t serialized_callback);
diff --git a/ppapi/proxy/ppb_url_request_info_proxy.cc b/ppapi/proxy/ppb_url_request_info_proxy.cc
index cf9dd3d..e5861f0 100644
--- a/ppapi/proxy/ppb_url_request_info_proxy.cc
+++ b/ppapi/proxy/ppb_url_request_info_proxy.cc
@@ -4,18 +4,10 @@
#include "ppapi/proxy/ppb_url_request_info_proxy.h"
-#include "ppapi/c/ppb_url_request_info.h"
-#include "ppapi/proxy/enter_proxy.h"
#include "ppapi/proxy/plugin_dispatcher.h"
-#include "ppapi/proxy/ppapi_messages.h"
-#include "ppapi/thunk/ppb_url_request_info_api.h"
-#include "ppapi/thunk/resource_creation_api.h"
+#include "ppapi/shared_impl/url_request_info_impl.h"
#include "ppapi/thunk/thunk.h"
-using ppapi::thunk::EnterFunctionNoLock;
-using ppapi::thunk::PPB_URLRequestInfo_API;
-using ppapi::thunk::ResourceCreationAPI;
-
namespace ppapi {
namespace proxy {
@@ -28,86 +20,6 @@ InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher,
} // namespace
-class URLRequestInfo : public Resource,
- public PPB_URLRequestInfo_API {
- public:
- URLRequestInfo(const HostResource& resource);
- virtual ~URLRequestInfo();
-
- virtual PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE;
-
- // PPB_URLRequestInfo_API implementation.
- virtual PP_Bool SetProperty(PP_URLRequestProperty property,
- PP_Var var) OVERRIDE;
- virtual PP_Bool AppendDataToBody(const void* data, uint32_t len) OVERRIDE;
- virtual PP_Bool AppendFileToBody(
- PP_Resource file_ref,
- int64_t start_offset,
- int64_t number_of_bytes,
- PP_Time expected_last_modified_time) OVERRIDE;
-
- private:
- PluginDispatcher* GetDispatcher() const {
- return PluginDispatcher::GetForResource(this);
- }
-
- DISALLOW_COPY_AND_ASSIGN(URLRequestInfo);
-};
-
-URLRequestInfo::URLRequestInfo(const HostResource& resource)
- : Resource(resource) {
-}
-
-URLRequestInfo::~URLRequestInfo() {
-}
-
-PPB_URLRequestInfo_API* URLRequestInfo::AsPPB_URLRequestInfo_API() {
- return this;
-}
-
-PP_Bool URLRequestInfo::SetProperty(PP_URLRequestProperty property,
- PP_Var var) {
- GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty(
- INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(),
- static_cast<int32_t>(property),
- SerializedVarSendInput(GetDispatcher(), var)));
-
- // TODO(brettw) do some validation on the types. We should be able to tell on
- // the plugin side whether the request will succeed or fail in the renderer.
- return PP_TRUE;
-}
-
-PP_Bool URLRequestInfo::AppendDataToBody(const void* data, uint32_t len) {
- GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody(
- INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(),
- std::string(static_cast<const char*>(data), len)));
-
- // TODO(brettw) do some validation. We should be able to tell on the plugin
- // side whether the request will succeed or fail in the renderer.
- return PP_TRUE;
-}
-
-PP_Bool URLRequestInfo::AppendFileToBody(PP_Resource file_ref,
- int64_t start_offset,
- int64_t number_of_bytes,
- PP_Time expected_last_modified_time) {
- Resource* file_ref_object =
- PluginResourceTracker::GetInstance()->GetResource(file_ref);
- if (!file_ref_object)
- return PP_FALSE;
-
- GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody(
- INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(),
- file_ref_object->host_resource(),
- start_offset, number_of_bytes, expected_last_modified_time));
-
- // TODO(brettw) do some validation. We should be able to tell on the plugin
- // side whether the request will succeed or fail in the renderer.
- return PP_TRUE;
-}
-
-// PPB_URLRequestInfo_Proxy ----------------------------------------------------
-
PPB_URLRequestInfo_Proxy::PPB_URLRequestInfo_Proxy(
Dispatcher* dispatcher,
const void* target_interface)
@@ -129,78 +41,9 @@ const InterfaceProxy::Info* PPB_URLRequestInfo_Proxy::GetInfo() {
return &info;
}
-// static
-PP_Resource PPB_URLRequestInfo_Proxy::CreateProxyResource(
- PP_Instance instance) {
- PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
- if (!dispatcher)
- return 0;
-
- HostResource result;
- dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create(
- INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result));
- if (result.is_null())
- return 0;
- return (new URLRequestInfo(result))->GetReference();
-}
-
bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(PPB_URLRequestInfo_Proxy, msg)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_Create, OnMsgCreate)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_SetProperty,
- OnMsgSetProperty)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody,
- OnMsgAppendDataToBody)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody,
- OnMsgAppendFileToBody)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- // TODO(brettw): handle bad messages.
- return handled;
-}
-
-void PPB_URLRequestInfo_Proxy::OnMsgCreate(
- PP_Instance instance,
- HostResource* result) {
- EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true);
- if (enter.succeeded()) {
- result->SetHostResource(instance,
- enter.functions()->CreateURLRequestInfo(instance));
- }
-}
-
-void PPB_URLRequestInfo_Proxy::OnMsgSetProperty(
- HostResource request,
- int32_t property,
- SerializedVarReceiveInput value) {
- EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request);
- if (enter.succeeded()) {
- enter.object()->SetProperty(static_cast<PP_URLRequestProperty>(property),
- value.Get(dispatcher()));
- }
-}
-
-void PPB_URLRequestInfo_Proxy::OnMsgAppendDataToBody(
- HostResource request,
- const std::string& data) {
- EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request);
- if (enter.succeeded())
- enter.object()->AppendDataToBody(data.c_str(), data.size());
-}
-
-void PPB_URLRequestInfo_Proxy::OnMsgAppendFileToBody(
- HostResource request,
- HostResource file_ref,
- int64_t start_offset,
- int64_t number_of_bytes,
- double expected_last_modified_time) {
- EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request);
- if (enter.succeeded()) {
- enter.object()->AppendFileToBody(
- file_ref.host_resource(), start_offset, number_of_bytes,
- expected_last_modified_time);
- }
+ // No messages to handle.
+ return false;
}
} // namespace proxy
diff --git a/ppapi/proxy/ppb_url_request_info_proxy.h b/ppapi/proxy/ppb_url_request_info_proxy.h
index e17ddb2..6242bf8 100644
--- a/ppapi/proxy/ppb_url_request_info_proxy.h
+++ b/ppapi/proxy/ppb_url_request_info_proxy.h
@@ -7,16 +7,13 @@
#include "base/basictypes.h"
#include "ppapi/c/pp_instance.h"
-#include "ppapi/c/pp_resource.h"
#include "ppapi/proxy/interface_proxy.h"
-#include "ppapi/shared_impl/host_resource.h"
-
-struct PPB_URLRequestInfo;
namespace ppapi {
-namespace proxy {
-class SerializedVarReceiveInput;
+struct PPB_URLRequestInfo_Data;
+
+namespace proxy {
class PPB_URLRequestInfo_Proxy : public InterfaceProxy {
public:
@@ -26,25 +23,10 @@ class PPB_URLRequestInfo_Proxy : public InterfaceProxy {
static const Info* GetInfo();
- static PP_Resource CreateProxyResource(PP_Instance instance);
-
// InterfaceProxy implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);
private:
- // Message handlers.
- void OnMsgCreate(PP_Instance instance, ppapi::HostResource* result);
- void OnMsgSetProperty(ppapi::HostResource request,
- int32_t property,
- SerializedVarReceiveInput value);
- void OnMsgAppendDataToBody(ppapi::HostResource request,
- const std::string& data);
- void OnMsgAppendFileToBody(ppapi::HostResource request,
- ppapi::HostResource file_ref,
- int64_t start_offset,
- int64_t number_of_bytes,
- double expected_last_modified_time);
-
DISALLOW_COPY_AND_ASSIGN(PPB_URLRequestInfo_Proxy);
};
diff --git a/ppapi/proxy/ppb_url_response_info_proxy.cc b/ppapi/proxy/ppb_url_response_info_proxy.cc
index 5be2afe..3801e5f 100644
--- a/ppapi/proxy/ppb_url_response_info_proxy.cc
+++ b/ppapi/proxy/ppb_url_response_info_proxy.cc
@@ -71,7 +71,7 @@ PP_Resource URLResponseInfo::GetBodyAsFileRef() {
// file ref when the request is streaming to a file and it's in the state
// where the file is ready. This will prevent us from having to do this sync
// IPC here.
- PPBFileRef_CreateInfo create_info;
+ PPB_FileRef_CreateInfo create_info;
PluginDispatcher::GetForResource(this)->Send(
new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef(
INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), &create_info));
@@ -135,7 +135,7 @@ void PPB_URLResponseInfo_Proxy::OnMsgGetProperty(
void PPB_URLResponseInfo_Proxy::OnMsgGetBodyAsFileRef(
const HostResource& response,
- PPBFileRef_CreateInfo* result) {
+ PPB_FileRef_CreateInfo* result) {
EnterHostFromHostResource<PPB_URLResponseInfo_API> enter(response);
PP_Resource file_ref = 0;
if (enter.succeeded())
diff --git a/ppapi/proxy/ppb_url_response_info_proxy.h b/ppapi/proxy/ppb_url_response_info_proxy.h
index 9713256..a81549d 100644
--- a/ppapi/proxy/ppb_url_response_info_proxy.h
+++ b/ppapi/proxy/ppb_url_response_info_proxy.h
@@ -15,9 +15,11 @@
struct PPB_URLResponseInfo;
namespace ppapi {
+
+struct PPB_FileRef_CreateInfo;
+
namespace proxy {
-struct PPBFileRef_CreateInfo;
class SerializedVarReturnValue;
class PPB_URLResponseInfo_Proxy : public InterfaceProxy {
@@ -45,7 +47,7 @@ class PPB_URLResponseInfo_Proxy : public InterfaceProxy {
int32_t property,
SerializedVarReturnValue result);
void OnMsgGetBodyAsFileRef(const ppapi::HostResource& response,
- PPBFileRef_CreateInfo* result);
+ PPB_FileRef_CreateInfo* result);
DISALLOW_COPY_AND_ASSIGN(PPB_URLResponseInfo_Proxy);
};
diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc
index 70f3f38..89d6504 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -27,7 +27,6 @@
#include "ppapi/proxy/ppb_image_data_proxy.h"
#include "ppapi/proxy/ppb_surface_3d_proxy.h"
#include "ppapi/proxy/ppb_url_loader_proxy.h"
-#include "ppapi/proxy/ppb_url_request_info_proxy.h"
#include "ppapi/proxy/ppb_video_capture_proxy.h"
#include "ppapi/proxy/ppb_video_decoder_proxy.h"
#include "ppapi/shared_impl/audio_config_impl.h"
@@ -35,6 +34,7 @@
#include "ppapi/shared_impl/function_group_base.h"
#include "ppapi/shared_impl/host_resource.h"
#include "ppapi/shared_impl/input_event_impl.h"
+#include "ppapi/shared_impl/url_request_info_impl.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_image_data_api.h"
@@ -289,8 +289,11 @@ PP_Resource ResourceCreationProxy::CreateURLLoader(PP_Instance instance) {
return PPB_URLLoader_Proxy::CreateProxyResource(instance);
}
-PP_Resource ResourceCreationProxy::CreateURLRequestInfo(PP_Instance instance) {
- return PPB_URLRequestInfo_Proxy::CreateProxyResource(instance);
+PP_Resource ResourceCreationProxy::CreateURLRequestInfo(
+ PP_Instance instance,
+ const PPB_URLRequestInfo_Data& data) {
+ return (new URLRequestInfoImpl(
+ HostResource::MakeInstanceOnly(instance), data))->GetReference();
}
PP_Resource ResourceCreationProxy::CreateVideoCapture(PP_Instance instance) {
diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h
index 0cbf230..3f2e76e 100644
--- a/ppapi/proxy/resource_creation_proxy.h
+++ b/ppapi/proxy/resource_creation_proxy.h
@@ -109,7 +109,9 @@ class ResourceCreationProxy : public FunctionGroupBase,
const char* name,
const char* proto) OVERRIDE;
virtual PP_Resource CreateURLLoader(PP_Instance instance) OVERRIDE;
- virtual PP_Resource CreateURLRequestInfo(PP_Instance instance) OVERRIDE;
+ virtual PP_Resource CreateURLRequestInfo(
+ PP_Instance instance,
+ const PPB_URLRequestInfo_Data& data) OVERRIDE;
virtual PP_Resource CreateVideoCapture(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateVideoDecoder(
PP_Instance instance,
diff --git a/ppapi/proxy/serialized_structs.cc b/ppapi/proxy/serialized_structs.cc
index 4fd62ca..e327b60 100644
--- a/ppapi/proxy/serialized_structs.cc
+++ b/ppapi/proxy/serialized_structs.cc
@@ -63,10 +63,6 @@ void SerializedFontDescription::SetToPPFontDescription(
desc->word_spacing = word_spacing;
}
-PPBFileRef_CreateInfo::PPBFileRef_CreateInfo()
- : file_system_type(PP_FILESYSTEMTYPE_EXTERNAL) {
-}
-
PPBFlash_DrawGlyphs_Params::PPBFlash_DrawGlyphs_Params()
: instance(0),
font_desc(),
diff --git a/ppapi/proxy/serialized_structs.h b/ppapi/proxy/serialized_structs.h
index 159ee39..706d6be 100644
--- a/ppapi/proxy/serialized_structs.h
+++ b/ppapi/proxy/serialized_structs.h
@@ -70,17 +70,6 @@ struct SerializedDirEntry {
bool is_dir;
};
-// FileRefs are created in a number of places and they include a number of
-// return values. This struct encapsulates everything in one place.
-struct PPBFileRef_CreateInfo {
- PPBFileRef_CreateInfo(); // Initializes to 0.
-
- ppapi::HostResource resource;
- int file_system_type; // One of PP_FileSystemType values.
- SerializedVar path;
- SerializedVar name;
-};
-
struct PPBFlash_DrawGlyphs_Params {
PPBFlash_DrawGlyphs_Params();
~PPBFlash_DrawGlyphs_Params();
diff --git a/ppapi/shared_impl/file_ref_impl.cc b/ppapi/shared_impl/file_ref_impl.cc
new file mode 100644
index 0000000..1eae27b
--- /dev/null
+++ b/ppapi/shared_impl/file_ref_impl.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2011 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/shared_impl/file_ref_impl.h"
+
+#include "base/logging.h"
+#include "ppapi/shared_impl/tracker_base.h"
+#include "ppapi/shared_impl/var.h"
+
+namespace ppapi {
+
+FileRefImpl::FileRefImpl(const InitAsImpl&, const PPB_FileRef_CreateInfo& info)
+ : Resource(info.resource.instance()),
+ create_info_(info) {
+ // Should not have been passed a host resource for the trusted constructor.
+ DCHECK(info.resource.is_null());
+
+ // Resource's constructor assigned a PP_Resource, so we can fill out our
+ // host resource now.
+ create_info_.resource = host_resource();
+ DCHECK(!create_info_.resource.is_null());
+}
+
+FileRefImpl::FileRefImpl(const InitAsProxy&, const PPB_FileRef_CreateInfo& info)
+ : Resource(info.resource),
+ create_info_(info) {
+}
+
+FileRefImpl::~FileRefImpl() {
+}
+
+thunk::PPB_FileRef_API* FileRefImpl::AsPPB_FileRef_API() {
+ return this;
+}
+
+PP_FileSystemType FileRefImpl::GetFileSystemType() const {
+ return static_cast<PP_FileSystemType>(create_info_.file_system_type);
+}
+
+PP_Var FileRefImpl::GetName() const {
+ if (!name_var_.get()) {
+ name_var_ = new StringVar(
+ TrackerBase::Get()->GetModuleForInstance(pp_instance()),
+ create_info_.name);
+ }
+ return name_var_->GetPPVar();
+}
+
+PP_Var FileRefImpl::GetPath() const {
+ if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL)
+ return PP_MakeUndefined();
+ if (!path_var_.get()) {
+ path_var_ = new StringVar(
+ TrackerBase::Get()->GetModuleForInstance(pp_instance()),
+ create_info_.path);
+ }
+ return path_var_->GetPPVar();
+}
+
+const PPB_FileRef_CreateInfo& FileRefImpl::GetCreateInfo() const {
+ return create_info_;
+}
+
+} // namespace ppapi
diff --git a/ppapi/shared_impl/file_ref_impl.h b/ppapi/shared_impl/file_ref_impl.h
new file mode 100644
index 0000000..515912b
--- /dev/null
+++ b/ppapi/shared_impl/file_ref_impl.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2011 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.
+
+#ifndef PPAPI_SHARED_IMPL_FILE_REF_IMPL_H_
+#define PPAPI_SHARED_IMPL_FILE_REF_IMPL_H_
+
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "ppapi/shared_impl/resource.h"
+#include "ppapi/thunk/ppb_file_ref_api.h"
+
+namespace ppapi {
+
+class StringVar;
+
+// FileRefs are created in a number of places and they include a number of
+// return values. This struct encapsulates everything in one place.
+struct PPB_FileRef_CreateInfo {
+ PPB_FileRef_CreateInfo() : file_system_type(PP_FILESYSTEMTYPE_EXTERNAL) {}
+
+ ppapi::HostResource resource;
+ int file_system_type; // One of PP_FileSystemType values.
+ std::string path;
+ std::string name;
+};
+
+// This class provides the shared implementation of a FileRef. The functions
+// that actually "do stuff" like Touch and MakeDirectory are implemented
+// differently for the proxied and non-proxied derived classes.
+class FileRefImpl : public Resource, public thunk::PPB_FileRef_API {
+ public:
+ struct InitAsImpl {};
+ struct InitAsProxy {};
+
+ FileRefImpl(const InitAsImpl&, const PPB_FileRef_CreateInfo& info);
+ FileRefImpl(const InitAsProxy&, const PPB_FileRef_CreateInfo& info);
+ virtual ~FileRefImpl();
+
+ // Resource overrides.
+ virtual thunk::PPB_FileRef_API* AsPPB_FileRef_API() OVERRIDE;
+
+ // PPB_FileRef_API implementation (partial).
+ virtual PP_FileSystemType GetFileSystemType() const OVERRIDE;
+ virtual PP_Var GetName() const OVERRIDE;
+ virtual PP_Var GetPath() const OVERRIDE;
+ virtual const PPB_FileRef_CreateInfo& GetCreateInfo() const OVERRIDE;
+
+ private:
+ PPB_FileRef_CreateInfo create_info_;
+
+ // Lazily initialized vars created from the create_info_. This is so we can
+ // return the identical string object every time they're requested.
+ mutable scoped_refptr<StringVar> name_var_;
+ mutable scoped_refptr<StringVar> path_var_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(FileRefImpl);
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_FILE_REF_IMPL_H_
diff --git a/ppapi/shared_impl/scoped_pp_resource.cc b/ppapi/shared_impl/scoped_pp_resource.cc
index 1b8f705..d5a9748 100644
--- a/ppapi/shared_impl/scoped_pp_resource.cc
+++ b/ppapi/shared_impl/scoped_pp_resource.cc
@@ -17,6 +17,10 @@ ScopedPPResource::ScopedPPResource(PP_Resource resource) : id_(resource) {
CallAddRef();
}
+ScopedPPResource::ScopedPPResource(const PassRef&, PP_Resource resource)
+ : id_(resource) {
+}
+
ScopedPPResource::ScopedPPResource(Resource* resource)
: id_(resource ? resource->GetReference() : 0) {
// GetReference AddRef's for us.
diff --git a/ppapi/shared_impl/scoped_pp_resource.h b/ppapi/shared_impl/scoped_pp_resource.h
index 74cb9eb..96db4ee 100644
--- a/ppapi/shared_impl/scoped_pp_resource.h
+++ b/ppapi/shared_impl/scoped_pp_resource.h
@@ -14,11 +14,16 @@ class Resource;
// This is a version of scoped_refptr but for PP_Resources.
class ScopedPPResource {
public:
+ struct PassRef {};
+
ScopedPPResource();
// Takes one reference to the given resource.
explicit ScopedPPResource(PP_Resource resource);
+ // Assumes responsibility for one ref that the resource already has.
+ explicit ScopedPPResource(const PassRef&, PP_Resource resource);
+
// Helper to get the PP_Resource out of the given object and take a reference
// to it.
explicit ScopedPPResource(Resource* resource);
diff --git a/ppapi/shared_impl/url_request_info_impl.cc b/ppapi/shared_impl/url_request_info_impl.cc
new file mode 100644
index 0000000..75fcb27
--- /dev/null
+++ b/ppapi/shared_impl/url_request_info_impl.cc
@@ -0,0 +1,337 @@
+// Copyright (c) 2011 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/shared_impl/url_request_info_impl.h"
+
+#include "base/string_util.h"
+#include "ppapi/shared_impl/var.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_file_ref_api.h"
+
+using ppapi::thunk::EnterResourceNoLock;
+
+namespace ppapi {
+
+namespace {
+
+const int32_t kDefaultPrefetchBufferUpperThreshold = 100 * 1000 * 1000;
+const int32_t kDefaultPrefetchBufferLowerThreshold = 50 * 1000 * 1000;
+
+// These methods are not allowed by the XMLHttpRequest standard.
+// http://www.w3.org/TR/XMLHttpRequest/#the-open-method
+const char* const kForbiddenHttpMethods[] = {
+ "connect",
+ "trace",
+ "track",
+};
+
+// These are the "known" methods in the Webkit XHR implementation. Also see
+// the XMLHttpRequest standard.
+// http://www.w3.org/TR/XMLHttpRequest/#the-open-method
+const char* const kKnownHttpMethods[] = {
+ "get",
+ "post",
+ "put",
+ "head",
+ "copy",
+ "delete",
+ "index",
+ "lock",
+ "m-post",
+ "mkcol",
+ "move",
+ "options",
+ "propfind",
+ "proppatch",
+ "unlock",
+};
+
+bool IsValidToken(const std::string& token) {
+ size_t length = token.size();
+ if (length == 0)
+ return false;
+
+ for (size_t i = 0; i < length; i++) {
+ char c = token[i];
+ if (c >= 127 || c <= 32)
+ return false;
+ if (c == '(' || c == ')' || c == '<' || c == '>' || c == '@' ||
+ c == ',' || c == ';' || c == ':' || c == '\\' || c == '\"' ||
+ c == '/' || c == '[' || c == ']' || c == '?' || c == '=' ||
+ c == '{' || c == '}')
+ return false;
+ }
+ return true;
+}
+
+} // namespace
+
+PPB_URLRequestInfo_Data::BodyItem::BodyItem()
+ : is_file(false),
+ start_offset(0),
+ number_of_bytes(-1),
+ expected_last_modified_time(0.0) {
+}
+
+PPB_URLRequestInfo_Data::BodyItem::BodyItem(const std::string& data)
+ : is_file(false),
+ data(data),
+ start_offset(0),
+ number_of_bytes(-1),
+ expected_last_modified_time(0.0) {
+}
+
+PPB_URLRequestInfo_Data::BodyItem::BodyItem(
+ Resource* file_ref,
+ int64_t start_offset,
+ int64_t number_of_bytes,
+ PP_Time expected_last_modified_time)
+ : is_file(true),
+ file_ref(file_ref),
+ file_ref_host_resource(file_ref->host_resource()),
+ start_offset(start_offset),
+ number_of_bytes(number_of_bytes),
+ expected_last_modified_time(expected_last_modified_time) {
+}
+
+PPB_URLRequestInfo_Data::PPB_URLRequestInfo_Data()
+ : url(),
+ method(),
+ headers(),
+ stream_to_file(false),
+ follow_redirects(true),
+ record_download_progress(false),
+ record_upload_progress(false),
+ has_custom_referrer_url(false),
+ custom_referrer_url(),
+ allow_cross_origin_requests(false),
+ allow_credentials(false),
+ has_custom_content_transfer_encoding(false),
+ custom_content_transfer_encoding(),
+ prefetch_buffer_upper_threshold(kDefaultPrefetchBufferUpperThreshold),
+ prefetch_buffer_lower_threshold(kDefaultPrefetchBufferLowerThreshold),
+ body() {
+}
+
+PPB_URLRequestInfo_Data::~PPB_URLRequestInfo_Data() {
+}
+
+URLRequestInfoImpl::URLRequestInfoImpl(PP_Instance instance,
+ const PPB_URLRequestInfo_Data& data)
+ : Resource(instance),
+ data_(data) {
+}
+
+URLRequestInfoImpl::URLRequestInfoImpl(const HostResource& host_resource,
+ const PPB_URLRequestInfo_Data& data)
+ : Resource(host_resource),
+ data_(data) {
+}
+
+URLRequestInfoImpl::~URLRequestInfoImpl() {
+}
+
+thunk::PPB_URLRequestInfo_API* URLRequestInfoImpl::AsPPB_URLRequestInfo_API() {
+ return this;
+}
+
+PP_Bool URLRequestInfoImpl::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 PPB_URLRequestInfo_Data, 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 URLRequestInfoImpl::AppendDataToBody(const void* data, uint32_t len) {
+ if (len > 0) {
+ data_.body.push_back(PPB_URLRequestInfo_Data::BodyItem(
+ std::string(static_cast<const char*>(data), len)));
+ }
+ return PP_TRUE;
+}
+
+PP_Bool URLRequestInfoImpl::AppendFileToBody(
+ PP_Resource file_ref,
+ int64_t start_offset,
+ int64_t number_of_bytes,
+ PP_Time expected_last_modified_time) {
+ 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(PPB_URLRequestInfo_Data::BodyItem(
+ enter.resource(),
+ start_offset,
+ number_of_bytes,
+ expected_last_modified_time));
+ return PP_TRUE;
+}
+
+const PPB_URLRequestInfo_Data& URLRequestInfoImpl::GetData() const {
+ return data_;
+}
+
+// static
+std::string URLRequestInfoImpl::ValidateMethod(const std::string& method) {
+ if (!IsValidToken(method))
+ return std::string();
+
+ for (size_t i = 0; i < arraysize(kForbiddenHttpMethods); ++i) {
+ if (LowerCaseEqualsASCII(method, kForbiddenHttpMethods[i]))
+ return std::string();
+ }
+ for (size_t i = 0; i < arraysize(kKnownHttpMethods); ++i) {
+ if (LowerCaseEqualsASCII(method, kKnownHttpMethods[i])) {
+ // Convert the method name to upper case to match Webkit and Firefox's
+ // XHR implementation.
+ return StringToUpperASCII(std::string(kKnownHttpMethods[i]));
+ }
+ }
+ // Pass through unknown methods that are not forbidden.
+ return method;
+}
+
+bool URLRequestInfoImpl::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;
+ default:
+ return false;
+ }
+}
+
+bool URLRequestInfoImpl::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 URLRequestInfoImpl::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 URLRequestInfoImpl::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: {
+ // Convenience check for synchronously returning errors to the plugin.
+ // This is re-checked in ValidateData.
+ std::string canonicalized = ValidateMethod(value);
+ if (canonicalized.empty())
+ return false;
+ data_.method = canonicalized;
+ 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;
+ default:
+ return false;
+ }
+}
+
+} // namespace ppapi
diff --git a/ppapi/shared_impl/url_request_info_impl.h b/ppapi/shared_impl/url_request_info_impl.h
new file mode 100644
index 0000000..622f8c5
--- /dev/null
+++ b/ppapi/shared_impl/url_request_info_impl.h
@@ -0,0 +1,143 @@
+// Copyright (c) 2011 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.
+
+#ifndef PPAPI_SHARED_IMPL_URL_REQUEST_INFO_IMPL_H_
+#define PPAPI_SHARED_IMPL_URL_REQUEST_INFO_IMPL_H_
+
+#include <string>
+#include <vector>
+
+#include "base/compiler_specific.h"
+#include "ppapi/shared_impl/resource.h"
+#include "ppapi/thunk/ppb_url_request_info_api.h"
+
+namespace ppapi {
+
+namespace thunk {
+class PPB_FileRef_API;
+}
+
+struct PPB_URLRequestInfo_Data {
+ struct BodyItem {
+ BodyItem();
+ explicit BodyItem(const std::string& data);
+ BodyItem(Resource* file_ref,
+ int64_t start_offset,
+ int64_t number_of_bytes,
+ PP_Time expected_last_modified_time);
+
+ // Set if the input is a file, false means the |data| is valid.
+ bool is_file;
+
+ std::string data;
+
+ // Is is_file is set, these variables are set. Note that the resource
+ // may still be NULL in some cases, such as deserialization errors.
+ //
+ // This is a bit tricky. In the plugin side of the proxy, both the file ref
+ // and the file_ref_host_resource will be set and valid. The scoped_ptr
+ // ensures that the resource is alive for as long as the BodyItem is.
+ //
+ // When we deserialize this in the renderer, only the
+ // file_ref_host_resource's are serialized over IPC. The file_refs won't be
+ // valid until the host resources are converted to Resource pointers in the
+ // PPB_URLRequestInfo_Impl.
+ scoped_refptr<Resource> file_ref;
+ HostResource file_ref_host_resource;
+
+ int64_t start_offset;
+ int64_t number_of_bytes;
+ PP_Time expected_last_modified_time;
+
+ // If you add more stuff here, be sure to modify the serialization rules in
+ // ppapi_messages.h
+ };
+
+ PPB_URLRequestInfo_Data();
+ ~PPB_URLRequestInfo_Data();
+
+ std::string url;
+ std::string method;
+ std::string headers;
+
+ bool stream_to_file;
+ bool follow_redirects;
+ bool record_download_progress;
+ bool record_upload_progress;
+
+ // |has_custom_referrer_url| is set to false if a custom referrer hasn't been
+ // set (or has been set to an Undefined Var) and the default referrer should
+ // be used. (Setting the custom referrer to an empty string indicates that no
+ // referrer header should be generated.)
+ bool has_custom_referrer_url;
+ std::string custom_referrer_url;
+
+ bool allow_cross_origin_requests;
+ bool allow_credentials;
+
+ // Similar to the custom referrer (above), but for custom content transfer
+ // encoding.
+ bool has_custom_content_transfer_encoding;
+ std::string custom_content_transfer_encoding;
+
+ int32_t prefetch_buffer_upper_threshold;
+ int32_t prefetch_buffer_lower_threshold;
+
+ std::vector<BodyItem> body;
+
+ // If you add more stuff here, be sure to modify the serialization rules in
+ // ppapi_messages.h
+};
+
+class URLRequestInfoImpl : public ::ppapi::Resource,
+ public ::ppapi::thunk::PPB_URLRequestInfo_API {
+ public:
+ // This constructor initializes the object as a proxy object with the given
+ // host resource.
+ URLRequestInfoImpl(const HostResource& host_resource,
+ const PPB_URLRequestInfo_Data& data);
+
+ ~URLRequestInfoImpl();
+
+ // Resource overrides.
+ virtual thunk::PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE;
+
+ // PPB_URLRequestInfo_API implementation.
+ virtual PP_Bool SetProperty(PP_URLRequestProperty property,
+ PP_Var var) OVERRIDE;
+ virtual PP_Bool AppendDataToBody(const void* data, uint32_t len) OVERRIDE;
+ virtual PP_Bool AppendFileToBody(
+ PP_Resource file_ref,
+ int64_t start_offset,
+ int64_t number_of_bytes,
+ PP_Time expected_last_modified_time) OVERRIDE;
+ virtual const PPB_URLRequestInfo_Data& GetData() const OVERRIDE;
+
+ protected:
+ // Constructor used by the webkit implementation.
+ URLRequestInfoImpl(PP_Instance instance,
+ const PPB_URLRequestInfo_Data& data);
+
+ // Checks that the HTTP method is valid, returning the canonicalized version
+ // if so. Returns empty string if it's invalid.
+ static std::string ValidateMethod(const std::string& method);
+
+ bool SetUndefinedProperty(PP_URLRequestProperty property);
+ bool SetBooleanProperty(PP_URLRequestProperty property, bool value);
+ bool SetIntegerProperty(PP_URLRequestProperty property, int32_t value);
+ bool SetStringProperty(PP_URLRequestProperty property,
+ const std::string& value);
+
+ const PPB_URLRequestInfo_Data& data() const { return data_; }
+ PPB_URLRequestInfo_Data& data() { return data_; }
+
+ private:
+ PPB_URLRequestInfo_Data data_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(URLRequestInfoImpl);
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_URL_REQUEST_INFO_IMPL_H_
diff --git a/ppapi/shared_impl/var.cc b/ppapi/shared_impl/var.cc
index 0542e50..165b8ff 100644
--- a/ppapi/shared_impl/var.cc
+++ b/ppapi/shared_impl/var.cc
@@ -97,6 +97,11 @@ void Var::AssignVarID(int32 id) {
// StringVar -------------------------------------------------------------------
+StringVar::StringVar(PP_Module module, const std::string& str)
+ : Var(module),
+ value_(str) {
+}
+
StringVar::StringVar(PP_Module module, const char* str, uint32 len)
: Var(module),
value_(str, len) {
diff --git a/ppapi/shared_impl/var.h b/ppapi/shared_impl/var.h
index 02553bb..ce5aa2b 100644
--- a/ppapi/shared_impl/var.h
+++ b/ppapi/shared_impl/var.h
@@ -90,6 +90,7 @@ class Var : public base::RefCounted<Var> {
// DoSomethingWithTheString(string->value());
class StringVar : public Var {
public:
+ StringVar(PP_Module module, const std::string& str);
StringVar(PP_Module module, const char* str, uint32 len);
virtual ~StringVar();
diff --git a/ppapi/tests/test_url_loader.cc b/ppapi/tests/test_url_loader.cc
index bcbef50..d28b347 100644
--- a/ppapi/tests/test_url_loader.cc
+++ b/ppapi/tests/test_url_loader.cc
@@ -79,7 +79,7 @@ void TestURLLoader::RunTest() {
RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST);
RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST);
RUN_TEST_FORCEASYNC_AND_NOT(CustomRequestHeader);
- RUN_TEST_FORCEASYNC_AND_NOT(IgnoresBogusContentLength);
+ RUN_TEST_FORCEASYNC_AND_NOT(FailsBogusContentLength);
RUN_TEST_FORCEASYNC_AND_NOT(SameOriginRestriction);
RUN_TEST_FORCEASYNC_AND_NOT(JavascriptURLRestriction);
RUN_TEST_FORCEASYNC_AND_NOT(CrossOriginRequest);
@@ -310,14 +310,25 @@ std::string TestURLLoader::TestCustomRequestHeader() {
return LoadAndCompareBody(request, "1");
}
-std::string TestURLLoader::TestIgnoresBogusContentLength() {
+std::string TestURLLoader::TestFailsBogusContentLength() {
pp::URLRequestInfo request(instance_);
request.SetURL("/echo");
request.SetMethod("POST");
request.SetHeaders("Content-Length: 400");
std::string postdata("postdata");
request.AppendDataToBody(postdata.data(), postdata.length());
- return LoadAndCompareBody(request, postdata);
+
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ pp::URLLoader loader(*instance_);
+ int32_t rv = loader.Open(request, callback);
+ if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+ return ReportError("URLLoader::Open force_async", rv);
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = callback.WaitForResult();
+
+ // The bad header should have made the request fail.
+ ASSERT_TRUE(rv == PP_ERROR_FAILED);
+ PASS();
}
std::string TestURLLoader::TestStreamToFile() {
diff --git a/ppapi/tests/test_url_loader.h b/ppapi/tests/test_url_loader.h
index f88813e..18817ed 100644
--- a/ppapi/tests/test_url_loader.h
+++ b/ppapi/tests/test_url_loader.h
@@ -46,7 +46,7 @@ class TestURLLoader : public TestCase {
std::string TestEmptyDataPOST();
std::string TestBinaryDataPOST();
std::string TestCustomRequestHeader();
- std::string TestIgnoresBogusContentLength();
+ std::string TestFailsBogusContentLength();
std::string TestStreamToFile();
std::string TestSameOriginRestriction();
std::string TestJavascriptURLRestriction();
diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h
index e7f0d0f..e83a1a1 100644
--- a/ppapi/thunk/enter.h
+++ b/ppapi/thunk/enter.h
@@ -97,10 +97,9 @@ class EnterResource {
public:
EnterResource(PP_Resource resource, bool report_error)
: object_(NULL) {
- Resource* base =
- TrackerBase::Get()->GetResourceTracker()->GetResource(resource);
- if (base)
- object_ = base->GetAs<ResourceT>();
+ resource_ = TrackerBase::Get()->GetResourceTracker()->GetResource(resource);
+ if (resource_)
+ object_ = resource_->GetAs<ResourceT>();
// TODO(brettw) check error and if report_error is set, do something.
}
~EnterResource() {}
@@ -109,8 +108,10 @@ class EnterResource {
bool failed() const { return !object_; }
ResourceT* object() { return object_; }
+ Resource* resource() { return resource_; }
private:
+ Resource* resource_;
ResourceT* object_;
DISALLOW_COPY_AND_ASSIGN(EnterResource);
diff --git a/ppapi/thunk/ppb_file_ref_api.h b/ppapi/thunk/ppb_file_ref_api.h
index be46cef..b2f0e9d 100644
--- a/ppapi/thunk/ppb_file_ref_api.h
+++ b/ppapi/thunk/ppb_file_ref_api.h
@@ -8,6 +8,9 @@
#include "ppapi/c/ppb_file_ref.h"
namespace ppapi {
+
+struct PPB_FileRef_CreateInfo;
+
namespace thunk {
class PPB_FileRef_API {
@@ -26,6 +29,10 @@ class PPB_FileRef_API {
virtual int32_t Delete(PP_CompletionCallback callback) = 0;
virtual int32_t Rename(PP_Resource new_file_ref,
PP_CompletionCallback callback) = 0;
+
+ // Intermal function for use in proxying. Returns the internal CreateInfo
+ // (the contained resource does not carry a ref on behalf of the caller).
+ virtual const PPB_FileRef_CreateInfo& GetCreateInfo() const = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_url_request_info_api.h b/ppapi/thunk/ppb_url_request_info_api.h
index 3f6d0ed..56634bc 100644
--- a/ppapi/thunk/ppb_url_request_info_api.h
+++ b/ppapi/thunk/ppb_url_request_info_api.h
@@ -8,6 +8,9 @@
#include "ppapi/c/ppb_url_request_info.h"
namespace ppapi {
+
+struct PPB_URLRequestInfo_Data;
+
namespace thunk {
class PPB_URLRequestInfo_API {
@@ -21,6 +24,9 @@ class PPB_URLRequestInfo_API {
int64_t start_offset,
int64_t number_of_bytes,
PP_Time expected_last_modified_time) = 0;
+
+ // Internal-only function for retrieving the current config.
+ virtual const PPB_URLRequestInfo_Data& GetData() const = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_url_request_info_thunk.cc b/ppapi/thunk/ppb_url_request_info_thunk.cc
index 5c99d18..4f41881 100644
--- a/ppapi/thunk/ppb_url_request_info_thunk.cc
+++ b/ppapi/thunk/ppb_url_request_info_thunk.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "ppapi/shared_impl/url_request_info_impl.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_url_request_info_api.h"
@@ -16,7 +17,8 @@ PP_Resource Create(PP_Instance instance) {
EnterFunction<ResourceCreationAPI> enter(instance, true);
if (enter.failed())
return 0;
- return enter.functions()->CreateURLRequestInfo(instance);
+ return enter.functions()->CreateURLRequestInfo(
+ instance, PPB_URLRequestInfo_Data());
}
PP_Bool IsURLRequestInfo(PP_Resource resource) {
diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h
index 948a1dd..5564eec 100644
--- a/ppapi/thunk/resource_creation_api.h
+++ b/ppapi/thunk/resource_creation_api.h
@@ -24,6 +24,9 @@ struct PP_VideoCaptureDeviceInfo_Dev;
struct PP_Size;
namespace ppapi {
+
+struct PPB_URLRequestInfo_Data;
+
namespace thunk {
// A functional API for creating resource types. Separating out the creation
@@ -108,7 +111,9 @@ class ResourceCreationAPI {
const char* name,
const char* proto) = 0;
virtual PP_Resource CreateURLLoader(PP_Instance instance) = 0;
- virtual PP_Resource CreateURLRequestInfo(PP_Instance instance) = 0;
+ virtual PP_Resource CreateURLRequestInfo(
+ PP_Instance instance,
+ const PPB_URLRequestInfo_Data& data) = 0;
virtual PP_Resource CreateVideoCapture(PP_Instance instance) = 0;
virtual PP_Resource CreateVideoDecoder(
PP_Instance instance,