diff options
author | Andras Becsi <andras.becsi@digia.com> | 2013-12-11 21:33:03 +0100 |
---|---|---|
committer | Andras Becsi <andras.becsi@digia.com> | 2013-12-13 12:34:07 +0100 |
commit | f2a33ff9cbc6d19943f1c7fbddd1f23d23975577 (patch) | |
tree | 0586a32aa390ade8557dfd6b4897f43a07449578 /chromium/ppapi/proxy | |
parent | 5362912cdb5eea702b68ebe23702468d17c3017a (diff) | |
download | qtwebengine-chromium-f2a33ff9cbc6d19943f1c7fbddd1f23d23975577.tar.gz |
Update Chromium to branch 1650 (31.0.1650.63)
Change-Id: I57d8c832eaec1eb2364e0a8e7352a6dd354db99f
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'chromium/ppapi/proxy')
70 files changed, 2125 insertions, 2136 deletions
diff --git a/chromium/ppapi/proxy/error_conversion.cc b/chromium/ppapi/proxy/error_conversion.cc new file mode 100644 index 00000000000..f3587ec671d --- /dev/null +++ b/chromium/ppapi/proxy/error_conversion.cc @@ -0,0 +1,26 @@ +// Copyright 2013 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/error_conversion.h" + +#include "ppapi/c/pp_errors.h" + +namespace ppapi { +namespace proxy { + +int32_t ConvertNetworkAPIErrorForCompatibility(int32_t pp_error, + bool private_api) { + // The private API doesn't return network-specific error codes or + // PP_ERROR_NOACCESS. In order to preserve the behavior, we convert those to + // PP_ERROR_FAILED. + if (private_api && + (pp_error <= PP_ERROR_CONNECTION_CLOSED || + pp_error == PP_ERROR_NOACCESS)) { + return PP_ERROR_FAILED; + } + return pp_error; +} + +} // namespace proxy +} // namespace ppapi diff --git a/chromium/ppapi/proxy/error_conversion.h b/chromium/ppapi/proxy/error_conversion.h new file mode 100644 index 00000000000..84bfb13a0ef --- /dev/null +++ b/chromium/ppapi/proxy/error_conversion.h @@ -0,0 +1,24 @@ +// Copyright 2013 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_PROXY_ERROR_CONVERSION_H_ +#define PPAPI_PROXY_ERROR_CONVERSION_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/proxy/ppapi_proxy_export.h" + +namespace ppapi { +namespace proxy { + +// When |private_api| is true, coverts all network-related errors +; +// PP_ERROR_NOACCESS to PP_ERROR_FAILED. Otherwise, returns |pp_error| +// as is. +PPAPI_PROXY_EXPORT int32_t ConvertNetworkAPIErrorForCompatibility( + int32_t pp_error, + bool private_api); + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_ERROR_CONVERSION_H_ diff --git a/chromium/ppapi/proxy/ext_crx_file_system_private_resource.cc b/chromium/ppapi/proxy/ext_crx_file_system_private_resource.cc index f0de598c2de..be4c3f7bbd5 100644 --- a/chromium/ppapi/proxy/ext_crx_file_system_private_resource.cc +++ b/chromium/ppapi/proxy/ext_crx_file_system_private_resource.cc @@ -6,6 +6,8 @@ #include "base/bind.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/c/pp_file_info.h" +#include "ppapi/proxy/file_system_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/resource_message_params.h" #include "ppapi/shared_impl/host_resource.h" @@ -15,6 +17,13 @@ namespace ppapi { namespace proxy { +namespace { +void RunTrackedCallback(scoped_refptr<TrackedCallback> callback, + int32_t rc) { + callback->Run(rc); +} +} // namespace + ExtCrxFileSystemPrivateResource::ExtCrxFileSystemPrivateResource( Connection connection, PP_Instance instance) : PluginResource(connection, instance), called_open_(false) { @@ -61,19 +70,12 @@ void ExtCrxFileSystemPrivateResource::OnBrowserOpenComplete( return; } - thunk::EnterResourceCreationNoLock enter(pp_instance()); - if (enter.failed()) { - callback->Run(enter.retval()); - return; - } - - *file_system_resource = enter.functions()->CreateIsolatedFileSystem( - pp_instance(), fsid.c_str()); - if (*file_system_resource != 0) { - callback->Run(PP_OK); - } else { + FileSystemResource* fs = new FileSystemResource( + connection(), pp_instance(), PP_FILESYSTEMTYPE_ISOLATED); + *file_system_resource = fs->GetReference(); + if (*file_system_resource == 0) callback->Run(PP_ERROR_FAILED); - } + fs->InitIsolatedFileSystem(fsid, base::Bind(&RunTrackedCallback, callback)); } } // namespace proxy diff --git a/chromium/ppapi/proxy/file_chooser_resource.cc b/chromium/ppapi/proxy/file_chooser_resource.cc index ebd545cfc38..9847e295c9c 100644 --- a/chromium/ppapi/proxy/file_chooser_resource.cc +++ b/chromium/ppapi/proxy/file_chooser_resource.cc @@ -9,8 +9,8 @@ #include "ipc/ipc_message.h" #include "ppapi/c/pp_errors.h" #include "ppapi/proxy/dispatch_reply_message.h" +#include "ppapi/proxy/file_ref_resource.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/shared_impl/var.h" namespace ppapi { @@ -100,19 +100,25 @@ void FileChooserResource::PopulateAcceptTypes( void FileChooserResource::OnPluginMsgShowReply( const ResourceMessageReplyParams& params, - const std::vector<PPB_FileRef_CreateInfo>& chosen_files) { + const std::vector<FileRefCreateInfo>& chosen_files) { if (output_.is_valid()) { // Using v0.6 of the API with the output array. std::vector<PP_Resource> files; - for (size_t i = 0; i < chosen_files.size(); i++) - files.push_back(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); + for (size_t i = 0; i < chosen_files.size(); i++) { + files.push_back(FileRefResource::CreateFileRef( + connection(), + pp_instance(), + chosen_files[i])); + } output_.StoreResourceVector(files); } else { // 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()); for (size_t i = 0; i < chosen_files.size(); i++) { - file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef( + file_queue_.push(FileRefResource::CreateFileRef( + connection(), + pp_instance(), chosen_files[i])); } } diff --git a/chromium/ppapi/proxy/file_chooser_resource.h b/chromium/ppapi/proxy/file_chooser_resource.h index 58331db7f4f..b744e917fce 100644 --- a/chromium/ppapi/proxy/file_chooser_resource.h +++ b/chromium/ppapi/proxy/file_chooser_resource.h @@ -17,7 +17,7 @@ namespace ppapi { -struct PPB_FileRef_CreateInfo; +struct FileRefCreateInfo; namespace proxy { @@ -56,7 +56,7 @@ class PPAPI_PROXY_EXPORT FileChooserResource private: void OnPluginMsgShowReply( const ResourceMessageReplyParams& params, - const std::vector<PPB_FileRef_CreateInfo>& chosen_files); + const std::vector<FileRefCreateInfo>& chosen_files); int32_t ShowInternal(PP_Bool save_as, const PP_Var& suggested_file_name, diff --git a/chromium/ppapi/proxy/file_chooser_resource_unittest.cc b/chromium/ppapi/proxy/file_chooser_resource_unittest.cc index a5801eed161..4ba5bd9da88 100644 --- a/chromium/ppapi/proxy/file_chooser_resource_unittest.cc +++ b/chromium/ppapi/proxy/file_chooser_resource_unittest.cc @@ -5,6 +5,7 @@ #include "base/message_loop/message_loop.h" #include "ppapi/c/dev/ppb_file_chooser_dev.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/c/ppb_file_ref.h" #include "ppapi/proxy/file_chooser_resource.h" #include "ppapi/proxy/locking_resource_releaser.h" #include "ppapi/proxy/ppapi_messages.h" @@ -91,13 +92,14 @@ TEST_F(FileChooserResourceTest, Show) { reply_params.set_result(PP_OK); // Synthesize a response with one file ref in it. Note that it must have a - // host resource value set or deserialization will fail. Since there isn't - // actually a host, this can be whatever we want. - std::vector<PPB_FileRef_CreateInfo> create_info_array; - PPB_FileRef_CreateInfo create_info; - create_info.resource.SetHostResource(pp_instance(), 123); - create_info.path = "foo/bar"; - create_info.name = "baz"; + // pending_host_resource_id set. Since there isn't actually a host, this can + // be whatever we want. + std::vector<FileRefCreateInfo> create_info_array; + FileRefCreateInfo create_info; + create_info.file_system_type = PP_FILESYSTEMTYPE_EXTERNAL; + create_info.display_name = "bar"; + create_info.browser_pending_host_resource_id = 12; + create_info.renderer_pending_host_resource_id = 15; create_info_array.push_back(create_info); ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( PpapiPluginMsg_ResourceReply(reply_params, @@ -115,9 +117,8 @@ TEST_F(FileChooserResourceTest, Show) { { ProxyAutoLock lock; ScopedPPVar release_name_var(ScopedPPVar::PassRef(), name_var); - EXPECT_VAR_IS_STRING(create_info.name, name_var); + EXPECT_VAR_IS_STRING("bar", name_var); } - // Path should be undefined since it's external filesystem. PP_Var path_var(file_ref_iface->GetPath(dest[0])); { ProxyAutoLock lock; diff --git a/chromium/ppapi/proxy/file_io_resource.cc b/chromium/ppapi/proxy/file_io_resource.cc index 76ee51c4e9c..fc53fb05243 100644 --- a/chromium/ppapi/proxy/file_io_resource.cc +++ b/chromium/ppapi/proxy/file_io_resource.cc @@ -111,9 +111,13 @@ int32_t FileIOResource::Open(PP_Resource file_ref, if (rv != PP_OK) return rv; + // Take a reference on the FileRef resource while we're opening the file; we + // don't want the plugin destroying it during the Open operation. + file_ref_ = enter.resource(); + Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, PpapiHostMsg_FileIO_Open( - enter.resource()->host_resource().host_resource(), + file_ref, open_flags), base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, callback)); @@ -410,6 +414,9 @@ void FileIOResource::OnPluginMsgOpenFileComplete( const ResourceMessageReplyParams& params) { DCHECK(state_manager_.get_pending_operation() == FileIOStateManager::OPERATION_EXCLUSIVE); + + // Release the FileRef resource. + file_ref_ = NULL; if (params.result() == PP_OK) state_manager_.SetOpenSucceed(); diff --git a/chromium/ppapi/proxy/file_io_resource.h b/chromium/ppapi/proxy/file_io_resource.h index 1a888d199d6..26c4abb9488 100644 --- a/chromium/ppapi/proxy/file_io_resource.h +++ b/chromium/ppapi/proxy/file_io_resource.h @@ -7,11 +7,13 @@ #include <string> +#include "base/memory/scoped_ptr.h" #include "ppapi/c/private/pp_file_handle.h" #include "ppapi/proxy/connection.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_proxy_export.h" #include "ppapi/shared_impl/file_io_state_manager.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_file_io_api.h" namespace ppapi { @@ -137,6 +139,8 @@ class PPAPI_PROXY_EXPORT FileIOResource PP_FileSystemType file_system_type_; FileIOStateManager state_manager_; + scoped_refptr<Resource> file_ref_; + DISALLOW_COPY_AND_ASSIGN(FileIOResource); }; diff --git a/chromium/ppapi/proxy/file_ref_resource.cc b/chromium/ppapi/proxy/file_ref_resource.cc index 4c098a567a9..7cd96bc60a0 100644 --- a/chromium/ppapi/proxy/file_ref_resource.cc +++ b/chromium/ppapi/proxy/file_ref_resource.cc @@ -22,7 +22,7 @@ namespace proxy { FileRefResource::FileRefResource( Connection connection, PP_Instance instance, - const FileRef_CreateInfo& create_info) + const FileRefCreateInfo& create_info) : PluginResource(connection, instance), create_info_(create_info), file_system_resource_(create_info.file_system_plugin_resource) { @@ -34,19 +34,26 @@ FileRefResource::FileRefResource( create_info_.internal_path.erase(path_size - 1, 1); path_var_ = new StringVar(create_info_.internal_path); - create_info_.display_name = GetNameForInternalFilePath( create_info_.internal_path); } name_var_ = new StringVar(create_info_.display_name); - if (create_info_.pending_host_resource_id != 0) { - AttachToPendingHost(BROWSER, create_info_.pending_host_resource_id); + if (create_info_.browser_pending_host_resource_id != 0 && + create_info_.renderer_pending_host_resource_id != 0) { + AttachToPendingHost(BROWSER, create_info_.browser_pending_host_resource_id); + AttachToPendingHost(RENDERER, + create_info_.renderer_pending_host_resource_id); } else { + CHECK(create_info_.browser_pending_host_resource_id == 0); + CHECK(create_info_.renderer_pending_host_resource_id == 0); CHECK(create_info_.file_system_type != PP_FILESYSTEMTYPE_EXTERNAL); SendCreate(BROWSER, PpapiHostMsg_FileRef_CreateInternal( create_info.file_system_plugin_resource, create_info.internal_path)); + SendCreate(RENDERER, PpapiHostMsg_FileRef_CreateInternal( + create_info.file_system_plugin_resource, + create_info.internal_path)); } } @@ -57,7 +64,7 @@ FileRefResource::~FileRefResource() { PP_Resource FileRefResource::CreateFileRef( Connection connection, PP_Instance instance, - const FileRef_CreateInfo& create_info) { + const FileRefCreateInfo& create_info) { // If we have a valid file_system resource, ensure that its type matches that // of the fs_type parameter. if (create_info.file_system_plugin_resource != 0) { @@ -82,9 +89,7 @@ PP_Resource FileRefResource::CreateFileRef( } thunk::PPB_FileRef_API* FileRefResource::AsPPB_FileRef_API() { - // TODO: return "this" once we update PPB_FileRef_API. - NOTREACHED(); - return NULL; + return this; } PP_FileSystemType FileRefResource::GetFileSystemType() const { @@ -111,7 +116,7 @@ PP_Resource FileRefResource::GetParent() { pos++; std::string parent_path = create_info_.internal_path.substr(0, pos); - ppapi::FileRef_CreateInfo parent_info; + ppapi::FileRefCreateInfo parent_info; parent_info.file_system_type = create_info_.file_system_type; parent_info.internal_path = parent_path; parent_info.display_name = GetNameForInternalFilePath(parent_path); @@ -184,33 +189,9 @@ int32_t FileRefResource::ReadDirectoryEntries( return PP_OK_COMPLETIONPENDING; } -/* -const FileRef_CreateInfo& FileRefResource::GetCreateInfo() const { +const FileRefCreateInfo& FileRefResource::GetCreateInfo() const { return create_info_; } -*/ -const PPB_FileRef_CreateInfo& FileRefResource::GetCreateInfo() const { - // FIXME - NOTREACHED(); - PPB_FileRef_CreateInfo *info = new PPB_FileRef_CreateInfo(); - return *info; -} - -// TODO(teravest): Remove this when we are finished moving to the new proxy. -int32_t FileRefResource::QueryInHost(linked_ptr<PP_FileInfo> info, - scoped_refptr<TrackedCallback> callback) { - NOTREACHED(); - return PP_ERROR_FAILED; -} - -// TODO(teravest): Remove this when we are finished moving to the new proxy. -int32_t FileRefResource::ReadDirectoryEntriesInHost( - linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, - linked_ptr<std::vector<PP_FileType> > file_types, - scoped_refptr<TrackedCallback> callback) { - NOTREACHED(); - return PP_ERROR_FAILED; -} PP_Var FileRefResource::GetAbsolutePath() { if (!absolute_path_var_.get()) { @@ -248,7 +229,7 @@ void FileRefResource::OnDirectoryEntriesReply( const PP_ArrayOutput& output, scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params, - const std::vector<ppapi::FileRef_CreateInfo>& infos, + const std::vector<ppapi::FileRefCreateInfo>& infos, const std::vector<PP_FileType>& file_types) { if (!TrackedCallback::IsPending(callback)) return; diff --git a/chromium/ppapi/proxy/file_ref_resource.h b/chromium/ppapi/proxy/file_ref_resource.h index 82570fbc09c..f982438fb0d 100644 --- a/chromium/ppapi/proxy/file_ref_resource.h +++ b/chromium/ppapi/proxy/file_ref_resource.h @@ -29,7 +29,7 @@ class PPAPI_PROXY_EXPORT FileRefResource public: static PP_Resource CreateFileRef(Connection connection, PP_Instance instance, - const FileRef_CreateInfo& info); + const FileRefCreateInfo& info); virtual ~FileRefResource(); @@ -55,13 +55,7 @@ class PPAPI_PROXY_EXPORT FileRefResource virtual int32_t ReadDirectoryEntries( const PP_ArrayOutput& output, scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual const PPB_FileRef_CreateInfo& GetCreateInfo() const OVERRIDE; - virtual int32_t QueryInHost(linked_ptr<PP_FileInfo> info, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual int32_t ReadDirectoryEntriesInHost( - linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, - linked_ptr<std::vector<PP_FileType> > file_types, - scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual const FileRefCreateInfo& GetCreateInfo() const OVERRIDE; // Private API virtual PP_Var GetAbsolutePath() OVERRIDE; @@ -69,7 +63,7 @@ class PPAPI_PROXY_EXPORT FileRefResource private: FileRefResource(Connection connection, PP_Instance instance, - const FileRef_CreateInfo& info); + const FileRefCreateInfo& info); void RunTrackedCallback(scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params); @@ -83,11 +77,11 @@ class PPAPI_PROXY_EXPORT FileRefResource const PP_ArrayOutput& output, scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params, - const std::vector<ppapi::FileRef_CreateInfo>& infos, + const std::vector<ppapi::FileRefCreateInfo>& infos, const std::vector<PP_FileType>& file_types); // Populated after creation. - FileRef_CreateInfo create_info_; + FileRefCreateInfo create_info_; // Some file ref operations may fail if the the file system resource inside // create_info_ is destroyed. Therefore, we explicitly hold a reference to diff --git a/chromium/ppapi/proxy/file_system_resource.cc b/chromium/ppapi/proxy/file_system_resource.cc index 5acac00964b..bab771929ac 100644 --- a/chromium/ppapi/proxy/file_system_resource.cc +++ b/chromium/ppapi/proxy/file_system_resource.cc @@ -38,6 +38,7 @@ PPB_FileSystem_API* FileSystemResource::AsPPB_FileSystem_API() { int32_t FileSystemResource::Open(int64_t expected_size, scoped_refptr<TrackedCallback> callback) { + DCHECK(type_ != PP_FILESYSTEMTYPE_ISOLATED); if (called_open_) return PP_ERROR_FAILED; called_open_ = true; @@ -59,11 +60,27 @@ PP_FileSystemType FileSystemResource::GetType() { return type_; } -void FileSystemResource::InitIsolatedFileSystem(const char* fsid) { - Post(RENDERER, - PpapiHostMsg_FileSystem_InitIsolatedFileSystem(std::string(fsid))); - Post(BROWSER, - PpapiHostMsg_FileSystem_InitIsolatedFileSystem(std::string(fsid))); +int32_t FileSystemResource::InitIsolatedFileSystem( + const std::string& fsid, + const base::Callback<void(int32_t)>& callback) { + // This call is mutually exclusive with Open() above, so we can reuse the + // called_open state. + DCHECK(type_ == PP_FILESYSTEMTYPE_ISOLATED); + if (called_open_) + return PP_ERROR_FAILED; + called_open_ = true; + + Call<PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply>(RENDERER, + PpapiHostMsg_FileSystem_InitIsolatedFileSystem(fsid), + base::Bind(&FileSystemResource::InitIsolatedFileSystemComplete, + this, + callback)); + Call<PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply>(BROWSER, + PpapiHostMsg_FileSystem_InitIsolatedFileSystem(fsid), + base::Bind(&FileSystemResource::InitIsolatedFileSystemComplete, + this, + callback)); + return PP_OK_COMPLETIONPENDING; } void FileSystemResource::OpenComplete( @@ -75,5 +92,14 @@ void FileSystemResource::OpenComplete( callback->Run(params.result()); } +void FileSystemResource::InitIsolatedFileSystemComplete( + const base::Callback<void(int32_t)>& callback, + const ResourceMessageReplyParams& params) { + ++callback_count_; + // Received callback from browser and renderer. + if (callback_count_ == 2) + callback.Run(params.result()); +} + } // namespace proxy } // namespace ppapi diff --git a/chromium/ppapi/proxy/file_system_resource.h b/chromium/ppapi/proxy/file_system_resource.h index b104db32420..74677f724ed 100644 --- a/chromium/ppapi/proxy/file_system_resource.h +++ b/chromium/ppapi/proxy/file_system_resource.h @@ -38,13 +38,18 @@ class PPAPI_PROXY_EXPORT FileSystemResource scoped_refptr<TrackedCallback> callback) OVERRIDE; virtual PP_FileSystemType GetType() OVERRIDE; - void InitIsolatedFileSystem(const char* fsid); + int32_t InitIsolatedFileSystem(const std::string& fsid, + const base::Callback<void(int32_t)>& callback); private: - // Called when the host has responded to our open request. void OpenComplete(scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params); + // Called when the host has responded to our InitIsolatedFileSystem request. + void InitIsolatedFileSystemComplete( + const base::Callback<void(int32_t)>& callback, + const ResourceMessageReplyParams& params); + PP_FileSystemType type_; bool called_open_; uint32_t callback_count_; diff --git a/chromium/ppapi/proxy/flash_drm_resource.cc b/chromium/ppapi/proxy/flash_drm_resource.cc index a4be23beb8a..889aa72b457 100644 --- a/chromium/ppapi/proxy/flash_drm_resource.cc +++ b/chromium/ppapi/proxy/flash_drm_resource.cc @@ -7,9 +7,8 @@ #include "base/bind.h" #include "ppapi/c/pp_errors.h" #include "ppapi/proxy/dispatch_reply_message.h" +#include "ppapi/proxy/file_ref_resource.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/ppb_file_ref_proxy.h" -#include "ppapi/shared_impl/ppb_file_ref_shared.h" #include "ppapi/shared_impl/var.h" namespace ppapi { @@ -88,10 +87,14 @@ void FlashDRMResource::OnPluginMsgGetVoucherFileReply( PP_Resource* dest, scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params, - const PPB_FileRef_CreateInfo& file_info) { + const FileRefCreateInfo& file_info) { if (TrackedCallback::IsPending(callback)) { - if (params.result() == PP_OK) - *dest = PPB_FileRef_Proxy::DeserializeFileRef(file_info); + if (params.result() == PP_OK) { + *dest = FileRefResource::CreateFileRef( + connection(), + pp_instance(), + file_info); + } callback->Run(params.result()); } } diff --git a/chromium/ppapi/proxy/flash_drm_resource.h b/chromium/ppapi/proxy/flash_drm_resource.h index 12c71e82817..9a4b31c941d 100644 --- a/chromium/ppapi/proxy/flash_drm_resource.h +++ b/chromium/ppapi/proxy/flash_drm_resource.h @@ -11,7 +11,7 @@ #include "ppapi/thunk/ppb_flash_drm_api.h" namespace ppapi { -struct PPB_FileRef_CreateInfo; +struct FileRefCreateInfo; } namespace ppapi { @@ -44,7 +44,7 @@ class FlashDRMResource void OnPluginMsgGetVoucherFileReply(PP_Resource* dest, scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params, - const PPB_FileRef_CreateInfo& file_info); + const FileRefCreateInfo& file_info); DISALLOW_COPY_AND_ASSIGN(FlashDRMResource); }; diff --git a/chromium/ppapi/proxy/flash_file_resource.cc b/chromium/ppapi/proxy/flash_file_resource.cc index 1387eb7c58b..ce7a2cee110 100644 --- a/chromium/ppapi/proxy/flash_file_resource.cc +++ b/chromium/ppapi/proxy/flash_file_resource.cc @@ -13,6 +13,7 @@ #include "ppapi/shared_impl/time_conversion.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_ref_api.h" namespace ppapi { namespace proxy { diff --git a/chromium/ppapi/proxy/host_resolver_resource_base.cc b/chromium/ppapi/proxy/host_resolver_resource_base.cc index 5cbbbb2aa9a..d552b76a578 100644 --- a/chromium/ppapi/proxy/host_resolver_resource_base.cc +++ b/chromium/ppapi/proxy/host_resolver_resource_base.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/proxy/error_conversion.h" #include "ppapi/proxy/net_address_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/tracked_callback.h" @@ -14,25 +15,6 @@ namespace ppapi { namespace proxy { -namespace { - -int32_t ConvertPPError(int32_t pp_error, bool private_api) { - // The private API doesn't return network-specific error codes or - // PP_ERROR_NOACCESS. In order to preserve the behavior, we convert those to - // PP_ERROR_FAILED. - // TODO(yzshen): Consider defining ranges for different kinds of PP_Error - // codes, so that we can detect network-specific error codes in a better way. - if (private_api && - (pp_error <= PP_ERROR_CONNECTION_CLOSED || - pp_error == PP_ERROR_NOACCESS)) { - return PP_ERROR_FAILED; - } - - return pp_error; -} - -} // namespace - HostResolverResourceBase::HostResolverResourceBase(Connection connection, PP_Instance instance, bool private_api) @@ -110,7 +92,8 @@ void HostResolverResourceBase::OnPluginMsgResolveReply( canonical_name_.clear(); net_address_list_.clear(); } - resolve_callback_->Run(ConvertPPError(params.result(), private_api_)); + resolve_callback_->Run(ConvertNetworkAPIErrorForCompatibility(params.result(), + private_api_)); } void HostResolverResourceBase::SendResolve( diff --git a/chromium/ppapi/proxy/interface_list.cc b/chromium/ppapi/proxy/interface_list.cc index d9feb89d08c..9c810a350ce 100644 --- a/chromium/ppapi/proxy/interface_list.cc +++ b/chromium/ppapi/proxy/interface_list.cc @@ -48,6 +48,8 @@ #include "ppapi/c/ppb_messaging.h" #include "ppapi/c/ppb_mouse_lock.h" #include "ppapi/c/ppb_net_address.h" +#include "ppapi/c/ppb_network_list.h" +#include "ppapi/c/ppb_network_monitor.h" #include "ppapi/c/ppb_network_proxy.h" #include "ppapi/c/ppb_opengles2.h" #include "ppapi/c/ppb_tcp_socket.h" @@ -79,9 +81,8 @@ #include "ppapi/c/private/ppb_flash_print.h" #include "ppapi/c/private/ppb_host_resolver_private.h" #include "ppapi/c/private/ppb_net_address_private.h" -#include "ppapi/c/private/ppb_network_list_private.h" -#include "ppapi/c/private/ppb_network_monitor_private.h" #include "ppapi/c/private/ppb_pdf.h" +#include "ppapi/c/private/ppb_platform_verification_private.h" #include "ppapi/c/private/ppb_talk_private.h" #include "ppapi/c/private/ppb_tcp_server_socket_private.h" #include "ppapi/c/private/ppb_tcp_socket_private.h" @@ -101,15 +102,11 @@ #include "ppapi/proxy/ppb_broker_proxy.h" #include "ppapi/proxy/ppb_buffer_proxy.h" #include "ppapi/proxy/ppb_core_proxy.h" -#include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/ppb_flash_message_loop_proxy.h" #include "ppapi/proxy/ppb_graphics_3d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" #include "ppapi/proxy/ppb_instance_proxy.h" #include "ppapi/proxy/ppb_message_loop_proxy.h" -#include "ppapi/proxy/ppb_network_monitor_private_proxy.h" -#include "ppapi/proxy/ppb_tcp_socket_private_proxy.h" -#include "ppapi/proxy/ppb_tcp_socket_proxy.h" #include "ppapi/proxy/ppb_testing_proxy.h" #include "ppapi/proxy/ppb_var_deprecated_proxy.h" #include "ppapi/proxy/ppb_video_decoder_proxy.h" diff --git a/chromium/ppapi/proxy/network_list_resource.cc b/chromium/ppapi/proxy/network_list_resource.cc new file mode 100644 index 00000000000..466e533daf7 --- /dev/null +++ b/chromium/ppapi/proxy/network_list_resource.cc @@ -0,0 +1,89 @@ +// 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/network_list_resource.h" + +#include <algorithm> + +#include "base/logging.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/shared_impl/array_writer.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/thunk/enter.h" + +namespace ppapi { +namespace proxy { + +NetworkListResource::NetworkListResource(PP_Instance instance, + const SerializedNetworkList& list) + : Resource(OBJECT_IS_PROXY, instance), + list_(list) { +} + +NetworkListResource::~NetworkListResource() {} + +thunk::PPB_NetworkList_API* NetworkListResource::AsPPB_NetworkList_API() { + return this; +} + +uint32_t NetworkListResource::GetCount() { + return static_cast<uint32_t>(list_.size()); +} + +PP_Var NetworkListResource::GetName(uint32_t index) { + if (index >= list_.size()) + return PP_MakeUndefined(); + return StringVar::StringToPPVar(list_.at(index).name); +} + +PP_NetworkList_Type NetworkListResource::GetType(uint32_t index) { + if (index >= list_.size()) + return PP_NETWORKLIST_TYPE_UNKNOWN; + return list_.at(index).type; +} + +PP_NetworkList_State NetworkListResource::GetState(uint32_t index) { + if (index >= list_.size()) + return PP_NETWORKLIST_STATE_DOWN; + return list_.at(index).state; +} + +int32_t NetworkListResource::GetIpAddresses(uint32_t index, + const PP_ArrayOutput& output) { + ArrayWriter writer(output); + if (index >= list_.size() || !writer.is_valid()) + return PP_ERROR_BADARGUMENT; + + thunk::EnterResourceCreationNoLock enter(pp_instance()); + if (enter.failed()) + return PP_ERROR_FAILED; + + const std::vector<PP_NetAddress_Private>& addresses = + list_.at(index).addresses; + std::vector<PP_Resource> addr_resources; + for (size_t i = 0; i < addresses.size(); ++i) { + addr_resources.push_back( + enter.functions()->CreateNetAddressFromNetAddressPrivate( + pp_instance(), addresses[i])); + } + if (!writer.StoreResourceVector(addr_resources)) + return PP_ERROR_FAILED; + + return PP_OK; +} + +PP_Var NetworkListResource::GetDisplayName(uint32_t index) { + if (index >= list_.size()) + return PP_MakeUndefined(); + return StringVar::StringToPPVar(list_.at(index).display_name); +} + +uint32_t NetworkListResource::GetMTU(uint32_t index) { + if (index >= list_.size()) + return 0; + return list_.at(index).mtu; +} + +} // namespace proxy +} // namespace thunk diff --git a/chromium/ppapi/proxy/network_list_resource.h b/chromium/ppapi/proxy/network_list_resource.h new file mode 100644 index 00000000000..36c98774ef7 --- /dev/null +++ b/chromium/ppapi/proxy/network_list_resource.h @@ -0,0 +1,52 @@ +// 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. + +#ifndef PPAPI_PROXY_NETWORK_LIST_RESOURCE_H_ +#define PPAPI_PROXY_NETWORK_LIST_RESOURCE_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "ppapi/c/private/ppb_net_address_private.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/proxy/serialized_structs.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/thunk/ppb_network_list_api.h" + +namespace ppapi { +namespace proxy { + +class NetworkListResource + : public Resource, + public thunk::PPB_NetworkList_API { + public: + NetworkListResource(PP_Instance instance, + const SerializedNetworkList& list); + virtual ~NetworkListResource(); + + // Resource override. + virtual thunk::PPB_NetworkList_API* AsPPB_NetworkList_API() OVERRIDE; + + // PPB_NetworkList_API implementation. + virtual uint32_t GetCount() OVERRIDE; + virtual PP_Var GetName(uint32_t index) OVERRIDE; + virtual PP_NetworkList_Type GetType(uint32_t index) OVERRIDE; + virtual PP_NetworkList_State GetState(uint32_t index) OVERRIDE; + virtual int32_t GetIpAddresses(uint32_t index, + const PP_ArrayOutput& output) OVERRIDE; + virtual PP_Var GetDisplayName(uint32_t index) OVERRIDE; + virtual uint32_t GetMTU(uint32_t index) OVERRIDE; + + private: + SerializedNetworkList list_; + + DISALLOW_COPY_AND_ASSIGN(NetworkListResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_NETWORK_LIST_RESOURCE_H_ diff --git a/chromium/ppapi/proxy/network_monitor_resource.cc b/chromium/ppapi/proxy/network_monitor_resource.cc new file mode 100644 index 00000000000..0dfb0b4b3eb --- /dev/null +++ b/chromium/ppapi/proxy/network_monitor_resource.cc @@ -0,0 +1,85 @@ +// Copyright 2013 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/network_monitor_resource.h" + +#include "ppapi/proxy/dispatch_reply_message.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_network_monitor_api.h" + +namespace ppapi { +namespace proxy { + +NetworkMonitorResource::NetworkMonitorResource(Connection connection, + PP_Instance instance) + : PluginResource(connection, instance), + current_list_(0), + forbidden_(false), + network_list_(NULL) { + SendCreate(BROWSER, PpapiHostMsg_NetworkMonitor_Create()); +} + +NetworkMonitorResource::~NetworkMonitorResource() {} + +ppapi::thunk::PPB_NetworkMonitor_API* +NetworkMonitorResource::AsPPB_NetworkMonitor_API() { + return this; +} + +void NetworkMonitorResource::OnReplyReceived( + const ResourceMessageReplyParams& params, + const IPC::Message& msg) { + IPC_BEGIN_MESSAGE_MAP(NetworkMonitorResource, msg) + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( + PpapiPluginMsg_NetworkMonitor_NetworkList, OnPluginMsgNetworkList) + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_0( + PpapiPluginMsg_NetworkMonitor_Forbidden, OnPluginMsgForbidden) + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( + PluginResource::OnReplyReceived(params, msg)) + IPC_END_MESSAGE_MAP() +} + +int32_t NetworkMonitorResource::UpdateNetworkList( + PP_Resource* network_list, + scoped_refptr<TrackedCallback> callback) { + if (!network_list) + return PP_ERROR_BADARGUMENT; + if (TrackedCallback::IsPending(update_callback_)) + return PP_ERROR_INPROGRESS; + if (forbidden_) + return PP_ERROR_NOACCESS; + + if (current_list_.get()) { + *network_list = current_list_.Release(); + return PP_OK; + } + + network_list_ = network_list; + update_callback_ = callback; + return PP_OK_COMPLETIONPENDING; +} + +void NetworkMonitorResource::OnPluginMsgNetworkList( + const ResourceMessageReplyParams& params, + const SerializedNetworkList& list) { + current_list_ = ScopedPPResource( + new NetworkListResource(pp_instance(), list)); + + if (TrackedCallback::IsPending(update_callback_)) { + *network_list_ = current_list_.Release(); + update_callback_->Run(PP_OK); + } +} + +void NetworkMonitorResource::OnPluginMsgForbidden( + const ResourceMessageReplyParams& params) { + forbidden_ = true; + + if (TrackedCallback::IsPending(update_callback_)) + update_callback_->Run(PP_ERROR_NOACCESS); +} + +} // namespace proxy +} // namespace ppapi diff --git a/chromium/ppapi/proxy/network_monitor_resource.h b/chromium/ppapi/proxy/network_monitor_resource.h new file mode 100644 index 00000000000..d227934aab0 --- /dev/null +++ b/chromium/ppapi/proxy/network_monitor_resource.h @@ -0,0 +1,58 @@ +// Copyright 2013 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_PROXY_NETWORK_MONITOR_RESOURCE_H_ +#define PPAPI_PROXY_NETWORK_MONITOR_RESOURCE_H_ + +#include <list> + +#include "ppapi/proxy/network_list_resource.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/shared_impl/scoped_pp_resource.h" +#include "ppapi/thunk/ppb_network_monitor_api.h" + +namespace base { +class MessageLoopProxy; +} // namespace base + +namespace ppapi { +namespace proxy { + +class NetworkMonitorResource : public PluginResource, + public thunk::PPB_NetworkMonitor_API { + public: + explicit NetworkMonitorResource(Connection connection, + PP_Instance instance); + virtual ~NetworkMonitorResource(); + + // PluginResource overrides. + ppapi::thunk::PPB_NetworkMonitor_API* AsPPB_NetworkMonitor_API() OVERRIDE; + virtual void OnReplyReceived(const ResourceMessageReplyParams& params, + const IPC::Message& msg) OVERRIDE; + + // thunk::PPB_NetworkMonitor_API interface + virtual int32_t UpdateNetworkList( + PP_Resource* network_list, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + + private: + // IPC message handlers for the messages received from the browser. + void OnPluginMsgNetworkList(const ResourceMessageReplyParams& params, + const SerializedNetworkList& list); + void OnPluginMsgForbidden(const ResourceMessageReplyParams& params); + + ScopedPPResource current_list_; + bool forbidden_; + + // Parameters passed to UpdateNetworkList(). + PP_Resource* network_list_; + scoped_refptr<TrackedCallback> update_callback_; + + DISALLOW_COPY_AND_ASSIGN(NetworkMonitorResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_NETWORK_MONITOR_RESOURCE_H_ diff --git a/chromium/ppapi/proxy/platform_verification_private_resource.cc b/chromium/ppapi/proxy/platform_verification_private_resource.cc new file mode 100644 index 00000000000..4da3ca0f34e --- /dev/null +++ b/chromium/ppapi/proxy/platform_verification_private_resource.cc @@ -0,0 +1,132 @@ +// Copyright 2013 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/platform_verification_private_resource.h" + +#include "base/bind.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/proxy/dispatch_reply_message.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/tracked_callback.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/shared_impl/var_tracker.h" + +namespace ppapi { +namespace proxy { + +PlatformVerificationPrivateResource::PlatformVerificationPrivateResource( + Connection connection, + PP_Instance instance) + : PluginResource(connection, instance) { + SendCreate(BROWSER, PpapiHostMsg_PlatformVerification_Create()); +} + +PlatformVerificationPrivateResource::~PlatformVerificationPrivateResource() {} + +thunk::PPB_PlatformVerification_API* +PlatformVerificationPrivateResource::AsPPB_PlatformVerification_API() { + return this; +} + +int32_t PlatformVerificationPrivateResource::CanChallengePlatform( + PP_Bool* can_challenge_platform, + const scoped_refptr<TrackedCallback>& callback) { + if (!can_challenge_platform) + return PP_ERROR_BADARGUMENT; + + Call<PpapiHostMsg_PlatformVerification_CanChallengePlatformReply>( + BROWSER, PpapiHostMsg_PlatformVerification_CanChallengePlatform(), + base::Bind( + &PlatformVerificationPrivateResource::OnCanChallengePlatformReply, + base::Unretained(this), can_challenge_platform, callback)); + + return PP_OK_COMPLETIONPENDING; +} + +void PlatformVerificationPrivateResource::OnCanChallengePlatformReply( + PP_Bool* can_challenge_platform, + const scoped_refptr<TrackedCallback>& callback, + const ResourceMessageReplyParams& params, + bool can_challenge_platform_response) { + if (!TrackedCallback::IsPending(callback) || + TrackedCallback::IsScheduledToRun(callback)) { + return; + } + + *can_challenge_platform = PP_FromBool(can_challenge_platform_response); + callback->Run(params.result()); +} + +int32_t PlatformVerificationPrivateResource::ChallengePlatform( + const PP_Var& service_id, + const PP_Var& challenge, + PP_Var* signed_data, + PP_Var* signed_data_signature, + PP_Var* platform_key_certificate, + const scoped_refptr<TrackedCallback>& callback) { + // Prevent null types for obvious reasons, but also ref-counted types to avoid + // leaks on challenge failures (since they're only written to on success). + if (!signed_data || !signed_data_signature || !platform_key_certificate || + VarTracker::IsVarTypeRefcounted(signed_data->type) || + VarTracker::IsVarTypeRefcounted(signed_data_signature->type) || + VarTracker::IsVarTypeRefcounted(platform_key_certificate->type)) { + return PP_ERROR_BADARGUMENT; + } + + StringVar* service_id_str = StringVar::FromPPVar(service_id); + if (!service_id_str) + return PP_ERROR_BADARGUMENT; + + scoped_refptr<ArrayBufferVar> challenge_buffer = + ArrayBufferVar::FromPPVar(challenge); + if (!challenge_buffer) + return PP_ERROR_BADARGUMENT; + + uint8_t* challenge_data = static_cast<uint8_t*>(challenge_buffer->Map()); + uint32 challenge_length = challenge_buffer->ByteLength(); + std::vector<uint8_t> challenge_vector(challenge_data, + challenge_data + challenge_length); + challenge_buffer->Unmap(); + + PpapiHostMsg_PlatformVerification_ChallengePlatform challenge_message( + service_id_str->value(), challenge_vector); + + ChallengePlatformParams output_params = { + signed_data, signed_data_signature, platform_key_certificate, callback }; + + Call<PpapiHostMsg_PlatformVerification_ChallengePlatformReply>( + BROWSER, challenge_message, base::Bind( + &PlatformVerificationPrivateResource::OnChallengePlatformReply, + base::Unretained(this), output_params)); + return PP_OK_COMPLETIONPENDING; +} + +void PlatformVerificationPrivateResource::OnChallengePlatformReply( + ChallengePlatformParams output_params, + const ResourceMessageReplyParams& params, + const std::vector<uint8_t>& raw_signed_data, + const std::vector<uint8_t>& raw_signed_data_signature, + const std::string& raw_platform_key_certificate) { + if (!TrackedCallback::IsPending(output_params.callback) || + TrackedCallback::IsScheduledToRun(output_params.callback)) { + return; + } + + if (params.result() == PP_OK) { + *(output_params.signed_data) = + (PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferVar( + raw_signed_data.size(), &raw_signed_data.front()))->GetPPVar(); + *(output_params.signed_data_signature) = + (PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferVar( + raw_signed_data_signature.size(), + &raw_signed_data_signature.front()))->GetPPVar(); + *(output_params.platform_key_certificate) = + (new StringVar(raw_platform_key_certificate))->GetPPVar(); + } + output_params.callback->Run(params.result()); +} + +} // namespace proxy +} // namespace ppapi diff --git a/chromium/ppapi/proxy/platform_verification_private_resource.h b/chromium/ppapi/proxy/platform_verification_private_resource.h new file mode 100644 index 00000000000..ba7d3b14014 --- /dev/null +++ b/chromium/ppapi/proxy/platform_verification_private_resource.h @@ -0,0 +1,66 @@ +// Copyright 2013 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_PROXY_PLATFORM_VERIFICATION_PRIVATE_RESOURCE_H_ +#define PPAPI_PROXY_PLATFORM_VERIFICATION_PRIVATE_RESOURCE_H_ + +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/thunk/ppb_platform_verification_api.h" + +namespace ppapi { +namespace proxy { + +class PPAPI_PROXY_EXPORT PlatformVerificationPrivateResource + : public PluginResource, + public thunk::PPB_PlatformVerification_API { + public: + PlatformVerificationPrivateResource(Connection connection, + PP_Instance instance); + + private: + struct ChallengePlatformParams { + PP_Var* signed_data; + PP_Var* signed_data_signature; + PP_Var* platform_key_certificate; + scoped_refptr<TrackedCallback> callback; + }; + + virtual ~PlatformVerificationPrivateResource(); + + // PluginResource overrides. + virtual thunk::PPB_PlatformVerification_API* + AsPPB_PlatformVerification_API() OVERRIDE; + + // PPB_PlatformVerification_API implementation. + virtual int32_t CanChallengePlatform( + PP_Bool* can_challenge_platform, + const scoped_refptr<TrackedCallback>& callback) OVERRIDE; + virtual int32_t ChallengePlatform( + const PP_Var& service_id, + const PP_Var& challenge, + PP_Var* signed_data, + PP_Var* signed_data_signature, + PP_Var* platform_key_certificate, + const scoped_refptr<TrackedCallback>& callback) OVERRIDE; + + void OnCanChallengePlatformReply( + PP_Bool* can_challenge_platform, + const scoped_refptr<TrackedCallback>& callback, + const ResourceMessageReplyParams& params, + bool can_challenge_platform_response); + void OnChallengePlatformReply( + ChallengePlatformParams output_params, + const ResourceMessageReplyParams& params, + const std::vector<uint8_t>& raw_signed_data, + const std::vector<uint8_t>& raw_signed_data_signature, + const std::string& raw_platform_key_certificate); + + DISALLOW_COPY_AND_ASSIGN(PlatformVerificationPrivateResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PLATFORM_VERIFICATION_PRIVATE_RESOURCE_H_ diff --git a/chromium/ppapi/proxy/plugin_globals.cc b/chromium/ppapi/proxy/plugin_globals.cc index 07ac6885601..83217f0d96b 100644 --- a/chromium/ppapi/proxy/plugin_globals.cc +++ b/chromium/ppapi/proxy/plugin_globals.cc @@ -128,10 +128,6 @@ void PluginGlobals::PreCacheFontForFlash(const void* logfontw) { plugin_proxy_delegate_->PreCacheFont(logfontw); } -base::Lock* PluginGlobals::GetProxyLock() { - return &proxy_lock_; -} - void PluginGlobals::LogWithSource(PP_Instance instance, PP_LogLevel level, const std::string& source, diff --git a/chromium/ppapi/proxy/plugin_globals.h b/chromium/ppapi/proxy/plugin_globals.h index 044cac7e25c..31adef55841 100644 --- a/chromium/ppapi/proxy/plugin_globals.h +++ b/chromium/ppapi/proxy/plugin_globals.h @@ -9,7 +9,6 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" -#include "base/synchronization/lock.h" #include "base/threading/thread_local_storage.h" #include "ppapi/proxy/connection.h" #include "ppapi/proxy/plugin_resource_tracker.h" @@ -64,7 +63,6 @@ class PPAPI_PROXY_EXPORT PluginGlobals : public PpapiGlobals { virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE; virtual std::string GetCmdLine() OVERRIDE; virtual void PreCacheFontForFlash(const void* logfontw) OVERRIDE; - virtual base::Lock* GetProxyLock() OVERRIDE; virtual void LogWithSource(PP_Instance instance, PP_LogLevel level, const std::string& source, @@ -143,8 +141,6 @@ class PPAPI_PROXY_EXPORT PluginGlobals : public PpapiGlobals { PluginVarTracker plugin_var_tracker_; scoped_refptr<CallbackTracker> callback_tracker_; - base::Lock proxy_lock_; - scoped_ptr<base::ThreadLocalStorage::Slot> msg_loop_slot_; // Note that loop_for_main_thread's constructor sets msg_loop_slot_, so it // must be initialized after msg_loop_slot_ (hence the order here). diff --git a/chromium/ppapi/proxy/plugin_resource_tracker.cc b/chromium/ppapi/proxy/plugin_resource_tracker.cc index 12e9d3faf6a..86cbf7cee43 100644 --- a/chromium/ppapi/proxy/plugin_resource_tracker.cc +++ b/chromium/ppapi/proxy/plugin_resource_tracker.cc @@ -18,6 +18,7 @@ namespace ppapi { namespace proxy { PluginResourceTracker::PluginResourceTracker() : ResourceTracker(THREAD_SAFE) { + UseOddResourceValueInDebugMode(); } PluginResourceTracker::~PluginResourceTracker() { diff --git a/chromium/ppapi/proxy/plugin_resource_var.cc b/chromium/ppapi/proxy/plugin_resource_var.cc new file mode 100644 index 00000000000..0ccff749e4d --- /dev/null +++ b/chromium/ppapi/proxy/plugin_resource_var.cc @@ -0,0 +1,20 @@ +// Copyright 2013 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/plugin_resource_var.h" + +PluginResourceVar::PluginResourceVar() {} + +PluginResourceVar::PluginResourceVar(ppapi::Resource* resource) + : resource_(resource) {} + +PP_Resource PluginResourceVar::GetPPResource() const { + return resource_->pp_resource(); +} + +bool PluginResourceVar::IsPending() const { + return false; +} + +PluginResourceVar::~PluginResourceVar() {} diff --git a/chromium/ppapi/proxy/plugin_resource_var.h b/chromium/ppapi/proxy/plugin_resource_var.h new file mode 100644 index 00000000000..b02718b6a9f --- /dev/null +++ b/chromium/ppapi/proxy/plugin_resource_var.h @@ -0,0 +1,39 @@ +// Copyright 2013 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_PROXY_PLUGIN_RESOURCE_VAR_H_ +#define PPAPI_PROXY_PLUGIN_RESOURCE_VAR_H_ + +#include "ppapi/c/pp_resource.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/resource_var.h" +#include "ppapi/shared_impl/var.h" + +// Represents a resource Var, usable on the plugin side. +class PPAPI_PROXY_EXPORT PluginResourceVar : public ppapi::ResourceVar { + public: + // Makes a null resource var. + PluginResourceVar(); + + // Makes a resource var with an existing resource. + // Takes one reference to the given resource. + explicit PluginResourceVar(ppapi::Resource* resource); + + // ResourceVar override. + virtual PP_Resource GetPPResource() const OVERRIDE; + virtual bool IsPending() const OVERRIDE; + + scoped_refptr<ppapi::Resource> resource() const { return resource_; } + + protected: + virtual ~PluginResourceVar(); + + private: + scoped_refptr<ppapi::Resource> resource_; + + DISALLOW_COPY_AND_ASSIGN(PluginResourceVar); +}; + +#endif diff --git a/chromium/ppapi/proxy/plugin_var_tracker.cc b/chromium/ppapi/proxy/plugin_var_tracker.cc index ee299852514..d2a4d74d0e3 100644 --- a/chromium/ppapi/proxy/plugin_var_tracker.cc +++ b/chromium/ppapi/proxy/plugin_var_tracker.cc @@ -10,10 +10,13 @@ #include "ppapi/c/ppb_var.h" #include "ppapi/proxy/plugin_array_buffer_var.h" #include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_resource_var.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/proxy_object_var.h" #include "ppapi/shared_impl/api_id.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/proxy_lock.h" +#include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/shared_impl/var.h" namespace ppapi { @@ -151,6 +154,14 @@ void PluginVarTracker::ReleaseHostObject(PluginDispatcher* dispatcher, ReleaseVar(found->second); } +ResourceVar* PluginVarTracker::MakeResourceVar(PP_Resource pp_resource) { + ResourceTracker* resource_tracker = PpapiGlobals::Get()->GetResourceTracker(); + ppapi::Resource* resource = resource_tracker->GetResource(pp_resource); + if (!resource) + return NULL; + return new PluginResourceVar(resource); +} + void PluginVarTracker::DidDeleteInstance(PP_Instance instance) { // Calling the destructors on plugin objects may in turn release other // objects which will mutate the map out from under us. So do a two-step diff --git a/chromium/ppapi/proxy/plugin_var_tracker.h b/chromium/ppapi/proxy/plugin_var_tracker.h index 670457f9c05..126c8fcac59 100644 --- a/chromium/ppapi/proxy/plugin_var_tracker.h +++ b/chromium/ppapi/proxy/plugin_var_tracker.h @@ -59,6 +59,7 @@ class PPAPI_PROXY_EXPORT PluginVarTracker : public VarTracker { const PP_Var& host_object); // VarTracker public overrides. + virtual ResourceVar* MakeResourceVar(PP_Resource pp_resource) OVERRIDE; virtual void DidDeleteInstance(PP_Instance instance) OVERRIDE; virtual int TrackSharedMemoryHandle(PP_Instance instance, base::SharedMemoryHandle file, diff --git a/chromium/ppapi/proxy/ppapi_messages.h b/chromium/ppapi/proxy/ppapi_messages.h index 3767f8f4c1c..60cc37fafdf 100644 --- a/chromium/ppapi/proxy/ppapi_messages.h +++ b/chromium/ppapi/proxy/ppapi_messages.h @@ -47,6 +47,7 @@ #include "ppapi/c/private/ppb_talk_private.h" #include "ppapi/c/private/ppp_flash_browser_operations.h" #include "ppapi/proxy/host_resolver_private_resource.h" +#include "ppapi/proxy/network_list_resource.h" #include "ppapi/proxy/ppapi_param_traits.h" #include "ppapi/proxy/ppapi_proxy_export.h" #include "ppapi/proxy/resource_message_params.h" @@ -61,7 +62,7 @@ #include "ppapi/shared_impl/ppapi_preferences.h" #include "ppapi/shared_impl/ppb_device_ref_shared.h" #include "ppapi/shared_impl/ppb_input_event_shared.h" -#include "ppapi/shared_impl/ppb_network_list_private_shared.h" +#include "ppapi/shared_impl/ppb_tcp_socket_shared.h" #include "ppapi/shared_impl/ppb_view_shared.h" #include "ppapi/shared_impl/ppp_flash_browser_operations_shared.h" #include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" @@ -74,6 +75,8 @@ #define IPC_MESSAGE_START PpapiMsgStart +IPC_ENUM_TRAITS_MAX_VALUE(ppapi::TCPSocketVersion, + ppapi::TCP_SOCKET_VERSION_1_1_OR_ABOVE) IPC_ENUM_TRAITS(PP_AudioSampleRate) IPC_ENUM_TRAITS(PP_DeviceType_Dev) IPC_ENUM_TRAITS(PP_DecryptorStreamType) @@ -87,8 +90,8 @@ IPC_ENUM_TRAITS(PP_InputEvent_MouseButton) IPC_ENUM_TRAITS(PP_InputEvent_Type) IPC_ENUM_TRAITS_MAX_VALUE(PP_NetAddressFamily_Private, PP_NETADDRESSFAMILY_PRIVATE_IPV6) -IPC_ENUM_TRAITS(PP_NetworkListState_Private) -IPC_ENUM_TRAITS(PP_NetworkListType_Private) +IPC_ENUM_TRAITS_MAX_VALUE(PP_NetworkList_State, PP_NETWORKLIST_STATE_UP) +IPC_ENUM_TRAITS_MAX_VALUE(PP_NetworkList_Type, PP_NETWORKLIST_TYPE_CELLULAR) IPC_ENUM_TRAITS(PP_PrintOrientation_Dev) IPC_ENUM_TRAITS(PP_PrintOutputFormat_Dev) IPC_ENUM_TRAITS(PP_PrintScalingOption_Dev) @@ -202,11 +205,12 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::DirEntry) IPC_STRUCT_TRAITS_MEMBER(is_dir) IPC_STRUCT_TRAITS_END() -IPC_STRUCT_TRAITS_BEGIN(ppapi::FileRef_CreateInfo) +IPC_STRUCT_TRAITS_BEGIN(ppapi::FileRefCreateInfo) IPC_STRUCT_TRAITS_MEMBER(file_system_type) IPC_STRUCT_TRAITS_MEMBER(internal_path) IPC_STRUCT_TRAITS_MEMBER(display_name) - IPC_STRUCT_TRAITS_MEMBER(pending_host_resource_id) + IPC_STRUCT_TRAITS_MEMBER(browser_pending_host_resource_id) + IPC_STRUCT_TRAITS_MEMBER(renderer_pending_host_resource_id) IPC_STRUCT_TRAITS_MEMBER(file_system_plugin_resource) IPC_STRUCT_TRAITS_END() @@ -259,6 +263,7 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::InputEventData) IPC_STRUCT_TRAITS_MEMBER(wheel_scroll_by_page) IPC_STRUCT_TRAITS_MEMBER(key_code) IPC_STRUCT_TRAITS_MEMBER(usb_key_code) + IPC_STRUCT_TRAITS_MEMBER(code) IPC_STRUCT_TRAITS_MEMBER(character_text) IPC_STRUCT_TRAITS_MEMBER(composition_segment_offsets) IPC_STRUCT_TRAITS_MEMBER(composition_target_segment) @@ -298,8 +303,7 @@ IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_BEGIN(ppapi::URLRequestInfoData::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(file_ref_pp_resource) IPC_STRUCT_TRAITS_MEMBER(start_offset) IPC_STRUCT_TRAITS_MEMBER(number_of_bytes) IPC_STRUCT_TRAITS_MEMBER(expected_last_modified_time) @@ -314,7 +318,7 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::URLResponseInfoData) IPC_STRUCT_TRAITS_MEMBER(body_as_file_ref) IPC_STRUCT_TRAITS_END() -IPC_STRUCT_TRAITS_BEGIN(ppapi::NetworkInfo) +IPC_STRUCT_TRAITS_BEGIN(ppapi::proxy::SerializedNetworkInfo) IPC_STRUCT_TRAITS_MEMBER(name) IPC_STRUCT_TRAITS_MEMBER(type) IPC_STRUCT_TRAITS_MEMBER(state) @@ -486,30 +490,6 @@ IPC_MESSAGE_ROUTED4(PpapiMsg_PPBAudio_NotifyAudioStreamCreated, ppapi::proxy::SerializedHandle /* socket_handle */, ppapi::proxy::SerializedHandle /* handle */) -// PPB_FileRef. -// TODO(teravest): Remove these messages when we've switched over to the "new" -// proxy. -IPC_MESSAGE_ROUTED3( - PpapiMsg_PPBFileRef_CallbackComplete, - ppapi::HostResource /* resource */, - uint32_t /* callback_id */, - int32_t /* result */) - -IPC_MESSAGE_ROUTED4( - PpapiMsg_PPBFileRef_QueryCallbackComplete, - ppapi::HostResource /* resource */, - PP_FileInfo /* file_info */, - uint32_t /* callback_id */, - int32_t /* result */) - -IPC_MESSAGE_ROUTED5( - PpapiMsg_PPBFileRef_ReadDirectoryEntriesCallbackComplete, - ppapi::HostResource /* resource */, - std::vector<ppapi::PPB_FileRef_CreateInfo> /* files */, - std::vector<PP_FileType> /* file_types */, - uint32_t /* callback_id */, - int32_t /* result */) - // PPB_FileSystem. IPC_MESSAGE_ROUTED2( PpapiMsg_PPBFileSystem_OpenComplete, @@ -624,11 +604,6 @@ IPC_MESSAGE_ROUTED2(PpapiMsg_PPPMessaging_HandleMessage, IPC_MESSAGE_ROUTED1(PpapiMsg_PPPMouseLock_MouseLockLost, PP_Instance /* instance */) -// PPB_NetworkMonitor_Private. -IPC_MESSAGE_ROUTED2(PpapiMsg_PPBNetworkMonitor_NetworkList, - uint32 /* plugin_dispatcher_id */, - ppapi::NetworkList /* network_list */) - // PPP_Printing IPC_SYNC_MESSAGE_ROUTED1_1(PpapiMsg_PPPPrinting_QuerySupportedFormats, PP_Instance /* instance */, @@ -661,9 +636,12 @@ IPC_MESSAGE_ROUTED3( int32_t /* result */) // PPP_ContentDecryptor_Dev -IPC_MESSAGE_ROUTED4(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest, +IPC_MESSAGE_ROUTED3(PpapiMsg_PPPContentDecryptor_Initialize, PP_Instance /* instance */, ppapi::proxy::SerializedVar /* key_system, String */, + bool /* can_challenge_platform */) +IPC_MESSAGE_ROUTED3(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest, + PP_Instance /* instance */, ppapi::proxy::SerializedVar /* type, String */, ppapi::proxy::SerializedVar /* init_data, ArrayBuffer */) IPC_MESSAGE_ROUTED4(PpapiMsg_PPPContentDecryptor_AddKey, @@ -703,32 +681,6 @@ IPC_MESSAGE_ROUTED4(PpapiMsg_PPPContentDecryptor_DecryptAndDecode, std::string /* serialized_block_info */) #endif // !defined(OS_NACL) && !defined(NACL_WIN64) -// PPB_TCPSocket and PPB_TCPSocket_Private. -IPC_MESSAGE_ROUTED5(PpapiMsg_PPBTCPSocket_ConnectACK, - uint32 /* plugin_dispatcher_id */, - uint32 /* socket_id */, - int32_t /* result */, - PP_NetAddress_Private /* local_addr */, - PP_NetAddress_Private /* remote_addr */) -IPC_MESSAGE_ROUTED4(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, - uint32 /* plugin_dispatcher_id */, - uint32 /* socket_id */, - bool /* succeeded */, - ppapi::PPB_X509Certificate_Fields /* certificate_fields */) -IPC_MESSAGE_ROUTED4(PpapiMsg_PPBTCPSocket_ReadACK, - uint32 /* plugin_dispatcher_id */, - uint32 /* socket_id */, - int32_t /* result */, - std::string /* data */) -IPC_MESSAGE_ROUTED3(PpapiMsg_PPBTCPSocket_WriteACK, - uint32 /* plugin_dispatcher_id */, - uint32 /* socket_id */, - int32_t /* result */) -IPC_MESSAGE_ROUTED3(PpapiMsg_PPBTCPSocket_SetOptionACK, - uint32 /* plugin_dispatcher_id */, - uint32 /* socket_id */, - int32_t /* result */) - #if !defined(OS_NACL) && !defined(NACL_WIN64) // PPP_Instance_Private. IPC_SYNC_MESSAGE_ROUTED1_1(PpapiMsg_PPPInstancePrivate_GetInstanceObject, @@ -798,43 +750,6 @@ IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBCore_AddRefResource, IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBCore_ReleaseResource, ppapi::HostResource) -// PPB_FileRef. -// TODO(teravest): Remove these messages when we've switched over to the "new" -// proxy. -IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFileRef_Create, - PP_Instance /* instance */, - PP_Resource /* file_system */, - std::string /* path */, - ppapi::PPB_FileRef_CreateInfo /* result */) -IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFileRef_GetParent, - ppapi::HostResource /* file_ref */, - ppapi::PPB_FileRef_CreateInfo /* result */) -IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileRef_MakeDirectory, - ppapi::HostResource /* file_ref */, - PP_Bool /* make_ancestors */, - uint32_t /* callback_id */) -IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFileRef_Touch, - ppapi::HostResource /* file_ref */, - PP_Time /* last_access */, - PP_Time /* last_modified */, - uint32_t /* callback_id */) -IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileRef_Delete, - ppapi::HostResource /* file_ref */, - uint32_t /* callback_id */) -IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileRef_Rename, - ppapi::HostResource /* file_ref */, - ppapi::HostResource /* new_file_ref */, - uint32_t /* callback_id */) -IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileRef_Query, - ppapi::HostResource /* file_ref */, - uint32_t /* callback_id */) -IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFileRef_GetAbsolutePath, - ppapi::HostResource /* file_ref */, - ppapi::proxy::SerializedVar /* result */) -IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileRef_ReadDirectoryEntries, - ppapi::HostResource /* file_ref */, - uint32_t /* callback_id */) - // PPB_Graphics3D. IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBGraphics3D_Create, PP_Instance /* instance */, @@ -962,6 +877,9 @@ IPC_SYNC_MESSAGE_ROUTED1_2(PpapiHostMsg_PPBInstance_GetDocumentURL, IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetPluginInstanceURL, PP_Instance /* active */, ppapi::proxy::SerializedVar /* result */) +IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetPluginReferrerURL, + PP_Instance /* instance */, + ppapi::proxy::SerializedVar /* result */) IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBInstance_SetCursor, PP_Instance /* instance */, int32_t /* type */, @@ -1056,11 +974,6 @@ IPC_SYNC_MESSAGE_ROUTED2_2( ppapi::proxy::SerializedHandle /* result_shm_handle */) // PPB_ContentDecryptor_Dev messages handled in PPB_Instance_Proxy. -IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBInstance_NeedKey, - PP_Instance /* instance */, - ppapi::proxy::SerializedVar /* key_system, String */, - ppapi::proxy::SerializedVar /* session_id, String */, - ppapi::proxy::SerializedVar /* init_data, ArrayBuffer */) IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBInstance_KeyAdded, PP_Instance /* instance */, ppapi::proxy::SerializedVar /* key_system, String */, @@ -1104,12 +1017,6 @@ IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBInstance_DeliverSamples, std::string /* serialized_block_info */) #endif // !defined(OS_NACL) && !defined(NACL_WIN64) -// PPB_NetworkMonitor_Private. -IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBNetworkMonitor_Start, - uint32 /* plugin_dispatcher_id */) -IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBNetworkMonitor_Stop, - uint32 /* plugin_dispatcher_id */) - // PPB_Testing. IPC_SYNC_MESSAGE_ROUTED3_1( PpapiHostMsg_PPBTesting_ReadImageData, @@ -1164,45 +1071,6 @@ IPC_SYNC_MESSAGE_ROUTED1_0(PpapiHostMsg_PPBFlashMessageLoop_Quit, ppapi::HostResource /* flash_message_loop */) #endif // !defined(OS_NACL) && !defined(NACL_WIN64) -// PPB_TCPSocket and PPB_TCPSocket_Private. -// Creates a PPB_TCPSocket resource. -IPC_SYNC_MESSAGE_CONTROL2_1(PpapiHostMsg_PPBTCPSocket_Create, - int32 /* routing_id */, - uint32 /* plugin_dispatcher_id */, - uint32 /* socket_id */) -// Creates a PPB_TCPSocket_Private resource. -IPC_SYNC_MESSAGE_CONTROL2_1(PpapiHostMsg_PPBTCPSocket_CreatePrivate, - int32 /* routing_id */, - uint32 /* plugin_dispatcher_id */, - uint32 /* socket_id */) -IPC_MESSAGE_CONTROL4(PpapiHostMsg_PPBTCPSocket_Connect, - int32 /* routing_id */, - uint32 /* socket_id */, - std::string /* host */, - uint16_t /* port */) -IPC_MESSAGE_CONTROL3(PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress, - int32 /* routing_id */, - uint32 /* socket_id */, - PP_NetAddress_Private /* net_addr */) -IPC_MESSAGE_CONTROL5(PpapiHostMsg_PPBTCPSocket_SSLHandshake, - uint32 /* socket_id */, - std::string /* server_name */, - uint16_t /* server_port */, - std::vector<std::vector<char> > /* trusted_certs */, - std::vector<std::vector<char> > /* untrusted_certs */) -IPC_MESSAGE_CONTROL2(PpapiHostMsg_PPBTCPSocket_Read, - uint32 /* socket_id */, - int32_t /* bytes_to_read */) -IPC_MESSAGE_CONTROL2(PpapiHostMsg_PPBTCPSocket_Write, - uint32 /* socket_id */, - std::string /* data */) -IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBTCPSocket_Disconnect, - uint32 /* socket_id */) -IPC_MESSAGE_CONTROL3(PpapiHostMsg_PPBTCPSocket_SetOption, - uint32 /* socket_id */, - PP_TCPSocket_Option /* name */, - ppapi::SocketOptionData /* value */) - // PPB_X509Certificate_Private IPC_SYNC_MESSAGE_CONTROL1_2(PpapiHostMsg_PPBX509Certificate_ParseDER, std::vector<char> /* der */, @@ -1267,7 +1135,6 @@ IPC_MESSAGE_ROUTED2( ppapi::proxy::ResourceMessageReplyParams /* reply_params */, IPC::Message /* nested_msg */) - IPC_SYNC_MESSAGE_CONTROL2_2(PpapiHostMsg_ResourceSyncCall, ppapi::proxy::ResourceMessageCallParams /* call_params */, IPC::Message /* nested_msg */, @@ -1275,27 +1142,27 @@ IPC_SYNC_MESSAGE_CONTROL2_2(PpapiHostMsg_ResourceSyncCall, IPC::Message /* reply_msg */) // This message is sent from the renderer to the browser when it wants to create -// a ResourceHost in the browser. It contains the process ID of the plugin and +// ResourceHosts in the browser. It contains the process ID of the plugin and // the instance of the plugin for which to create the resource for. params // contains the sequence number for the message to track the response. -// The nested message is a ResourceHost creation message. +// The nested messages are ResourceHost creation messages. IPC_MESSAGE_CONTROL5( - PpapiHostMsg_CreateResourceHostFromHost, + PpapiHostMsg_CreateResourceHostsFromHost, int /* routing_id */, int /* child_process_id */, ppapi::proxy::ResourceMessageCallParams /* params */, PP_Instance /* instance */, - IPC::Message /* nested_msg */) + std::vector<IPC::Message> /* nested_msgs */) -// This message is sent from the browser to the renderer when it has created a -// ResourceHost for the renderer. It contains the sequence number that was sent -// in the request and the ID of the pending ResourceHost which was created in -// the browser. This ID is only useful for the plugin which can attach to the -// ResourceHost in the browser. +// This message is sent from the browser to the renderer when it has created +// ResourceHosts for the renderer. It contains the sequence number that was sent +// in the request and the IDs of the pending ResourceHosts which were created in +// the browser. These IDs are only useful for the plugin which can attach to the +// ResourceHosts in the browser. IPC_MESSAGE_ROUTED2( - PpapiHostMsg_CreateResourceHostFromHostReply, + PpapiHostMsg_CreateResourceHostsFromHostReply, int32_t /* sequence */, - int /* pending_host_id */) + std::vector<int> /* pending_host_ids */) //----------------------------------------------------------------------------- // Messages for resources using call/reply above. @@ -1341,7 +1208,7 @@ IPC_MESSAGE_CONTROL4(PpapiHostMsg_FileChooser_Show, std::string /* suggested_file_name */, std::vector<std::string> /* accept_mime_types */) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FileChooser_ShowReply, - std::vector<ppapi::PPB_FileRef_CreateInfo> /* files */) + std::vector<ppapi::FileRefCreateInfo> /* files */) // FileIO IPC_MESSAGE_CONTROL0(PpapiHostMsg_FileIO_Create) @@ -1417,10 +1284,10 @@ IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FileRef_QueryReply, // location indicated by the FileRef. IPC_MESSAGE_CONTROL0(PpapiHostMsg_FileRef_ReadDirectoryEntries) -// FileRef_CreateInfo does not provide file type information, so two +// FileRefCreateInfo does not provide file type information, so two // corresponding vectors are returned. IPC_MESSAGE_CONTROL2(PpapiPluginMsg_FileRef_ReadDirectoryEntriesReply, - std::vector<ppapi::FileRef_CreateInfo> /* files */, + std::vector<ppapi::FileRefCreateInfo> /* files */, std::vector<PP_FileType> /* file_types */) // Requests that the browser reply with the absolute path to the indicated @@ -1437,6 +1304,7 @@ IPC_MESSAGE_CONTROL1(PpapiHostMsg_FileSystem_Open, IPC_MESSAGE_CONTROL0(PpapiPluginMsg_FileSystem_OpenReply) IPC_MESSAGE_CONTROL1(PpapiHostMsg_FileSystem_InitIsolatedFileSystem, std::string /* fsid */) +IPC_MESSAGE_CONTROL0(PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply) // Flash DRM ------------------------------------------------------------------ IPC_MESSAGE_CONTROL0(PpapiHostMsg_FlashDRM_Create) @@ -1460,7 +1328,7 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_FlashDRM_GetVoucherFile) // Reply message for GetVoucherFile which contains the CreateInfo for a // PPB_FileRef which points to the voucher file. IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FlashDRM_GetVoucherFileReply, - ppapi::PPB_FileRef_CreateInfo /* file_info */) + ppapi::FileRefCreateInfo /* file_info */) // Gamepad. IPC_MESSAGE_CONTROL0(PpapiHostMsg_Gamepad_Create) @@ -1501,6 +1369,13 @@ IPC_MESSAGE_CONTROL2(PpapiHostMsg_Graphics2D_ReadImageData, PP_Point /* top_left */) IPC_MESSAGE_CONTROL0(PpapiPluginMsg_Graphics2D_ReadImageDataAck) +// NetworkMonitor. +IPC_MESSAGE_CONTROL0(PpapiHostMsg_NetworkMonitor_Create) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_NetworkMonitor_NetworkList, + ppapi::proxy::SerializedNetworkList /* network_list */) +IPC_MESSAGE_CONTROL0(PpapiPluginMsg_NetworkMonitor_Forbidden) + + // NetworkProxy ---------------------------------------------------------------- IPC_MESSAGE_CONTROL0(PpapiHostMsg_NetworkProxy_Create) @@ -1556,12 +1431,74 @@ IPC_MESSAGE_CONTROL2(PpapiPluginMsg_HostResolver_ResolveReply, std::string /* canonical_name */, std::vector<PP_NetAddress_Private> /* net_address_list */) +// Platform Verification ------------------------------------------------------- +IPC_MESSAGE_CONTROL0(PpapiHostMsg_PlatformVerification_Create) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_PlatformVerification_CanChallengePlatform) +IPC_MESSAGE_CONTROL1( + PpapiHostMsg_PlatformVerification_CanChallengePlatformReply, + bool /* can_challenge_platform */) +IPC_MESSAGE_CONTROL2(PpapiHostMsg_PlatformVerification_ChallengePlatform, + std::string /* service_id */, + std::vector<uint8_t> /* challenge */) +IPC_MESSAGE_CONTROL3(PpapiHostMsg_PlatformVerification_ChallengePlatformReply, + std::vector<uint8_t> /* signed_data */, + std::vector<uint8_t> /* signed_data_signature */, + std::string /* platform_key_certificate */) + // Printing. IPC_MESSAGE_CONTROL0(PpapiHostMsg_Printing_Create) IPC_MESSAGE_CONTROL0(PpapiHostMsg_Printing_GetDefaultPrintSettings) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply, PP_PrintSettings_Dev /* print_settings */) +// TCP Socket ------------------------------------------------------------------ +// Creates a PPB_TCPSocket resource. +IPC_MESSAGE_CONTROL1(PpapiHostMsg_TCPSocket_Create, + ppapi::TCPSocketVersion /* version */) + +// Creates a PPB_TCPSocket_Private resource. +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TCPSocket_CreatePrivate) + +IPC_MESSAGE_CONTROL1(PpapiHostMsg_TCPSocket_Bind, + PP_NetAddress_Private /* net_addr */) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TCPSocket_BindReply, + PP_NetAddress_Private /* local_addr */) +IPC_MESSAGE_CONTROL2(PpapiHostMsg_TCPSocket_Connect, + std::string /* host */, + uint16_t /* port */) +IPC_MESSAGE_CONTROL1(PpapiHostMsg_TCPSocket_ConnectWithNetAddress, + PP_NetAddress_Private /* net_addr */) +IPC_MESSAGE_CONTROL2(PpapiPluginMsg_TCPSocket_ConnectReply, + PP_NetAddress_Private /* local_addr */, + PP_NetAddress_Private /* remote_addr */) +IPC_MESSAGE_CONTROL4(PpapiHostMsg_TCPSocket_SSLHandshake, + std::string /* server_name */, + uint16_t /* server_port */, + std::vector<std::vector<char> > /* trusted_certs */, + std::vector<std::vector<char> > /* untrusted_certs */) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TCPSocket_SSLHandshakeReply, + ppapi::PPB_X509Certificate_Fields /* certificate_fields */) +IPC_MESSAGE_CONTROL1(PpapiHostMsg_TCPSocket_Read, + int32_t /* bytes_to_read */) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TCPSocket_ReadReply, + std::string /* data */) +IPC_MESSAGE_CONTROL1(PpapiHostMsg_TCPSocket_Write, + std::string /* data */) +IPC_MESSAGE_CONTROL0(PpapiPluginMsg_TCPSocket_WriteReply) +IPC_MESSAGE_CONTROL1(PpapiHostMsg_TCPSocket_Listen, + int32_t /* backlog */) +IPC_MESSAGE_CONTROL0(PpapiPluginMsg_TCPSocket_ListenReply) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TCPSocket_Accept) +IPC_MESSAGE_CONTROL3(PpapiPluginMsg_TCPSocket_AcceptReply, + int /* pending_host_id*/, + PP_NetAddress_Private /* local_addr */, + PP_NetAddress_Private /* remote_addr */) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TCPSocket_Close) +IPC_MESSAGE_CONTROL2(PpapiHostMsg_TCPSocket_SetOption, + PP_TCPSocket_Option /* name */, + ppapi::SocketOptionData /* value */) +IPC_MESSAGE_CONTROL0(PpapiPluginMsg_TCPSocket_SetOptionReply) + // TCP Server Socket ----------------------------------------------------------- // Creates a PPB_TCPServerSocket_Private resource. IPC_MESSAGE_CONTROL0(PpapiHostMsg_TCPServerSocket_CreatePrivate) @@ -1571,10 +1508,9 @@ IPC_MESSAGE_CONTROL2(PpapiHostMsg_TCPServerSocket_Listen, int32_t /* backlog */) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TCPServerSocket_ListenReply, PP_NetAddress_Private /* local_addr */) -IPC_MESSAGE_CONTROL1(PpapiHostMsg_TCPServerSocket_Accept, - uint32 /* plugin_dispatcher_id */) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TCPServerSocket_Accept) IPC_MESSAGE_CONTROL3(PpapiPluginMsg_TCPServerSocket_AcceptReply, - uint32 /* accepted_socket_id */, + int /* pending_resource_id */, PP_NetAddress_Private /* local_addr */, PP_NetAddress_Private /* remote_addr */) IPC_MESSAGE_CONTROL0(PpapiHostMsg_TCPServerSocket_StopListening) @@ -1805,30 +1741,6 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_BrowserFontSingleton_GetFontFamilies) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_BrowserFontSingleton_GetFontFamiliesReply, std::string /* families */) -// FileRef. -// Requests that the browser reply with file system and path information about -// the resource indicated in |params| which exists in the given -// |child_process_id|. |routing_id| is sent so that the reply can be routed -// properly in the renderer. -// Only sent from the renderer to the browser. -IPC_MESSAGE_CONTROL4(PpapiHostMsg_FileRef_GetInfoForRenderer, - int /* routing_id */, - int /* child_process_id */, - int32_t /* sequence */, - std::vector<PP_Resource> /* resources */) - -// Reply to PpapiHostMsg_FileRef_GetInfoForRenderer with a sequence number for -// invoking the right callback, |fs_type| which indicates the file system, and -// path information in either |file_system_url_spec| (for internal file systems) -// or |external_path| (for external file systems). -// Only sent from the browser to the renderer. -IPC_MESSAGE_ROUTED5(PpapiHostMsg_FileRef_GetInfoForRendererReply, - int32_t /* sequence */, - std::vector<PP_Resource> /* resources */, - std::vector<PP_FileSystemType> /* fs_type */, - std::vector<std::string> /* file_system_url_spec */, - std::vector<base::FilePath> /* external_path */) - // Flash ----------------------------------------------------------------------- IPC_MESSAGE_CONTROL0(PpapiHostMsg_Flash_Create) diff --git a/chromium/ppapi/proxy/ppapi_param_traits.cc b/chromium/ppapi/proxy/ppapi_param_traits.cc index ca25f82f257..5d4345f85aa 100644 --- a/chromium/ppapi/proxy/ppapi_param_traits.cc +++ b/chromium/ppapi/proxy/ppapi_param_traits.cc @@ -175,36 +175,6 @@ void ParamTraits<PP_NetAddress_Private>::Log(const param_type& p, l->append(" bytes)>"); } -// TODO(teravest): Remove this when FileRef is moved to the "new" proxy. -// PPB_FileRef_CreateInfo ------------------------------------------------------ - -// static -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<std::string>::Write(m, p.path); - ParamTraits<std::string>::Write(m, p.name); - ParamTraits<PP_Resource>::Write(m, p.file_system_plugin_resource); -} - -// static -bool ParamTraits<ppapi::PPB_FileRef_CreateInfo>::Read(const Message* m, - PickleIterator* iter, - param_type* r) { - return - ParamTraits<ppapi::HostResource>::Read(m, iter, &r->resource) && - ParamTraits<int>::Read(m, iter, &r->file_system_type) && - ParamTraits<std::string>::Read(m, iter, &r->path) && - ParamTraits<std::string>::Read(m, iter, &r->name) && - ParamTraits<PP_Resource>::Read(m, iter, &r->file_system_plugin_resource); -} - -// static -void ParamTraits<ppapi::PPB_FileRef_CreateInfo>::Log(const param_type& p, - std::string* l) { -} - // HostResource ---------------------------------------------------------------- // static @@ -274,28 +244,6 @@ void ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Log( std::string* l) { } -// std::vector<PPB_FileRef_CreateInfo> ----------------------------------------- - -void ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Write( - Message* m, - const param_type& p) { - WriteVectorWithoutCopy(m, p); -} - -// static -bool ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Read( - const Message* m, - PickleIterator* iter, - param_type* r) { - return ReadVectorWithoutCopy(m, iter, r); -} - -// static -void ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Log( - const param_type& p, - std::string* l) { -} - // ppapi::PpapiPermissions ----------------------------------------------------- void ParamTraits<ppapi::PpapiPermissions>::Write(Message* m, diff --git a/chromium/ppapi/proxy/ppapi_param_traits.h b/chromium/ppapi/proxy/ppapi_param_traits.h index f56415a869f..b56ec3e3d4b 100644 --- a/chromium/ppapi/proxy/ppapi_param_traits.h +++ b/chromium/ppapi/proxy/ppapi_param_traits.h @@ -17,7 +17,6 @@ #include "ppapi/shared_impl/file_path.h" #include "ppapi/shared_impl/file_ref_create_info.h" #include "ppapi/shared_impl/ppapi_permissions.h" -#include "ppapi/shared_impl/ppb_file_ref_shared.h" #include "ppapi/shared_impl/socket_option_data.h" struct PP_FileInfo; @@ -77,15 +76,6 @@ struct PPAPI_PROXY_EXPORT ParamTraits< static void Log(const param_type& p, std::string* l); }; -// TODO(teravest): Remove this when we've switched over to the new proxy. -template<> -struct PPAPI_PROXY_EXPORT 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, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - template<> struct PPAPI_PROXY_EXPORT ParamTraits< ppapi::proxy::PPBURLLoader_UpdateProgress_Params> { @@ -154,15 +144,6 @@ struct PPAPI_PROXY_EXPORT ParamTraits< }; template<> -struct PPAPI_PROXY_EXPORT 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, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template<> struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::PpapiPermissions> { typedef ppapi::PpapiPermissions param_type; static void Write(Message* m, const param_type& p); diff --git a/chromium/ppapi/proxy/ppapi_proxy_test.cc b/chromium/ppapi/proxy/ppapi_proxy_test.cc index 5e4b67bc4f3..87aa22b2860 100644 --- a/chromium/ppapi/proxy/ppapi_proxy_test.cc +++ b/chromium/ppapi/proxy/ppapi_proxy_test.cc @@ -227,8 +227,12 @@ void PluginProxyTestHarness::CreatePluginGlobals() { if (globals_config_ == PER_THREAD_GLOBALS) { plugin_globals_.reset(new PluginGlobals(PpapiGlobals::PerThreadForTest())); PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); + // Enable locking in case some other unit test ran before us and disabled + // locking. + ProxyLock::EnableLockingOnThreadForTest(); } else { plugin_globals_.reset(new PluginGlobals()); + ProxyLock::EnableLockingOnThreadForTest(); } } @@ -471,7 +475,10 @@ void HostProxyTestHarness::CreateHostGlobals() { if (globals_config_ == PER_THREAD_GLOBALS) { host_globals_.reset(new TestGlobals(PpapiGlobals::PerThreadForTest())); PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); + // The host side of the proxy does not lock. + ProxyLock::DisableLockingOnThreadForTest(); } else { + ProxyLock::DisableLockingOnThreadForTest(); host_globals_.reset(new TestGlobals()); } } diff --git a/chromium/ppapi/proxy/ppb_audio_proxy.cc b/chromium/ppapi/proxy/ppb_audio_proxy.cc index aae9a5de198..49ed0afb2d2 100644 --- a/chromium/ppapi/proxy/ppb_audio_proxy.cc +++ b/chromium/ppapi/proxy/ppb_audio_proxy.cc @@ -37,7 +37,7 @@ class Audio : public Resource, public PPB_Audio_Shared { public: Audio(const HostResource& audio_id, PP_Resource config_id, - PPB_Audio_Callback callback, + const AudioCallbackCombined& callback, void* user_data); virtual ~Audio(); @@ -64,7 +64,7 @@ class Audio : public Resource, public PPB_Audio_Shared { Audio::Audio(const HostResource& audio_id, PP_Resource config_id, - PPB_Audio_Callback callback, + const AudioCallbackCombined& callback, void* user_data) : Resource(OBJECT_IS_PROXY, audio_id), config_(config_id) { @@ -138,7 +138,7 @@ PPB_Audio_Proxy::~PPB_Audio_Proxy() { PP_Resource PPB_Audio_Proxy::CreateProxyResource( PP_Instance instance_id, PP_Resource config_id, - PPB_Audio_Callback audio_callback, + const AudioCallbackCombined& audio_callback, void* user_data) { PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); if (!dispatcher) @@ -148,7 +148,7 @@ PP_Resource PPB_Audio_Proxy::CreateProxyResource( if (config.failed()) return 0; - if (!audio_callback) + if (!audio_callback.IsValid()) return 0; HostResource result; @@ -341,6 +341,7 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( enter.resource()->pp_instance(), handle.shmem(), media::PacketSizeInBytes(handle.size()), IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()), + config.object()->GetSampleRate(), config.object()->GetSampleFrameCount()); } } diff --git a/chromium/ppapi/proxy/ppb_audio_proxy.h b/chromium/ppapi/proxy/ppb_audio_proxy.h index fa887de7f1a..cc8af6cb9da 100644 --- a/chromium/ppapi/proxy/ppb_audio_proxy.h +++ b/chromium/ppapi/proxy/ppb_audio_proxy.h @@ -21,6 +21,7 @@ namespace ppapi { +class AudioCallbackCombined; class HostResource; namespace proxy { @@ -33,11 +34,11 @@ class PPB_Audio_Proxy : public InterfaceProxy { virtual ~PPB_Audio_Proxy(); // Creates an Audio object in the plugin process. - static PP_Resource CreateProxyResource(PP_Instance instance_id, - PP_Resource config_id, - PPB_Audio_Callback audio_callback, - void* user_data); - + static PP_Resource CreateProxyResource( + PP_Instance instance_id, + PP_Resource config_id, + const AudioCallbackCombined& audio_callback, + void* user_data); // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); diff --git a/chromium/ppapi/proxy/ppb_file_ref_proxy.cc b/chromium/ppapi/proxy/ppb_file_ref_proxy.cc deleted file mode 100644 index 62c55da9d8b..00000000000 --- a/chromium/ppapi/proxy/ppb_file_ref_proxy.cc +++ /dev/null @@ -1,549 +0,0 @@ -// 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/ppb_file_ref_proxy.h" - -#include <map> - -#include "base/bind.h" -#include "ppapi/c/pp_directory_entry.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/c/ppb_file_ref.h" -#include "ppapi/c/private/ppb_file_ref_private.h" -#include "ppapi/c/private/ppb_proxy_private.h" -#include "ppapi/proxy/enter_proxy.h" -#include "ppapi/proxy/host_dispatcher.h" -#include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/serialized_var.h" -#include "ppapi/shared_impl/array_writer.h" -#include "ppapi/shared_impl/ppb_file_ref_shared.h" -#include "ppapi/shared_impl/scoped_pp_resource.h" -#include "ppapi/shared_impl/tracked_callback.h" -#include "ppapi/thunk/resource_creation_api.h" -#include "ppapi/thunk/thunk.h" - -using ppapi::thunk::EnterResourceNoLock; -using ppapi::thunk::PPB_FileRef_API; -using ppapi::thunk::ResourceCreationAPI; - -namespace ppapi { -namespace proxy { - -namespace { - -void ReleaseEntries(const std::vector<PP_DirectoryEntry>& entries) { - ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); - for (std::vector<PP_DirectoryEntry>::const_iterator it = entries.begin(); - it != entries.end(); ++it) - tracker->ReleaseResource(it->file_ref); -} - -} // namespace - -class FileRef : public PPB_FileRef_Shared { - public: - explicit FileRef(const PPB_FileRef_CreateInfo& info); - virtual ~FileRef(); - - // Resource overrides. - virtual void LastPluginRefWasDeleted() OVERRIDE; - - // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). - virtual PP_Resource GetParent() OVERRIDE; - virtual int32_t MakeDirectory( - PP_Bool make_ancestors, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual int32_t Touch(PP_Time last_access_time, - PP_Time last_modified_time, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual int32_t Rename(PP_Resource new_file_ref, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual int32_t Query(PP_FileInfo* info, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual int32_t ReadDirectoryEntries( - const PP_ArrayOutput& output, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual int32_t QueryInHost( - linked_ptr<PP_FileInfo> info, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual int32_t ReadDirectoryEntriesInHost( - linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, - linked_ptr<std::vector<PP_FileType> > file_types, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual PP_Var GetAbsolutePath() OVERRIDE; - - // Executes the pending callback with the given ID. See pending_callbacks_. - void ExecuteCallback(uint32_t callback_id, int32_t result); - int32_t SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); - int32_t SetReadDirectoryEntriesOutput( - uint32_t callback_id, - const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, - const std::vector<PP_FileType>& file_types); - - private: - PluginDispatcher* GetDispatcher() const { - return PluginDispatcher::GetForResource(this); - } - - // Adds a callback to the list and returns its ID. - uint32_t SendCallback(scoped_refptr<TrackedCallback> callback); - - // This class can have any number of out-standing requests with completion - // callbacks, in contrast to most resources which have one possible pending - // callback pending (like a Flush callback). - // - // To keep track of them, assign integer IDs to the callbacks, which is how - // the callback will be identified when it's passed to the host and then - // back here. Use unsigned so that overflow is well-defined. - uint32_t next_callback_id_; - typedef std::map<uint32_t, - scoped_refptr<TrackedCallback> > PendingCallbackMap; - PendingCallbackMap pending_callbacks_; - - // Used to keep pointers to PP_FileInfo instances that are written before - // callbacks are invoked. The id of a pending file info will match that of - // the corresponding callback. - typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; - PendingFileInfoMap pending_file_infos_; - - // Used to keep PP_ArrayOutput instances that are written before callbacks - // are invoked. The id of a pending array output will match that of the - // corresponding callback. - typedef std::map<uint32_t, PP_ArrayOutput> - PendingReadDirectoryEntriesOutputMap; - PendingReadDirectoryEntriesOutputMap pending_read_entries_outputs_; - - // Holds a reference on plugin side when running out of process, so that - // FileSystem won't die before FileRef. See PPB_FileRef_Impl for - // corresponding code for in-process mode. Note that this workaround will - // be no longer needed after FileRef refactoring. - ScopedPPResource file_system_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); -}; - -FileRef::FileRef(const PPB_FileRef_CreateInfo& info) - : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), - next_callback_id_(0u), - file_system_(info.file_system_plugin_resource) { -} - -FileRef::~FileRef() { - // The callbacks map should have been cleared by LastPluginRefWasDeleted. - DCHECK(pending_callbacks_.empty()); - DCHECK(pending_file_infos_.empty()); - DCHECK(pending_read_entries_outputs_.empty()); -} - -void FileRef::LastPluginRefWasDeleted() { - // The callback tracker will abort our callbacks for us. - pending_callbacks_.clear(); - pending_file_infos_.clear(); - pending_read_entries_outputs_.clear(); -} - -PP_Resource FileRef::GetParent() { - PPB_FileRef_CreateInfo create_info; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( - API_ID_PPB_FILE_REF, host_resource(), &create_info)); - return PPB_FileRef_Proxy::DeserializeFileRef(create_info); -} - -int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, - scoped_refptr<TrackedCallback> callback) { - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_MakeDirectory( - API_ID_PPB_FILE_REF, host_resource(), make_ancestors, - SendCallback(callback))); - return PP_OK_COMPLETIONPENDING; -} - -int32_t FileRef::Touch(PP_Time last_access_time, - PP_Time last_modified_time, - scoped_refptr<TrackedCallback> callback) { - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Touch( - API_ID_PPB_FILE_REF, host_resource(), last_access_time, - last_modified_time, SendCallback(callback))); - return PP_OK_COMPLETIONPENDING; -} - -int32_t FileRef::Delete(scoped_refptr<TrackedCallback> callback) { - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Delete( - API_ID_PPB_FILE_REF, host_resource(), SendCallback(callback))); - return PP_OK_COMPLETIONPENDING; -} - -int32_t FileRef::Rename(PP_Resource new_file_ref, - scoped_refptr<TrackedCallback> callback) { - Resource* new_file_ref_object = - PpapiGlobals::Get()->GetResourceTracker()->GetResource(new_file_ref); - if (!new_file_ref_object || - new_file_ref_object->host_resource().instance() != pp_instance()) - return PP_ERROR_BADRESOURCE; - - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename( - API_ID_PPB_FILE_REF, host_resource(), - new_file_ref_object->host_resource(), SendCallback(callback))); - return PP_OK_COMPLETIONPENDING; -} - -int32_t FileRef::Query(PP_FileInfo* info, - scoped_refptr<TrackedCallback> callback) { - // Store the pending file info id. - uint32_t id = SendCallback(callback); - pending_file_infos_[id] = info; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( - API_ID_PPB_FILE_REF, host_resource(), id)); - return PP_OK_COMPLETIONPENDING; -} - -int32_t FileRef::ReadDirectoryEntries( - const PP_ArrayOutput& output, - scoped_refptr<TrackedCallback> callback) { - // Store the pending read entries output id. - uint32_t id = SendCallback(callback); - pending_read_entries_outputs_[id] = output; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_ReadDirectoryEntries( - API_ID_PPB_FILE_REF, host_resource(), id)); - return PP_OK_COMPLETIONPENDING; -} - -int32_t FileRef::QueryInHost( - linked_ptr<PP_FileInfo> info, - scoped_refptr<TrackedCallback> callback) { - NOTREACHED(); - return PP_ERROR_FAILED; -} - -int32_t FileRef::ReadDirectoryEntriesInHost( - linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, - linked_ptr<std::vector<PP_FileType> > file_types, - scoped_refptr<TrackedCallback> callback) { - NOTREACHED(); - return PP_ERROR_FAILED; -} - -PP_Var FileRef::GetAbsolutePath() { - ReceiveSerializedVarReturnValue result; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( - API_ID_PPB_FILE_REF, host_resource(), &result)); - return result.Return(GetDispatcher()); -} - -void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) { - PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); - if (found == pending_callbacks_.end()) { - // This will happen when the plugin deletes its resource with a pending - // callback. The callback will be locally issued with an ABORTED call while - // the operation may still be pending in the renderer. - return; - } - - // Executing the callback may mutate the callback list. - scoped_refptr<TrackedCallback> callback = found->second; - pending_callbacks_.erase(found); - callback->Run(result); -} - -int32_t FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { - PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); - if (found == pending_file_infos_.end()) - return PP_ERROR_FAILED; - PP_FileInfo* target_info = found->second; - *target_info = info; - pending_file_infos_.erase(found); - return PP_OK; -} - -int32_t FileRef::SetReadDirectoryEntriesOutput( - uint32_t callback_id, - const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, - const std::vector<PP_FileType>& file_types) { - PendingReadDirectoryEntriesOutputMap::iterator found = - pending_read_entries_outputs_.find(callback_id); - if (found == pending_read_entries_outputs_.end()) - return PP_ERROR_FAILED; - - PP_ArrayOutput output = found->second; - pending_read_entries_outputs_.erase(found); - - std::vector<PP_DirectoryEntry> entries; - for (size_t i = 0; i < infos.size(); ++i) { - PP_DirectoryEntry entry; - entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]); - entry.file_type = file_types[i]; - entries.push_back(entry); - } - - ArrayWriter writer(output); - if (!writer.is_valid()) { - ReleaseEntries(entries); - return PP_ERROR_BADARGUMENT; - } - - writer.StoreVector(entries); - return PP_OK; -} - -uint32_t FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) { - // In extreme cases the IDs may wrap around, so avoid duplicates. - while (pending_callbacks_.count(next_callback_id_)) - ++next_callback_id_; - - pending_callbacks_[next_callback_id_] = callback; - return next_callback_id_++; -} - -PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - callback_factory_(this) { -} - -PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { -} - -// static -PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Instance instance, - PP_Resource file_system, - const char* path) { - PPB_FileRef_CreateInfo create_info; - PluginDispatcher::GetForInstance(instance)->Send( - new PpapiHostMsg_PPBFileRef_Create( - API_ID_PPB_FILE_REF, instance, file_system, path, &create_info)); - return PPB_FileRef_Proxy::DeserializeFileRef(create_info); -} - -bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg) -#if !defined(OS_NACL) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory, - OnMsgMakeDirectory) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Touch, OnMsgTouch) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Delete, OnMsgDelete) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Rename, OnMsgRename) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Query, OnMsgQuery) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_ReadDirectoryEntries, - OnMsgReadDirectoryEntries) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath, - OnMsgGetAbsolutePath) -#endif // !defined(OS_NACL) - - IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete, - OnMsgCallbackComplete) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete, - OnMsgQueryCallbackComplete) - IPC_MESSAGE_HANDLER( - PpapiMsg_PPBFileRef_ReadDirectoryEntriesCallbackComplete, - OnMsgReadDirectoryEntriesCallbackComplete) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -// static -void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, - PPB_FileRef_CreateInfo* result) { - EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false); - if (enter.succeeded()) - *result = enter.object()->GetCreateInfo(); -} - -// static -PP_Resource PPB_FileRef_Proxy::DeserializeFileRef( - const PPB_FileRef_CreateInfo& serialized) { - if (serialized.resource.is_null()) - return 0; // Resource invalid. - return (new FileRef(serialized))->GetReference(); -} - -#if !defined(OS_NACL) -void PPB_FileRef_Proxy::OnMsgCreate(PP_Instance pp_instance, - PP_Resource file_system, - const std::string& path, - PPB_FileRef_CreateInfo* result) { - thunk::EnterResourceCreation enter(pp_instance); - if (enter.failed()) - return; - - PP_Resource resource = enter.functions()->CreateFileRef( - pp_instance, file_system, path.c_str()); - if (!resource) - return; // CreateInfo default constructor initializes to 0. - SerializeFileRef(resource, result); -} - -void PPB_FileRef_Proxy::OnMsgGetParent(const HostResource& host_resource, - PPB_FileRef_CreateInfo* result) { - EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); - if (enter.succeeded()) - SerializeFileRef(enter.object()->GetParent(), result); -} - -void PPB_FileRef_Proxy::OnMsgMakeDirectory(const HostResource& host_resource, - PP_Bool make_ancestors, - uint32_t callback_id) { - EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( - host_resource, callback_factory_, - &PPB_FileRef_Proxy::OnCallbackCompleteInHost, host_resource, callback_id); - if (enter.succeeded()) { - enter.SetResult(enter.object()->MakeDirectory(make_ancestors, - enter.callback())); - } -} - -void PPB_FileRef_Proxy::OnMsgTouch(const HostResource& host_resource, - PP_Time last_access, - PP_Time last_modified, - uint32_t callback_id) { - EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( - host_resource, callback_factory_, - &PPB_FileRef_Proxy::OnCallbackCompleteInHost, host_resource, callback_id); - if (enter.succeeded()) { - enter.SetResult(enter.object()->Touch(last_access, last_modified, - enter.callback())); - } -} - -void PPB_FileRef_Proxy::OnMsgDelete(const HostResource& host_resource, - uint32_t callback_id) { - EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( - host_resource, callback_factory_, - &PPB_FileRef_Proxy::OnCallbackCompleteInHost, host_resource, callback_id); - if (enter.succeeded()) - enter.SetResult(enter.object()->Delete(enter.callback())); -} - -void PPB_FileRef_Proxy::OnMsgRename(const HostResource& file_ref, - const HostResource& new_file_ref, - uint32_t callback_id) { - EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( - file_ref, callback_factory_, - &PPB_FileRef_Proxy::OnCallbackCompleteInHost, file_ref, callback_id); - if (enter.succeeded()) { - enter.SetResult(enter.object()->Rename(new_file_ref.host_resource(), - enter.callback())); - } -} - -void PPB_FileRef_Proxy::OnMsgQuery(const HostResource& file_ref, - uint32_t callback_id) { - linked_ptr<PP_FileInfo> info(new PP_FileInfo()); - EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( - file_ref, callback_factory_, - &PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost, file_ref, - info, callback_id); - if (enter.succeeded()) - enter.SetResult(enter.object()->QueryInHost(info, enter.callback())); -} - -void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource, - SerializedVarReturnValue result) { - EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); - if (enter.succeeded()) - result.Return(dispatcher(), enter.object()->GetAbsolutePath()); -} - -void PPB_FileRef_Proxy::OnMsgReadDirectoryEntries(const HostResource& file_ref, - uint32_t callback_id) { - linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files( - new std::vector<ppapi::PPB_FileRef_CreateInfo>()); - linked_ptr<std::vector<PP_FileType> > file_types( - new std::vector<PP_FileType>()); - HostCallbackParams params(file_ref, callback_id); - EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( - file_ref, callback_factory_, - &PPB_FileRef_Proxy::OnReadDirectoryEntriesCallbackCompleteInHost, - params, files, file_types); - if (enter.succeeded()) { - enter.SetResult(enter.object()->ReadDirectoryEntriesInHost( - files, file_types, enter.callback())); - } -} - -#endif // !defined(OS_NACL) - -void PPB_FileRef_Proxy::OnMsgCallbackComplete( - const HostResource& host_resource, - uint32_t callback_id, - int32_t result) { - // Forward the callback info to the plugin resource. - EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); - if (enter.succeeded()) - static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); -} - -void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( - const HostResource& host_resource, - const PP_FileInfo& info, - uint32_t callback_id, - int32_t result) { - EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); - if (!enter.succeeded()) - return; - - if (result == PP_OK) { - result = static_cast<FileRef*>(enter.object())->SetFileInfo( - callback_id, info); - } - static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); -} - -void PPB_FileRef_Proxy::OnMsgReadDirectoryEntriesCallbackComplete( - const HostResource& host_resource, - const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, - const std::vector<PP_FileType>& file_types, - uint32_t callback_id, - int32_t result) { - CHECK_EQ(infos.size(), file_types.size()); - - EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); - if (!enter.succeeded()) - return; - - if (result == PP_OK) { - result = - static_cast<FileRef*>(enter.object())->SetReadDirectoryEntriesOutput( - callback_id, infos, file_types); - } - static_cast<FileRef*>(enter.object())->ExecuteCallback( - callback_id, result); -} - -#if !defined(OS_NACL) -void PPB_FileRef_Proxy::OnCallbackCompleteInHost( - int32_t result, - const HostResource& host_resource, - uint32_t callback_id) { - // Execute OnMsgCallbackComplete in the plugin process. - Send(new PpapiMsg_PPBFileRef_CallbackComplete( - API_ID_PPB_FILE_REF, host_resource, callback_id, result)); -} - -void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( - int32_t result, - const HostResource& host_resource, - linked_ptr<PP_FileInfo> info, - uint32_t callback_id) { - Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( - API_ID_PPB_FILE_REF, host_resource, *info, callback_id, result)); -} - -void PPB_FileRef_Proxy::OnReadDirectoryEntriesCallbackCompleteInHost( - int32_t result, - HostCallbackParams params, - linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, - linked_ptr<std::vector<PP_FileType> > file_types) { - Send(new PpapiMsg_PPBFileRef_ReadDirectoryEntriesCallbackComplete( - API_ID_PPB_FILE_REF, params.host_resource, - *files, *file_types, params.callback_id, result)); -} - -#endif // !defined(OS_NACL) - -} // namespace proxy -} // namespace ppapi diff --git a/chromium/ppapi/proxy/ppb_file_ref_proxy.h b/chromium/ppapi/proxy/ppb_file_ref_proxy.h deleted file mode 100644 index cbfadb5b5f4..00000000000 --- a/chromium/ppapi/proxy/ppb_file_ref_proxy.h +++ /dev/null @@ -1,138 +0,0 @@ -// 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_PROXY_PPB_FILE_REF_PROXY_H_ -#define PPAPI_PROXY_PPB_FILE_REF_PROXY_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/memory/linked_ptr.h" -#include "ppapi/c/pp_file_info.h" -#include "ppapi/c/pp_module.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/c/pp_time.h" -#include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/ppapi_proxy_export.h" -#include "ppapi/proxy/proxy_completion_callback_factory.h" -#include "ppapi/shared_impl/host_resource.h" -#include "ppapi/utility/completion_callback_factory.h" - -namespace ppapi { - -struct PPB_FileRef_CreateInfo; - -namespace proxy { - -class SerializedVarReturnValue; - -class PPAPI_PROXY_EXPORT PPB_FileRef_Proxy - : public NON_EXPORTED_BASE(InterfaceProxy) { - public: - explicit PPB_FileRef_Proxy(Dispatcher* dispatcher); - virtual ~PPB_FileRef_Proxy(); - - static PP_Resource CreateProxyResource(PP_Instance instance, - PP_Resource file_system, - const char* path); - static PP_Resource CreateProxyResource( - const PPB_FileRef_CreateInfo& serialized); - - // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); - - // Takes a resource in the host and converts it into a serialized file ref - // "create info" for reconstitution in the plugin. This struct contains all - // the necessary information about the file ref. - // - // Various PPAPI functions return file refs from various interfaces, so this - // function is public so anybody can send a file ref. - static void SerializeFileRef(PP_Resource file_ref, - 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. - // This represents passing the resource ownership to the plugin. This - // function also checks the validity of the result and returns 0 on failure. - // - // 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 PPB_FileRef_CreateInfo& serialized); - - static const ApiID kApiID = API_ID_PPB_FILE_REF; - - private: - // Plugin -> host message handlers. - void OnMsgCreate(PP_Instance instance, - PP_Resource file_system, - const std::string& path, - PPB_FileRef_CreateInfo* result); - void OnMsgGetParent(const HostResource& host_resource, - PPB_FileRef_CreateInfo* result); - void OnMsgMakeDirectory(const HostResource& host_resource, - PP_Bool make_ancestors, - uint32_t callback_id); - void OnMsgTouch(const HostResource& host_resource, - PP_Time last_access, - PP_Time last_modified, - uint32_t callback_id); - void OnMsgDelete(const HostResource& host_resource, - uint32_t callback_id); - void OnMsgRename(const HostResource& file_ref, - const HostResource& new_file_ref, - uint32_t callback_id); - void OnMsgQuery(const HostResource& file_ref, - uint32_t callback_id); - void OnMsgGetAbsolutePath(const HostResource& host_resource, - SerializedVarReturnValue result); - void OnMsgReadDirectoryEntries(const HostResource& file_ref, - uint32_t callback_id); - - // Host -> Plugin message handlers. - void OnMsgCallbackComplete(const HostResource& host_resource, - uint32_t callback_id, - int32_t result); - void OnMsgQueryCallbackComplete(const HostResource& host_resource, - const PP_FileInfo& info, - uint32_t callback_id, - int32_t result); - void OnMsgReadDirectoryEntriesCallbackComplete( - const HostResource& host_resource, - const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, - const std::vector<PP_FileType>& file_types, - uint32_t callback_id, - int32_t result); - - struct HostCallbackParams { - HostCallbackParams(const HostResource& host_res, uint32_t cb_id) - : host_resource(host_res), callback_id(cb_id) { - } - HostResource host_resource; - uint32_t callback_id; - }; - - void OnCallbackCompleteInHost(int32_t result, - const HostResource& host_resource, - uint32_t callback_id); - void OnQueryCallbackCompleteInHost( - int32_t result, - const HostResource& host_resource, - linked_ptr<PP_FileInfo> info, - uint32_t callback_id); - void OnReadDirectoryEntriesCallbackCompleteInHost( - int32_t result, - HostCallbackParams params, - linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, - linked_ptr<std::vector<PP_FileType> > file_types); - - ProxyCompletionCallbackFactory<PPB_FileRef_Proxy> callback_factory_; - - DISALLOW_COPY_AND_ASSIGN(PPB_FileRef_Proxy); -}; - -} // namespace proxy -} // namespace ppapi - -#endif // PPAPI_PROXY_PPB_FILE_REF_PROXY_H_ diff --git a/chromium/ppapi/proxy/ppb_graphics_3d_proxy.cc b/chromium/ppapi/proxy/ppb_graphics_3d_proxy.cc index 7d18850ea3c..5fb1d1098c8 100644 --- a/chromium/ppapi/proxy/ppb_graphics_3d_proxy.cc +++ b/chromium/ppapi/proxy/ppb_graphics_3d_proxy.cc @@ -62,7 +62,9 @@ gpu::CommandBuffer::State GetErrorState() { // Graphics3D context; this isn't allowed, and will likely either crash or // result in undefined behavior. It is assumed that the thread which creates // the Graphics3D context will be the thread on which subsequent gl rendering -// will be done. +// will be done. This is why it is okay to read need_to_lock_ without the lock; +// it should only ever be read and written on the same thread where the context +// was created. // // TODO(nfullagar): At some point, allow multiple threads to concurrently render // each to its own context. First step is to allow a single thread (either main @@ -258,6 +260,10 @@ int32 Graphics3D::DoSwapBuffers() { void Graphics3D::PushAlreadyLocked() { ppapi::ProxyLock::AssertAcquired(); + if (!locking_command_buffer_) { + NOTREACHED(); + return; + } if (num_already_locked_calls_ == 0) locking_command_buffer_->set_need_to_lock(false); ++num_already_locked_calls_; @@ -268,6 +274,10 @@ void Graphics3D::PopAlreadyLocked() { DCHECK(!locking_command_buffer_->need_to_lock()); DCHECK_GT(num_already_locked_calls_, 0); ppapi::ProxyLock::AssertAcquired(); + if (!locking_command_buffer_) { + NOTREACHED(); + return; + } --num_already_locked_calls_; if (num_already_locked_calls_ == 0) locking_command_buffer_->set_need_to_lock(true); diff --git a/chromium/ppapi/proxy/ppb_instance_proxy.cc b/chromium/ppapi/proxy/ppb_instance_proxy.cc index 20b93649ece..fdaa8c47d25 100644 --- a/chromium/ppapi/proxy/ppb_instance_proxy.cc +++ b/chromium/ppapi/proxy/ppb_instance_proxy.cc @@ -173,8 +173,8 @@ bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { OnHostMsgDocumentCanAccessDocument) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL, OnHostMsgGetPluginInstanceURL) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_NeedKey, - OnHostMsgNeedKey) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginReferrerURL, + OnHostMsgGetPluginReferrerURL) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_KeyAdded, OnHostMsgKeyAdded) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_KeyMessage, @@ -526,17 +526,15 @@ PP_Var PPB_Instance_Proxy::GetPluginInstanceURL( components); } -void PPB_Instance_Proxy::NeedKey(PP_Instance instance, - PP_Var key_system, - PP_Var session_id, - PP_Var init_data) { - dispatcher()->Send( - new PpapiHostMsg_PPBInstance_NeedKey( - API_ID_PPB_INSTANCE, - instance, - SerializedVarSendInput(dispatcher(), key_system), - SerializedVarSendInput(dispatcher(), session_id), - SerializedVarSendInput(dispatcher(), init_data))); +PP_Var PPB_Instance_Proxy::GetPluginReferrerURL( + PP_Instance instance, + PP_URLComponents_Dev* components) { + ReceiveSerializedVarReturnValue result; + dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginReferrerURL( + API_ID_PPB_INSTANCE, instance, &result)); + return PPB_URLUtil_Shared::ConvertComponentsAndReturnURL( + result.Return(dispatcher()), + components); } void PPB_Instance_Proxy::KeyAdded(PP_Instance instance, @@ -1032,18 +1030,15 @@ void PPB_Instance_Proxy::OnHostMsgGetPluginInstanceURL( } } -void PPB_Instance_Proxy::OnHostMsgNeedKey(PP_Instance instance, - SerializedVarReceiveInput key_system, - SerializedVarReceiveInput session_id, - SerializedVarReceiveInput init_data) { - if (!dispatcher()->permissions().HasPermission(PERMISSION_PRIVATE)) +void PPB_Instance_Proxy::OnHostMsgGetPluginReferrerURL( + PP_Instance instance, + SerializedVarReturnValue result) { + if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV)) return; EnterInstanceNoLock enter(instance); if (enter.succeeded()) { - enter.functions()->NeedKey(instance, - key_system.Get(dispatcher()), - session_id.Get(dispatcher()), - init_data.Get(dispatcher())); + result.Return(dispatcher(), + enter.functions()->GetPluginReferrerURL(instance, NULL)); } } diff --git a/chromium/ppapi/proxy/ppb_instance_proxy.h b/chromium/ppapi/proxy/ppb_instance_proxy.h index 6df4f8d9eab..a6516bc1754 100644 --- a/chromium/ppapi/proxy/ppb_instance_proxy.h +++ b/chromium/ppapi/proxy/ppb_instance_proxy.h @@ -114,10 +114,9 @@ class PPB_Instance_Proxy : public InterfaceProxy, virtual PP_Var GetPluginInstanceURL( PP_Instance instance, PP_URLComponents_Dev* components) OVERRIDE; - virtual void NeedKey(PP_Instance instance, - PP_Var key_system, - PP_Var session_id, - PP_Var init_data) OVERRIDE; + virtual PP_Var GetPluginReferrerURL( + PP_Instance instance, + PP_URLComponents_Dev* components) OVERRIDE; virtual void KeyAdded(PP_Instance instance, PP_Var key_system, PP_Var session_id) OVERRIDE; @@ -218,10 +217,8 @@ class PPB_Instance_Proxy : public InterfaceProxy, PP_Bool* result); void OnHostMsgGetPluginInstanceURL(PP_Instance instance, SerializedVarReturnValue result); - virtual void OnHostMsgNeedKey(PP_Instance instance, - SerializedVarReceiveInput key_system, - SerializedVarReceiveInput session_id, - SerializedVarReceiveInput init_data); + void OnHostMsgGetPluginReferrerURL(PP_Instance instance, + SerializedVarReturnValue result); virtual void OnHostMsgKeyAdded(PP_Instance instance, SerializedVarReceiveInput key_system, SerializedVarReceiveInput session_id); diff --git a/chromium/ppapi/proxy/ppb_network_monitor_private_proxy.cc b/chromium/ppapi/proxy/ppb_network_monitor_private_proxy.cc deleted file mode 100644 index 055ed2e3a7b..00000000000 --- a/chromium/ppapi/proxy/ppb_network_monitor_private_proxy.cc +++ /dev/null @@ -1,156 +0,0 @@ -// 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/ppb_network_monitor_private_proxy.h" - -#include "ppapi/proxy/enter_proxy.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/proxy_lock.h" -#include "ppapi/thunk/ppb_network_monitor_private_api.h" - -namespace ppapi { -namespace proxy { - -class PPB_NetworkMonitor_Private_Proxy::NetworkMonitor - : public Resource, - public thunk::PPB_NetworkMonitor_Private_API, - public base::SupportsWeakPtr< - PPB_NetworkMonitor_Private_Proxy::NetworkMonitor> { - public: - NetworkMonitor(PP_Instance instance, - PPB_NetworkMonitor_Private_Proxy* proxy, - PPB_NetworkMonitor_Callback callback, - void* user_data) - : Resource(OBJECT_IS_PROXY, instance), - proxy_(proxy), - callback_(callback), - user_data_(user_data) { - } - - virtual ~NetworkMonitor() { - proxy_->OnNetworkMonitorDeleted(this, pp_instance()); - } - - - // Resource overrides. - virtual ppapi::thunk::PPB_NetworkMonitor_Private_API* - AsPPB_NetworkMonitor_Private_API() OVERRIDE { - return this; - } - - // This is invoked when a network list is received for this monitor (either - // initially or on a change). It acquires the ProxyLock inside because - // ObserverListThreadSafe does not support Bind/Closure, otherwise we would - // wrap the call with a lock using RunWhileLocked. - void OnNetworkListReceivedLocks( - const scoped_refptr<NetworkListStorage>& list) { - ProxyAutoLock lock; - PP_Resource list_resource = - PPB_NetworkList_Private_Shared::Create( - OBJECT_IS_PROXY, pp_instance(), list); - CallWhileUnlocked(callback_, user_data_, list_resource); - } - - private: - PPB_NetworkMonitor_Private_Proxy* proxy_; - PPB_NetworkMonitor_Callback callback_; - void* user_data_; - - DISALLOW_COPY_AND_ASSIGN(NetworkMonitor); -}; - -PPB_NetworkMonitor_Private_Proxy::PPB_NetworkMonitor_Private_Proxy( - Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - monitors_(new ObserverListThreadSafe<NetworkMonitor>()), - monitors_count_(0) { -} - -PPB_NetworkMonitor_Private_Proxy::~PPB_NetworkMonitor_Private_Proxy() { - monitors_->AssertEmpty(); -} - -// static -PP_Resource PPB_NetworkMonitor_Private_Proxy::CreateProxyResource( - PP_Instance instance, - PPB_NetworkMonitor_Callback callback, - void* user_data) { - // TODO(dmichael): Check that this thread has a valid message loop associated - // with it. - if (!callback) - return 0; - - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return 0; - PPB_NetworkMonitor_Private_Proxy* proxy = - static_cast<PPB_NetworkMonitor_Private_Proxy*>( - dispatcher->GetInterfaceProxy(kApiID)); - if (!proxy) - return 0; - - scoped_refptr<NetworkMonitor> result( - new NetworkMonitor(instance, proxy, callback, user_data)); - proxy->monitors_->AddObserver(result.get()); - - proxy->monitors_count_++; - if (proxy->monitors_count_ == 1) { - // If that is the first network monitor then send Start message. - PluginGlobals::Get()->GetBrowserSender()->Send( - new PpapiHostMsg_PPBNetworkMonitor_Start( - dispatcher->plugin_dispatcher_id())); - - // We could have received network list message after sending the - // previous Stop message. This list is stale now, so reset it - // here. - proxy->current_list_ = NULL; - } else if (proxy->current_list_.get()) { - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&NetworkMonitor::OnNetworkListReceivedLocks, - result->AsWeakPtr(), - proxy->current_list_)); - } - - return result->GetReference(); -} - -bool PPB_NetworkMonitor_Private_Proxy::OnMessageReceived( - const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PPB_NetworkMonitor_Private_Proxy, msg) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBNetworkMonitor_NetworkList, - OnPluginMsgNetworkList) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void PPB_NetworkMonitor_Private_Proxy::OnPluginMsgNetworkList( - uint32 plugin_dispatcher_id, - const ppapi::NetworkList& list) { - scoped_refptr<NetworkListStorage> list_storage(new NetworkListStorage(list)); - current_list_ = list_storage; - monitors_->Notify(&NetworkMonitor::OnNetworkListReceivedLocks, list_storage); -} - -void PPB_NetworkMonitor_Private_Proxy::OnNetworkMonitorDeleted( - NetworkMonitor* monitor, - PP_Instance instance) { - monitors_->RemoveObserver(monitor); - monitors_count_--; - if (monitors_count_ == 0) { - // Send Stop message if that was the last NetworkMonitor. - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (dispatcher) { - PluginGlobals::Get()->GetBrowserSender()->Send( - new PpapiHostMsg_PPBNetworkMonitor_Stop( - dispatcher->plugin_dispatcher_id())); - } - current_list_ = NULL; - } -} - -} // namespace proxy -} // namespace ppapi diff --git a/chromium/ppapi/proxy/ppb_network_monitor_private_proxy.h b/chromium/ppapi/proxy/ppb_network_monitor_private_proxy.h deleted file mode 100644 index e764b0cb34f..00000000000 --- a/chromium/ppapi/proxy/ppb_network_monitor_private_proxy.h +++ /dev/null @@ -1,63 +0,0 @@ -// 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. - -#ifndef PPAPI_PROXY_PPB_NETWORK_MONITOR_PRIVATE_PROXY_H_ -#define PPAPI_PROXY_PPB_NETWORK_MONITOR_PRIVATE_PROXY_H_ - -#include <list> - -#include "base/observer_list_threadsafe.h" -#include "ppapi/proxy/interface_proxy.h" -#include "ppapi/shared_impl/ppb_network_list_private_shared.h" -#include "ppapi/shared_impl/scoped_pp_resource.h" -#include "ppapi/thunk/ppb_network_monitor_private_api.h" - -namespace base { -class MessageLoopProxy; -} // namespace base - -namespace ppapi { -namespace proxy { - -class PPB_NetworkMonitor_Private_Proxy : public InterfaceProxy { - public: - explicit PPB_NetworkMonitor_Private_Proxy(Dispatcher* dispatcher); - virtual ~PPB_NetworkMonitor_Private_Proxy(); - - // Creates n NetworkManager object in the plugin process. - static PP_Resource CreateProxyResource(PP_Instance instance, - PPB_NetworkMonitor_Callback callback, - void* user_data); - - // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); - - static const ApiID kApiID = API_ID_PPB_NETWORKMANAGER_PRIVATE; - - private: - class NetworkMonitor; - friend class NetworkMonitor; - - // IPC message handler for the messages received from the browser. - void OnPluginMsgNetworkList(uint32 plugin_dispatcher_id, - const ppapi::NetworkList& list); - - // Called by NetworkMonitor destructor. - void OnNetworkMonitorDeleted(NetworkMonitor* monitor, - PP_Instance instance); - - // We use ObserverListThreadSafe because we want to send notifications to the - // same thread that created the NetworkMonitor. - scoped_refptr<ObserverListThreadSafe<NetworkMonitor> > monitors_; - - int monitors_count_; - scoped_refptr<NetworkListStorage> current_list_; - - DISALLOW_COPY_AND_ASSIGN(PPB_NetworkMonitor_Private_Proxy); -}; - -} // namespace proxy -} // namespace ppapi - -#endif // PPAPI_PROXY_PPB_NETWORK_MONITOR_PRIVATE_PROXY_H_ diff --git a/chromium/ppapi/proxy/ppb_tcp_socket_private_proxy.cc b/chromium/ppapi/proxy/ppb_tcp_socket_private_proxy.cc deleted file mode 100644 index 58199fd140e..00000000000 --- a/chromium/ppapi/proxy/ppb_tcp_socket_private_proxy.cc +++ /dev/null @@ -1,263 +0,0 @@ -// 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/ppb_tcp_socket_private_proxy.h" - -#include <map> - -#include "base/logging.h" -#include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_globals.h" -#include "ppapi/proxy/plugin_resource_tracker.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" -#include "ppapi/shared_impl/private/tcp_socket_private_impl.h" -#include "ppapi/shared_impl/resource.h" -#include "ppapi/shared_impl/socket_option_data.h" -#include "ppapi/thunk/thunk.h" - -namespace ppapi { -namespace proxy { - -namespace { - -typedef std::map<uint32, TCPSocketPrivateImpl*> IDToSocketMap; -IDToSocketMap* g_id_to_socket = NULL; - -class TCPSocket : public TCPSocketPrivateImpl { - public: - // C-tor for new sockets. - TCPSocket(const HostResource& resource, uint32 socket_id); - // C-tor for already connected sockets. - TCPSocket(const HostResource& resource, - uint32 socket_id, - const PP_NetAddress_Private& local_addr, - const PP_NetAddress_Private& remote_addr); - virtual ~TCPSocket(); - - virtual void SendConnect(const std::string& host, uint16_t port) OVERRIDE; - virtual void SendConnectWithNetAddress( - const PP_NetAddress_Private& addr) OVERRIDE; - virtual void SendSSLHandshake( - const std::string& server_name, - uint16_t server_port, - const std::vector<std::vector<char> >& trusted_certs, - const std::vector<std::vector<char> >& untrusted_certs) OVERRIDE; - virtual void SendRead(int32_t bytes_to_read) OVERRIDE; - virtual void SendWrite(const std::string& buffer) OVERRIDE; - virtual void SendDisconnect() OVERRIDE; - virtual void SendSetOption(PP_TCPSocket_Option name, - const SocketOptionData& value) OVERRIDE; - - private: - void SendToBrowser(IPC::Message* msg); - - DISALLOW_COPY_AND_ASSIGN(TCPSocket); -}; - -TCPSocket::TCPSocket(const HostResource& resource, uint32 socket_id) - : TCPSocketPrivateImpl(resource, socket_id) { - if (!g_id_to_socket) - g_id_to_socket = new IDToSocketMap(); - DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end()); - (*g_id_to_socket)[socket_id] = this; -} - -TCPSocket::TCPSocket(const HostResource& resource, - uint32 socket_id, - const PP_NetAddress_Private& local_addr, - const PP_NetAddress_Private& remote_addr) - : TCPSocketPrivateImpl(resource, socket_id) { - if (!g_id_to_socket) - g_id_to_socket = new IDToSocketMap(); - DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end()); - - connection_state_ = CONNECTED; - local_addr_ = local_addr; - remote_addr_ = remote_addr; - - (*g_id_to_socket)[socket_id] = this; -} - -TCPSocket::~TCPSocket() { - Disconnect(); -} - -void TCPSocket::SendConnect(const std::string& host, uint16_t port) { - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_Connect( - API_ID_PPB_TCPSOCKET_PRIVATE, socket_id_, host, port)); -} - -void TCPSocket::SendConnectWithNetAddress(const PP_NetAddress_Private& addr) { - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress( - API_ID_PPB_TCPSOCKET_PRIVATE, socket_id_, addr)); -} - -void TCPSocket::SendSSLHandshake( - const std::string& server_name, - uint16_t server_port, - const std::vector<std::vector<char> >& trusted_certs, - const std::vector<std::vector<char> >& untrusted_certs) { - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_SSLHandshake( - socket_id_, server_name, server_port, trusted_certs, untrusted_certs)); -} - -void TCPSocket::SendRead(int32_t bytes_to_read) { - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_Read(socket_id_, bytes_to_read)); -} - -void TCPSocket::SendWrite(const std::string& buffer) { - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_Write(socket_id_, buffer)); -} - -void TCPSocket::SendDisconnect() { - // After removed from the mapping, this object won't receive any notifications - // from the proxy. - DCHECK(g_id_to_socket->find(socket_id_) != g_id_to_socket->end()); - g_id_to_socket->erase(socket_id_); - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id_)); -} - -void TCPSocket::SendSetOption(PP_TCPSocket_Option name, - const SocketOptionData& value) { - SendToBrowser( - new PpapiHostMsg_PPBTCPSocket_SetOption(socket_id_, name, value)); -} - -void TCPSocket::SendToBrowser(IPC::Message* msg) { - PluginGlobals::Get()->GetBrowserSender()->Send(msg); -} - -} // namespace - -//------------------------------------------------------------------------------ - -PPB_TCPSocket_Private_Proxy::PPB_TCPSocket_Private_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { -} - -PPB_TCPSocket_Private_Proxy::~PPB_TCPSocket_Private_Proxy() { -} - -// static -PP_Resource PPB_TCPSocket_Private_Proxy::CreateProxyResource( - PP_Instance instance) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return 0; - - uint32 socket_id = 0; - PluginGlobals::Get()->GetBrowserSender()->Send( - new PpapiHostMsg_PPBTCPSocket_CreatePrivate( - API_ID_PPB_TCPSOCKET_PRIVATE, dispatcher->plugin_dispatcher_id(), - &socket_id)); - if (socket_id == 0) - return 0; - return (new TCPSocket(HostResource::MakeInstanceOnly(instance), - socket_id))->GetReference(); -} - -// static -PP_Resource PPB_TCPSocket_Private_Proxy::CreateProxyResourceForConnectedSocket( - PP_Instance instance, - uint32 socket_id, - const PP_NetAddress_Private& local_addr, - const PP_NetAddress_Private& remote_addr) { - return (new TCPSocket(HostResource::MakeInstanceOnly(instance), - socket_id, - local_addr, - remote_addr))->GetReference(); -} - -bool PPB_TCPSocket_Private_Proxy::OnMessageReceived(const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PPB_TCPSocket_Private_Proxy, msg) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK, - OnMsgConnectACK) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, - OnMsgSSLHandshakeACK) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnMsgReadACK) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnMsgWriteACK) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SetOptionACK, OnMsgSetOptionACK) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void PPB_TCPSocket_Private_Proxy::OnMsgConnectACK( - uint32 /* plugin_dispatcher_id */, - uint32 socket_id, - int32_t result, - const PP_NetAddress_Private& local_addr, - const PP_NetAddress_Private& remote_addr) { - if (!g_id_to_socket) { - NOTREACHED(); - return; - } - IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); - if (iter == g_id_to_socket->end()) - return; - iter->second->OnConnectCompleted(result, local_addr, remote_addr); -} - -void PPB_TCPSocket_Private_Proxy::OnMsgSSLHandshakeACK( - uint32 /* plugin_dispatcher_id */, - uint32 socket_id, - bool succeeded, - const PPB_X509Certificate_Fields& certificate_fields) { - if (!g_id_to_socket) { - NOTREACHED(); - return; - } - IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); - if (iter == g_id_to_socket->end()) - return; - iter->second->OnSSLHandshakeCompleted(succeeded, certificate_fields); -} - -void PPB_TCPSocket_Private_Proxy::OnMsgReadACK( - uint32 /* plugin_dispatcher_id */, - uint32 socket_id, - int32_t result, - const std::string& data) { - if (!g_id_to_socket) { - NOTREACHED(); - return; - } - IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); - if (iter == g_id_to_socket->end()) - return; - iter->second->OnReadCompleted(result, data); -} - -void PPB_TCPSocket_Private_Proxy::OnMsgWriteACK( - uint32 /* plugin_dispatcher_id */, - uint32 socket_id, - int32_t result) { - if (!g_id_to_socket) { - NOTREACHED(); - return; - } - IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); - if (iter == g_id_to_socket->end()) - return; - iter->second->OnWriteCompleted(result); -} - -void PPB_TCPSocket_Private_Proxy::OnMsgSetOptionACK( - uint32 /* plugin_dispatcher_id */, - uint32 socket_id, - int32_t result) { - if (!g_id_to_socket) { - NOTREACHED(); - return; - } - IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); - if (iter == g_id_to_socket->end()) - return; - iter->second->OnSetOptionCompleted(result); -} - -} // namespace proxy -} // namespace ppapi diff --git a/chromium/ppapi/proxy/ppb_tcp_socket_private_proxy.h b/chromium/ppapi/proxy/ppb_tcp_socket_private_proxy.h deleted file mode 100644 index 0813531a00e..00000000000 --- a/chromium/ppapi/proxy/ppb_tcp_socket_private_proxy.h +++ /dev/null @@ -1,69 +0,0 @@ -// 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. - -#ifndef PPAPI_PROXY_PPB_TCP_SOCKET_PRIVATE_PROXY_H_ -#define PPAPI_PROXY_PPB_TCP_SOCKET_PRIVATE_PROXY_H_ - -#include <string> - -#include "base/basictypes.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/c/private/ppb_tcp_socket_private.h" -#include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/ppapi_proxy_export.h" - -namespace ppapi { - -class PPB_X509Certificate_Fields; - -namespace proxy { - -class PPB_TCPSocket_Private_Proxy : public InterfaceProxy { - public: - explicit PPB_TCPSocket_Private_Proxy(Dispatcher* dispatcher); - virtual ~PPB_TCPSocket_Private_Proxy(); - - static PP_Resource CreateProxyResource(PP_Instance instance); - static PP_Resource CreateProxyResourceForConnectedSocket( - PP_Instance instance, - uint32 socket_id, - const PP_NetAddress_Private& local_addr, - const PP_NetAddress_Private& remote_addr); - - // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); - - static const ApiID kApiID = API_ID_PPB_TCPSOCKET_PRIVATE; - - private: - // Browser->plugin message handlers. - void OnMsgConnectACK(uint32 plugin_dispatcher_id, - uint32 socket_id, - int32_t result, - const PP_NetAddress_Private& local_addr, - const PP_NetAddress_Private& remote_addr); - void OnMsgSSLHandshakeACK( - uint32 plugin_dispatcher_id, - uint32 socket_id, - bool succeeded, - const PPB_X509Certificate_Fields& certificate_fields); - void OnMsgReadACK(uint32 plugin_dispatcher_id, - uint32 socket_id, - int32_t result, - const std::string& data); - void OnMsgWriteACK(uint32 plugin_dispatcher_id, - uint32 socket_id, - int32_t result); - void OnMsgSetOptionACK(uint32 plugin_dispatcher_id, - uint32 socket_id, - int32_t result); - - DISALLOW_COPY_AND_ASSIGN(PPB_TCPSocket_Private_Proxy); -}; - -} // namespace proxy -} // namespace ppapi - -#endif // PPAPI_PROXY_PPB_TCP_SOCKET_PRIVATE_PROXY_H_ diff --git a/chromium/ppapi/proxy/ppb_tcp_socket_proxy.cc b/chromium/ppapi/proxy/ppb_tcp_socket_proxy.cc deleted file mode 100644 index 2ec16603300..00000000000 --- a/chromium/ppapi/proxy/ppb_tcp_socket_proxy.cc +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright 2013 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/ppb_tcp_socket_proxy.h" - -#include <map> - -#include "base/logging.h" -#include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_globals.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/resource.h" -#include "ppapi/shared_impl/socket_option_data.h" -#include "ppapi/shared_impl/tcp_socket_shared.h" -#include "ppapi/thunk/enter.h" -#include "ppapi/thunk/ppb_net_address_api.h" -#include "ppapi/thunk/ppb_tcp_socket_api.h" -#include "ppapi/thunk/thunk.h" - -namespace ppapi { -namespace proxy { - -namespace { - -typedef thunk::EnterResourceNoLock<thunk::PPB_NetAddress_API> - EnterNetAddressNoLock; - -typedef std::map<uint32, TCPSocketShared*> IDToSocketMap; -IDToSocketMap* g_id_to_socket = NULL; - -class TCPSocket : public thunk::PPB_TCPSocket_API, - public Resource, - public TCPSocketShared { - public: - TCPSocket(const HostResource& resource, uint32 socket_id); - virtual ~TCPSocket(); - - // Resource overrides. - virtual thunk::PPB_TCPSocket_API* AsPPB_TCPSocket_API() OVERRIDE; - - // thunk::PPB_TCPSocket_API implementation. - virtual int32_t Connect(PP_Resource addr, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual PP_Resource GetLocalAddress() OVERRIDE; - virtual PP_Resource GetRemoteAddress() OVERRIDE; - virtual int32_t Read(char* buffer, - int32_t bytes_to_read, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual int32_t Write(const char* buffer, - int32_t bytes_to_write, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual void Close() OVERRIDE; - virtual int32_t SetOption(PP_TCPSocket_Option name, - const PP_Var& value, - scoped_refptr<TrackedCallback> callback) OVERRIDE; - - // TCPSocketShared implementation. - virtual void SendConnect(const std::string& host, uint16_t port) OVERRIDE; - virtual void SendConnectWithNetAddress( - const PP_NetAddress_Private& addr) OVERRIDE; - virtual void SendSSLHandshake( - const std::string& server_name, - uint16_t server_port, - const std::vector<std::vector<char> >& trusted_certs, - const std::vector<std::vector<char> >& untrusted_certs) OVERRIDE; - virtual void SendRead(int32_t bytes_to_read) OVERRIDE; - virtual void SendWrite(const std::string& buffer) OVERRIDE; - virtual void SendDisconnect() OVERRIDE; - virtual void SendSetOption(PP_TCPSocket_Option name, - const SocketOptionData& value) OVERRIDE; - virtual Resource* GetOwnerResource() OVERRIDE; - - private: - void SendToBrowser(IPC::Message* msg); - - DISALLOW_COPY_AND_ASSIGN(TCPSocket); -}; - -TCPSocket::TCPSocket(const HostResource& resource, uint32 socket_id) - : Resource(OBJECT_IS_PROXY, resource), - TCPSocketShared(OBJECT_IS_PROXY, socket_id) { - if (!g_id_to_socket) - g_id_to_socket = new IDToSocketMap(); - DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end()); - (*g_id_to_socket)[socket_id] = this; -} - -TCPSocket::~TCPSocket() { - DisconnectImpl(); -} - -thunk::PPB_TCPSocket_API* TCPSocket::AsPPB_TCPSocket_API() { - return this; -} - -int32_t TCPSocket::Connect(PP_Resource addr, - scoped_refptr<TrackedCallback> callback) { - EnterNetAddressNoLock enter(addr, true); - if (enter.failed()) - return PP_ERROR_BADARGUMENT; - - return ConnectWithNetAddressImpl(&enter.object()->GetNetAddressPrivate(), - callback); -} - -PP_Resource TCPSocket::GetLocalAddress() { - PP_NetAddress_Private addr_private; - if (!GetLocalAddressImpl(&addr_private)) - return 0; - - thunk::EnterResourceCreationNoLock enter(pp_instance()); - if (enter.failed()) - return 0; - return enter.functions()->CreateNetAddressFromNetAddressPrivate( - pp_instance(), addr_private); -} - -PP_Resource TCPSocket::GetRemoteAddress() { - PP_NetAddress_Private addr_private; - if (!GetRemoteAddressImpl(&addr_private)) - return 0; - - thunk::EnterResourceCreationNoLock enter(pp_instance()); - if (enter.failed()) - return 0; - return enter.functions()->CreateNetAddressFromNetAddressPrivate( - pp_instance(), addr_private); -} - -int32_t TCPSocket::Read(char* buffer, - int32_t bytes_to_read, - scoped_refptr<TrackedCallback> callback) { - return ReadImpl(buffer, bytes_to_read, callback); -} - -int32_t TCPSocket::Write(const char* buffer, - int32_t bytes_to_write, - scoped_refptr<TrackedCallback> callback) { - return WriteImpl(buffer, bytes_to_write, callback); -} - -void TCPSocket::Close() { - DisconnectImpl(); -} - -int32_t TCPSocket::SetOption(PP_TCPSocket_Option name, - const PP_Var& value, - scoped_refptr<TrackedCallback> callback) { - return SetOptionImpl(name, value, callback); -} - -void TCPSocket::SendConnect(const std::string& host, uint16_t port) { - NOTREACHED(); -} - -void TCPSocket::SendConnectWithNetAddress(const PP_NetAddress_Private& addr) { - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress( - API_ID_PPB_TCPSOCKET, socket_id_, addr)); -} - -void TCPSocket::SendSSLHandshake( - const std::string& server_name, - uint16_t server_port, - const std::vector<std::vector<char> >& trusted_certs, - const std::vector<std::vector<char> >& untrusted_certs) { - NOTREACHED(); -} - -void TCPSocket::SendRead(int32_t bytes_to_read) { - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_Read(socket_id_, bytes_to_read)); -} - -void TCPSocket::SendWrite(const std::string& buffer) { - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_Write(socket_id_, buffer)); -} - -void TCPSocket::SendDisconnect() { - // After removed from the mapping, this object won't receive any notifications - // from the proxy. - DCHECK(g_id_to_socket->find(socket_id_) != g_id_to_socket->end()); - g_id_to_socket->erase(socket_id_); - SendToBrowser(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id_)); -} - -void TCPSocket::SendSetOption(PP_TCPSocket_Option name, - const SocketOptionData& value) { - SendToBrowser( - new PpapiHostMsg_PPBTCPSocket_SetOption(socket_id_, name, value)); -} - -Resource* TCPSocket::GetOwnerResource() { - return this; -} - -void TCPSocket::SendToBrowser(IPC::Message* msg) { - PluginGlobals::Get()->GetBrowserSender()->Send(msg); -} - -} // namespace - -//------------------------------------------------------------------------------ - -PPB_TCPSocket_Proxy::PPB_TCPSocket_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { -} - -PPB_TCPSocket_Proxy::~PPB_TCPSocket_Proxy() { -} - -// static -PP_Resource PPB_TCPSocket_Proxy::CreateProxyResource(PP_Instance instance) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return 0; - - uint32 socket_id = 0; - PluginGlobals::Get()->GetBrowserSender()->Send( - new PpapiHostMsg_PPBTCPSocket_Create( - API_ID_PPB_TCPSOCKET, dispatcher->plugin_dispatcher_id(), - &socket_id)); - if (socket_id == 0) - return 0; - return (new TCPSocket(HostResource::MakeInstanceOnly(instance), - socket_id))->GetReference(); -} - -bool PPB_TCPSocket_Proxy::OnMessageReceived(const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PPB_TCPSocket_Proxy, msg) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK, - OnMsgConnectACK) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnMsgReadACK) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnMsgWriteACK) - IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SetOptionACK, - OnMsgSetOptionACK) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void PPB_TCPSocket_Proxy::OnMsgConnectACK( - uint32 /* plugin_dispatcher_id */, - uint32 socket_id, - int32_t result, - const PP_NetAddress_Private& local_addr, - const PP_NetAddress_Private& remote_addr) { - if (!g_id_to_socket) { - NOTREACHED(); - return; - } - IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); - if (iter == g_id_to_socket->end()) - return; - iter->second->OnConnectCompleted(result, local_addr, remote_addr); -} - -void PPB_TCPSocket_Proxy::OnMsgReadACK(uint32 /* plugin_dispatcher_id */, - uint32 socket_id, - int32_t result, - const std::string& data) { - if (!g_id_to_socket) { - NOTREACHED(); - return; - } - IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); - if (iter == g_id_to_socket->end()) - return; - iter->second->OnReadCompleted(result, data); -} - -void PPB_TCPSocket_Proxy::OnMsgWriteACK(uint32 /* plugin_dispatcher_id */, - uint32 socket_id, - int32_t result) { - if (!g_id_to_socket) { - NOTREACHED(); - return; - } - IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); - if (iter == g_id_to_socket->end()) - return; - iter->second->OnWriteCompleted(result); -} - -void PPB_TCPSocket_Proxy::OnMsgSetOptionACK(uint32 /* plugin_dispatcher_id */, - uint32 socket_id, - int32_t result) { - if (!g_id_to_socket) { - NOTREACHED(); - return; - } - IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); - if (iter == g_id_to_socket->end()) - return; - iter->second->OnSetOptionCompleted(result); -} - -} // namespace proxy -} // namespace ppapi diff --git a/chromium/ppapi/proxy/ppb_tcp_socket_proxy.h b/chromium/ppapi/proxy/ppb_tcp_socket_proxy.h deleted file mode 100644 index c5a3de8c721..00000000000 --- a/chromium/ppapi/proxy/ppb_tcp_socket_proxy.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2013 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_PROXY_PPB_TCP_SOCKET_PROXY_H_ -#define PPAPI_PROXY_PPB_TCP_SOCKET_PROXY_H_ - -#include <string> - -#include "base/basictypes.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/ppapi_proxy_export.h" - -struct PP_NetAddress_Private; - -namespace ppapi { -namespace proxy { - -class PPB_TCPSocket_Proxy : public InterfaceProxy { - public: - explicit PPB_TCPSocket_Proxy(Dispatcher* dispatcher); - virtual ~PPB_TCPSocket_Proxy(); - - static PP_Resource CreateProxyResource(PP_Instance instance); - - // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); - - static const ApiID kApiID = API_ID_PPB_TCPSOCKET; - - private: - // Browser->plugin message handlers. - void OnMsgConnectACK(uint32 plugin_dispatcher_id, - uint32 socket_id, - int32_t result, - const PP_NetAddress_Private& local_addr, - const PP_NetAddress_Private& remote_addr); - void OnMsgReadACK(uint32 plugin_dispatcher_id, - uint32 socket_id, - int32_t result, - const std::string& data); - void OnMsgWriteACK(uint32 plugin_dispatcher_id, - uint32 socket_id, - int32_t result); - void OnMsgSetOptionACK(uint32 plugin_dispatcher_id, - uint32 socket_id, - int32_t result); - - DISALLOW_COPY_AND_ASSIGN(PPB_TCPSocket_Proxy); -}; - -} // namespace proxy -} // namespace ppapi - -#endif // PPAPI_PROXY_PPB_TCP_SOCKET_PROXY_H_ diff --git a/chromium/ppapi/proxy/ppp_content_decryptor_private_proxy.cc b/chromium/ppapi/proxy/ppp_content_decryptor_private_proxy.cc index f986e7f8d72..d32e6320094 100644 --- a/chromium/ppapi/proxy/ppp_content_decryptor_private_proxy.cc +++ b/chromium/ppapi/proxy/ppp_content_decryptor_private_proxy.cc @@ -109,8 +109,24 @@ bool InitializePppDecryptorBuffer(PP_Instance instance, return true; } +void Initialize(PP_Instance instance, + PP_Var key_system, + PP_Bool can_challenge_platform) { + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); + if (!dispatcher) { + NOTREACHED(); + return; + } + + dispatcher->Send( + new PpapiMsg_PPPContentDecryptor_Initialize( + API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, + instance, + SerializedVarSendInput(dispatcher, key_system), + PP_ToBool(can_challenge_platform))); +} + void GenerateKeyRequest(PP_Instance instance, - PP_Var key_system, PP_Var type, PP_Var init_data) { HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); @@ -123,7 +139,6 @@ void GenerateKeyRequest(PP_Instance instance, new PpapiMsg_PPPContentDecryptor_GenerateKeyRequest( API_ID_PPP_CONTENT_DECRYPTOR_PRIVATE, instance, - SerializedVarSendInput(dispatcher, key_system), SerializedVarSendInput(dispatcher, type), SerializedVarSendInput(dispatcher, init_data))); } @@ -349,6 +364,7 @@ void DecryptAndDecode(PP_Instance instance, } static const PPP_ContentDecryptor_Private content_decryptor_interface = { + &Initialize, &GenerateKeyRequest, &AddKey, &CancelKeyRequest, @@ -390,6 +406,8 @@ bool PPP_ContentDecryptor_Private_Proxy::OnMessageReceived( bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPP_ContentDecryptor_Private_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_Initialize, + OnMsgInitialize) IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_GenerateKeyRequest, OnMsgGenerateKeyRequest) IPC_MESSAGE_HANDLER(PpapiMsg_PPPContentDecryptor_AddKey, @@ -414,15 +432,26 @@ bool PPP_ContentDecryptor_Private_Proxy::OnMessageReceived( return handled; } -void PPP_ContentDecryptor_Private_Proxy::OnMsgGenerateKeyRequest( +void PPP_ContentDecryptor_Private_Proxy::OnMsgInitialize( PP_Instance instance, SerializedVarReceiveInput key_system, + bool can_challenge_platform) { + if (ppp_decryptor_impl_) { + CallWhileUnlocked( + ppp_decryptor_impl_->Initialize, + instance, + ExtractReceivedVarAndAddRef(dispatcher(), &key_system), + PP_FromBool(can_challenge_platform)); + } +} + +void PPP_ContentDecryptor_Private_Proxy::OnMsgGenerateKeyRequest( + PP_Instance instance, SerializedVarReceiveInput type, SerializedVarReceiveInput init_data) { if (ppp_decryptor_impl_) { CallWhileUnlocked(ppp_decryptor_impl_->GenerateKeyRequest, instance, - ExtractReceivedVarAndAddRef(dispatcher(), &key_system), ExtractReceivedVarAndAddRef(dispatcher(), &type), ExtractReceivedVarAndAddRef(dispatcher(), &init_data)); } diff --git a/chromium/ppapi/proxy/ppp_content_decryptor_private_proxy.h b/chromium/ppapi/proxy/ppp_content_decryptor_private_proxy.h index 5e7ecc85dba..2e4ad8548a9 100644 --- a/chromium/ppapi/proxy/ppp_content_decryptor_private_proxy.h +++ b/chromium/ppapi/proxy/ppp_content_decryptor_private_proxy.h @@ -30,8 +30,10 @@ class PPP_ContentDecryptor_Private_Proxy : public InterfaceProxy { virtual bool OnMessageReceived(const IPC::Message& msg); // Message handlers. + void OnMsgInitialize(PP_Instance instance, + SerializedVarReceiveInput key_system, + bool can_challenge_platform); void OnMsgGenerateKeyRequest(PP_Instance instance, - SerializedVarReceiveInput key_system, SerializedVarReceiveInput type, SerializedVarReceiveInput init_data); void OnMsgAddKey(PP_Instance instance, diff --git a/chromium/ppapi/proxy/ppp_messaging_proxy_perftest.cc b/chromium/ppapi/proxy/ppp_messaging_proxy_perftest.cc index c52ea116687..666609a51b3 100644 --- a/chromium/ppapi/proxy/ppp_messaging_proxy_perftest.cc +++ b/chromium/ppapi/proxy/ppp_messaging_proxy_perftest.cc @@ -3,8 +3,8 @@ // found in the LICENSE file. #include "base/command_line.h" -#include "base/perftimer.h" #include "base/strings/string_number_conversions.h" +#include "base/test/perf_time_logger.h" #include "ppapi/c/ppp_messaging.h" #include "ppapi/proxy/ppapi_proxy_test.h" #include "ppapi/proxy/serialized_var.h" @@ -73,7 +73,7 @@ TEST_F(PppMessagingPerfTest, StringPerformance) { } } srand(seed); - PerfTimeLogger logger("PppMessagingPerfTest.StringPerformance"); + base::PerfTimeLogger logger("PppMessagingPerfTest.StringPerformance"); for (int i = 0; i < string_count; ++i) { const std::string test_string(rand() % max_string_size, 'a'); PP_Var host_string = StringVar::StringToPPVar(test_string); diff --git a/chromium/ppapi/proxy/raw_var_data.cc b/chromium/ppapi/proxy/raw_var_data.cc index a550c3fca05..b41304849ba 100644 --- a/chromium/ppapi/proxy/raw_var_data.cc +++ b/chromium/ppapi/proxy/raw_var_data.cc @@ -240,6 +240,11 @@ RawVarData* RawVarData::Create(PP_VarType type) { return new ArrayRawVarData(); case PP_VARTYPE_DICTIONARY: return new DictionaryRawVarData(); + case PP_VARTYPE_RESOURCE: + // TODO(mgiuca): Add ResourceRawVarData. (http://crbug.com/177017) + // This path will be reached if a NaCl module attempts to pass a + // PP_VARTYPE_RESOURCE in a message. + break; } NOTREACHED(); return NULL; diff --git a/chromium/ppapi/proxy/raw_var_data_unittest.cc b/chromium/ppapi/proxy/raw_var_data_unittest.cc index 2ee69144f61..c45ca9d6967 100644 --- a/chromium/ppapi/proxy/raw_var_data_unittest.cc +++ b/chromium/ppapi/proxy/raw_var_data_unittest.cc @@ -37,6 +37,7 @@ class RawVarDataTest : public testing::Test { // testing::Test implementation. virtual void SetUp() { + ProxyLock::EnableLockingOnThreadForTest(); ProxyLock::Acquire(); } virtual void TearDown() { diff --git a/chromium/ppapi/proxy/resource_creation_proxy.cc b/chromium/ppapi/proxy/resource_creation_proxy.cc index 53cade1e91a..d1b99ecb014 100644 --- a/chromium/ppapi/proxy/resource_creation_proxy.cc +++ b/chromium/ppapi/proxy/resource_creation_proxy.cc @@ -11,6 +11,7 @@ #include "ppapi/proxy/ext_crx_file_system_private_resource.h" #include "ppapi/proxy/file_chooser_resource.h" #include "ppapi/proxy/file_io_resource.h" +#include "ppapi/proxy/file_ref_resource.h" #include "ppapi/proxy/file_system_resource.h" #include "ppapi/proxy/flash_drm_resource.h" #include "ppapi/proxy/flash_font_file_resource.h" @@ -19,6 +20,8 @@ #include "ppapi/proxy/host_resolver_private_resource.h" #include "ppapi/proxy/host_resolver_resource.h" #include "ppapi/proxy/net_address_resource.h" +#include "ppapi/proxy/network_monitor_resource.h" +#include "ppapi/proxy/platform_verification_private_resource.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_globals.h" #include "ppapi/proxy/plugin_resource_tracker.h" @@ -26,18 +29,16 @@ #include "ppapi/proxy/ppb_audio_proxy.h" #include "ppapi/proxy/ppb_broker_proxy.h" #include "ppapi/proxy/ppb_buffer_proxy.h" -#include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/ppb_flash_message_loop_proxy.h" #include "ppapi/proxy/ppb_graphics_3d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" -#include "ppapi/proxy/ppb_network_monitor_private_proxy.h" -#include "ppapi/proxy/ppb_tcp_socket_private_proxy.h" -#include "ppapi/proxy/ppb_tcp_socket_proxy.h" #include "ppapi/proxy/ppb_video_decoder_proxy.h" #include "ppapi/proxy/ppb_x509_certificate_private_proxy.h" #include "ppapi/proxy/printing_resource.h" #include "ppapi/proxy/talk_resource.h" #include "ppapi/proxy/tcp_server_socket_private_resource.h" +#include "ppapi/proxy/tcp_socket_private_resource.h" +#include "ppapi/proxy/tcp_socket_resource.h" #include "ppapi/proxy/truetype_font_resource.h" #include "ppapi/proxy/udp_socket_private_resource.h" #include "ppapi/proxy/udp_socket_resource.h" @@ -51,6 +52,7 @@ #include "ppapi/shared_impl/api_id.h" #include "ppapi/shared_impl/host_resource.h" #include "ppapi/shared_impl/ppb_audio_config_shared.h" +#include "ppapi/shared_impl/ppb_audio_shared.h" #include "ppapi/shared_impl/ppb_input_event_shared.h" #include "ppapi/shared_impl/ppb_resource_array_shared.h" #include "ppapi/shared_impl/var.h" @@ -78,15 +80,10 @@ PP_Resource ResourceCreationProxy::CreateFileIO(PP_Instance instance) { return (new FileIOResource(GetConnection(), instance))->GetReference(); } -PP_Resource ResourceCreationProxy::CreateFileRef(PP_Instance instance, - PP_Resource file_system, - const char* path) { - return PPB_FileRef_Proxy::CreateProxyResource(instance, file_system, path); -} - PP_Resource ResourceCreationProxy::CreateFileRef( - const PPB_FileRef_CreateInfo& create_info) { - return PPB_FileRef_Proxy::DeserializeFileRef(create_info); + PP_Instance instance, + const FileRefCreateInfo& create_info) { + return FileRefResource::CreateFileRef(GetConnection(), instance, create_info); } PP_Resource ResourceCreationProxy::CreateFileSystem( @@ -96,15 +93,6 @@ PP_Resource ResourceCreationProxy::CreateFileSystem( type))->GetReference(); } -PP_Resource ResourceCreationProxy::CreateIsolatedFileSystem( - PP_Instance instance, - const char* fsid) { - FileSystemResource* fs = new FileSystemResource( - GetConnection(), instance, PP_FILESYSTEMTYPE_ISOLATED); - fs->InitIsolatedFileSystem(fsid); - return fs->GetReference(); -} - PP_Resource ResourceCreationProxy::CreateIMEInputEvent( PP_Instance instance, PP_InputEvent_Type type, @@ -194,13 +182,22 @@ PP_Resource ResourceCreationProxy::CreateWheelInputEvent( wheel_delta, wheel_ticks, scroll_by_page); } +PP_Resource ResourceCreationProxy::CreateAudio1_0( + PP_Instance instance, + PP_Resource config_id, + PPB_Audio_Callback_1_0 audio_callback, + void* user_data) { + return PPB_Audio_Proxy::CreateProxyResource( + instance, config_id, AudioCallbackCombined(audio_callback), user_data); +} + PP_Resource ResourceCreationProxy::CreateAudio( PP_Instance instance, PP_Resource config_id, PPB_Audio_Callback audio_callback, void* user_data) { - return PPB_Audio_Proxy::CreateProxyResource(instance, config_id, - audio_callback, user_data); + return PPB_Audio_Proxy::CreateProxyResource( + instance, config_id, AudioCallbackCombined(audio_callback), user_data); } PP_Resource ResourceCreationProxy::CreateAudioTrusted(PP_Instance instance) { @@ -311,11 +308,9 @@ PP_Resource ResourceCreationProxy::CreateNetAddressFromNetAddressPrivate( } PP_Resource ResourceCreationProxy::CreateNetworkMonitor( - PP_Instance instance, - PPB_NetworkMonitor_Callback callback, - void* user_data) { - return PPB_NetworkMonitor_Private_Proxy::CreateProxyResource( - instance, callback, user_data); + PP_Instance instance) { + return (new NetworkMonitorResource(GetConnection(), instance))-> + GetReference(); } PP_Resource ResourceCreationProxy::CreatePrinting(PP_Instance instance) { @@ -328,14 +323,23 @@ PP_Resource ResourceCreationProxy::CreateTCPServerSocketPrivate( GetReference(); } +PP_Resource ResourceCreationProxy::CreateTCPSocket1_0( + PP_Instance instance) { + return (new TCPSocketResource(GetConnection(), instance, + TCP_SOCKET_VERSION_1_0))->GetReference(); +} + PP_Resource ResourceCreationProxy::CreateTCPSocket( PP_Instance instance) { - return PPB_TCPSocket_Proxy::CreateProxyResource(instance); + return (new TCPSocketResource( + GetConnection(), instance, TCP_SOCKET_VERSION_1_1_OR_ABOVE))-> + GetReference(); } PP_Resource ResourceCreationProxy::CreateTCPSocketPrivate( PP_Instance instance) { - return PPB_TCPSocket_Private_Proxy::CreateProxyResource(instance); + return (new TCPSocketPrivateResource(GetConnection(), instance))-> + GetReference(); } PP_Resource ResourceCreationProxy::CreateUDPSocket(PP_Instance instance) { @@ -420,6 +424,12 @@ PP_Resource ResourceCreationProxy::CreateFlashMessageLoop( return PPB_Flash_MessageLoop_Proxy::CreateProxyResource(instance); } +PP_Resource ResourceCreationProxy::CreatePlatformVerificationPrivate( + PP_Instance instance) { + return (new PlatformVerificationPrivateResource(GetConnection(), instance))-> + GetReference(); +} + PP_Resource ResourceCreationProxy::CreateScrollbar(PP_Instance instance, PP_Bool vertical) { NOTIMPLEMENTED(); // Not proxied yet. diff --git a/chromium/ppapi/proxy/resource_creation_proxy.h b/chromium/ppapi/proxy/resource_creation_proxy.h index 47b40a83927..1507dc8c6c5 100644 --- a/chromium/ppapi/proxy/resource_creation_proxy.h +++ b/chromium/ppapi/proxy/resource_creation_proxy.h @@ -38,16 +38,11 @@ class ResourceCreationProxy : public InterfaceProxy, // ResourceCreationAPI (called in plugin). virtual PP_Resource CreateFileIO(PP_Instance instance) OVERRIDE; - virtual PP_Resource CreateFileRef(PP_Instance instance, - PP_Resource file_system, - const char* path) OVERRIDE; virtual PP_Resource CreateFileRef( - const PPB_FileRef_CreateInfo& create_info) OVERRIDE; + PP_Instance instance, + const FileRefCreateInfo& create_info) OVERRIDE; virtual PP_Resource CreateFileSystem(PP_Instance instance, PP_FileSystemType type) OVERRIDE; - virtual PP_Resource CreateIsolatedFileSystem( - PP_Instance instance, - const char* fsid) OVERRIDE; virtual PP_Resource CreateIMEInputEvent(PP_Instance instance, PP_InputEvent_Type type, PP_TimeTicks time_stamp, @@ -94,7 +89,10 @@ class ResourceCreationProxy : public InterfaceProxy, const PP_FloatPoint* wheel_delta, const PP_FloatPoint* wheel_ticks, PP_Bool scroll_by_page) OVERRIDE; - + virtual PP_Resource CreateAudio1_0(PP_Instance instance, + PP_Resource config_id, + PPB_Audio_Callback_1_0 audio_callback, + void* user_data) OVERRIDE; virtual PP_Resource CreateAudio(PP_Instance instance, PP_Resource config_id, PPB_Audio_Callback audio_callback, @@ -135,13 +133,11 @@ class ResourceCreationProxy : public InterfaceProxy, virtual PP_Resource CreateNetAddressFromNetAddressPrivate( PP_Instance instance, const PP_NetAddress_Private& private_addr) OVERRIDE; - virtual PP_Resource CreateNetworkMonitor( - PP_Instance instance, - PPB_NetworkMonitor_Callback callback, - void* user_data) OVERRIDE; + virtual PP_Resource CreateNetworkMonitor(PP_Instance instance) OVERRIDE; virtual PP_Resource CreatePrinting(PP_Instance) OVERRIDE; virtual PP_Resource CreateTCPServerSocketPrivate( PP_Instance instance) OVERRIDE; + virtual PP_Resource CreateTCPSocket1_0(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateTCPSocket(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateTCPSocketPrivate(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateUDPSocket(PP_Instance instance) OVERRIDE; @@ -167,6 +163,8 @@ class ResourceCreationProxy : public InterfaceProxy, virtual PP_Resource CreateFlashMenu(PP_Instance instance, const PP_Flash_Menu* menu_data) OVERRIDE; virtual PP_Resource CreateFlashMessageLoop(PP_Instance instance) OVERRIDE; + virtual PP_Resource CreatePlatformVerificationPrivate( + PP_Instance instance) OVERRIDE; virtual PP_Resource CreateScrollbar(PP_Instance instance, PP_Bool vertical) OVERRIDE; virtual PP_Resource CreateTalk(PP_Instance instance) OVERRIDE; diff --git a/chromium/ppapi/proxy/run_all_unittests.cc b/chromium/ppapi/proxy/run_all_unittests.cc deleted file mode 100644 index 7fd6ef2e80e..00000000000 --- a/chromium/ppapi/proxy/run_all_unittests.cc +++ /dev/null @@ -1,9 +0,0 @@ -// 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 "base/test/test_suite.h" - -int main(int argc, char** argv) { - return base::TestSuite(argc, argv).Run(); -} diff --git a/chromium/ppapi/proxy/serialized_structs.cc b/chromium/ppapi/proxy/serialized_structs.cc index 8c984d55dba..255865a65dc 100644 --- a/chromium/ppapi/proxy/serialized_structs.cc +++ b/chromium/ppapi/proxy/serialized_structs.cc @@ -80,6 +80,14 @@ void SerializedFontDescription::SetToPPBrowserFontDescription( desc->word_spacing = word_spacing; } +SerializedNetworkInfo::SerializedNetworkInfo() + : type(PP_NETWORKLIST_TYPE_UNKNOWN), + state(PP_NETWORKLIST_STATE_DOWN), + mtu(0) { +} + +SerializedNetworkInfo::~SerializedNetworkInfo() {} + SerializedTrueTypeFontDesc::SerializedTrueTypeFontDesc() : family(), generic_family(), diff --git a/chromium/ppapi/proxy/serialized_structs.h b/chromium/ppapi/proxy/serialized_structs.h index 1f89ae2047c..fb93dd16d03 100644 --- a/chromium/ppapi/proxy/serialized_structs.h +++ b/chromium/ppapi/proxy/serialized_structs.h @@ -16,6 +16,8 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_point.h" #include "ppapi/c/pp_rect.h" +#include "ppapi/c/ppb_network_list.h" +#include "ppapi/c/private/ppb_net_address_private.h" #include "ppapi/proxy/ppapi_proxy_export.h" #include "ppapi/shared_impl/host_resource.h" @@ -57,6 +59,19 @@ struct PPAPI_PROXY_EXPORT SerializedFontDescription { int32_t word_spacing; }; +struct PPAPI_PROXY_EXPORT SerializedNetworkInfo { + SerializedNetworkInfo(); + ~SerializedNetworkInfo(); + + std::string name; + PP_NetworkList_Type type; + PP_NetworkList_State state; + std::vector<PP_NetAddress_Private> addresses; + std::string display_name; + int mtu; +}; +typedef std::vector<SerializedNetworkInfo> SerializedNetworkList; + struct PPAPI_PROXY_EXPORT SerializedTrueTypeFontDesc { SerializedTrueTypeFontDesc(); ~SerializedTrueTypeFontDesc(); diff --git a/chromium/ppapi/proxy/tcp_server_socket_private_resource.cc b/chromium/ppapi/proxy/tcp_server_socket_private_resource.cc index 6bbf4667ee7..745ed622fa2 100644 --- a/chromium/ppapi/proxy/tcp_server_socket_private_resource.cc +++ b/chromium/ppapi/proxy/tcp_server_socket_private_resource.cc @@ -4,9 +4,8 @@ #include "ppapi/proxy/tcp_server_socket_private_resource.h" -#include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/ppb_tcp_socket_private_proxy.h" +#include "ppapi/proxy/tcp_socket_private_resource.h" namespace ppapi { namespace proxy { @@ -16,15 +15,8 @@ TCPServerSocketPrivateResource::TCPServerSocketPrivateResource( PP_Instance instance) : PluginResource(connection, instance), state_(STATE_BEFORE_LISTENING), - local_addr_(), - plugin_dispatcher_id_(0) { + local_addr_() { SendCreate(BROWSER, PpapiHostMsg_TCPServerSocket_CreatePrivate()); - - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (dispatcher) - plugin_dispatcher_id_ = dispatcher->plugin_dispatcher_id(); - else - NOTREACHED(); } TCPServerSocketPrivateResource::~TCPServerSocketPrivateResource() { @@ -71,7 +63,7 @@ int32_t TCPServerSocketPrivateResource::Accept( Call<PpapiPluginMsg_TCPServerSocket_AcceptReply>( BROWSER, - PpapiHostMsg_TCPServerSocket_Accept(plugin_dispatcher_id_), + PpapiHostMsg_TCPServerSocket_Accept(), base::Bind(&TCPServerSocketPrivateResource::OnPluginMsgAcceptReply, base::Unretained(this), tcp_socket)); return PP_OK_COMPLETIONPENDING; @@ -115,7 +107,7 @@ void TCPServerSocketPrivateResource::OnPluginMsgListenReply( void TCPServerSocketPrivateResource::OnPluginMsgAcceptReply( PP_Resource* tcp_socket, const ResourceMessageReplyParams& params, - uint32 accepted_socket_id, + int pending_resource_id, const PP_NetAddress_Private& local_addr, const PP_NetAddress_Private& remote_addr) { DCHECK(tcp_socket); @@ -124,12 +116,10 @@ void TCPServerSocketPrivateResource::OnPluginMsgAcceptReply( return; } if (params.result() == PP_OK) { - *tcp_socket = - PPB_TCPSocket_Private_Proxy::CreateProxyResourceForConnectedSocket( - pp_instance(), - accepted_socket_id, - local_addr, - remote_addr); + *tcp_socket = (new TCPSocketPrivateResource(connection(), pp_instance(), + pending_resource_id, + local_addr, + remote_addr))->GetReference(); } accept_callback_->Run(params.result()); } diff --git a/chromium/ppapi/proxy/tcp_server_socket_private_resource.h b/chromium/ppapi/proxy/tcp_server_socket_private_resource.h index 95febde92cd..21e190a6278 100644 --- a/chromium/ppapi/proxy/tcp_server_socket_private_resource.h +++ b/chromium/ppapi/proxy/tcp_server_socket_private_resource.h @@ -48,15 +48,13 @@ class PPAPI_PROXY_EXPORT TCPServerSocketPrivateResource const PP_NetAddress_Private& local_addr); void OnPluginMsgAcceptReply(PP_Resource* tcp_socket, const ResourceMessageReplyParams& params, - uint32 accepted_socket_id, + int pending_resource_id, const PP_NetAddress_Private& local_addr, const PP_NetAddress_Private& remote_addr); State state_; PP_NetAddress_Private local_addr_; - uint32 plugin_dispatcher_id_; - scoped_refptr<TrackedCallback> listen_callback_; scoped_refptr<TrackedCallback> accept_callback_; diff --git a/chromium/ppapi/proxy/tcp_socket_private_resource.cc b/chromium/ppapi/proxy/tcp_socket_private_resource.cc new file mode 100644 index 00000000000..76ed4b9e1e2 --- /dev/null +++ b/chromium/ppapi/proxy/tcp_socket_private_resource.cc @@ -0,0 +1,120 @@ +// Copyright 2013 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/tcp_socket_private_resource.h" + +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppb_tcp_socket_shared.h" + +namespace ppapi { +namespace proxy { + +TCPSocketPrivateResource::TCPSocketPrivateResource(Connection connection, + PP_Instance instance) + : TCPSocketResourceBase(connection, instance, TCP_SOCKET_VERSION_PRIVATE) { + SendCreate(BROWSER, PpapiHostMsg_TCPSocket_CreatePrivate()); +} + +TCPSocketPrivateResource::TCPSocketPrivateResource( + Connection connection, + PP_Instance instance, + int pending_resource_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) + : TCPSocketResourceBase(connection, instance, TCP_SOCKET_VERSION_PRIVATE, + local_addr, remote_addr) { + AttachToPendingHost(BROWSER, pending_resource_id); +} + +TCPSocketPrivateResource::~TCPSocketPrivateResource() { +} + +thunk::PPB_TCPSocket_Private_API* +TCPSocketPrivateResource::AsPPB_TCPSocket_Private_API() { + return this; +} + +int32_t TCPSocketPrivateResource::Connect( + const char* host, + uint16_t port, + scoped_refptr<TrackedCallback> callback) { + return ConnectImpl(host, port, callback); +} + +int32_t TCPSocketPrivateResource::ConnectWithNetAddress( + const PP_NetAddress_Private* addr, + scoped_refptr<TrackedCallback> callback) { + return ConnectWithNetAddressImpl(addr, callback); +} + +PP_Bool TCPSocketPrivateResource::GetLocalAddress( + PP_NetAddress_Private* local_addr) { + return GetLocalAddressImpl(local_addr); +} + +PP_Bool TCPSocketPrivateResource::GetRemoteAddress( + PP_NetAddress_Private* remote_addr) { + return GetRemoteAddressImpl(remote_addr); +} + +int32_t TCPSocketPrivateResource::SSLHandshake( + const char* server_name, + uint16_t server_port, + scoped_refptr<TrackedCallback> callback) { + return SSLHandshakeImpl(server_name, server_port, callback); +} + +PP_Resource TCPSocketPrivateResource::GetServerCertificate() { + return GetServerCertificateImpl(); +} + +PP_Bool TCPSocketPrivateResource::AddChainBuildingCertificate( + PP_Resource certificate, + PP_Bool trusted) { + return AddChainBuildingCertificateImpl(certificate, trusted); +} + +int32_t TCPSocketPrivateResource::Read( + char* buffer, + int32_t bytes_to_read, + scoped_refptr<TrackedCallback> callback) { + return ReadImpl(buffer, bytes_to_read, callback); +} + +int32_t TCPSocketPrivateResource::Write( + const char* buffer, + int32_t bytes_to_write, + scoped_refptr<TrackedCallback> callback) { + return WriteImpl(buffer, bytes_to_write, callback); +} + +void TCPSocketPrivateResource::Disconnect() { + CloseImpl(); +} + +int32_t TCPSocketPrivateResource::SetOption( + PP_TCPSocketOption_Private name, + const PP_Var& value, + scoped_refptr<TrackedCallback> callback) { + switch (name) { + case PP_TCPSOCKETOPTION_PRIVATE_INVALID: + return PP_ERROR_BADARGUMENT; + case PP_TCPSOCKETOPTION_PRIVATE_NO_DELAY: + return SetOptionImpl(PP_TCPSOCKET_OPTION_NO_DELAY, value, callback); + default: + NOTREACHED(); + return PP_ERROR_BADARGUMENT; + } +} + +PP_Resource TCPSocketPrivateResource::CreateAcceptedSocket( + int /* pending_host_id */, + const PP_NetAddress_Private& /* local_addr */, + const PP_NetAddress_Private& /* remote_addr */) { + NOTREACHED(); + return 0; +} + +} // namespace proxy +} // namespace ppapi diff --git a/chromium/ppapi/proxy/tcp_socket_private_resource.h b/chromium/ppapi/proxy/tcp_socket_private_resource.h new file mode 100644 index 00000000000..9ae9bb2d939 --- /dev/null +++ b/chromium/ppapi/proxy/tcp_socket_private_resource.h @@ -0,0 +1,75 @@ +// Copyright 2013 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_PROXY_TCP_SOCKET_PRIVATE_RESOURCE_H_ +#define PPAPI_PROXY_TCP_SOCKET_PRIVATE_RESOURCE_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ppapi/proxy/tcp_socket_resource_base.h" +#include "ppapi/thunk/ppb_tcp_socket_private_api.h" + +namespace ppapi { +namespace proxy { + +class PPAPI_PROXY_EXPORT TCPSocketPrivateResource + : public thunk::PPB_TCPSocket_Private_API, + public TCPSocketResourceBase { + public: + // C-tor used for new sockets. + TCPSocketPrivateResource(Connection connection, PP_Instance instance); + + // C-tor used for already accepted sockets. + TCPSocketPrivateResource(Connection connection, + PP_Instance instance, + int pending_resource_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr); + + virtual ~TCPSocketPrivateResource(); + + // PluginResource overrides. + virtual PPB_TCPSocket_Private_API* AsPPB_TCPSocket_Private_API() OVERRIDE; + + // PPB_TCPSocket_Private_API implementation. + virtual int32_t Connect(const char* host, + uint16_t port, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t ConnectWithNetAddress( + const PP_NetAddress_Private* addr, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual PP_Bool GetLocalAddress(PP_NetAddress_Private* local_addr) OVERRIDE; + virtual PP_Bool GetRemoteAddress(PP_NetAddress_Private* remote_addr) OVERRIDE; + virtual int32_t SSLHandshake( + const char* server_name, + uint16_t server_port, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual PP_Resource GetServerCertificate() OVERRIDE; + virtual PP_Bool AddChainBuildingCertificate(PP_Resource certificate, + PP_Bool trusted) OVERRIDE; + virtual int32_t Read(char* buffer, + int32_t bytes_to_read, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Write(const char* buffer, + int32_t bytes_to_write, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual void Disconnect() OVERRIDE; + virtual int32_t SetOption(PP_TCPSocketOption_Private name, + const PP_Var& value, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + + // TCPSocketResourceBase implementation. + virtual PP_Resource CreateAcceptedSocket( + int pending_host_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(TCPSocketPrivateResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_TCP_SOCKET_PRIVATE_RESOURCE_H_ diff --git a/chromium/ppapi/proxy/tcp_socket_resource.cc b/chromium/ppapi/proxy/tcp_socket_resource.cc new file mode 100644 index 00000000000..f8f8f68f261 --- /dev/null +++ b/chromium/ppapi/proxy/tcp_socket_resource.cc @@ -0,0 +1,133 @@ +// Copyright 2013 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/tcp_socket_resource.h" + +#include "base/logging.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppb_tcp_socket_shared.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_net_address_api.h" + +namespace ppapi { +namespace proxy { + +namespace { + +typedef thunk::EnterResourceNoLock<thunk::PPB_NetAddress_API> + EnterNetAddressNoLock; + +} // namespace + +TCPSocketResource::TCPSocketResource(Connection connection, + PP_Instance instance, + TCPSocketVersion version) + : TCPSocketResourceBase(connection, instance, version) { + DCHECK_NE(version, TCP_SOCKET_VERSION_PRIVATE); + SendCreate(BROWSER, PpapiHostMsg_TCPSocket_Create(version)); +} + +TCPSocketResource::TCPSocketResource(Connection connection, + PP_Instance instance, + int pending_host_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) + : TCPSocketResourceBase(connection, instance, + TCP_SOCKET_VERSION_1_1_OR_ABOVE, local_addr, + remote_addr) { + AttachToPendingHost(BROWSER, pending_host_id); +} + +TCPSocketResource::~TCPSocketResource() { +} + +thunk::PPB_TCPSocket_API* TCPSocketResource::AsPPB_TCPSocket_API() { + return this; +} + +int32_t TCPSocketResource::Bind(PP_Resource addr, + scoped_refptr<TrackedCallback> callback) { + EnterNetAddressNoLock enter(addr, true); + if (enter.failed()) + return PP_ERROR_BADARGUMENT; + + return BindImpl(&enter.object()->GetNetAddressPrivate(), callback); +} + +int32_t TCPSocketResource::Connect(PP_Resource addr, + scoped_refptr<TrackedCallback> callback) { + EnterNetAddressNoLock enter(addr, true); + if (enter.failed()) + return PP_ERROR_BADARGUMENT; + + return ConnectWithNetAddressImpl(&enter.object()->GetNetAddressPrivate(), + callback); +} + +PP_Resource TCPSocketResource::GetLocalAddress() { + PP_NetAddress_Private addr_private; + if (!GetLocalAddressImpl(&addr_private)) + return 0; + + thunk::EnterResourceCreationNoLock enter(pp_instance()); + if (enter.failed()) + return 0; + return enter.functions()->CreateNetAddressFromNetAddressPrivate( + pp_instance(), addr_private); +} + +PP_Resource TCPSocketResource::GetRemoteAddress() { + PP_NetAddress_Private addr_private; + if (!GetRemoteAddressImpl(&addr_private)) + return 0; + + thunk::EnterResourceCreationNoLock enter(pp_instance()); + if (enter.failed()) + return 0; + return enter.functions()->CreateNetAddressFromNetAddressPrivate( + pp_instance(), addr_private); +} + +int32_t TCPSocketResource::Read(char* buffer, + int32_t bytes_to_read, + scoped_refptr<TrackedCallback> callback) { + return ReadImpl(buffer, bytes_to_read, callback); +} + +int32_t TCPSocketResource::Write(const char* buffer, + int32_t bytes_to_write, + scoped_refptr<TrackedCallback> callback) { + return WriteImpl(buffer, bytes_to_write, callback); +} + +int32_t TCPSocketResource::Listen(int32_t backlog, + scoped_refptr<TrackedCallback> callback) { + return ListenImpl(backlog, callback); +} + +int32_t TCPSocketResource::Accept(PP_Resource* accepted_tcp_socket, + scoped_refptr<TrackedCallback> callback) { + return AcceptImpl(accepted_tcp_socket, callback); +} + +void TCPSocketResource::Close() { + CloseImpl(); +} + +int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name, + const PP_Var& value, + scoped_refptr<TrackedCallback> callback) { + return SetOptionImpl(name, value, callback); +} + +PP_Resource TCPSocketResource::CreateAcceptedSocket( + int pending_host_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) { + return (new TCPSocketResource(connection(), pp_instance(), pending_host_id, + local_addr, remote_addr))->GetReference(); +} + +} // namespace proxy +} // namespace ppapi diff --git a/chromium/ppapi/proxy/tcp_socket_resource.h b/chromium/ppapi/proxy/tcp_socket_resource.h new file mode 100644 index 00000000000..5dbfdd54a57 --- /dev/null +++ b/chromium/ppapi/proxy/tcp_socket_resource.h @@ -0,0 +1,74 @@ +// Copyright 2013 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_PROXY_TCP_SOCKET_RESOURCE_H_ +#define PPAPI_PROXY_TCP_SOCKET_RESOURCE_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ppapi/proxy/tcp_socket_resource_base.h" +#include "ppapi/thunk/ppb_tcp_socket_api.h" + +namespace ppapi { + +enum TCPSocketVersion; + +namespace proxy { + +class PPAPI_PROXY_EXPORT TCPSocketResource : public thunk::PPB_TCPSocket_API, + public TCPSocketResourceBase { + public: + // C-tor used for new sockets created. + TCPSocketResource(Connection connection, + PP_Instance instance, + TCPSocketVersion version); + + virtual ~TCPSocketResource(); + + // PluginResource overrides. + virtual thunk::PPB_TCPSocket_API* AsPPB_TCPSocket_API() OVERRIDE; + + // thunk::PPB_TCPSocket_API implementation. + virtual int32_t Bind(PP_Resource addr, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Connect(PP_Resource addr, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual PP_Resource GetLocalAddress() OVERRIDE; + virtual PP_Resource GetRemoteAddress() OVERRIDE; + virtual int32_t Read(char* buffer, + int32_t bytes_to_read, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Write(const char* buffer, + int32_t bytes_to_write, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Listen(int32_t backlog, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Accept(PP_Resource* accepted_tcp_socket, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual void Close() OVERRIDE; + virtual int32_t SetOption(PP_TCPSocket_Option name, + const PP_Var& value, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + + // TCPSocketResourceBase implementation. + virtual PP_Resource CreateAcceptedSocket( + int pending_host_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) OVERRIDE; + + private: + // C-tor used for accepted sockets. + TCPSocketResource(Connection connection, + PP_Instance instance, + int pending_host_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr); + + DISALLOW_COPY_AND_ASSIGN(TCPSocketResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_TCP_SOCKET_RESOURCE_H_ diff --git a/chromium/ppapi/proxy/tcp_socket_resource_base.cc b/chromium/ppapi/proxy/tcp_socket_resource_base.cc new file mode 100644 index 00000000000..6cb9d0b7b51 --- /dev/null +++ b/chromium/ppapi/proxy/tcp_socket_resource_base.cc @@ -0,0 +1,521 @@ +// Copyright 2013 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/tcp_socket_resource_base.h" + +#include <cstring> + +#include "base/bind.h" +#include "base/logging.h" +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/proxy/error_conversion.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" +#include "ppapi/shared_impl/socket_option_data.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/shared_impl/var_tracker.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_x509_certificate_private_api.h" + +namespace ppapi { +namespace proxy { + +const int32_t TCPSocketResourceBase::kMaxReadSize = 1024 * 1024; +const int32_t TCPSocketResourceBase::kMaxWriteSize = 1024 * 1024; +const int32_t TCPSocketResourceBase::kMaxSendBufferSize = + 1024 * TCPSocketResourceBase::kMaxWriteSize; +const int32_t TCPSocketResourceBase::kMaxReceiveBufferSize = + 1024 * TCPSocketResourceBase::kMaxReadSize; + +TCPSocketResourceBase::TCPSocketResourceBase(Connection connection, + PP_Instance instance, + TCPSocketVersion version) + : PluginResource(connection, instance), + state_(TCPSocketState::INITIAL), + read_buffer_(NULL), + bytes_to_read_(-1), + accepted_tcp_socket_(NULL), + version_(version) { + local_addr_.size = 0; + memset(local_addr_.data, 0, + arraysize(local_addr_.data) * sizeof(*local_addr_.data)); + remote_addr_.size = 0; + memset(remote_addr_.data, 0, + arraysize(remote_addr_.data) * sizeof(*remote_addr_.data)); +} + +TCPSocketResourceBase::TCPSocketResourceBase( + Connection connection, + PP_Instance instance, + TCPSocketVersion version, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) + : PluginResource(connection, instance), + state_(TCPSocketState::CONNECTED), + read_buffer_(NULL), + bytes_to_read_(-1), + local_addr_(local_addr), + remote_addr_(remote_addr), + accepted_tcp_socket_(NULL), + version_(version) { +} + +TCPSocketResourceBase::~TCPSocketResourceBase() { + CloseImpl(); +} + +int32_t TCPSocketResourceBase::BindImpl( + const PP_NetAddress_Private* addr, + scoped_refptr<TrackedCallback> callback) { + if (!addr) + return PP_ERROR_BADARGUMENT; + if (state_.IsPending(TCPSocketState::BIND)) + return PP_ERROR_INPROGRESS; + if (!state_.IsValidTransition(TCPSocketState::BIND)) + return PP_ERROR_FAILED; + + bind_callback_ = callback; + state_.SetPendingTransition(TCPSocketState::BIND); + + Call<PpapiPluginMsg_TCPSocket_BindReply>( + BROWSER, + PpapiHostMsg_TCPSocket_Bind(*addr), + base::Bind(&TCPSocketResourceBase::OnPluginMsgBindReply, + base::Unretained(this))); + return PP_OK_COMPLETIONPENDING; +} + +int32_t TCPSocketResourceBase::ConnectImpl( + const char* host, + uint16_t port, + scoped_refptr<TrackedCallback> callback) { + if (!host) + return PP_ERROR_BADARGUMENT; + if (state_.IsPending(TCPSocketState::CONNECT)) + return PP_ERROR_INPROGRESS; + if (!state_.IsValidTransition(TCPSocketState::CONNECT)) + return PP_ERROR_FAILED; + + connect_callback_ = callback; + state_.SetPendingTransition(TCPSocketState::CONNECT); + + Call<PpapiPluginMsg_TCPSocket_ConnectReply>( + BROWSER, + PpapiHostMsg_TCPSocket_Connect(host, port), + base::Bind(&TCPSocketResourceBase::OnPluginMsgConnectReply, + base::Unretained(this))); + return PP_OK_COMPLETIONPENDING; +} + +int32_t TCPSocketResourceBase::ConnectWithNetAddressImpl( + const PP_NetAddress_Private* addr, + scoped_refptr<TrackedCallback> callback) { + if (!addr) + return PP_ERROR_BADARGUMENT; + if (state_.IsPending(TCPSocketState::CONNECT)) + return PP_ERROR_INPROGRESS; + if (!state_.IsValidTransition(TCPSocketState::CONNECT)) + return PP_ERROR_FAILED; + + connect_callback_ = callback; + state_.SetPendingTransition(TCPSocketState::CONNECT); + + Call<PpapiPluginMsg_TCPSocket_ConnectReply>( + BROWSER, + PpapiHostMsg_TCPSocket_ConnectWithNetAddress(*addr), + base::Bind(&TCPSocketResourceBase::OnPluginMsgConnectReply, + base::Unretained(this))); + return PP_OK_COMPLETIONPENDING; +} + +PP_Bool TCPSocketResourceBase::GetLocalAddressImpl( + PP_NetAddress_Private* local_addr) { + if (!state_.IsBound() || !local_addr) + return PP_FALSE; + *local_addr = local_addr_; + return PP_TRUE; +} + +PP_Bool TCPSocketResourceBase::GetRemoteAddressImpl( + PP_NetAddress_Private* remote_addr) { + if (!state_.IsConnected() || !remote_addr) + return PP_FALSE; + *remote_addr = remote_addr_; + return PP_TRUE; +} + +int32_t TCPSocketResourceBase::SSLHandshakeImpl( + const char* server_name, + uint16_t server_port, + scoped_refptr<TrackedCallback> callback) { + if (!server_name) + return PP_ERROR_BADARGUMENT; + + if (state_.IsPending(TCPSocketState::SSL_CONNECT) || + TrackedCallback::IsPending(read_callback_) || + TrackedCallback::IsPending(write_callback_)) { + return PP_ERROR_INPROGRESS; + } + if (!state_.IsValidTransition(TCPSocketState::SSL_CONNECT)) + return PP_ERROR_FAILED; + + ssl_handshake_callback_ = callback; + state_.SetPendingTransition(TCPSocketState::SSL_CONNECT); + + Call<PpapiPluginMsg_TCPSocket_SSLHandshakeReply>( + BROWSER, + PpapiHostMsg_TCPSocket_SSLHandshake(server_name, + server_port, + trusted_certificates_, + untrusted_certificates_), + base::Bind(&TCPSocketResourceBase::OnPluginMsgSSLHandshakeReply, + base::Unretained(this))); + return PP_OK_COMPLETIONPENDING; +} + +PP_Resource TCPSocketResourceBase::GetServerCertificateImpl() { + if (!server_certificate_.get()) + return 0; + return server_certificate_->GetReference(); +} + +PP_Bool TCPSocketResourceBase::AddChainBuildingCertificateImpl( + PP_Resource certificate, + PP_Bool trusted) { + // TODO(raymes): The plumbing for this functionality is implemented but the + // certificates aren't yet used for the connection, so just return false for + // now. + return PP_FALSE; + + thunk::EnterResourceNoLock<thunk::PPB_X509Certificate_Private_API> + enter_cert(certificate, true); + if (enter_cert.failed()) + return PP_FALSE; + + PP_Var der_var = enter_cert.object()->GetField( + PP_X509CERTIFICATE_PRIVATE_RAW); + ArrayBufferVar* der_array_buffer = ArrayBufferVar::FromPPVar(der_var); + PP_Bool success = PP_FALSE; + if (der_array_buffer) { + const char* der_bytes = static_cast<const char*>(der_array_buffer->Map()); + uint32_t der_length = der_array_buffer->ByteLength(); + std::vector<char> der(der_bytes, der_bytes + der_length); + if (PP_ToBool(trusted)) + trusted_certificates_.push_back(der); + else + untrusted_certificates_.push_back(der); + success = PP_TRUE; + } + PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(der_var); + return success; +} + +int32_t TCPSocketResourceBase::ReadImpl( + char* buffer, + int32_t bytes_to_read, + scoped_refptr<TrackedCallback> callback) { + if (!buffer || bytes_to_read <= 0) + return PP_ERROR_BADARGUMENT; + + if (!state_.IsConnected()) + return PP_ERROR_FAILED; + if (TrackedCallback::IsPending(read_callback_) || + state_.IsPending(TCPSocketState::SSL_CONNECT)) + return PP_ERROR_INPROGRESS; + read_buffer_ = buffer; + bytes_to_read_ = std::min(bytes_to_read, kMaxReadSize); + read_callback_ = callback; + + Call<PpapiPluginMsg_TCPSocket_ReadReply>( + BROWSER, + PpapiHostMsg_TCPSocket_Read(bytes_to_read_), + base::Bind(&TCPSocketResourceBase::OnPluginMsgReadReply, + base::Unretained(this))); + return PP_OK_COMPLETIONPENDING; +} + +int32_t TCPSocketResourceBase::WriteImpl( + const char* buffer, + int32_t bytes_to_write, + scoped_refptr<TrackedCallback> callback) { + if (!buffer || bytes_to_write <= 0) + return PP_ERROR_BADARGUMENT; + + if (!state_.IsConnected()) + return PP_ERROR_FAILED; + if (TrackedCallback::IsPending(write_callback_) || + state_.IsPending(TCPSocketState::SSL_CONNECT)) + return PP_ERROR_INPROGRESS; + + if (bytes_to_write > kMaxWriteSize) + bytes_to_write = kMaxWriteSize; + + write_callback_ = callback; + + Call<PpapiPluginMsg_TCPSocket_WriteReply>( + BROWSER, + PpapiHostMsg_TCPSocket_Write(std::string(buffer, bytes_to_write)), + base::Bind(&TCPSocketResourceBase::OnPluginMsgWriteReply, + base::Unretained(this))); + return PP_OK_COMPLETIONPENDING; +} + +int32_t TCPSocketResourceBase::ListenImpl( + int32_t backlog, + scoped_refptr<TrackedCallback> callback) { + if (backlog <= 0) + return PP_ERROR_BADARGUMENT; + if (state_.IsPending(TCPSocketState::LISTEN)) + return PP_ERROR_INPROGRESS; + if (!state_.IsValidTransition(TCPSocketState::LISTEN)) + return PP_ERROR_FAILED; + + listen_callback_ = callback; + state_.SetPendingTransition(TCPSocketState::LISTEN); + + Call<PpapiPluginMsg_TCPSocket_ListenReply>( + BROWSER, + PpapiHostMsg_TCPSocket_Listen(backlog), + base::Bind(&TCPSocketResourceBase::OnPluginMsgListenReply, + base::Unretained(this))); + return PP_OK_COMPLETIONPENDING; +} + +int32_t TCPSocketResourceBase::AcceptImpl( + PP_Resource* accepted_tcp_socket, + scoped_refptr<TrackedCallback> callback) { + if (!accepted_tcp_socket) + return PP_ERROR_BADARGUMENT; + if (TrackedCallback::IsPending(accept_callback_)) + return PP_ERROR_INPROGRESS; + if (state_.state() != TCPSocketState::LISTENING) + return PP_ERROR_FAILED; + + accept_callback_ = callback; + accepted_tcp_socket_ = accepted_tcp_socket; + + Call<PpapiPluginMsg_TCPSocket_AcceptReply>( + BROWSER, + PpapiHostMsg_TCPSocket_Accept(), + base::Bind(&TCPSocketResourceBase::OnPluginMsgAcceptReply, + base::Unretained(this))); + return PP_OK_COMPLETIONPENDING; +} + +void TCPSocketResourceBase::CloseImpl() { + if (state_.state() == TCPSocketState::CLOSED) + return; + + state_.DoTransition(TCPSocketState::CLOSE, true); + + Post(BROWSER, PpapiHostMsg_TCPSocket_Close()); + + PostAbortIfNecessary(&bind_callback_); + PostAbortIfNecessary(&connect_callback_); + PostAbortIfNecessary(&ssl_handshake_callback_); + PostAbortIfNecessary(&read_callback_); + PostAbortIfNecessary(&write_callback_); + PostAbortIfNecessary(&listen_callback_); + PostAbortIfNecessary(&accept_callback_); + read_buffer_ = NULL; + bytes_to_read_ = -1; + server_certificate_ = NULL; + accepted_tcp_socket_ = NULL; +} + +int32_t TCPSocketResourceBase::SetOptionImpl( + PP_TCPSocket_Option name, + const PP_Var& value, + scoped_refptr<TrackedCallback> callback) { + SocketOptionData option_data; + switch (name) { + case PP_TCPSOCKET_OPTION_NO_DELAY: { + if (!state_.IsConnected()) + return PP_ERROR_FAILED; + + if (value.type != PP_VARTYPE_BOOL) + return PP_ERROR_BADARGUMENT; + option_data.SetBool(PP_ToBool(value.value.as_bool)); + break; + } + case PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE: + case PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE: { + if (!state_.IsConnected()) + return PP_ERROR_FAILED; + + if (value.type != PP_VARTYPE_INT32) + return PP_ERROR_BADARGUMENT; + option_data.SetInt32(value.value.as_int); + break; + } + default: { + NOTREACHED(); + return PP_ERROR_BADARGUMENT; + } + } + + set_option_callbacks_.push(callback); + + Call<PpapiPluginMsg_TCPSocket_SetOptionReply>( + BROWSER, + PpapiHostMsg_TCPSocket_SetOption(name, option_data), + base::Bind(&TCPSocketResourceBase::OnPluginMsgSetOptionReply, + base::Unretained(this))); + return PP_OK_COMPLETIONPENDING; +} + +void TCPSocketResourceBase::PostAbortIfNecessary( + scoped_refptr<TrackedCallback>* callback) { + if (TrackedCallback::IsPending(*callback)) + (*callback)->PostAbort(); +} + +void TCPSocketResourceBase::OnPluginMsgBindReply( + const ResourceMessageReplyParams& params, + const PP_NetAddress_Private& local_addr) { + // It is possible that CloseImpl() has been called. We don't want to update + // class members in this case. + if (!state_.IsPending(TCPSocketState::BIND)) + return; + + DCHECK(TrackedCallback::IsPending(bind_callback_)); + if (params.result() == PP_OK) { + local_addr_ = local_addr; + state_.CompletePendingTransition(true); + } else { + state_.CompletePendingTransition(false); + } + RunCallback(bind_callback_, params.result()); +} + +void TCPSocketResourceBase::OnPluginMsgConnectReply( + const ResourceMessageReplyParams& params, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) { + // It is possible that CloseImpl() has been called. We don't want to update + // class members in this case. + if (!state_.IsPending(TCPSocketState::CONNECT)) + return; + + DCHECK(TrackedCallback::IsPending(connect_callback_)); + if (params.result() == PP_OK) { + local_addr_ = local_addr; + remote_addr_ = remote_addr; + state_.CompletePendingTransition(true); + } else { + if (version_ == TCP_SOCKET_VERSION_1_1_OR_ABOVE) { + state_.CompletePendingTransition(false); + } else { + // In order to maintain backward compatibility, allow to connect the + // socket again. + state_ = TCPSocketState(TCPSocketState::INITIAL); + } + } + RunCallback(connect_callback_, params.result()); +} + +void TCPSocketResourceBase::OnPluginMsgSSLHandshakeReply( + const ResourceMessageReplyParams& params, + const PPB_X509Certificate_Fields& certificate_fields) { + // It is possible that CloseImpl() has been called. We don't want to + // update class members in this case. + if (!state_.IsPending(TCPSocketState::SSL_CONNECT)) + return; + + DCHECK(TrackedCallback::IsPending(ssl_handshake_callback_)); + if (params.result() == PP_OK) { + state_.CompletePendingTransition(true); + server_certificate_ = new PPB_X509Certificate_Private_Shared( + OBJECT_IS_PROXY, + pp_instance(), + certificate_fields); + } else { + state_.CompletePendingTransition(false); + } + RunCallback(ssl_handshake_callback_, params.result()); +} + +void TCPSocketResourceBase::OnPluginMsgReadReply( + const ResourceMessageReplyParams& params, + const std::string& data) { + // It is possible that CloseImpl() has been called. We shouldn't access the + // buffer in that case. The user may have released it. + if (!state_.IsConnected() || !TrackedCallback::IsPending(read_callback_) || + !read_buffer_) { + return; + } + + const bool succeeded = params.result() == PP_OK; + if (succeeded) { + CHECK_LE(static_cast<int32_t>(data.size()), bytes_to_read_); + if (!data.empty()) + memmove(read_buffer_, data.c_str(), data.size()); + } + read_buffer_ = NULL; + bytes_to_read_ = -1; + + RunCallback(read_callback_, + succeeded ? static_cast<int32_t>(data.size()) : params.result()); +} + +void TCPSocketResourceBase::OnPluginMsgWriteReply( + const ResourceMessageReplyParams& params) { + if (!state_.IsConnected() || !TrackedCallback::IsPending(write_callback_)) + return; + RunCallback(write_callback_, params.result()); +} + +void TCPSocketResourceBase::OnPluginMsgListenReply( + const ResourceMessageReplyParams& params) { + if (!state_.IsPending(TCPSocketState::LISTEN)) + return; + + DCHECK(TrackedCallback::IsPending(listen_callback_)); + state_.CompletePendingTransition(params.result() == PP_OK); + + RunCallback(listen_callback_, params.result()); +} + +void TCPSocketResourceBase::OnPluginMsgAcceptReply( + const ResourceMessageReplyParams& params, + int pending_host_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) { + // It is possible that CloseImpl() has been called. We shouldn't access the + // output parameter in that case. The user may have released it. + if (state_.state() != TCPSocketState::LISTENING || + !TrackedCallback::IsPending(accept_callback_) || !accepted_tcp_socket_) { + return; + } + + if (params.result() == PP_OK) { + *accepted_tcp_socket_ = CreateAcceptedSocket(pending_host_id, local_addr, + remote_addr); + } + accepted_tcp_socket_ = NULL; + RunCallback(accept_callback_, params.result()); +} + +void TCPSocketResourceBase::OnPluginMsgSetOptionReply( + const ResourceMessageReplyParams& params) { + if (set_option_callbacks_.empty()) { + NOTREACHED(); + return; + } + scoped_refptr<TrackedCallback> callback = set_option_callbacks_.front(); + set_option_callbacks_.pop(); + if (TrackedCallback::IsPending(callback)) + RunCallback(callback, params.result()); +} + +void TCPSocketResourceBase::RunCallback(scoped_refptr<TrackedCallback> callback, + int32_t pp_result) { + callback->Run(ConvertNetworkAPIErrorForCompatibility( + pp_result, version_ == TCP_SOCKET_VERSION_PRIVATE)); +} + +} // namespace ppapi +} // namespace proxy diff --git a/chromium/ppapi/proxy/tcp_socket_resource_base.h b/chromium/ppapi/proxy/tcp_socket_resource_base.h new file mode 100644 index 00000000000..8835ab974b1 --- /dev/null +++ b/chromium/ppapi/proxy/tcp_socket_resource_base.h @@ -0,0 +1,155 @@ +// Copyright 2013 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_PROXY_TCP_SOCKET_RESOURCE_BASE_H_ +#define PPAPI_PROXY_TCP_SOCKET_RESOURCE_BASE_H_ + +#include <queue> +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "ppapi/c/ppb_tcp_socket.h" +#include "ppapi/c/private/ppb_net_address_private.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/shared_impl/ppb_tcp_socket_shared.h" +#include "ppapi/shared_impl/tracked_callback.h" + +namespace ppapi { + +class PPB_X509Certificate_Fields; +class PPB_X509Certificate_Private_Shared; +class SocketOptionData; + +namespace proxy { + +class PPAPI_PROXY_EXPORT TCPSocketResourceBase : public PluginResource { + public: + // TODO(yzshen): Move these constants to ppb_tcp_socket_shared. + // The maximum number of bytes that each PpapiHostMsg_PPBTCPSocket_Read + // message is allowed to request. + static const int32_t kMaxReadSize; + // The maximum number of bytes that each PpapiHostMsg_PPBTCPSocket_Write + // message is allowed to carry. + static const int32_t kMaxWriteSize; + + // The maximum number that we allow for setting + // PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE. This number is only for input + // argument sanity check, it doesn't mean the browser guarantees to support + // such a buffer size. + static const int32_t kMaxSendBufferSize; + // The maximum number that we allow for setting + // PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE. This number is only for input + // argument sanity check, it doesn't mean the browser guarantees to support + // such a buffer size. + static const int32_t kMaxReceiveBufferSize; + + protected: + // C-tor used for new sockets. + TCPSocketResourceBase(Connection connection, + PP_Instance instance, + TCPSocketVersion version); + + // C-tor used for already accepted sockets. + TCPSocketResourceBase(Connection connection, + PP_Instance instance, + TCPSocketVersion version, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr); + + virtual ~TCPSocketResourceBase(); + + // Implemented by subclasses to create resources for accepted sockets. + virtual PP_Resource CreateAcceptedSocket( + int pending_host_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr) = 0; + + int32_t BindImpl(const PP_NetAddress_Private* addr, + scoped_refptr<TrackedCallback> callback); + int32_t ConnectImpl(const char* host, + uint16_t port, + scoped_refptr<TrackedCallback> callback); + int32_t ConnectWithNetAddressImpl(const PP_NetAddress_Private* addr, + scoped_refptr<TrackedCallback> callback); + PP_Bool GetLocalAddressImpl(PP_NetAddress_Private* local_addr); + PP_Bool GetRemoteAddressImpl(PP_NetAddress_Private* remote_addr); + int32_t SSLHandshakeImpl(const char* server_name, + uint16_t server_port, + scoped_refptr<TrackedCallback> callback); + PP_Resource GetServerCertificateImpl(); + PP_Bool AddChainBuildingCertificateImpl(PP_Resource certificate, + PP_Bool trusted); + int32_t ReadImpl(char* buffer, + int32_t bytes_to_read, + scoped_refptr<TrackedCallback> callback); + int32_t WriteImpl(const char* buffer, + int32_t bytes_to_write, + scoped_refptr<TrackedCallback> callback); + int32_t ListenImpl(int32_t backlog, scoped_refptr<TrackedCallback> callback); + int32_t AcceptImpl(PP_Resource* accepted_tcp_socket, + scoped_refptr<TrackedCallback> callback); + void CloseImpl(); + int32_t SetOptionImpl(PP_TCPSocket_Option name, + const PP_Var& value, + scoped_refptr<TrackedCallback> callback); + + void PostAbortIfNecessary(scoped_refptr<TrackedCallback>* callback); + + // IPC message handlers. + void OnPluginMsgBindReply(const ResourceMessageReplyParams& params, + const PP_NetAddress_Private& local_addr); + void OnPluginMsgConnectReply(const ResourceMessageReplyParams& params, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr); + void OnPluginMsgSSLHandshakeReply( + const ResourceMessageReplyParams& params, + const PPB_X509Certificate_Fields& certificate_fields); + void OnPluginMsgReadReply(const ResourceMessageReplyParams& params, + const std::string& data); + void OnPluginMsgWriteReply(const ResourceMessageReplyParams& params); + void OnPluginMsgListenReply(const ResourceMessageReplyParams& params); + void OnPluginMsgAcceptReply(const ResourceMessageReplyParams& params, + int pending_host_id, + const PP_NetAddress_Private& local_addr, + const PP_NetAddress_Private& remote_addr); + void OnPluginMsgSetOptionReply(const ResourceMessageReplyParams& params); + + scoped_refptr<TrackedCallback> bind_callback_; + scoped_refptr<TrackedCallback> connect_callback_; + scoped_refptr<TrackedCallback> ssl_handshake_callback_; + scoped_refptr<TrackedCallback> read_callback_; + scoped_refptr<TrackedCallback> write_callback_; + scoped_refptr<TrackedCallback> listen_callback_; + scoped_refptr<TrackedCallback> accept_callback_; + std::queue<scoped_refptr<TrackedCallback> > set_option_callbacks_; + + TCPSocketState state_; + char* read_buffer_; + int32_t bytes_to_read_; + + PP_NetAddress_Private local_addr_; + PP_NetAddress_Private remote_addr_; + + scoped_refptr<PPB_X509Certificate_Private_Shared> server_certificate_; + + std::vector<std::vector<char> > trusted_certificates_; + std::vector<std::vector<char> > untrusted_certificates_; + + PP_Resource* accepted_tcp_socket_; + + private: + void RunCallback(scoped_refptr<TrackedCallback> callback, int32_t pp_result); + + TCPSocketVersion version_; + + DISALLOW_COPY_AND_ASSIGN(TCPSocketResourceBase); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_TCP_SOCKET_RESOURCE_BASE_H_ diff --git a/chromium/ppapi/proxy/udp_socket_resource_base.cc b/chromium/ppapi/proxy/udp_socket_resource_base.cc index 166f2e30856..8ef3835feca 100644 --- a/chromium/ppapi/proxy/udp_socket_resource_base.cc +++ b/chromium/ppapi/proxy/udp_socket_resource_base.cc @@ -11,6 +11,7 @@ #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/proxy/error_conversion.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/socket_option_data.h" #include "ppapi/thunk/enter.h" @@ -19,23 +20,6 @@ namespace ppapi { namespace proxy { -namespace { - -int32_t ConvertPPError(int32_t pp_error, bool private_api) { - // The private API doesn't return network-specific error codes or - // PP_ERROR_NOACCESS. In order to preserve the behavior, we convert those to - // PP_ERROR_FAILED. - if (private_api && - (pp_error <= PP_ERROR_CONNECTION_CLOSED || - pp_error == PP_ERROR_NOACCESS)) { - return PP_ERROR_FAILED; - } - - return pp_error; -} - -} // namespace - const int32_t UDPSocketResourceBase::kMaxReadSize = 1024 * 1024; const int32_t UDPSocketResourceBase::kMaxWriteSize = 1024 * 1024; const int32_t UDPSocketResourceBase::kMaxSendBufferSize = @@ -227,7 +211,7 @@ void UDPSocketResourceBase::OnPluginMsgSetOptionReply( scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params) { if (TrackedCallback::IsPending(callback)) - callback->Run(ConvertPPError(params.result(), private_api_)); + RunCallback(callback, params.result()); } void UDPSocketResourceBase::OnPluginMsgBindReply( @@ -243,7 +227,7 @@ void UDPSocketResourceBase::OnPluginMsgBindReply( if (params.result() == PP_OK) bound_ = true; bound_addr_ = bound_addr; - bind_callback_->Run(ConvertPPError(params.result(), private_api_)); + RunCallback(bind_callback_, params.result()); } void UDPSocketResourceBase::OnPluginMsgRecvFromReply( @@ -280,9 +264,9 @@ void UDPSocketResourceBase::OnPluginMsgRecvFromReply( recvfrom_addr_ = addr; if (result == PP_OK) - recvfrom_callback_->Run(static_cast<int32_t>(data.size())); + RunCallback(recvfrom_callback_, static_cast<int32_t>(data.size())); else - recvfrom_callback_->Run(ConvertPPError(result, private_api_)); + RunCallback(recvfrom_callback_, result); } void UDPSocketResourceBase::OnPluginMsgSendToReply( @@ -292,9 +276,15 @@ void UDPSocketResourceBase::OnPluginMsgSendToReply( return; if (params.result() == PP_OK) - sendto_callback_->Run(bytes_written); + RunCallback(sendto_callback_, bytes_written); else - sendto_callback_->Run(ConvertPPError(params.result(), private_api_)); + RunCallback(sendto_callback_, params.result()); +} + +void UDPSocketResourceBase::RunCallback(scoped_refptr<TrackedCallback> callback, + int32_t pp_result) { + callback->Run(ConvertNetworkAPIErrorForCompatibility(pp_result, + private_api_)); } } // namespace proxy diff --git a/chromium/ppapi/proxy/udp_socket_resource_base.h b/chromium/ppapi/proxy/udp_socket_resource_base.h index 925475e0e1a..978e774d404 100644 --- a/chromium/ppapi/proxy/udp_socket_resource_base.h +++ b/chromium/ppapi/proxy/udp_socket_resource_base.h @@ -80,6 +80,8 @@ class PPAPI_PROXY_EXPORT UDPSocketResourceBase: public PluginResource { void OnPluginMsgSendToReply(const ResourceMessageReplyParams& params, int32_t bytes_written); + void RunCallback(scoped_refptr<TrackedCallback> callback, int32_t pp_result); + bool private_api_; bool bound_; bool closed_; diff --git a/chromium/ppapi/proxy/url_loader_resource.cc b/chromium/ppapi/proxy/url_loader_resource.cc index 5bbc9372ff2..1ff0a5e1a98 100644 --- a/chromium/ppapi/proxy/url_loader_resource.cc +++ b/chromium/ppapi/proxy/url_loader_resource.cc @@ -9,8 +9,8 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_url_loader.h" #include "ppapi/proxy/dispatch_reply_message.h" +#include "ppapi/proxy/file_ref_resource.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/url_request_info_resource.h" #include "ppapi/proxy/url_response_info_resource.h" #include "ppapi/shared_impl/ppapi_globals.h" @@ -158,9 +158,14 @@ int32_t URLLoaderResource::ReadResponseBody( int32_t rv = ValidateCallback(callback); if (rv != PP_OK) return rv; - if (!response_info_.get() || - !response_info_->data().body_as_file_ref.resource.is_null()) + if (!response_info_.get()) return PP_ERROR_FAILED; + + // Fail if we have a valid file ref. + // ReadResponseBody() is for reading to a user-provided buffer. + if (response_info_->data().body_as_file_ref.IsValid()) + return PP_ERROR_FAILED; + if (bytes_to_read <= 0 || !buffer) return PP_ERROR_BADARGUMENT; @@ -186,8 +191,11 @@ int32_t URLLoaderResource::FinishStreamingToFile( int32_t rv = ValidateCallback(callback); if (rv != PP_OK) return rv; - if (!response_info_.get() || - response_info_->data().body_as_file_ref.resource.is_null()) + if (!response_info_.get()) + return PP_ERROR_FAILED; + + // Fail if we do not have a valid file ref. + if (!response_info_->data().body_as_file_ref.IsValid()) return PP_ERROR_FAILED; // We may have already reached EOF. @@ -357,10 +365,10 @@ void URLLoaderResource::RunCallback(int32_t result) { void URLLoaderResource::SaveResponseInfo(const URLResponseInfoData& data) { // Create a proxy resource for the the file ref host resource if needed. PP_Resource body_as_file_ref = 0; - if (!data.body_as_file_ref.resource.is_null()) { - thunk::EnterResourceCreationNoLock enter(pp_instance()); - body_as_file_ref = - enter.functions()->CreateFileRef(data.body_as_file_ref); + if (data.body_as_file_ref.IsValid()) { + body_as_file_ref = FileRefResource::CreateFileRef(connection(), + pp_instance(), + data.body_as_file_ref); } response_info_ = new URLResponseInfoResource( connection(), pp_instance(), data, body_as_file_ref); @@ -389,4 +397,4 @@ size_t URLLoaderResource::FillUserBuffer() { } } // namespace proxy -} // namespace ppapi
\ No newline at end of file +} // namespace ppapi diff --git a/chromium/ppapi/proxy/url_loader_resource.h b/chromium/ppapi/proxy/url_loader_resource.h index 685ccfe1243..f4a80dacd9f 100644 --- a/chromium/ppapi/proxy/url_loader_resource.h +++ b/chromium/ppapi/proxy/url_loader_resource.h @@ -143,4 +143,4 @@ class PPAPI_PROXY_EXPORT URLLoaderResource } // namespace proxy } // namespace ppapi -#endif // PPAPI_PROXY_URL_LOADER_RESOURCE_H_
\ No newline at end of file +#endif // PPAPI_PROXY_URL_LOADER_RESOURCE_H_ diff --git a/chromium/ppapi/proxy/url_response_info_resource.cc b/chromium/ppapi/proxy/url_response_info_resource.cc index 85dae9a1aef..315b4a109d3 100644 --- a/chromium/ppapi/proxy/url_response_info_resource.cc +++ b/chromium/ppapi/proxy/url_response_info_resource.cc @@ -4,7 +4,7 @@ #include "ppapi/proxy/url_response_info_resource.h" -#include "ppapi/proxy/ppb_file_ref_proxy.h" +#include "ppapi/proxy/file_ref_resource.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/resource_creation_api.h" |