diff options
Diffstat (limited to 'ppapi/proxy')
26 files changed, 452 insertions, 507 deletions
diff --git a/ppapi/proxy/enter_proxy.h b/ppapi/proxy/enter_proxy.h deleted file mode 100644 index 6e52705..0000000 --- a/ppapi/proxy/enter_proxy.h +++ /dev/null @@ -1,58 +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_ENTER_PROXY_H_ -#define PPAPI_PROXY_ENTER_PROXY_H_ - -#include "base/logging.h" -#include "ppapi/proxy/host_dispatcher.h" -#include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/plugin_resource_tracker.h" -#include "ppapi/thunk/enter.h" - -namespace pp { -namespace proxy { - -// Wrapper around EnterResourceNoLock that takes a host resource. This is used -// when handling messages in the plugin from the host and we need to convert to -// an object in the plugin side corresponding to that. -// -// This never locks since we assume the host Resource is coming from IPC, and -// never logs errors since we assume the host is doing reasonable things. -template<typename ResourceT> -class EnterPluginFromHostResource - : public ::ppapi::thunk::EnterResourceNoLock<ResourceT> { - public: - EnterPluginFromHostResource(const HostResource& host_resource) - : ::ppapi::thunk::EnterResourceNoLock<ResourceT>( - PluginResourceTracker::GetInstance()->PluginResourceForHostResource( - host_resource), - false) { - // Validate that we're in the plugin rather than the host. Otherwise this - // object will do the wrong thing. In the plugin, the instance should have - // a corresponding plugin dispatcher (assuming the resource is valid). - DCHECK(this->failed() || - PluginDispatcher::GetForInstance(host_resource.instance())); - } -}; - -template<typename ResourceT> -class EnterHostFromHostResource - : public ::ppapi::thunk::EnterResourceNoLock<ResourceT> { - public: - EnterHostFromHostResource(const HostResource& host_resource) - : ::ppapi::thunk::EnterResourceNoLock<ResourceT>( - host_resource.host_resource(), false) { - // Validate that we're in the host rather than the plugin. Otherwise this - // object will do the wrong thing. In the host, the instance should have - // a corresponding host disptacher (assuming the resource is valid). - DCHECK(this->failed() || - HostDispatcher::GetForInstance(host_resource.instance())); - } -}; - -} // namespace proxy -} // namespace pp - -#endif // PPAPI_PROXY_ENTER_PROXY_H_ diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h index 7363340..039008c 100644 --- a/ppapi/proxy/interface_id.h +++ b/ppapi/proxy/interface_id.h @@ -26,7 +26,6 @@ enum InterfaceID { INTERFACE_ID_PPB_FILE_CHOOSER, INTERFACE_ID_PPB_FILE_REF, INTERFACE_ID_PPB_FILE_SYSTEM, - INTERFACE_ID_PPB_FIND, INTERFACE_ID_PPB_FLASH, INTERFACE_ID_PPB_FLASH_CLIPBOARD, INTERFACE_ID_PPB_FLASH_FILE_FILEREF, diff --git a/ppapi/proxy/plugin_resource_tracker.cc b/ppapi/proxy/plugin_resource_tracker.cc index e1726cf..a6e087f 100644 --- a/ppapi/proxy/plugin_resource_tracker.cc +++ b/ppapi/proxy/plugin_resource_tracker.cc @@ -139,14 +139,6 @@ PP_Resource PluginResourceTracker::PluginResourceForHostResource( return NULL; } -PP_Instance PluginResourceTracker::GetInstanceForResource( - PP_Resource resource) { - ResourceMap::iterator found = resource_map_.find(resource); - if (found == resource_map_.end()) - return 0; - return found->second.resource->instance(); -} - void PluginResourceTracker::ReleasePluginResourceRef( const PP_Resource& resource, bool notify_browser_on_release) { diff --git a/ppapi/proxy/plugin_resource_tracker.h b/ppapi/proxy/plugin_resource_tracker.h index c00d3f2..5dfdf82 100644 --- a/ppapi/proxy/plugin_resource_tracker.h +++ b/ppapi/proxy/plugin_resource_tracker.h @@ -8,7 +8,6 @@ #include <map> #include <utility> -#include "base/compiler_specific.h" #include "base/memory/linked_ptr.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_instance.h" @@ -57,11 +56,10 @@ class PluginResourceTracker : public ::ppapi::TrackerBase { // TrackerBase. virtual ::ppapi::ResourceObjectBase* GetResourceAPI( - PP_Resource res) OVERRIDE; + PP_Resource res); virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( PP_Instance inst, - pp::proxy::InterfaceID id) OVERRIDE; - virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE; + pp::proxy::InterfaceID id); private: friend struct DefaultSingletonTraits<PluginResourceTracker>; diff --git a/ppapi/proxy/ppb_audio_config_proxy.cc b/ppapi/proxy/ppb_audio_config_proxy.cc index e8eb056..8e78ecd 100644 --- a/ppapi/proxy/ppb_audio_config_proxy.cc +++ b/ppapi/proxy/ppb_audio_config_proxy.cc @@ -23,7 +23,7 @@ class AudioConfig : public PluginResource, virtual ~AudioConfig(); // ResourceObjectBase overrides. - virtual ::ppapi::thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; + virtual ::ppapi::thunk::PPB_AudioConfig_API* AsAudioConfig_API() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(AudioConfig); @@ -36,7 +36,7 @@ AudioConfig::AudioConfig(const HostResource& resource) AudioConfig::~AudioConfig() { } -::ppapi::thunk::PPB_AudioConfig_API* AudioConfig::AsPPB_AudioConfig_API() { +::ppapi::thunk::PPB_AudioConfig_API* AudioConfig::AsAudioConfig_API() { return this; } diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc index 22ddddd..6c2cc7a 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -10,7 +10,6 @@ #include "ppapi/c/ppb_audio_config.h" #include "ppapi/c/ppb_var.h" #include "ppapi/c/trusted/ppb_audio_trusted.h" -#include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/interface_id.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" @@ -22,8 +21,6 @@ #include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" -using ::ppapi::thunk::PPB_Audio_API; - namespace pp { namespace proxy { @@ -36,7 +33,7 @@ class Audio : public PluginResource, public ppapi::AudioImpl { virtual ~Audio(); // ResourceObjectBase overrides. - virtual PPB_Audio_API* AsPPB_Audio_API(); + virtual ::ppapi::thunk::PPB_Audio_API* AsAudio_API(); // PPB_Audio_API implementation. virtual PP_Resource GetCurrentConfig() OVERRIDE; @@ -65,7 +62,7 @@ Audio::~Audio() { PluginResourceTracker::GetInstance()->ReleaseResource(config_); } -PPB_Audio_API* Audio::AsPPB_Audio_API() { +::ppapi::thunk::PPB_Audio_API* Audio::AsAudio_API() { return this; } @@ -235,7 +232,11 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( IPC::PlatformFileForTransit socket_handle, base::SharedMemoryHandle handle, uint32_t length) { - EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); + PP_Resource plugin_resource = + PluginResourceTracker::GetInstance()->PluginResourceForHostResource( + audio_id); + ppapi::thunk::EnterResource<ppapi::thunk::PPB_Audio_API> enter( + plugin_resource, false); if (enter.failed() || result_code != PP_OK) { // The caller may still have given us these handles in the failure case. // The easiest way to clean these up is to just put them in the objects @@ -243,11 +244,11 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( base::SyncSocket temp_socket( IPC::PlatformFileForTransitToPlatformFile(socket_handle)); base::SharedMemory temp_mem(handle, false); - } else { - static_cast<Audio*>(enter.object())->SetStreamInfo( - handle, length, - IPC::PlatformFileForTransitToPlatformFile(socket_handle)); + return; } + Audio* audio = static_cast<Audio*>(enter.object()); + audio->SetStreamInfo( + handle, length, IPC::PlatformFileForTransitToPlatformFile(socket_handle)); } void PPB_Audio_Proxy::AudioChannelConnected( diff --git a/ppapi/proxy/ppb_broker_proxy.cc b/ppapi/proxy/ppb_broker_proxy.cc index 97fe0d0..74aa4a2 100644 --- a/ppapi/proxy/ppb_broker_proxy.cc +++ b/ppapi/proxy/ppb_broker_proxy.cc @@ -52,7 +52,7 @@ class Broker : public ppapi::thunk::PPB_Broker_API, virtual ~Broker(); // ResourceObjectBase overries. - virtual ppapi::thunk::PPB_Broker_API* AsPPB_Broker_API() OVERRIDE; + virtual ppapi::thunk::PPB_Broker_API* AsBroker_API() OVERRIDE; // PPB_Broker_API implementation. virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE; @@ -95,7 +95,7 @@ Broker::~Broker() { socket_handle_ = base::kInvalidPlatformFileValue; } -ppapi::thunk::PPB_Broker_API* Broker::AsPPB_Broker_API() { +ppapi::thunk::PPB_Broker_API* Broker::AsBroker_API() { return this; } diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc index 5c2fd8a..d6f910f 100644 --- a/ppapi/proxy/ppb_buffer_proxy.cc +++ b/ppapi/proxy/ppb_buffer_proxy.cc @@ -41,7 +41,7 @@ class Buffer : public ppapi::thunk::PPB_Buffer_API, virtual Buffer* AsBuffer() OVERRIDE; // ResourceObjectBase overries. - virtual ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE; + virtual ppapi::thunk::PPB_Buffer_API* AsBuffer_API() OVERRIDE; // PPB_Buffer_API implementation. virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE; @@ -75,7 +75,7 @@ Buffer* Buffer::AsBuffer() { return this; } -ppapi::thunk::PPB_Buffer_API* Buffer::AsPPB_Buffer_API() { +ppapi::thunk::PPB_Buffer_API* Buffer::AsBuffer_API() { return this; } diff --git a/ppapi/proxy/ppb_char_set_proxy.cc b/ppapi/proxy/ppb_char_set_proxy.cc index 1887549..a896693 100644 --- a/ppapi/proxy/ppb_char_set_proxy.cc +++ b/ppapi/proxy/ppb_char_set_proxy.cc @@ -52,7 +52,7 @@ const InterfaceProxy::Info* PPB_CharSet_Proxy::GetInfo() { } ppapi::thunk::PPB_CharSet_FunctionAPI* -PPB_CharSet_Proxy::AsPPB_CharSet_FunctionAPI() { +PPB_CharSet_Proxy::AsCharSet_FunctionAPI() { return this; } diff --git a/ppapi/proxy/ppb_char_set_proxy.h b/ppapi/proxy/ppb_char_set_proxy.h index 0f70ab5..b64884c 100644 --- a/ppapi/proxy/ppb_char_set_proxy.h +++ b/ppapi/proxy/ppb_char_set_proxy.h @@ -29,7 +29,7 @@ class PPB_CharSet_Proxy : public ppapi::FunctionGroupBase, static const Info* GetInfo(); // FunctionGroupBase overrides. - virtual ppapi::thunk::PPB_CharSet_FunctionAPI* AsPPB_CharSet_FunctionAPI() + virtual ppapi::thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI() OVERRIDE; // PPB_CharSet_FunctionAPI implementation. diff --git a/ppapi/proxy/ppb_cursor_control_proxy.cc b/ppapi/proxy/ppb_cursor_control_proxy.cc index 993efe8..37619b7 100644 --- a/ppapi/proxy/ppb_cursor_control_proxy.cc +++ b/ppapi/proxy/ppb_cursor_control_proxy.cc @@ -49,7 +49,7 @@ const InterfaceProxy::Info* PPB_CursorControl_Proxy::GetInfo() { } ppapi::thunk::PPB_CursorControl_FunctionAPI* -PPB_CursorControl_Proxy::AsPPB_CursorControl_FunctionAPI() { +PPB_CursorControl_Proxy::AsCursorControl_FunctionAPI() { return this; } diff --git a/ppapi/proxy/ppb_cursor_control_proxy.h b/ppapi/proxy/ppb_cursor_control_proxy.h index 8657dc9..234f6cd 100644 --- a/ppapi/proxy/ppb_cursor_control_proxy.h +++ b/ppapi/proxy/ppb_cursor_control_proxy.h @@ -31,7 +31,7 @@ class PPB_CursorControl_Proxy static const Info* GetInfo(); // FunctionGroupBase overrides. - ppapi::thunk::PPB_CursorControl_FunctionAPI* AsPPB_CursorControl_FunctionAPI() + ppapi::thunk::PPB_CursorControl_FunctionAPI* AsCursorControl_FunctionAPI() OVERRIDE; // PPB_CursorControl_FunctionAPI implementation. diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc index 38bc058..6307806 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -9,39 +9,23 @@ #include "ppapi/c/dev/ppb_file_chooser_dev.h" #include "ppapi/c/pp_errors.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/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/serialized_var.h" -#include "ppapi/thunk/thunk.h" - -using ::ppapi::thunk::PPB_FileChooser_API; namespace pp { namespace proxy { -class FileChooser : public PluginResource, - public PPB_FileChooser_API { +class FileChooser : public PluginResource { public: FileChooser(const HostResource& resource); virtual ~FileChooser(); - // ResourceObjectBase overrides. - virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; - - // PPB_FileChooser_API implementation. - virtual int32_t Show(PP_CompletionCallback callback) OVERRIDE; - virtual PP_Resource GetNextChosenFile() OVERRIDE; - - // Handles the choose complete notification from the host. - void ChooseComplete( - int32_t result_code, - const std::vector<PPBFileRef_CreateInfo>& chosen_files); + virtual FileChooser* AsFileChooser(); - private: PP_CompletionCallback current_show_callback_; // All files returned by the current show callback that haven't yet been @@ -50,6 +34,7 @@ class FileChooser : public PluginResource, // has transferred to the plugin. std::queue<PP_Resource> file_queue_; + private: DISALLOW_COPY_AND_ASSIGN(FileChooser); }; @@ -77,47 +62,73 @@ FileChooser::~FileChooser() { } } -PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() { +FileChooser* FileChooser::AsFileChooser() { return this; } -int32_t FileChooser::Show(PP_CompletionCallback callback) { - if (current_show_callback_.func) +namespace { + +PP_Resource Create(PP_Instance instance, + const PP_FileChooserOptions_Dev* options) { + Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return 0; + + HostResource result; + dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Create( + INTERFACE_ID_PPB_FILE_CHOOSER, instance, + options->mode, + options->accept_mime_types ? options->accept_mime_types : std::string(), + &result)); + + if (result.is_null()) + return 0; + linked_ptr<FileChooser> object(new FileChooser(result)); + return PluginResourceTracker::GetInstance()->AddResource(object); +} + +PP_Bool IsFileChooser(PP_Resource resource) { + FileChooser* object = PluginResource::GetAs<FileChooser>(resource); + return BoolToPPBool(!!object); +} + +int32_t Show(PP_Resource chooser, struct PP_CompletionCallback callback) { + FileChooser* object = PluginResource::GetAs<FileChooser>(chooser); + if (!object) + return PP_ERROR_BADRESOURCE; + Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance()); + if (!dispatcher) + return PP_ERROR_BADARGUMENT; + + if (object->current_show_callback_.func) return PP_ERROR_INPROGRESS; // Can't show more than once. - current_show_callback_ = callback; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileChooser_Show( - INTERFACE_ID_PPB_FILE_CHOOSER, host_resource())); + object->current_show_callback_ = callback; + dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Show( + INTERFACE_ID_PPB_FILE_CHOOSER, + object->host_resource())); return PP_OK_COMPLETIONPENDING; } -PP_Resource FileChooser::GetNextChosenFile() { - if (file_queue_.empty()) +PP_Resource GetNextChosenFile(PP_Resource chooser) { + FileChooser* object = PluginResource::GetAs<FileChooser>(chooser); + if (!object || object->file_queue_.empty()) return 0; // Return the next resource in the queue. These resource have already been // addrefed (they're currently owned by the FileChooser) and returning them // transfers ownership of that reference to the plugin. - PP_Resource next = file_queue_.front(); - file_queue_.pop(); + PP_Resource next = object->file_queue_.front(); + object->file_queue_.pop(); return next; } -void FileChooser::ChooseComplete( - int32_t result_code, - const std::vector<PPBFileRef_CreateInfo>& chosen_files) { - // Convert each of the passed in file infos to resources. These will be owned - // by the FileChooser object until they're passed to the plugin. - DCHECK(file_queue_.empty()); - for (size_t i = 0; i < chosen_files.size(); i++) - file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); - - // Notify the plugin of the new data. - PP_RunAndClearCompletionCallback(¤t_show_callback_, result_code); - // DANGER: May delete |this|! -} - -namespace { +const PPB_FileChooser_Dev file_chooser_interface = { + &Create, + &IsFileChooser, + &Show, + &GetNextChosenFile +}; InterfaceProxy* CreateFileChooserProxy(Dispatcher* dispatcher, const void* target_interface) { @@ -137,7 +148,7 @@ PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() { const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo() { static const Info info = { - ::ppapi::thunk::GetPPB_FileChooser_Thunk(), + &file_chooser_interface, PPB_FILECHOOSER_DEV_INTERFACE, INTERFACE_ID_PPB_FILE_CHOOSER, false, @@ -146,27 +157,6 @@ const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo() { return &info; } -// static -PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( - PP_Instance instance, - const PP_FileChooserOptions_Dev* options) { - Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return 0; - - HostResource result; - dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Create( - INTERFACE_ID_PPB_FILE_CHOOSER, instance, - options->mode, - options->accept_mime_types ? options->accept_mime_types : std::string(), - &result)); - - if (result.is_null()) - return 0; - linked_ptr<FileChooser> object(new FileChooser(result)); - return PluginResourceTracker::GetInstance()->AddResource(object); -} - bool PPB_FileChooser_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_FileChooser_Proxy, msg) @@ -207,11 +197,30 @@ void PPB_FileChooser_Proxy::OnMsgChooseComplete( const HostResource& chooser, int32_t result_code, const std::vector<PPBFileRef_CreateInfo>& chosen_files) { - EnterPluginFromHostResource<PPB_FileChooser_API> enter(chooser); - if (enter.succeeded()) { - static_cast<FileChooser*>(enter.object())->ChooseComplete( - result_code, chosen_files); + PP_Resource plugin_resource = + PluginResourceTracker::GetInstance()->PluginResourceForHostResource( + chooser); + if (!plugin_resource) + return; + FileChooser* object = PluginResource::GetAs<FileChooser>(plugin_resource); + if (!object) + return; + + // 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(object->file_queue_.empty()); + for (size_t i = 0; i < chosen_files.size(); i++) { + object->file_queue_.push( + PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); } + + // Notify the plugin of the new data. We have to swap out the callback + // because the plugin may trigger deleting the object from the callback, and + // the FileChooser object will attempt to call the callback in its destructor + // with the ABORTED status. + PP_RunAndClearCompletionCallback(&object->current_show_callback_, + result_code); + // DANGER: May delete |object|! } void PPB_FileChooser_Proxy::OnShowCallback(int32_t result, diff --git a/ppapi/proxy/ppb_file_chooser_proxy.h b/ppapi/proxy/ppb_file_chooser_proxy.h index 4b83e950..97b3aa2 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.h +++ b/ppapi/proxy/ppb_file_chooser_proxy.h @@ -13,7 +13,6 @@ #include "ppapi/cpp/completion_callback.h" #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" -#include "ppapi/thunk/ppb_file_chooser_api.h" struct PPB_FileChooser_Dev; @@ -30,10 +29,6 @@ class PPB_FileChooser_Proxy : public InterfaceProxy { static const Info* GetInfo(); - static PP_Resource CreateProxyResource( - PP_Instance instance, - const PP_FileChooserOptions_Dev* options); - const PPB_FileChooser_Dev* ppb_file_chooser_target() const { return static_cast<const PPB_FileChooser_Dev*>(target_interface()); } diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc index 149e23b..3348818 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.cc +++ b/ppapi/proxy/ppb_file_ref_proxy.cc @@ -7,54 +7,28 @@ #include "ppapi/c/dev/ppb_file_ref_dev.h" #include "ppapi/c/pp_errors.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/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" -#include "ppapi/thunk/ppb_file_ref_api.h" -#include "ppapi/thunk/resource_creation_api.h" -#include "ppapi/thunk/thunk.h" - -using ppapi::thunk::EnterFunctionNoLock; -using ppapi::thunk::EnterResourceNoLock; -using ppapi::thunk::PPB_FileRef_API; -using ppapi::thunk::ResourceCreationAPI; namespace pp { namespace proxy { -namespace { - -InterfaceProxy* CreateFileRefProxy(Dispatcher* dispatcher, - const void* target_interface) { - return new PPB_FileRef_Proxy(dispatcher, target_interface); -} - -} // namespace - -class FileRef : public PluginResource, public PPB_FileRef_API { +// This object maintains most of the state of the ref in the plugin for fast +// querying. It's all set in the constructor from the "create info" sent from +// the host. +class FileRef : public PluginResource { public: - explicit FileRef(const PPBFileRef_CreateInfo& info); + FileRef(const PPBFileRef_CreateInfo& info); virtual ~FileRef(); - // ResourceObjectBase overrides. - virtual PPB_FileRef_API* AsPPB_FileRef_API() OVERRIDE; - - // PPB_FileRef_API implementation. - virtual PP_FileSystemType_Dev GetFileSystemType() const OVERRIDE; - virtual PP_Var GetName() const OVERRIDE; - virtual PP_Var GetPath() const OVERRIDE; - virtual PP_Resource GetParent() OVERRIDE; - virtual int32_t MakeDirectory(PP_Bool make_ancestors, - PP_CompletionCallback callback) OVERRIDE; - virtual int32_t Touch(PP_Time last_access_time, - PP_Time last_modified_time, - PP_CompletionCallback callback) OVERRIDE; - virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE; - virtual int32_t Rename(PP_Resource new_file_ref, - PP_CompletionCallback callback) OVERRIDE; + virtual FileRef* AsFileRef(); + + PP_FileSystemType_Dev file_system_type() const { return file_system_type_; } + const PP_Var& path() const { return path_; } + const PP_Var& name() const { return name_; } private: PP_FileSystemType_Dev file_system_type_; @@ -79,71 +53,168 @@ FileRef::~FileRef() { PluginVarTracker::GetInstance()->Release(name_); } -PPB_FileRef_API* FileRef::AsPPB_FileRef_API() { +FileRef* FileRef::AsFileRef() { return this; } -PP_FileSystemType_Dev FileRef::GetFileSystemType() const { - return file_system_type_; +namespace { + +bool FileRefAndDispatcherForResource(PP_Resource resource, + FileRef** file_ref, + Dispatcher** dispatcher) { + *file_ref = PluginResource::GetAs<FileRef>(resource); + if (!file_ref) + return false; + *dispatcher = PluginDispatcher::GetForInstance((*file_ref)->instance()); + return !!(*dispatcher); +} + +PP_Resource Create(PP_Resource file_system, const char* path) { + PluginResource* file_system_object = + PluginResourceTracker::GetInstance()->GetResourceObject(file_system); + if (!file_system_object) + return 0; + + Dispatcher* dispatcher = + PluginDispatcher::GetForInstance(file_system_object->instance()); + if (!dispatcher) + return 0; + + PPBFileRef_CreateInfo create_info; + dispatcher->Send(new PpapiHostMsg_PPBFileRef_Create( + INTERFACE_ID_PPB_FILE_REF, file_system_object->host_resource(), + path, &create_info)); + return PPB_FileRef_Proxy::DeserializeFileRef(create_info); +} + +PP_Bool IsFileRef(PP_Resource resource) { + FileRef* object = PluginResource::GetAs<FileRef>(resource); + return BoolToPPBool(!!object); } -PP_Var FileRef::GetName() const { - PluginVarTracker::GetInstance()->AddRef(name_); - return name_; +PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref) { + FileRef* object = PluginResource::GetAs<FileRef>(file_ref); + if (!object) + return PP_FILESYSTEMTYPE_EXTERNAL; + return object->file_system_type(); } -PP_Var FileRef::GetPath() const { - PluginVarTracker::GetInstance()->AddRef(path_); - return path_; +PP_Var GetName(PP_Resource file_ref) { + FileRef* object = PluginResource::GetAs<FileRef>(file_ref); + if (!object) + return PP_MakeUndefined(); + + PluginVarTracker::GetInstance()->AddRef(object->name()); + return object->name(); } -PP_Resource FileRef::GetParent() { +PP_Var GetPath(PP_Resource file_ref) { + FileRef* object = PluginResource::GetAs<FileRef>(file_ref); + if (!object) + return PP_MakeUndefined(); + + PluginVarTracker::GetInstance()->AddRef(object->path()); + return object->path(); +} + +PP_Resource GetParent(PP_Resource file_ref) { + FileRef* object; + Dispatcher* dispatcher; + if (!FileRefAndDispatcherForResource(file_ref, &object, &dispatcher)) + return 0; + PPBFileRef_CreateInfo create_info; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( - INTERFACE_ID_PPB_FILE_REF, host_resource(), &create_info)); + dispatcher->Send(new PpapiHostMsg_PPBFileRef_GetParent( + INTERFACE_ID_PPB_FILE_REF, object->host_resource(), &create_info)); return PPB_FileRef_Proxy::DeserializeFileRef(create_info); } -int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, - PP_CompletionCallback callback) { - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_MakeDirectory( - INTERFACE_ID_PPB_FILE_REF, host_resource(), make_ancestors, - GetDispatcher()->callback_tracker().SendCallback(callback))); +int32_t MakeDirectory(PP_Resource directory_ref, + PP_Bool make_ancestors, + struct PP_CompletionCallback callback) { + FileRef* object; + Dispatcher* dispatcher; + if (!FileRefAndDispatcherForResource(directory_ref, &object, &dispatcher)) + return PP_ERROR_BADRESOURCE; + + dispatcher->Send(new PpapiHostMsg_PPBFileRef_MakeDirectory( + INTERFACE_ID_PPB_FILE_REF, object->host_resource(), make_ancestors, + dispatcher->callback_tracker().SendCallback(callback))); return PP_OK_COMPLETIONPENDING; } -int32_t FileRef::Touch(PP_Time last_access_time, - PP_Time last_modified_time, - PP_CompletionCallback callback) { - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Touch( - INTERFACE_ID_PPB_FILE_REF, host_resource(), +int32_t Touch(PP_Resource file_ref, + PP_Time last_access_time, + PP_Time last_modified_time, + struct PP_CompletionCallback callback) { + FileRef* object; + Dispatcher* dispatcher; + if (!FileRefAndDispatcherForResource(file_ref, &object, &dispatcher)) + return PP_ERROR_BADRESOURCE; + + dispatcher->Send(new PpapiHostMsg_PPBFileRef_Touch( + INTERFACE_ID_PPB_FILE_REF, object->host_resource(), last_access_time, last_modified_time, - GetDispatcher()->callback_tracker().SendCallback(callback))); + dispatcher->callback_tracker().SendCallback(callback))); return PP_OK_COMPLETIONPENDING; } -int32_t FileRef::Delete(PP_CompletionCallback callback) { - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Delete( - INTERFACE_ID_PPB_FILE_REF, host_resource(), - GetDispatcher()->callback_tracker().SendCallback(callback))); +int32_t Delete(PP_Resource file_ref, + struct PP_CompletionCallback callback) { + FileRef* object; + Dispatcher* dispatcher; + if (!FileRefAndDispatcherForResource(file_ref, &object, &dispatcher)) + return PP_ERROR_BADRESOURCE; + + dispatcher->Send(new PpapiHostMsg_PPBFileRef_Delete( + INTERFACE_ID_PPB_FILE_REF, object->host_resource(), + dispatcher->callback_tracker().SendCallback(callback))); return PP_OK_COMPLETIONPENDING; } -int32_t FileRef::Rename(PP_Resource new_file_ref, - PP_CompletionCallback callback) { - PluginResource* new_file_ref_object = - PluginResourceTracker::GetInstance()->GetResourceObject(new_file_ref); - if (!new_file_ref_object || - new_file_ref_object->host_resource().instance() != instance()) +int32_t Rename(PP_Resource file_ref, + PP_Resource new_file_ref, + struct PP_CompletionCallback callback) { + FileRef* obj1; + Dispatcher* dispatcher1; + if (!FileRefAndDispatcherForResource(file_ref, &obj1, &dispatcher1)) + return PP_ERROR_BADRESOURCE; + + FileRef* obj2; + Dispatcher* dispatcher2; + if (!FileRefAndDispatcherForResource(new_file_ref, &obj2, &dispatcher2)) + return PP_ERROR_BADRESOURCE; + + if (obj1->instance() != obj2->instance()) return PP_ERROR_BADRESOURCE; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename( - INTERFACE_ID_PPB_FILE_REF, host_resource(), - new_file_ref_object->host_resource(), - GetDispatcher()->callback_tracker().SendCallback(callback))); + dispatcher1->Send(new PpapiHostMsg_PPBFileRef_Rename( + INTERFACE_ID_PPB_FILE_REF, obj1->host_resource(), + obj2->host_resource(), + dispatcher1->callback_tracker().SendCallback(callback))); return PP_OK_COMPLETIONPENDING; } +const PPB_FileRef_Dev file_ref_interface = { + &Create, + &IsFileRef, + &GetFileSystemType, + &GetName, + &GetPath, + &GetParent, + &MakeDirectory, + &Touch, + &Delete, + &Rename +}; + +InterfaceProxy* CreateFileRefProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_FileRef_Proxy(dispatcher, target_interface); +} + +} // namespace + PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher, const void* target_interface) : InterfaceProxy(dispatcher, target_interface) { @@ -154,7 +225,7 @@ PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { const InterfaceProxy::Info* PPB_FileRef_Proxy::GetInfo() { static const Info info = { - ::ppapi::thunk::GetPPB_FileRef_Thunk(), + &file_ref_interface, PPB_FILEREF_DEV_INTERFACE, INTERFACE_ID_PPB_FILE_REF, false, @@ -163,21 +234,6 @@ const InterfaceProxy::Info* PPB_FileRef_Proxy::GetInfo() { return &info; } -// static -PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Resource file_system, - const char* path) { - PluginResource* file_system_object = - PluginResourceTracker::GetInstance()->GetResourceObject(file_system); - if (!file_system_object) - return 0; - - PPBFileRef_CreateInfo create_info; - file_system_object->GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Create( - INTERFACE_ID_PPB_FILE_REF, file_system_object->host_resource(), - 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) @@ -195,12 +251,6 @@ bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, PPBFileRef_CreateInfo* result) { - EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false); - if (enter.failed()) { - NOTREACHED(); - return; - } - // We need the instance out of the resource for serializing back to the // plugin. This code can only run in the host. if (dispatcher()->IsPlugin()) { @@ -213,11 +263,13 @@ void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, result->resource.SetHostResource(instance, file_ref); result->file_system_type = - static_cast<int>(enter.object()->GetFileSystemType()); - result->path = SerializedVarReturnValue::Convert(dispatcher(), - enter.object()->GetPath()); - result->name = SerializedVarReturnValue::Convert(dispatcher(), - enter.object()->GetName()); + static_cast<int>(ppb_file_ref_target()->GetFileSystemType(file_ref)); + result->path = SerializedVarReturnValue::Convert( + dispatcher(), + ppb_file_ref_target()->GetPath(file_ref)); + result->name = SerializedVarReturnValue::Convert( + dispatcher(), + ppb_file_ref_target()->GetName(file_ref)); } // static @@ -233,10 +285,8 @@ PP_Resource PPB_FileRef_Proxy::DeserializeFileRef( void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system, const std::string& path, PPBFileRef_CreateInfo* result) { - EnterFunctionNoLock<ResourceCreationAPI> enter(file_system.instance(), true); - if (enter.failed()) - return; - PP_Resource resource = enter.functions()->CreateFileRef( + + PP_Resource resource = ppb_file_ref_target()->Create( file_system.host_resource(), path.c_str()); if (!resource) return; // CreateInfo default constructor initializes to 0. @@ -245,19 +295,18 @@ void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system, void PPB_FileRef_Proxy::OnMsgGetParent(const HostResource& host_resource, PPBFileRef_CreateInfo* result) { - EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); - if (enter.succeeded()) - SerializeFileRef(enter.object()->GetParent(), result); + PP_Resource resource = ppb_file_ref_target()->GetParent( + host_resource.host_resource()); + SerializeFileRef(resource, result); } void PPB_FileRef_Proxy::OnMsgMakeDirectory(const HostResource& host_resource, PP_Bool make_ancestors, uint32_t serialized_callback) { - EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); - if (enter.failed()) - return; PP_CompletionCallback callback = ReceiveCallback(serialized_callback); - int32_t result = enter.object()->MakeDirectory(make_ancestors, callback); + int32_t result = + ppb_file_ref_target()->MakeDirectory(host_resource.host_resource(), + make_ancestors, callback); if (result != PP_OK_COMPLETIONPENDING) PP_RunCompletionCallback(&callback, result); } @@ -266,22 +315,19 @@ void PPB_FileRef_Proxy::OnMsgTouch(const HostResource& host_resource, PP_Time last_access, PP_Time last_modified, uint32_t serialized_callback) { - EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); - if (enter.failed()) - return; PP_CompletionCallback callback = ReceiveCallback(serialized_callback); - int32_t result = enter.object()->Touch(last_access, last_modified, callback); + int32_t result = + ppb_file_ref_target()->Touch(host_resource.host_resource(), + last_access, last_modified, callback); if (result != PP_OK_COMPLETIONPENDING) PP_RunCompletionCallback(&callback, result); } void PPB_FileRef_Proxy::OnMsgDelete(const HostResource& host_resource, uint32_t serialized_callback) { - EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); - if (enter.failed()) - return; PP_CompletionCallback callback = ReceiveCallback(serialized_callback); - int32_t result = enter.object()->Delete(callback); + int32_t result = + ppb_file_ref_target()->Delete(host_resource.host_resource(), callback); if (result != PP_OK_COMPLETIONPENDING) PP_RunCompletionCallback(&callback, result); } @@ -289,12 +335,11 @@ void PPB_FileRef_Proxy::OnMsgDelete(const HostResource& host_resource, void PPB_FileRef_Proxy::OnMsgRename(const HostResource& file_ref, const HostResource& new_file_ref, uint32_t serialized_callback) { - EnterHostFromHostResource<PPB_FileRef_API> enter(file_ref); - if (enter.failed()) - return; PP_CompletionCallback callback = ReceiveCallback(serialized_callback); - int32_t result = enter.object()->Rename(new_file_ref.host_resource(), - callback); + int32_t result = + ppb_file_ref_target()->Rename(file_ref.host_resource(), + new_file_ref.host_resource(), + callback); if (result != PP_OK_COMPLETIONPENDING) PP_RunCompletionCallback(&callback, result); } diff --git a/ppapi/proxy/ppb_file_ref_proxy.h b/ppapi/proxy/ppb_file_ref_proxy.h index 076bea2..ca0b588 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.h +++ b/ppapi/proxy/ppb_file_ref_proxy.h @@ -28,8 +28,9 @@ class PPB_FileRef_Proxy : public InterfaceProxy { static const Info* GetInfo(); - static PP_Resource CreateProxyResource(PP_Resource file_system, - const char* path); + const PPB_FileRef_Dev* ppb_file_ref_target() const { + return static_cast<const PPB_FileRef_Dev*>(target_interface()); + } // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); diff --git a/ppapi/proxy/ppb_file_system_proxy.cc b/ppapi/proxy/ppb_file_system_proxy.cc index c6b7caa..f75ebc7 100644 --- a/ppapi/proxy/ppb_file_system_proxy.cc +++ b/ppapi/proxy/ppb_file_system_proxy.cc @@ -8,57 +8,30 @@ #include "base/task.h" #include "ppapi/c/dev/ppb_file_system_dev.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" -#include "ppapi/thunk/enter.h" -#include "ppapi/thunk/ppb_file_system_api.h" -#include "ppapi/thunk/resource_creation_api.h" -#include "ppapi/thunk/thunk.h" - -using ppapi::thunk::EnterFunctionNoLock; -using ppapi::thunk::PPB_FileSystem_API; -using ppapi::thunk::ResourceCreationAPI; namespace pp { namespace proxy { -namespace { - -InterfaceProxy* CreateFileSystemProxy(Dispatcher* dispatcher, - const void* target_interface) { - return new PPB_FileSystem_Proxy(dispatcher, target_interface); -} - -} // namespace - // This object maintains most of the state of the ref in the plugin for fast // querying. It's all set in the constructor from the "create info" sent from // the host. -class FileSystem : public PluginResource, public PPB_FileSystem_API { +class FileSystem : public PluginResource { public: FileSystem(const HostResource& host_resource, PP_FileSystemType_Dev type); virtual ~FileSystem(); - // ResourceObjectBase override. - virtual PPB_FileSystem_API* AsPPB_FileSystem_API() OVERRIDE; - - // PPB_FileSystem_APi implementation. - virtual int32_t Open(int64_t expected_size, - PP_CompletionCallback callback) OVERRIDE; - virtual PP_FileSystemType_Dev GetType() OVERRIDE; - - // Called when the host has responded to our open request. - void OpenComplete(int32_t result); + virtual FileSystem* AsFileSystem(); - private: PP_FileSystemType_Dev type_; bool called_open_; PP_CompletionCallback current_open_callback_; + private: DISALLOW_COPY_AND_ASSIGN(FileSystem); }; @@ -84,32 +57,77 @@ FileSystem::~FileSystem() { } } -PPB_FileSystem_API* FileSystem::AsPPB_FileSystem_API() { +FileSystem* FileSystem::AsFileSystem() { return this; } -int32_t FileSystem::Open(int64_t expected_size, - PP_CompletionCallback callback) { - if (current_open_callback_.func) +namespace { + +PP_Resource Create(PP_Instance instance, PP_FileSystemType_Dev type) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return PP_ERROR_BADARGUMENT; + + HostResource result; + dispatcher->Send(new PpapiHostMsg_PPBFileSystem_Create( + INTERFACE_ID_PPB_FILE_SYSTEM, instance, type, &result)); + if (result.is_null()) + return 0; + + linked_ptr<FileSystem> object(new FileSystem(result, type)); + return PluginResourceTracker::GetInstance()->AddResource(object); +} + +PP_Bool IsFileSystem(PP_Resource resource) { + FileSystem* object = PluginResource::GetAs<FileSystem>(resource); + return BoolToPPBool(!!object); +} + +int32_t Open(PP_Resource file_system, + int64_t expected_size, + struct PP_CompletionCallback callback) { + FileSystem* object = PluginResource::GetAs<FileSystem>(file_system); + if (!object) + return PP_ERROR_BADRESOURCE; + + Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance()); + if (!dispatcher) + return PP_ERROR_BADARGUMENT; + + if (object->current_open_callback_.func) return PP_ERROR_INPROGRESS; - if (called_open_) + else if (object->called_open_) return PP_ERROR_FAILED; - current_open_callback_ = callback; - called_open_ = true; - GetDispatcher()->Send(new PpapiHostMsg_PPBFileSystem_Open( - INTERFACE_ID_PPB_FILE_SYSTEM, host_resource(), expected_size)); + object->current_open_callback_ = callback; + object->called_open_ = true; + + dispatcher->Send(new PpapiHostMsg_PPBFileSystem_Open( + INTERFACE_ID_PPB_FILE_SYSTEM, object->host_resource(), expected_size)); return PP_OK_COMPLETIONPENDING; } -PP_FileSystemType_Dev FileSystem::GetType() { - return type_; +PP_FileSystemType_Dev GetType(PP_Resource resource) { + FileSystem* object = PluginResource::GetAs<FileSystem>(resource); + if (!object) + return PP_FILESYSTEMTYPE_INVALID; + return object->type_; } -void FileSystem::OpenComplete(int32_t result) { - PP_RunAndClearCompletionCallback(¤t_open_callback_, result); +const PPB_FileSystem_Dev file_system_interface = { + &Create, + &IsFileSystem, + &Open, + &GetType +}; + +InterfaceProxy* CreateFileSystemProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_FileSystem_Proxy(dispatcher, target_interface); } +} // namespace + PPB_FileSystem_Proxy::PPB_FileSystem_Proxy(Dispatcher* dispatcher, const void* target_interface) : InterfaceProxy(dispatcher, target_interface), @@ -121,7 +139,7 @@ PPB_FileSystem_Proxy::~PPB_FileSystem_Proxy() { const InterfaceProxy::Info* PPB_FileSystem_Proxy::GetInfo() { static const Info info = { - ::ppapi::thunk::GetPPB_FileSystem_Thunk(), + &file_system_interface, PPB_FILESYSTEM_DEV_INTERFACE, INTERFACE_ID_PPB_FILE_SYSTEM, false, @@ -130,24 +148,6 @@ const InterfaceProxy::Info* PPB_FileSystem_Proxy::GetInfo() { return &info; } -// static -PP_Resource PPB_FileSystem_Proxy::CreateProxyResource( - PP_Instance instance, - PP_FileSystemType_Dev type) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return PP_ERROR_BADARGUMENT; - - HostResource result; - dispatcher->Send(new PpapiHostMsg_PPBFileSystem_Create( - INTERFACE_ID_PPB_FILE_SYSTEM, instance, type, &result)); - if (result.is_null()) - return 0; - - linked_ptr<FileSystem> object(new FileSystem(result, type)); - return PluginResourceTracker::GetInstance()->AddResource(object); -} - bool PPB_FileSystem_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_FileSystem_Proxy, msg) @@ -162,10 +162,7 @@ bool PPB_FileSystem_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_FileSystem_Proxy::OnMsgCreate(PP_Instance instance, int type, HostResource* result) { - EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); - if (enter.failed()) - return; - PP_Resource resource = enter.functions()->CreateFileSystem( + PP_Resource resource = ppb_file_system_target()->Create( instance, static_cast<PP_FileSystemType_Dev>(type)); if (!resource) return; // CreateInfo default constructor initializes to 0. @@ -174,24 +171,25 @@ void PPB_FileSystem_Proxy::OnMsgCreate(PP_Instance instance, void PPB_FileSystem_Proxy::OnMsgOpen(const HostResource& host_resource, int64_t expected_size) { - EnterHostFromHostResource<PPB_FileSystem_API> enter(host_resource); - if (enter.failed()) - return; - CompletionCallback callback = callback_factory_.NewCallback( &PPB_FileSystem_Proxy::OpenCompleteInHost, host_resource); - int32_t result = enter.object()->Open(expected_size, - callback.pp_completion_callback()); + + int32_t result = ppb_file_system_target()->Open( + host_resource.host_resource(), expected_size, + callback.pp_completion_callback()); if (result != PP_OK_COMPLETIONPENDING) callback.Run(result); } // Called in the plugin to handle the open callback. -void PPB_FileSystem_Proxy::OnMsgOpenComplete(const HostResource& host_resource, +void PPB_FileSystem_Proxy::OnMsgOpenComplete(const HostResource& filesystem, int32_t result) { - EnterPluginFromHostResource<PPB_FileSystem_API> enter(host_resource); - if (enter.succeeded()) - static_cast<FileSystem*>(enter.object())->OpenComplete(result); + FileSystem* object = PluginResource::GetAs<FileSystem>( + PluginResourceTracker::GetInstance()->PluginResourceForHostResource( + filesystem)); + if (!object || !object->current_open_callback_.func) + return; + PP_RunAndClearCompletionCallback(&object->current_open_callback_, result); } void PPB_FileSystem_Proxy::OpenCompleteInHost( diff --git a/ppapi/proxy/ppb_file_system_proxy.h b/ppapi/proxy/ppb_file_system_proxy.h index e00a11d..acfe171 100644 --- a/ppapi/proxy/ppb_file_system_proxy.h +++ b/ppapi/proxy/ppb_file_system_proxy.h @@ -8,7 +8,6 @@ #include <string> #include "base/basictypes.h" -#include "ppapi/c/dev/ppb_file_system_dev.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_time.h" @@ -30,8 +29,9 @@ class PPB_FileSystem_Proxy : public InterfaceProxy { static const Info* GetInfo(); - static PP_Resource CreateProxyResource(PP_Instance instance, - PP_FileSystemType_Dev type); + const PPB_FileSystem_Dev* ppb_file_system_target() const { + return static_cast<const PPB_FileSystem_Dev*>(target_interface()); + } // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc index c8f621a..eab4494 100644 --- a/ppapi/proxy/ppb_font_proxy.cc +++ b/ppapi/proxy/ppb_font_proxy.cc @@ -64,7 +64,7 @@ const InterfaceProxy::Info* PPB_Font_Proxy::GetInfo() { return &info; } -::ppapi::thunk::PPB_Font_FunctionAPI* PPB_Font_Proxy::AsPPB_Font_FunctionAPI() { +::ppapi::thunk::PPB_Font_FunctionAPI* PPB_Font_Proxy::AsFont_FunctionAPI() { return this; } @@ -114,7 +114,7 @@ Font::Font(const HostResource& resource, Font::~Font() { } -ppapi::thunk::PPB_Font_API* Font::AsPPB_Font_API() { +ppapi::thunk::PPB_Font_API* Font::AsFont_API() { return this; } diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h index 32893ea..bb351ea 100644 --- a/ppapi/proxy/ppb_font_proxy.h +++ b/ppapi/proxy/ppb_font_proxy.h @@ -30,7 +30,7 @@ class PPB_Font_Proxy : public ppapi::FunctionGroupBase, static const Info* GetInfo(); // FunctionGroupBase overrides. - virtual ppapi::thunk::PPB_Font_FunctionAPI* AsPPB_Font_FunctionAPI() OVERRIDE; + virtual ppapi::thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() OVERRIDE; // PPB_Font_FunctionAPI implementation. virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; @@ -54,7 +54,7 @@ class Font : public PluginResource, virtual ~Font(); // ResourceObjectBase. - virtual ppapi::thunk::PPB_Font_API* AsPPB_Font_API() OVERRIDE; + virtual ppapi::thunk::PPB_Font_API* AsFont_API() OVERRIDE; // PluginResource overrides. virtual Font* AsFont() OVERRIDE; diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc index 8027956..38777b7 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc @@ -12,15 +12,14 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/ppb_graphics_2d.h" -#include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/thunk/enter.h" -#include "ppapi/thunk/ppb_graphics_2d_api.h" #include "ppapi/thunk/thunk.h" using ::ppapi::thunk::PPB_Graphics2D_API; +using ::ppapi::thunk::EnterResource; namespace pp { namespace proxy { @@ -34,54 +33,7 @@ InterfaceProxy* CreateGraphics2DProxy(Dispatcher* dispatcher, } // namespace -class Graphics2D : public PluginResource, - public ::ppapi::thunk::PPB_Graphics2D_API { - public: - Graphics2D(const HostResource& host_resource, - const PP_Size& size, - PP_Bool is_always_opaque); - virtual ~Graphics2D(); - - // ResourceObjectBase. - virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API(); - - // PPB_Graphics_2D_API. - PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); - void PaintImageData(PP_Resource image_data, - const PP_Point* top_left, - const PP_Rect* src_rect); - void Scroll(const PP_Rect* clip_rect, - const PP_Point* amount); - void ReplaceContents(PP_Resource image_data); - int32_t Flush(PP_CompletionCallback callback); - - // Notification that the host has sent an ACK for a pending Flush. - void FlushACK(int32_t result_code); - - private: - PP_Size size_; - PP_Bool is_always_opaque_; - - // In the plugin, this is the current callback set for Flushes. When the - // callback function pointer is non-NULL, we're waiting for a flush ACK. - PP_CompletionCallback current_flush_callback_; - - DISALLOW_COPY_AND_ASSIGN(Graphics2D); -}; - -Graphics2D::Graphics2D(const HostResource& host_resource, - const PP_Size& size, - PP_Bool is_always_opaque) - : PluginResource(host_resource), - size_(size), - is_always_opaque_(is_always_opaque), - current_flush_callback_(PP_BlockUntilComplete()) { -} - -Graphics2D::~Graphics2D() { -} - -PPB_Graphics2D_API* Graphics2D::AsPPB_Graphics2D_API() { +PPB_Graphics2D_API* Graphics2D::AsGraphics2D_API() { return this; } @@ -133,19 +85,15 @@ int32_t Graphics2D::Flush(PP_CompletionCallback callback) { if (!callback.func) return PP_ERROR_BADARGUMENT; - if (current_flush_callback_.func) + if (is_flush_pending()) return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. - current_flush_callback_ = callback; + set_current_flush_callback(callback); GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush( INTERFACE_ID_PPB_GRAPHICS_2D, host_resource())); return PP_OK_COMPLETIONPENDING; } -void Graphics2D::FlushACK(int32_t result_code) { - PP_RunAndClearCompletionCallback(¤t_flush_callback_, result_code); -} - PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher, const void* target_interface) : InterfaceProxy(dispatcher, target_interface), @@ -167,26 +115,6 @@ const InterfaceProxy::Info* PPB_Graphics2D_Proxy::GetInfo() { return &info; } -// static -PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource( - PP_Instance instance, - const PP_Size& size, - PP_Bool is_always_opaque) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return 0; - - HostResource result; - dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D( - INTERFACE_ID_RESOURCE_CREATION, instance, size, is_always_opaque, - &result)); - if (result.is_null()) - return 0; - linked_ptr<Graphics2D> graphics_2d(new Graphics2D(result, size, - is_always_opaque)); - return PluginResourceTracker::GetInstance()->AddResource(graphics_2d); -} - bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) @@ -213,7 +141,7 @@ void PPB_Graphics2D_Proxy::OnMsgPaintImageData( const PP_Point& top_left, bool src_rect_specified, const PP_Rect& src_rect) { - EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); + EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false); if (enter.failed()) return; enter.object()->PaintImageData(image_data.host_resource(), &top_left, @@ -224,7 +152,7 @@ void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d, bool clip_specified, const PP_Rect& clip, const PP_Point& amount) { - EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); + EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false); if (enter.failed()) return; enter.object()->Scroll(clip_specified ? &clip : NULL, &amount); @@ -233,7 +161,7 @@ void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d, void PPB_Graphics2D_Proxy::OnMsgReplaceContents( const HostResource& graphics_2d, const HostResource& image_data) { - EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); + EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false); if (enter.failed()) return; enter.object()->ReplaceContents(image_data.host_resource()); @@ -254,9 +182,24 @@ void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) { void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource, int32_t pp_error) { - EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); - if (enter.succeeded()) - static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); + PP_Resource plugin_resource = + PluginResourceTracker::GetInstance()->PluginResourceForHostResource( + host_resource); + if (!plugin_resource) + return; + + Graphics2D* object = PluginResource::GetAs<Graphics2D>(plugin_resource); + if (!object) { + // The plugin has released the graphics 2D object so don't issue the + // callback. + return; + } + + // Be careful to make the callback NULL again before issuing the callback + // since the plugin might want to flush from within the callback. + PP_CompletionCallback callback = object->current_flush_callback(); + object->set_current_flush_callback(PP_BlockUntilComplete()); + PP_RunCompletionCallback(&callback, pp_error); } void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.h b/ppapi/proxy/ppb_graphics_2d_proxy.h index 9be7f83..b799950 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.h +++ b/ppapi/proxy/ppb_graphics_2d_proxy.h @@ -17,6 +17,7 @@ #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" +#include "ppapi/thunk/ppb_graphics_2d_api.h" struct PPB_Graphics2D; struct PP_Point; @@ -32,10 +33,6 @@ class PPB_Graphics2D_Proxy : public InterfaceProxy { static const Info* GetInfo(); - static PP_Resource CreateProxyResource(PP_Instance instance, - const PP_Size& size, - PP_Bool is_always_opaque); - const PPB_Graphics2D* ppb_graphics_2d_target() const { return static_cast<const PPB_Graphics2D*>(target_interface()); } @@ -70,6 +67,60 @@ class PPB_Graphics2D_Proxy : public InterfaceProxy { ProxyNonThreadSafeRefCount> callback_factory_; }; +class Graphics2D : public PluginResource, + public ::ppapi::thunk::PPB_Graphics2D_API { + public: + Graphics2D(const HostResource& host_resource, + const PP_Size& size, + PP_Bool is_always_opaque) + : PluginResource(host_resource), + size_(size), + is_always_opaque_(is_always_opaque), + current_flush_callback_(PP_BlockUntilComplete()) { + } + virtual ~Graphics2D() { + } + + // Resource overrides. + virtual Graphics2D* AsGraphics2D() { return this; } + + const PP_Size& size() const { return size_; } + PP_Bool is_always_opaque() const { return is_always_opaque_; } + + bool is_flush_pending() const { return !!current_flush_callback_.func; } + + PP_CompletionCallback current_flush_callback() const { + return current_flush_callback_; + } + void set_current_flush_callback(PP_CompletionCallback cb) { + current_flush_callback_ = cb; + } + + // ResourceObjectBase. + virtual PPB_Graphics2D_API* AsGraphics2D_API(); + + // PPB_Graphics_2D_API. + PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); + void PaintImageData(PP_Resource image_data, + const PP_Point* top_left, + const PP_Rect* src_rect); + void Scroll(const PP_Rect* clip_rect, + const PP_Point* amount); + void ReplaceContents(PP_Resource image_data); + int32_t Flush(PP_CompletionCallback callback); + + private: + PP_Size size_; + PP_Bool is_always_opaque_; + + // In the plugin, this is the current callback set for Flushes. When the + // callback function pointer is non-NULL, we're waiting for a flush ACK. + PP_CompletionCallback current_flush_callback_; + + DISALLOW_COPY_AND_ASSIGN(Graphics2D); +}; + + } // namespace proxy } // namespace pp diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc index 2d8e7f9..2117e82 100644 --- a/ppapi/proxy/ppb_image_data_proxy.cc +++ b/ppapi/proxy/ppb_image_data_proxy.cc @@ -76,7 +76,7 @@ ImageData::ImageData(const HostResource& resource, ImageData::~ImageData() { } -::ppapi::thunk::PPB_ImageData_API* ImageData::AsPPB_ImageData_API() { +::ppapi::thunk::PPB_ImageData_API* ImageData::AsImageData_API() { return this; } diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h index 366b6b4..6bd97a5ad 100644 --- a/ppapi/proxy/ppb_image_data_proxy.h +++ b/ppapi/proxy/ppb_image_data_proxy.h @@ -55,7 +55,7 @@ class ImageData : public PluginResource, virtual ~ImageData(); // ResourceObjectBase overrides. - virtual ::ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API(); + virtual ::ppapi::thunk::PPB_ImageData_API* AsImageData_API(); // Resource overrides. virtual ImageData* AsImageData(); diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 8d26528..0045bbb 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -16,9 +16,6 @@ #include "ppapi/proxy/ppb_audio_proxy.h" #include "ppapi/proxy/ppb_buffer_proxy.h" #include "ppapi/proxy/ppb_broker_proxy.h" -#include "ppapi/proxy/ppb_file_chooser_proxy.h" -#include "ppapi/proxy/ppb_file_ref_proxy.h" -#include "ppapi/proxy/ppb_file_system_proxy.h" #include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppb_graphics_2d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" @@ -40,7 +37,7 @@ ResourceCreationProxy::~ResourceCreationProxy() { } ::ppapi::thunk::ResourceCreationAPI* -ResourceCreationProxy::AsResourceCreationAPI() { +ResourceCreationProxy::AsResourceCreation() { return this; } @@ -75,34 +72,6 @@ PP_Resource ResourceCreationProxy::CreateBuffer(PP_Instance instance, return PPB_Buffer_Proxy::CreateProxyResource(instance, size); } -PP_Resource ResourceCreationProxy::CreateDirectoryReader( - PP_Resource directory_ref) { - // Not proxied yet. - return 0; -} - -PP_Resource ResourceCreationProxy::CreateFileChooser( - PP_Instance instance, - const PP_FileChooserOptions_Dev* options) { - return PPB_FileChooser_Proxy::CreateProxyResource(instance, options); -} - -PP_Resource ResourceCreationProxy::CreateFileIO(PP_Instance instance) { - // Not proxied yet. - return 0; -} - -PP_Resource ResourceCreationProxy::CreateFileRef(PP_Resource file_system, - const char* path) { - return PPB_FileRef_Proxy::CreateProxyResource(file_system, path); -} - -PP_Resource ResourceCreationProxy::CreateFileSystem( - PP_Instance instance, - PP_FileSystemType_Dev type) { - return PPB_FileSystem_Proxy::CreateProxyResource(instance, type); -} - PP_Resource ResourceCreationProxy::CreateFontObject( PP_Instance instance, const PP_FontDescription_Dev* description) { @@ -114,11 +83,22 @@ PP_Resource ResourceCreationProxy::CreateFontObject( return PluginResourceTracker::GetInstance()->AddResource(object); } -PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance, +PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance pp_instance, const PP_Size& size, PP_Bool is_always_opaque) { - return PPB_Graphics2D_Proxy::CreateProxyResource(instance, size, - is_always_opaque); + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance); + if (!dispatcher) + return PP_ERROR_BADARGUMENT; + + HostResource result; + dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D( + INTERFACE_ID_RESOURCE_CREATION, pp_instance, size, is_always_opaque, + &result)); + if (result.is_null()) + return 0; + linked_ptr<Graphics2D> graphics_2d(new Graphics2D(result, size, + is_always_opaque)); + return PluginResourceTracker::GetInstance()->AddResource(graphics_2d); } PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance, diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 501e70b..bd24bda 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -29,7 +29,7 @@ class ResourceCreationProxy : public ::ppapi::FunctionGroupBase, ResourceCreationProxy(Dispatcher* dispatcher); virtual ~ResourceCreationProxy(); - virtual ::ppapi::thunk::ResourceCreationAPI* AsResourceCreationAPI() OVERRIDE; + virtual ::ppapi::thunk::ResourceCreationAPI* AsResourceCreation() OVERRIDE; // ResourceCreationAPI (called in plugin). virtual PP_Resource CreateAudio(PP_Instance instance, @@ -43,15 +43,6 @@ class ResourceCreationProxy : public ::ppapi::FunctionGroupBase, virtual PP_Resource CreateBroker(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateBuffer(PP_Instance instance, uint32_t size) OVERRIDE; - virtual PP_Resource CreateDirectoryReader(PP_Resource directory_ref) OVERRIDE; - virtual PP_Resource CreateFileChooser( - PP_Instance instance, - const PP_FileChooserOptions_Dev* options) OVERRIDE; - virtual PP_Resource CreateFileIO(PP_Instance instance) OVERRIDE; - virtual PP_Resource CreateFileRef(PP_Resource file_system, - const char* path) OVERRIDE; - virtual PP_Resource CreateFileSystem(PP_Instance instance, - PP_FileSystemType_Dev type) OVERRIDE; virtual PP_Resource CreateFontObject( PP_Instance instance, const PP_FontDescription_Dev* description) OVERRIDE; |