diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-01 07:19:31 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-01 07:19:31 +0000 |
commit | cd910b93160f754297e51b27bdbc5f98cf52a743 (patch) | |
tree | 098dd0816260568abeae1662fa7de759e8372c49 | |
parent | 20da3817eb403599ec87537bf2bc862446a13abf (diff) | |
download | chromium_src-cd910b93160f754297e51b27bdbc5f98cf52a743.zip chromium_src-cd910b93160f754297e51b27bdbc5f98cf52a743.tar.gz chromium_src-cd910b93160f754297e51b27bdbc5f98cf52a743.tar.bz2 |
Convert more interfaces to the new thunk system. This goes up to and including
the ones starting with "F".
Since this adds a lot more interfaces, I added the macro stuff we used for the
old system to generate the various template specializations. This involded a
lot of renaming since the As* needs to match the name (I was previously leaving
off the "PPB_" part). I did other misc cleanup to the infrastructure.
Review URL: http://codereview.chromium.org/7082036
Reland 87415
Review URL: http://codereview.chromium.org/7105013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87444 0039d316-1c4b-4281-b951-d872f2087c98
86 files changed, 1861 insertions, 1211 deletions
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 43e6c28..bfcd435 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -33,10 +33,14 @@ 'shared_impl/crypto_impl.h', 'shared_impl/font_impl.cc', 'shared_impl/font_impl.h', + 'shared_impl/function_group_base.cc', + 'shared_impl/function_group_base.h', 'shared_impl/image_data_impl.cc', 'shared_impl/image_data_impl.h', 'shared_impl/ppapi_preferences.cc', 'shared_impl/ppapi_preferences.h', + 'shared_impl/resource_object_base.cc', + 'shared_impl/resource_object_base.h', 'shared_impl/tracker_base.cc', 'shared_impl/tracker_base.h', 'shared_impl/url_util_impl.cc', @@ -59,6 +63,19 @@ 'thunk/ppb_char_set_thunk.cc', 'thunk/ppb_cursor_control_api.h', 'thunk/ppb_cursor_control_thunk.cc', + 'thunk/ppb_directory_reader_api.h', + 'thunk/ppb_directory_reader_thunk.cc', + 'thunk/ppb_file_chooser_api.h', + 'thunk/ppb_file_chooser_thunk.cc', + 'thunk/ppb_file_io_api.h', + 'thunk/ppb_file_io_thunk.cc', + 'thunk/ppb_file_io_trusted_thunk.cc', + 'thunk/ppb_file_ref_api.h', + 'thunk/ppb_file_ref_thunk.cc', + 'thunk/ppb_file_system_api.h', + 'thunk/ppb_file_system_thunk.cc', + 'thunk/ppb_find_api.h', + 'thunk/ppb_find_thunk.cc', 'thunk/ppb_font_api.h', 'thunk/ppb_font_thunk.cc', 'thunk/ppb_graphics_2d_api.h', diff --git a/ppapi/proxy/enter_proxy.h b/ppapi/proxy/enter_proxy.h new file mode 100644 index 0000000..6e52705 --- /dev/null +++ b/ppapi/proxy/enter_proxy.h @@ -0,0 +1,58 @@ +// 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 039008c..7363340 100644 --- a/ppapi/proxy/interface_id.h +++ b/ppapi/proxy/interface_id.h @@ -26,6 +26,7 @@ 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 a6e087f..e1726cf 100644 --- a/ppapi/proxy/plugin_resource_tracker.cc +++ b/ppapi/proxy/plugin_resource_tracker.cc @@ -139,6 +139,14 @@ 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 5dfdf82..c00d3f2 100644 --- a/ppapi/proxy/plugin_resource_tracker.h +++ b/ppapi/proxy/plugin_resource_tracker.h @@ -8,6 +8,7 @@ #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" @@ -56,10 +57,11 @@ class PluginResourceTracker : public ::ppapi::TrackerBase { // TrackerBase. virtual ::ppapi::ResourceObjectBase* GetResourceAPI( - PP_Resource res); + PP_Resource res) OVERRIDE; virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( PP_Instance inst, - pp::proxy::InterfaceID id); + pp::proxy::InterfaceID id) OVERRIDE; + virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE; private: friend struct DefaultSingletonTraits<PluginResourceTracker>; diff --git a/ppapi/proxy/ppb_audio_config_proxy.cc b/ppapi/proxy/ppb_audio_config_proxy.cc index 8e78ecd..e8eb056 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* AsAudioConfig_API() OVERRIDE; + virtual ::ppapi::thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_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::AsAudioConfig_API() { +::ppapi::thunk::PPB_AudioConfig_API* AudioConfig::AsPPB_AudioConfig_API() { return this; } diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc index 6c2cc7a..22ddddd 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -10,6 +10,7 @@ #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" @@ -21,6 +22,8 @@ #include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" +using ::ppapi::thunk::PPB_Audio_API; + namespace pp { namespace proxy { @@ -33,7 +36,7 @@ class Audio : public PluginResource, public ppapi::AudioImpl { virtual ~Audio(); // ResourceObjectBase overrides. - virtual ::ppapi::thunk::PPB_Audio_API* AsAudio_API(); + virtual PPB_Audio_API* AsPPB_Audio_API(); // PPB_Audio_API implementation. virtual PP_Resource GetCurrentConfig() OVERRIDE; @@ -62,7 +65,7 @@ Audio::~Audio() { PluginResourceTracker::GetInstance()->ReleaseResource(config_); } -::ppapi::thunk::PPB_Audio_API* Audio::AsAudio_API() { +PPB_Audio_API* Audio::AsPPB_Audio_API() { return this; } @@ -232,11 +235,7 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( IPC::PlatformFileForTransit socket_handle, base::SharedMemoryHandle handle, uint32_t length) { - PP_Resource plugin_resource = - PluginResourceTracker::GetInstance()->PluginResourceForHostResource( - audio_id); - ppapi::thunk::EnterResource<ppapi::thunk::PPB_Audio_API> enter( - plugin_resource, false); + EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); 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 @@ -244,11 +243,11 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( base::SyncSocket temp_socket( IPC::PlatformFileForTransitToPlatformFile(socket_handle)); base::SharedMemory temp_mem(handle, false); - return; + } else { + static_cast<Audio*>(enter.object())->SetStreamInfo( + handle, length, + IPC::PlatformFileForTransitToPlatformFile(socket_handle)); } - 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 74aa4a2..97fe0d0 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* AsBroker_API() OVERRIDE; + virtual ppapi::thunk::PPB_Broker_API* AsPPB_Broker_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::AsBroker_API() { +ppapi::thunk::PPB_Broker_API* Broker::AsPPB_Broker_API() { return this; } diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc index d6f910f..5c2fd8a 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* AsBuffer_API() OVERRIDE; + virtual ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_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::AsBuffer_API() { +ppapi::thunk::PPB_Buffer_API* Buffer::AsPPB_Buffer_API() { return this; } diff --git a/ppapi/proxy/ppb_char_set_proxy.cc b/ppapi/proxy/ppb_char_set_proxy.cc index a896693..1887549 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::AsCharSet_FunctionAPI() { +PPB_CharSet_Proxy::AsPPB_CharSet_FunctionAPI() { return this; } diff --git a/ppapi/proxy/ppb_char_set_proxy.h b/ppapi/proxy/ppb_char_set_proxy.h index b64884c..0f70ab5 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* AsCharSet_FunctionAPI() + virtual ppapi::thunk::PPB_CharSet_FunctionAPI* AsPPB_CharSet_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 37619b7..993efe8 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::AsCursorControl_FunctionAPI() { +PPB_CursorControl_Proxy::AsPPB_CursorControl_FunctionAPI() { return this; } diff --git a/ppapi/proxy/ppb_cursor_control_proxy.h b/ppapi/proxy/ppb_cursor_control_proxy.h index 234f6cd..8657dc9 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* AsCursorControl_FunctionAPI() + ppapi::thunk::PPB_CursorControl_FunctionAPI* AsPPB_CursorControl_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 6307806..38bc058 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -9,23 +9,39 @@ #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 { +class FileChooser : public PluginResource, + public PPB_FileChooser_API { public: FileChooser(const HostResource& resource); virtual ~FileChooser(); - virtual FileChooser* AsFileChooser(); + // 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); + private: PP_CompletionCallback current_show_callback_; // All files returned by the current show callback that haven't yet been @@ -34,7 +50,6 @@ class FileChooser : public PluginResource { // has transferred to the plugin. std::queue<PP_Resource> file_queue_; - private: DISALLOW_COPY_AND_ASSIGN(FileChooser); }; @@ -62,73 +77,47 @@ FileChooser::~FileChooser() { } } -FileChooser* FileChooser::AsFileChooser() { +PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() { return this; } -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) +int32_t FileChooser::Show(PP_CompletionCallback callback) { + if (current_show_callback_.func) return PP_ERROR_INPROGRESS; // Can't show more than once. - object->current_show_callback_ = callback; - dispatcher->Send(new PpapiHostMsg_PPBFileChooser_Show( - INTERFACE_ID_PPB_FILE_CHOOSER, - object->host_resource())); + current_show_callback_ = callback; + GetDispatcher()->Send(new PpapiHostMsg_PPBFileChooser_Show( + INTERFACE_ID_PPB_FILE_CHOOSER, host_resource())); return PP_OK_COMPLETIONPENDING; } -PP_Resource GetNextChosenFile(PP_Resource chooser) { - FileChooser* object = PluginResource::GetAs<FileChooser>(chooser); - if (!object || object->file_queue_.empty()) +PP_Resource FileChooser::GetNextChosenFile() { + if (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 = object->file_queue_.front(); - object->file_queue_.pop(); + PP_Resource next = file_queue_.front(); + file_queue_.pop(); return next; } -const PPB_FileChooser_Dev file_chooser_interface = { - &Create, - &IsFileChooser, - &Show, - &GetNextChosenFile -}; +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 { InterfaceProxy* CreateFileChooserProxy(Dispatcher* dispatcher, const void* target_interface) { @@ -148,7 +137,7 @@ PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() { const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo() { static const Info info = { - &file_chooser_interface, + ::ppapi::thunk::GetPPB_FileChooser_Thunk(), PPB_FILECHOOSER_DEV_INTERFACE, INTERFACE_ID_PPB_FILE_CHOOSER, false, @@ -157,6 +146,27 @@ 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) @@ -197,30 +207,11 @@ void PPB_FileChooser_Proxy::OnMsgChooseComplete( const HostResource& chooser, int32_t result_code, const std::vector<PPBFileRef_CreateInfo>& 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])); + EnterPluginFromHostResource<PPB_FileChooser_API> enter(chooser); + if (enter.succeeded()) { + static_cast<FileChooser*>(enter.object())->ChooseComplete( + result_code, chosen_files); } - - // 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 97b3aa2..4b83e950 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.h +++ b/ppapi/proxy/ppb_file_chooser_proxy.h @@ -13,6 +13,7 @@ #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; @@ -29,6 +30,10 @@ 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 3348818..149e23b 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.cc +++ b/ppapi/proxy/ppb_file_ref_proxy.cc @@ -7,28 +7,54 @@ #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 { -// 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 { +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 { public: - FileRef(const PPBFileRef_CreateInfo& info); + explicit FileRef(const PPBFileRef_CreateInfo& info); virtual ~FileRef(); - 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_; } + // 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; private: PP_FileSystemType_Dev file_system_type_; @@ -53,168 +79,71 @@ FileRef::~FileRef() { PluginVarTracker::GetInstance()->Release(name_); } -FileRef* FileRef::AsFileRef() { +PPB_FileRef_API* FileRef::AsPPB_FileRef_API() { return this; } -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_FileSystemType_Dev FileRef::GetFileSystemType() const { + return file_system_type_; } -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::GetName() const { + PluginVarTracker::GetInstance()->AddRef(name_); + return name_; } -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_Var FileRef::GetPath() const { + PluginVarTracker::GetInstance()->AddRef(path_); + return path_; } -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; - +PP_Resource FileRef::GetParent() { PPBFileRef_CreateInfo create_info; - dispatcher->Send(new PpapiHostMsg_PPBFileRef_GetParent( - INTERFACE_ID_PPB_FILE_REF, object->host_resource(), &create_info)); + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( + INTERFACE_ID_PPB_FILE_REF, host_resource(), &create_info)); return PPB_FileRef_Proxy::DeserializeFileRef(create_info); } -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))); +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))); return PP_OK_COMPLETIONPENDING; } -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(), +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(), last_access_time, last_modified_time, - dispatcher->callback_tracker().SendCallback(callback))); + GetDispatcher()->callback_tracker().SendCallback(callback))); return PP_OK_COMPLETIONPENDING; } -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))); +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))); return PP_OK_COMPLETIONPENDING; } -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()) +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()) return PP_ERROR_BADRESOURCE; - dispatcher1->Send(new PpapiHostMsg_PPBFileRef_Rename( - INTERFACE_ID_PPB_FILE_REF, obj1->host_resource(), - obj2->host_resource(), - dispatcher1->callback_tracker().SendCallback(callback))); + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename( + INTERFACE_ID_PPB_FILE_REF, host_resource(), + new_file_ref_object->host_resource(), + GetDispatcher()->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) { @@ -225,7 +154,7 @@ PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { const InterfaceProxy::Info* PPB_FileRef_Proxy::GetInfo() { static const Info info = { - &file_ref_interface, + ::ppapi::thunk::GetPPB_FileRef_Thunk(), PPB_FILEREF_DEV_INTERFACE, INTERFACE_ID_PPB_FILE_REF, false, @@ -234,6 +163,21 @@ 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) @@ -251,6 +195,12 @@ 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()) { @@ -263,13 +213,11 @@ void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, result->resource.SetHostResource(instance, file_ref); result->file_system_type = - 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_cast<int>(enter.object()->GetFileSystemType()); + result->path = SerializedVarReturnValue::Convert(dispatcher(), + enter.object()->GetPath()); + result->name = SerializedVarReturnValue::Convert(dispatcher(), + enter.object()->GetName()); } // static @@ -285,8 +233,10 @@ PP_Resource PPB_FileRef_Proxy::DeserializeFileRef( void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system, const std::string& path, PPBFileRef_CreateInfo* result) { - - PP_Resource resource = ppb_file_ref_target()->Create( + EnterFunctionNoLock<ResourceCreationAPI> enter(file_system.instance(), true); + if (enter.failed()) + return; + PP_Resource resource = enter.functions()->CreateFileRef( file_system.host_resource(), path.c_str()); if (!resource) return; // CreateInfo default constructor initializes to 0. @@ -295,18 +245,19 @@ void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system, void PPB_FileRef_Proxy::OnMsgGetParent(const HostResource& host_resource, PPBFileRef_CreateInfo* result) { - PP_Resource resource = ppb_file_ref_target()->GetParent( - host_resource.host_resource()); - SerializeFileRef(resource, 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 serialized_callback) { + EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); + if (enter.failed()) + return; PP_CompletionCallback callback = ReceiveCallback(serialized_callback); - int32_t result = - ppb_file_ref_target()->MakeDirectory(host_resource.host_resource(), - make_ancestors, callback); + int32_t result = enter.object()->MakeDirectory(make_ancestors, callback); if (result != PP_OK_COMPLETIONPENDING) PP_RunCompletionCallback(&callback, result); } @@ -315,19 +266,22 @@ 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 = - ppb_file_ref_target()->Touch(host_resource.host_resource(), - last_access, last_modified, callback); + int32_t result = enter.object()->Touch(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 = - ppb_file_ref_target()->Delete(host_resource.host_resource(), callback); + int32_t result = enter.object()->Delete(callback); if (result != PP_OK_COMPLETIONPENDING) PP_RunCompletionCallback(&callback, result); } @@ -335,11 +289,12 @@ 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 = - ppb_file_ref_target()->Rename(file_ref.host_resource(), - new_file_ref.host_resource(), - callback); + int32_t result = enter.object()->Rename(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 ca0b588..076bea2 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.h +++ b/ppapi/proxy/ppb_file_ref_proxy.h @@ -28,9 +28,8 @@ class PPB_FileRef_Proxy : public InterfaceProxy { static const Info* GetInfo(); - const PPB_FileRef_Dev* ppb_file_ref_target() const { - return static_cast<const PPB_FileRef_Dev*>(target_interface()); - } + static PP_Resource CreateProxyResource(PP_Resource file_system, + const char* path); // 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 f75ebc7..c6b7caa 100644 --- a/ppapi/proxy/ppb_file_system_proxy.cc +++ b/ppapi/proxy/ppb_file_system_proxy.cc @@ -8,30 +8,57 @@ #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 { +class FileSystem : public PluginResource, public PPB_FileSystem_API { public: FileSystem(const HostResource& host_resource, PP_FileSystemType_Dev type); virtual ~FileSystem(); - virtual FileSystem* AsFileSystem(); + // 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); + private: PP_FileSystemType_Dev type_; bool called_open_; PP_CompletionCallback current_open_callback_; - private: DISALLOW_COPY_AND_ASSIGN(FileSystem); }; @@ -57,77 +84,32 @@ FileSystem::~FileSystem() { } } -FileSystem* FileSystem::AsFileSystem() { +PPB_FileSystem_API* FileSystem::AsPPB_FileSystem_API() { return this; } -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) +int32_t FileSystem::Open(int64_t expected_size, + PP_CompletionCallback callback) { + if (current_open_callback_.func) return PP_ERROR_INPROGRESS; - else if (object->called_open_) + if (called_open_) return PP_ERROR_FAILED; - 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)); + current_open_callback_ = callback; + called_open_ = true; + GetDispatcher()->Send(new PpapiHostMsg_PPBFileSystem_Open( + INTERFACE_ID_PPB_FILE_SYSTEM, host_resource(), expected_size)); return PP_OK_COMPLETIONPENDING; } -PP_FileSystemType_Dev GetType(PP_Resource resource) { - FileSystem* object = PluginResource::GetAs<FileSystem>(resource); - if (!object) - return PP_FILESYSTEMTYPE_INVALID; - return object->type_; +PP_FileSystemType_Dev FileSystem::GetType() { + return type_; } -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); +void FileSystem::OpenComplete(int32_t result) { + PP_RunAndClearCompletionCallback(¤t_open_callback_, result); } -} // namespace - PPB_FileSystem_Proxy::PPB_FileSystem_Proxy(Dispatcher* dispatcher, const void* target_interface) : InterfaceProxy(dispatcher, target_interface), @@ -139,7 +121,7 @@ PPB_FileSystem_Proxy::~PPB_FileSystem_Proxy() { const InterfaceProxy::Info* PPB_FileSystem_Proxy::GetInfo() { static const Info info = { - &file_system_interface, + ::ppapi::thunk::GetPPB_FileSystem_Thunk(), PPB_FILESYSTEM_DEV_INTERFACE, INTERFACE_ID_PPB_FILE_SYSTEM, false, @@ -148,6 +130,24 @@ 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,7 +162,10 @@ bool PPB_FileSystem_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_FileSystem_Proxy::OnMsgCreate(PP_Instance instance, int type, HostResource* result) { - PP_Resource resource = ppb_file_system_target()->Create( + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return; + PP_Resource resource = enter.functions()->CreateFileSystem( instance, static_cast<PP_FileSystemType_Dev>(type)); if (!resource) return; // CreateInfo default constructor initializes to 0. @@ -171,25 +174,24 @@ 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 = ppb_file_system_target()->Open( - host_resource.host_resource(), expected_size, - callback.pp_completion_callback()); + int32_t result = enter.object()->Open(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& filesystem, +void PPB_FileSystem_Proxy::OnMsgOpenComplete(const HostResource& host_resource, int32_t 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); + EnterPluginFromHostResource<PPB_FileSystem_API> enter(host_resource); + if (enter.succeeded()) + static_cast<FileSystem*>(enter.object())->OpenComplete(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 acfe171..e00a11d 100644 --- a/ppapi/proxy/ppb_file_system_proxy.h +++ b/ppapi/proxy/ppb_file_system_proxy.h @@ -8,6 +8,7 @@ #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" @@ -29,9 +30,8 @@ class PPB_FileSystem_Proxy : public InterfaceProxy { static const Info* GetInfo(); - const PPB_FileSystem_Dev* ppb_file_system_target() const { - return static_cast<const PPB_FileSystem_Dev*>(target_interface()); - } + static PP_Resource CreateProxyResource(PP_Instance instance, + PP_FileSystemType_Dev type); // 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 eab4494..c8f621a 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::AsFont_FunctionAPI() { +::ppapi::thunk::PPB_Font_FunctionAPI* PPB_Font_Proxy::AsPPB_Font_FunctionAPI() { return this; } @@ -114,7 +114,7 @@ Font::Font(const HostResource& resource, Font::~Font() { } -ppapi::thunk::PPB_Font_API* Font::AsFont_API() { +ppapi::thunk::PPB_Font_API* Font::AsPPB_Font_API() { return this; } diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h index bb351ea..32893ea 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* AsFont_FunctionAPI() OVERRIDE; + virtual ppapi::thunk::PPB_Font_FunctionAPI* AsPPB_Font_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* AsFont_API() OVERRIDE; + virtual ppapi::thunk::PPB_Font_API* AsPPB_Font_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 38777b7..8027956 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc @@ -12,14 +12,15 @@ #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 { @@ -33,7 +34,54 @@ InterfaceProxy* CreateGraphics2DProxy(Dispatcher* dispatcher, } // namespace -PPB_Graphics2D_API* Graphics2D::AsGraphics2D_API() { +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() { return this; } @@ -85,15 +133,19 @@ int32_t Graphics2D::Flush(PP_CompletionCallback callback) { if (!callback.func) return PP_ERROR_BADARGUMENT; - if (is_flush_pending()) + if (current_flush_callback_.func) return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. - set_current_flush_callback(callback); + 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), @@ -115,6 +167,26 @@ 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) @@ -141,7 +213,7 @@ void PPB_Graphics2D_Proxy::OnMsgPaintImageData( const PP_Point& top_left, bool src_rect_specified, const PP_Rect& src_rect) { - EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false); + EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); if (enter.failed()) return; enter.object()->PaintImageData(image_data.host_resource(), &top_left, @@ -152,7 +224,7 @@ void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d, bool clip_specified, const PP_Rect& clip, const PP_Point& amount) { - EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false); + EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); if (enter.failed()) return; enter.object()->Scroll(clip_specified ? &clip : NULL, &amount); @@ -161,7 +233,7 @@ void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d, void PPB_Graphics2D_Proxy::OnMsgReplaceContents( const HostResource& graphics_2d, const HostResource& image_data) { - EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false); + EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); if (enter.failed()) return; enter.object()->ReplaceContents(image_data.host_resource()); @@ -182,24 +254,9 @@ void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) { void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource, int32_t 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); + EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); + if (enter.succeeded()) + static_cast<Graphics2D*>(enter.object())->FlushACK(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 b799950..9be7f83 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.h +++ b/ppapi/proxy/ppb_graphics_2d_proxy.h @@ -17,7 +17,6 @@ #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; @@ -33,6 +32,10 @@ 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()); } @@ -67,60 +70,6 @@ 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 2117e82..2d8e7f9 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::AsImageData_API() { +::ppapi::thunk::PPB_ImageData_API* ImageData::AsPPB_ImageData_API() { return this; } diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h index 6bd97a5ad..366b6b4 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* AsImageData_API(); + virtual ::ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API(); // Resource overrides. virtual ImageData* AsImageData(); diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 0045bbb..8d26528 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -16,6 +16,9 @@ #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" @@ -37,7 +40,7 @@ ResourceCreationProxy::~ResourceCreationProxy() { } ::ppapi::thunk::ResourceCreationAPI* -ResourceCreationProxy::AsResourceCreation() { +ResourceCreationProxy::AsResourceCreationAPI() { return this; } @@ -72,6 +75,34 @@ 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) { @@ -83,22 +114,11 @@ PP_Resource ResourceCreationProxy::CreateFontObject( return PluginResourceTracker::GetInstance()->AddResource(object); } -PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance pp_instance, +PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance, const PP_Size& size, PP_Bool 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); + return PPB_Graphics2D_Proxy::CreateProxyResource(instance, size, + is_always_opaque); } PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance, diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index bd24bda..501e70b 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* AsResourceCreation() OVERRIDE; + virtual ::ppapi::thunk::ResourceCreationAPI* AsResourceCreationAPI() OVERRIDE; // ResourceCreationAPI (called in plugin). virtual PP_Resource CreateAudio(PP_Instance instance, @@ -43,6 +43,15 @@ 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; diff --git a/ppapi/shared_impl/audio_impl.cc b/ppapi/shared_impl/audio_impl.cc index 0173d6e..09d4589 100644 --- a/ppapi/shared_impl/audio_impl.cc +++ b/ppapi/shared_impl/audio_impl.cc @@ -25,7 +25,7 @@ AudioImpl::~AudioImpl() { } } -::ppapi::thunk::PPB_Audio_API* AudioImpl::AsAudio_API() { +::ppapi::thunk::PPB_Audio_API* AudioImpl::AsPPB_Audio_API() { return this; } diff --git a/ppapi/shared_impl/audio_impl.h b/ppapi/shared_impl/audio_impl.h index ba7c780..4916cd6 100644 --- a/ppapi/shared_impl/audio_impl.h +++ b/ppapi/shared_impl/audio_impl.h @@ -26,7 +26,7 @@ class AudioImpl : public ResourceObjectBase, virtual ~AudioImpl(); // ResourceObjectBase implementation. - virtual ::ppapi::thunk::PPB_Audio_API* AsAudio_API() OVERRIDE; + virtual ::ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API() OVERRIDE; bool playing() const { return playing_; } diff --git a/ppapi/shared_impl/function_group_base.cc b/ppapi/shared_impl/function_group_base.cc new file mode 100644 index 0000000..8fb7ad5 --- /dev/null +++ b/ppapi/shared_impl/function_group_base.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/shared_impl/function_group_base.h" + +namespace ppapi { + +FunctionGroupBase::~FunctionGroupBase() { +} + +#define DEFINE_TYPE_GETTER(FUNCTIONS) \ + thunk::FUNCTIONS* FunctionGroupBase::As##FUNCTIONS() { return NULL; } +FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_TYPE_GETTER) +#undef DEFINE_TYPE_GETTER + +} // namespace ppapi diff --git a/ppapi/shared_impl/function_group_base.h b/ppapi/shared_impl/function_group_base.h index 4f98396..6f828ae 100644 --- a/ppapi/shared_impl/function_group_base.h +++ b/ppapi/shared_impl/function_group_base.h @@ -5,53 +5,49 @@ #ifndef PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ #define PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ +#include <stddef.h> // For NULL. + +#define FOR_ALL_PPAPI_FUNCTION_APIS(F) \ + F(PPB_CharSet_FunctionAPI) \ + F(PPB_CursorControl_FunctionAPI) \ + F(PPB_Find_FunctionAPI) \ + F(PPB_Font_FunctionAPI) \ + F(ResourceCreationAPI) + namespace ppapi { +// Forward declare all the function APIs. namespace thunk { -class PPB_CharSet_FunctionAPI; -class PPB_CursorControl_FunctionAPI; -class PPB_Font_FunctionAPI; -class ResourceCreationAPI; -} +#define DECLARE_FUNCTION_CLASS(FUNCTIONS) class FUNCTIONS; +FOR_ALL_PPAPI_FUNCTION_APIS(DECLARE_FUNCTION_CLASS) +#undef DECLARE_FUNCTION_CLASS +} // namespace thunk class FunctionGroupBase { public: - virtual ~FunctionGroupBase() {} + virtual ~FunctionGroupBase(); // Dynamic casting for this object. Returns the pointer to the given type if - // it's supported. - virtual thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI() { - return NULL; - } - virtual thunk::PPB_CursorControl_FunctionAPI* AsCursorControl_FunctionAPI() { - return NULL; - } - virtual thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() { - return NULL; - } - virtual thunk::ResourceCreationAPI* AsResourceCreation() { - return NULL; - } - + // Inheritance-based dynamic casting for this object. Returns the pointer to + // the given type if it's supported. Derived classes override the functions + // they support to return the interface. + #define DEFINE_TYPE_GETTER(FUNCTIONS) \ + virtual thunk::FUNCTIONS* As##FUNCTIONS(); + FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_TYPE_GETTER) + #undef DEFINE_TYPE_GETTER + + // Template-based dynamic casting. See specializations below. template <typename T> T* GetAs() { return NULL; } }; -template<> -inline thunk::PPB_CharSet_FunctionAPI* FunctionGroupBase::GetAs() { - return AsCharSet_FunctionAPI(); -} -template<> -inline thunk::PPB_CursorControl_FunctionAPI* FunctionGroupBase::GetAs() { - return AsCursorControl_FunctionAPI(); -} -template<> -inline thunk::PPB_Font_FunctionAPI* FunctionGroupBase::GetAs() { - return AsFont_FunctionAPI(); -} -template<> -inline ppapi::thunk::ResourceCreationAPI* FunctionGroupBase::GetAs() { - return AsResourceCreation(); -} +// Template-based dynamic casting. These specializations forward to the +// AsXXX virtual functions to return whether the given type is supported. +#define DEFINE_FUNCTION_CAST(FUNCTIONS) \ + template<> inline thunk::FUNCTIONS* FunctionGroupBase::GetAs() { \ + return As##FUNCTIONS(); \ + } +FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_FUNCTION_CAST) +#undef DEFINE_FUNCTION_CAST } // namespace ppapi diff --git a/ppapi/shared_impl/resource_object_base.cc b/ppapi/shared_impl/resource_object_base.cc new file mode 100644 index 0000000..4c0a9af --- /dev/null +++ b/ppapi/shared_impl/resource_object_base.cc @@ -0,0 +1,18 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/shared_impl/resource_object_base.h" + +namespace ppapi { + +ResourceObjectBase::~ResourceObjectBase() { +} + +#define DEFINE_TYPE_GETTER(RESOURCE) \ + thunk::RESOURCE* ResourceObjectBase::As##RESOURCE() { return NULL; } +FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) +#undef DEFINE_TYPE_GETTER + +} // namespace ppapi + diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h index c8d88c1..00ac498 100644 --- a/ppapi/shared_impl/resource_object_base.h +++ b/ppapi/shared_impl/resource_object_base.h @@ -5,66 +5,58 @@ #ifndef PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ #define PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ +#include <stddef.h> // For NULL. + +#define FOR_ALL_PPAPI_RESOURCE_APIS(F) \ + F(PPB_Audio_API) \ + F(PPB_AudioConfig_API) \ + F(PPB_AudioTrusted_API) \ + F(PPB_Broker_API) \ + F(PPB_Buffer_API) \ + F(PPB_DirectoryReader_API) \ + F(PPB_FileChooser_API) \ + F(PPB_FileIO_API) \ + F(PPB_FileRef_API) \ + F(PPB_FileSystem_API) \ + F(PPB_Find_API) \ + F(PPB_Font_API) \ + F(PPB_Graphics2D_API) \ + F(PPB_ImageData_API) + namespace ppapi { +// Forward declare all the resource APIs. namespace thunk { -class PPB_Audio_API; -class PPB_AudioConfig_API; -class PPB_AudioTrusted_API; -class PPB_Broker_API; -class PPB_Buffer_API; -class PPB_Font_API; -class PPB_Graphics2D_API; -class PPB_ImageData_API; -} +#define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; +FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS) +#undef DECLARE_RESOURCE_CLASS +} // namespace thunk class ResourceObjectBase { public: - - virtual thunk::PPB_Audio_API* AsAudio_API() { return NULL; } - virtual thunk::PPB_AudioConfig_API* AsAudioConfig_API() { return NULL; } - virtual thunk::PPB_AudioTrusted_API* AsAudioTrusted_API() { return NULL; } - virtual thunk::PPB_Buffer_API* AsBuffer_API() { return NULL; } - virtual thunk::PPB_Broker_API* AsBroker_API() { return NULL; } - virtual thunk::PPB_Font_API* AsFont_API() { return NULL; } - virtual thunk::PPB_Graphics2D_API* AsGraphics2D_API() { return NULL; } - virtual thunk::PPB_ImageData_API* AsImageData_API() { return NULL; } - + virtual ~ResourceObjectBase(); + + // Dynamic casting for this object. Returns the pointer to the given type if + // Inheritance-based dynamic casting for this object. Returns the pointer to + // the given type if it's supported. Derived classes override the functions + // they support to return the interface. + #define DEFINE_TYPE_GETTER(RESOURCE) \ + virtual thunk::RESOURCE* As##RESOURCE(); + FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) + #undef DEFINE_TYPE_GETTER + + // Template-based dynamic casting. See specializations below. template <typename T> T* GetAs() { return NULL; } }; -template<> -inline thunk::PPB_Audio_API* ResourceObjectBase::GetAs() { - return AsAudio_API(); -} -template<> -inline thunk::PPB_AudioConfig_API* ResourceObjectBase::GetAs() { - return AsAudioConfig_API(); -} -template<> -inline thunk::PPB_AudioTrusted_API* ResourceObjectBase::GetAs() { - return AsAudioTrusted_API(); -} -template<> -inline thunk::PPB_Broker_API* ResourceObjectBase::GetAs() { - return AsBroker_API(); -} -template<> -inline thunk::PPB_Buffer_API* ResourceObjectBase::GetAs() { - return AsBuffer_API(); -} -template<> -inline thunk::PPB_Font_API* ResourceObjectBase::GetAs() { - return AsFont_API(); -} -template<> -inline thunk::PPB_Graphics2D_API* ResourceObjectBase::GetAs() { - return AsGraphics2D_API(); -} -template<> -inline thunk::PPB_ImageData_API* ResourceObjectBase::GetAs() { - return AsImageData_API(); -} +// Template-based dynamic casting. These specializations forward to the +// AsXXX virtual functions to return whether the given type is supported. +#define DEFINE_RESOURCE_CAST(RESOURCE) \ + template<> inline thunk::RESOURCE* ResourceObjectBase::GetAs() { \ + return As##RESOURCE(); \ + } +FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_RESOURCE_CAST) +#undef DEFINE_RESOURCE_CAST } // namespace ppapi diff --git a/ppapi/shared_impl/tracker_base.h b/ppapi/shared_impl/tracker_base.h index 4b7e447..28cd442 100644 --- a/ppapi/shared_impl/tracker_base.h +++ b/ppapi/shared_impl/tracker_base.h @@ -40,6 +40,10 @@ class TrackerBase { // there isn't one. virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, pp::proxy::InterfaceID id) = 0; + + // Returns the instance corresponding to the given resource, or 0 if the + // resource is invalid. + virtual PP_Instance GetInstanceForResource(PP_Resource resource) = 0; }; } // namespace ppapi diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h index b7e2f8b..dc06381 100644 --- a/ppapi/thunk/enter.h +++ b/ppapi/thunk/enter.h @@ -52,9 +52,11 @@ class EnterFunction { bool succeeded() const { return !!functions_; } bool failed() const { return !functions_; } + PP_Instance instance() const { return instance_; } FunctionsT* functions() { return functions_; } private: + PP_Instance instance_; FunctionsT* functions_; DISALLOW_COPY_AND_ASSIGN(EnterFunction); @@ -71,6 +73,20 @@ class EnterFunctionNoLock : public EnterFunction<FunctionsT> { } }; +// Used when a caller has a resource, and wants to do EnterFunction for the +// instance corresponding to that resource. +template<typename FunctionsT> +class EnterFunctionGivenResource : public EnterFunction<FunctionsT> { + public: + EnterFunctionGivenResource(PP_Resource resource, bool report_error) + : EnterFunction<FunctionsT>( + TrackerBase::Get()->GetInstanceForResource(resource), + report_error) { + } +}; + +// EnterResource --------------------------------------------------------------- + template<typename ResourceT> class EnterResource { public: diff --git a/ppapi/thunk/ppb_directory_reader_api.h b/ppapi/thunk/ppb_directory_reader_api.h new file mode 100644 index 0000000..b651a57 --- /dev/null +++ b/ppapi/thunk/ppb_directory_reader_api.h @@ -0,0 +1,22 @@ +// 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_THUNK_DIRECTORY_READER_API_H_ +#define PPAPI_THUNK_DIRECTORY_READER_API_H_ + +#include "ppapi/c/dev/ppb_directory_reader_dev.h" + +namespace ppapi { +namespace thunk { + +class PPB_DirectoryReader_API { + public: + virtual int32_t GetNextEntry(PP_DirectoryEntry_Dev* entry, + PP_CompletionCallback callback) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_DIRECTORY_READER_API_H_ diff --git a/ppapi/thunk/ppb_directory_reader_thunk.cc b/ppapi/thunk/ppb_directory_reader_thunk.cc new file mode 100644 index 0000000..d1dfed4 --- /dev/null +++ b/ppapi/thunk/ppb_directory_reader_thunk.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/ppb_directory_reader_dev.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_directory_reader_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Resource directory_ref) { + EnterFunctionGivenResource<ResourceCreationAPI> enter(directory_ref, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateDirectoryReader(directory_ref); +} + +PP_Bool IsDirectoryReader(PP_Resource resource) { + EnterResource<PPB_DirectoryReader_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t GetNextEntry(PP_Resource directory_reader, + PP_DirectoryEntry_Dev* entry, + PP_CompletionCallback callback) { + EnterResource<PPB_DirectoryReader_API> enter(directory_reader, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->GetNextEntry(entry, callback); +} + +const PPB_DirectoryReader_Dev g_ppb_directory_reader_thunk = { + &Create, + &IsDirectoryReader, + &GetNextEntry +}; + +} // namespace + +const PPB_DirectoryReader_Dev* GetPPB_DirectoryReader_Thunk() { + return &g_ppb_directory_reader_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_file_chooser_api.h b/ppapi/thunk/ppb_file_chooser_api.h new file mode 100644 index 0000000..cc54527 --- /dev/null +++ b/ppapi/thunk/ppb_file_chooser_api.h @@ -0,0 +1,22 @@ +// 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_THUNK_PPB_FILE_CHOOSER_API_H_ +#define PPAPI_THUNK_PPB_FILE_CHOOSER_API_H_ + +#include "ppapi/c/dev/ppb_file_chooser_dev.h" + +namespace ppapi { +namespace thunk { + +class PPB_FileChooser_API { + public: + virtual int32_t Show(PP_CompletionCallback callback) = 0; + virtual PP_Resource GetNextChosenFile() = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FILE_CHOOSER_API_H_ diff --git a/ppapi/thunk/ppb_file_chooser_thunk.cc b/ppapi/thunk/ppb_file_chooser_thunk.cc new file mode 100644 index 0000000..8389725 --- /dev/null +++ b/ppapi/thunk/ppb_file_chooser_thunk.cc @@ -0,0 +1,59 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/ppb_file_chooser_dev.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_chooser_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance, + const PP_FileChooserOptions_Dev* options) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateFileChooser(instance, options); +} + +PP_Bool IsFileChooser(PP_Resource resource) { + EnterResource<PPB_FileChooser_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t Show(PP_Resource chooser, PP_CompletionCallback callback) { + EnterResource<PPB_FileChooser_API> enter(chooser, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Show(callback); +} + +PP_Resource GetNextChosenFile(PP_Resource chooser) { + EnterResource<PPB_FileChooser_API> enter(chooser, true); + if (enter.failed()) + return 0; + return enter.object()->GetNextChosenFile(); +} + +const PPB_FileChooser_Dev g_ppb_file_chooser_thunk = { + &Create, + &IsFileChooser, + &Show, + &GetNextChosenFile +}; + +} // namespace + +const PPB_FileChooser_Dev* GetPPB_FileChooser_Thunk() { + return &g_ppb_file_chooser_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_file_io_api.h b/ppapi/thunk/ppb_file_io_api.h new file mode 100644 index 0000000..123e4c2 --- /dev/null +++ b/ppapi/thunk/ppb_file_io_api.h @@ -0,0 +1,48 @@ +// 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_THUNK_PPB_FILE_IO_API_H_ +#define PPAPI_THUNK_PPB_FILE_IO_API_H_ + +#include "ppapi/c/dev/ppb_file_io_dev.h" + +namespace ppapi { +namespace thunk { + +class PPB_FileIO_API { + public: + virtual int32_t Open(PP_Resource file_ref, + int32_t open_flags, + PP_CompletionCallback callback) = 0; + virtual int32_t Query(PP_FileInfo_Dev* info, + PP_CompletionCallback callback) = 0; + virtual int32_t Touch(PP_Time last_access_time, + PP_Time last_modified_time, + PP_CompletionCallback callback) = 0; + virtual int32_t Read(int64_t offset, + char* buffer, + int32_t bytes_to_read, + PP_CompletionCallback callback) = 0; + virtual int32_t Write(int64_t offset, + const char* buffer, + int32_t bytes_to_write, + PP_CompletionCallback callback) = 0; + virtual int32_t SetLength(int64_t length, + PP_CompletionCallback callback) = 0; + virtual int32_t Flush(PP_CompletionCallback callback) = 0; + virtual void Close() = 0; + + // Trusted API. + virtual int32_t GetOSFileDescriptor() = 0; + virtual int32_t WillWrite(int64_t offset, + int32_t bytes_to_write, + PP_CompletionCallback callback) = 0; + virtual int32_t WillSetLength(int64_t length, + PP_CompletionCallback callback) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FILE_IO_API_H_ diff --git a/ppapi/thunk/ppb_file_io_thunk.cc b/ppapi/thunk/ppb_file_io_thunk.cc new file mode 100644 index 0000000..2aaaaa4 --- /dev/null +++ b/ppapi/thunk/ppb_file_io_thunk.cc @@ -0,0 +1,124 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/ppb_file_io_dev.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_io_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateFileIO(instance); +} + +PP_Bool IsFileIO(PP_Resource resource) { + EnterResource<PPB_FileIO_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t Open(PP_Resource file_io, + PP_Resource file_ref, + int32_t open_flags, + PP_CompletionCallback callback) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Open(file_ref, open_flags, callback); +} + +int32_t Query(PP_Resource file_io, + PP_FileInfo_Dev* info, + PP_CompletionCallback callback) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Query(info, callback); +} + +int32_t Touch(PP_Resource file_io, + PP_Time last_access_time, + PP_Time last_modified_time, + PP_CompletionCallback callback) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Touch(last_access_time, last_modified_time, callback); +} + +int32_t Read(PP_Resource file_io, + int64_t offset, + char* buffer, + int32_t bytes_to_read, + PP_CompletionCallback callback) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Read(offset, buffer, bytes_to_read, callback); +} + +int32_t Write(PP_Resource file_io, + int64_t offset, + const char* buffer, + int32_t bytes_to_write, + PP_CompletionCallback callback) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Write(offset, buffer, bytes_to_write, callback); +} + +int32_t SetLength(PP_Resource file_io, + int64_t length, + PP_CompletionCallback callback) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->SetLength(length, callback); +} + +int32_t Flush(PP_Resource file_io, + PP_CompletionCallback callback) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Flush(callback); +} + +void Close(PP_Resource file_io) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.succeeded()) + enter.object()->Close(); +} + +const PPB_FileIO_Dev g_ppb_file_io_thunk = { + &Create, + &IsFileIO, + &Open, + &Query, + &Touch, + &Read, + &Write, + &SetLength, + &Flush, + &Close +}; + +} // namespace + +const PPB_FileIO_Dev* GetPPB_FileIO_Thunk() { + return &g_ppb_file_io_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_file_io_trusted_thunk.cc b/ppapi/thunk/ppb_file_io_trusted_thunk.cc new file mode 100644 index 0000000..1cba025 --- /dev/null +++ b/ppapi/thunk/ppb_file_io_trusted_thunk.cc @@ -0,0 +1,57 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/ppb_file_io_trusted_dev.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_io_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +int32_t GetOSFileDescriptor(PP_Resource file_io) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->GetOSFileDescriptor(); +} + +int32_t WillWrite(PP_Resource file_io, + int64_t offset, + int32_t bytes_to_write, + PP_CompletionCallback callback) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->WillWrite(offset, bytes_to_write, callback); +} + +int32_t WillSetLength(PP_Resource file_io, + int64_t length, + PP_CompletionCallback callback) { + EnterResource<PPB_FileIO_API> enter(file_io, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->WillSetLength(length, callback); +} + +const PPB_FileIOTrusted_Dev g_ppb_file_io_trusted_thunk = { + &GetOSFileDescriptor, + &WillWrite, + &WillSetLength +}; + +} // namespace + +const PPB_FileIOTrusted_Dev* GetPPB_FileIOTrusted_Thunk() { + return &g_ppb_file_io_trusted_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_file_ref_api.h b/ppapi/thunk/ppb_file_ref_api.h new file mode 100644 index 0000000..936fa3d --- /dev/null +++ b/ppapi/thunk/ppb_file_ref_api.h @@ -0,0 +1,32 @@ +// 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_THUNK_PPB_FILE_REF_API_H_ +#define PPAPI_THUNK_PPB_FILE_REF_API_H_ + +#include "ppapi/c/dev/ppb_file_ref_dev.h" + +namespace ppapi { +namespace thunk { + +class PPB_FileRef_API { + public: + virtual PP_FileSystemType_Dev GetFileSystemType() const = 0; + virtual PP_Var GetName() const = 0; + virtual PP_Var GetPath() const = 0; + virtual PP_Resource GetParent() = 0; + virtual int32_t MakeDirectory(PP_Bool make_ancestors, + PP_CompletionCallback callback) = 0; + virtual int32_t Touch(PP_Time last_access_time, + PP_Time last_modified_time, + PP_CompletionCallback callback) = 0; + virtual int32_t Delete(PP_CompletionCallback callback) = 0; + virtual int32_t Rename(PP_Resource new_file_ref, + PP_CompletionCallback callback) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FILE_REF_API_H_ diff --git a/ppapi/thunk/ppb_file_ref_thunk.cc b/ppapi/thunk/ppb_file_ref_thunk.cc new file mode 100644 index 0000000..aeac135 --- /dev/null +++ b/ppapi/thunk/ppb_file_ref_thunk.cc @@ -0,0 +1,115 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/pp_file_info_dev.h" +#include "ppapi/c/dev/ppb_file_ref_dev.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_ref_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Resource file_system, const char* path) { + EnterFunctionGivenResource<ResourceCreationAPI> enter(file_system, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateFileRef(file_system, path); +} + +PP_Bool IsFileRef(PP_Resource resource) { + EnterResource<PPB_FileRef_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref) { + EnterResource<PPB_FileRef_API> enter(file_ref, true); + if (enter.failed()) + return PP_FILESYSTEMTYPE_INVALID; + return enter.object()->GetFileSystemType(); +} + +PP_Var GetName(PP_Resource file_ref) { + EnterResource<PPB_FileRef_API> enter(file_ref, true); + if (enter.failed()) + return PP_MakeUndefined(); + return enter.object()->GetName(); +} + +PP_Var GetPath(PP_Resource file_ref) { + EnterResource<PPB_FileRef_API> enter(file_ref, true); + if (enter.failed()) + return PP_MakeUndefined(); + return enter.object()->GetPath(); +} + +PP_Resource GetParent(PP_Resource file_ref) { + EnterResource<PPB_FileRef_API> enter(file_ref, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->GetParent(); +} + +int32_t MakeDirectory(PP_Resource directory_ref, + PP_Bool make_ancestors, + PP_CompletionCallback callback) { + EnterResource<PPB_FileRef_API> enter(directory_ref, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->MakeDirectory(make_ancestors, callback); +} + +int32_t Touch(PP_Resource file_ref, + PP_Time last_access_time, + PP_Time last_modified_time, + PP_CompletionCallback callback) { + EnterResource<PPB_FileRef_API> enter(file_ref, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Touch(last_access_time, last_modified_time, callback); +} + +int32_t Delete(PP_Resource file_ref, + PP_CompletionCallback callback) { + EnterResource<PPB_FileRef_API> enter(file_ref, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Delete(callback); +} + +int32_t Rename(PP_Resource file_ref, + PP_Resource new_file_ref, + PP_CompletionCallback callback) { + EnterResource<PPB_FileRef_API> enter(file_ref, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Rename(new_file_ref, callback); +} + +const PPB_FileRef_Dev g_ppb_file_ref_thunk = { + &Create, + &IsFileRef, + &GetFileSystemType, + &GetName, + &GetPath, + &GetParent, + &MakeDirectory, + &Touch, + &Delete, + &Rename +}; + +} // namespace + +const PPB_FileRef_Dev* GetPPB_FileRef_Thunk() { + return &g_ppb_file_ref_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_file_system_api.h b/ppapi/thunk/ppb_file_system_api.h new file mode 100644 index 0000000..097d53f --- /dev/null +++ b/ppapi/thunk/ppb_file_system_api.h @@ -0,0 +1,23 @@ +// 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_THUNK_PPB_FILE_SYSTEM_API_H_ +#define PPAPI_THUNK_PPB_FILE_SYSTEM_API_H_ + +#include "ppapi/c/dev/ppb_file_system_dev.h" + +namespace ppapi { +namespace thunk { + +class PPB_FileSystem_API { + public: + virtual int32_t Open(int64_t expected_size, + PP_CompletionCallback callback) = 0; + virtual PP_FileSystemType_Dev GetType() = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FILE_SYSTEM_API_H_ diff --git a/ppapi/thunk/ppb_file_system_thunk.cc b/ppapi/thunk/ppb_file_system_thunk.cc new file mode 100644 index 0000000..e1c4f6a --- /dev/null +++ b/ppapi/thunk/ppb_file_system_thunk.cc @@ -0,0 +1,60 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/ppb_file_system_dev.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_system_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance, PP_FileSystemType_Dev type) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateFileSystem(instance, type); +} + +PP_Bool IsFileSystem(PP_Resource resource) { + EnterResource<PPB_FileSystem_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t Open(PP_Resource file_system, + int64 expected_size, + PP_CompletionCallback callback) { + EnterResource<PPB_FileSystem_API> enter(file_system, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Open(expected_size, callback); +} + +PP_FileSystemType_Dev GetType(PP_Resource file_system) { + EnterResource<PPB_FileSystem_API> enter(file_system, true); + if (enter.failed()) + return PP_FILESYSTEMTYPE_INVALID; + return enter.object()->GetType(); +} + +const PPB_FileSystem_Dev g_ppb_file_system_thunk = { + &Create, + &IsFileSystem, + &Open, + &GetType +}; + +} // namespace + +const PPB_FileSystem_Dev* GetPPB_FileSystem_Thunk() { + return &g_ppb_file_system_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_find_api.h b/ppapi/thunk/ppb_find_api.h new file mode 100644 index 0000000..2c0e058 --- /dev/null +++ b/ppapi/thunk/ppb_find_api.h @@ -0,0 +1,29 @@ +// 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_THUNK_PPB_FIND_API_H_ +#define PPAPI_THUNK_PPB_FIND_API_H_ + +#include "ppapi/c/dev/ppb_find_dev.h" +#include "ppapi/proxy/interface_id.h" + +namespace ppapi { +namespace thunk { + +class PPB_Find_FunctionAPI { + public: + static const ::pp::proxy::InterfaceID interface_id = + ::pp::proxy::INTERFACE_ID_PPB_FIND; + + virtual void NumberOfFindResultsChanged(PP_Instance instance, + int32_t total, + PP_Bool final_result) = 0; + virtual void SelectedFindResultChanged(PP_Instance instance, + int32_t index) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FIND_API_H_ diff --git a/ppapi/thunk/ppb_find_thunk.cc b/ppapi/thunk/ppb_find_thunk.cc new file mode 100644 index 0000000..e37e8ed --- /dev/null +++ b/ppapi/thunk/ppb_find_thunk.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/ppb_find_dev.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_find_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +void NumberOfFindResultsChanged(PP_Instance instance, + int32_t total, + PP_Bool final) { + EnterFunction<PPB_Find_FunctionAPI> enter(instance, true); + if (enter.succeeded()) + enter.functions()->NumberOfFindResultsChanged(instance, total, final); +} + +void SelectedFindResultChanged(PP_Instance instance, int32_t index) { + EnterFunction<PPB_Find_FunctionAPI> enter(instance, true); + if (enter.succeeded()) + enter.functions()->SelectedFindResultChanged(instance, index); +} + +const PPB_Find_Dev g_ppb_find_thunk = { + &NumberOfFindResultsChanged, + &SelectedFindResultChanged +}; + +} // namespace + +const PPB_Find_Dev* GetPPB_Find_Thunk() { + return &g_ppb_find_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index d25285f..8a8cefc 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -5,6 +5,8 @@ #ifndef PPAPI_THUNK_RESOURCE_CREATION_API_H_ #define PPAPI_THUNK_RESOURCE_CREATION_API_H_ +#include "ppapi/c/dev/ppb_file_chooser_dev.h" +#include "ppapi/c/dev/ppb_file_system_dev.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_resource.h" @@ -39,6 +41,15 @@ class ResourceCreationAPI { uint32_t sample_frame_count) = 0; virtual PP_Resource CreateBroker(PP_Instance instance) = 0; virtual PP_Resource CreateBuffer(PP_Instance instance, uint32_t size) = 0; + virtual PP_Resource CreateDirectoryReader(PP_Resource directory_ref) = 0; + virtual PP_Resource CreateFileChooser( + PP_Instance instance, + const PP_FileChooserOptions_Dev* options) = 0; + virtual PP_Resource CreateFileIO(PP_Instance instance) = 0; + virtual PP_Resource CreateFileRef(PP_Resource file_system, + const char* path) = 0; + virtual PP_Resource CreateFileSystem(PP_Instance instance, + PP_FileSystemType_Dev type) = 0; // Note: can't be called CreateFont due to Windows #defines. virtual PP_Resource CreateFontObject( PP_Instance instance, diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index 647f6eb..1738edd 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -12,6 +12,13 @@ struct PPB_BrokerTrusted; struct PPB_Buffer_Dev; struct PPB_CharSet_Dev; struct PPB_CursorControl_Dev; +struct PPB_DirectoryReader_Dev; +struct PPB_FileChooser_Dev; +struct PPB_FileIO_Dev; +struct PPB_FileIOTrusted_Dev; +struct PPB_FileRef_Dev; +struct PPB_FileSystem_Dev; +struct PPB_Find_Dev; struct PPB_Font_Dev; struct PPB_Graphics2D; struct PPB_ImageData; @@ -26,6 +33,13 @@ const PPB_BrokerTrusted* GetPPB_Broker_Thunk(); const PPB_Buffer_Dev* GetPPB_Buffer_Thunk(); const PPB_CharSet_Dev* GetPPB_CharSet_Thunk(); const PPB_CursorControl_Dev* GetPPB_CursorControl_Thunk(); +const PPB_DirectoryReader_Dev* GetPPB_DirectoryReader_Thunk(); +const PPB_FileChooser_Dev* GetPPB_FileChooser_Thunk(); +const PPB_FileIO_Dev* GetPPB_FileIO_Thunk(); +const PPB_FileIOTrusted_Dev* GetPPB_FileIOTrusted_Thunk(); +const PPB_FileRef_Dev* GetPPB_FileRef_Thunk(); +const PPB_FileSystem_Dev* GetPPB_FileSystem_Thunk(); +const PPB_Find_Dev* GetPPB_Find_Thunk(); const PPB_Font_Dev* GetPPB_Font_Thunk(); const PPB_Graphics2D* GetPPB_Graphics2D_Thunk(); const PPB_ImageData* GetPPB_ImageData_Thunk(); diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 73dae78..0ee2ac0 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -258,6 +258,8 @@ '../plugins/ppapi/ppb_file_ref_impl.h', '../plugins/ppapi/ppb_file_system_impl.cc', '../plugins/ppapi/ppb_file_system_impl.h', + '../plugins/ppapi/ppb_find_impl.cc', + '../plugins/ppapi/ppb_find_impl.h', '../plugins/ppapi/ppb_flash_clipboard_impl.cc', '../plugins/ppapi/ppb_flash_clipboard_impl.h', '../plugins/ppapi/ppb_flash_file_impl.cc', diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 7d5bb74..0f16cc1 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -270,21 +270,21 @@ const void* GetInterface(const char* name) { if (strcmp(name, PPB_CURSOR_CONTROL_DEV_INTERFACE) == 0) return ::ppapi::thunk::GetPPB_CursorControl_Thunk(); if (strcmp(name, PPB_DIRECTORYREADER_DEV_INTERFACE) == 0) - return PPB_DirectoryReader_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_DirectoryReader_Thunk(); if (strcmp(name, PPB_FILECHOOSER_DEV_INTERFACE) == 0) - return PPB_FileChooser_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_FileChooser_Thunk(); if (strcmp(name, PPB_FILEIO_DEV_INTERFACE) == 0) - return PPB_FileIO_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_FileIO_Thunk(); if (strcmp(name, PPB_NACL_PRIVATE_INTERFACE) == 0) return PPB_NaCl_Private_Impl::GetInterface(); if (strcmp(name, PPB_FILEIOTRUSTED_DEV_INTERFACE) == 0) - return PPB_FileIO_Impl::GetTrustedInterface(); + return ::ppapi::thunk::GetPPB_FileIOTrusted_Thunk(); if (strcmp(name, PPB_FILEREF_DEV_INTERFACE) == 0) - return PPB_FileRef_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_FileRef_Thunk(); if (strcmp(name, PPB_FILESYSTEM_DEV_INTERFACE) == 0) - return PPB_FileSystem_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_FileSystem_Thunk(); if (strcmp(name, PPB_FIND_DEV_INTERFACE) == 0) - return PluginInstance::GetFindInterface(); + return ::ppapi::thunk::GetPPB_Find_Thunk(); if (strcmp(name, PPB_FLASH_INTERFACE) == 0) return PPB_Flash_Impl::GetInterface(); if (strcmp(name, PPB_FLASH_CLIPBOARD_INTERFACE) == 0) diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index fbbc69e..e73cf09 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -233,34 +233,6 @@ const PPB_Instance_Private ppb_instance_private = { &ExecuteScript }; -void NumberOfFindResultsChanged(PP_Instance instance_id, - int32_t total, - PP_Bool final_result) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return; - - DCHECK_NE(instance->find_identifier(), -1); - instance->delegate()->NumberOfFindResultsChanged( - instance->find_identifier(), total, PPBoolToBool(final_result)); -} - -void SelectedFindResultChanged(PP_Instance instance_id, - int32_t index) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return; - - DCHECK_NE(instance->find_identifier(), -1); - instance->delegate()->SelectedFindResultChanged( - instance->find_identifier(), index); -} - -const PPB_Find_Dev ppb_find = { - &NumberOfFindResultsChanged, - &SelectedFindResultChanged, -}; - PP_Bool IsFullscreen(PP_Instance instance_id) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); if (!instance) @@ -410,11 +382,6 @@ const void* PluginInstance::GetInterface(const char* if_name) { } // static -const PPB_Find_Dev* PluginInstance::GetFindInterface() { - return &ppb_find; -} - -// static const PPB_Fullscreen_Dev* PluginInstance::GetFullscreenInterface() { return &ppb_fullscreen; } diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 87d86ed..6c60edc 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -34,7 +34,6 @@ typedef struct NPObject NPObject; struct PP_Var; struct PPB_Instance; struct PPB_Instance_Private; -struct PPB_Find_Dev; struct PPB_Fullscreen_Dev; struct PPB_Messaging; struct PPB_Zoom_Dev; @@ -97,7 +96,6 @@ class PluginInstance : public base::RefCounted<PluginInstance> { // Returns a pointer to the interface implementing PPB_Find that is // exposed to the plugin. - static const PPB_Find_Dev* GetFindInterface(); static const PPB_Fullscreen_Dev* GetFullscreenInterface(); static const PPB_Messaging* GetMessagingInterface(); static const PPB_Zoom_Dev* GetZoomInterface(); diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc index 1709b83..b592649 100644 --- a/webkit/plugins/ppapi/ppb_audio_impl.cc +++ b/webkit/plugins/ppapi/ppb_audio_impl.cc @@ -26,7 +26,8 @@ PPB_AudioConfig_Impl::PPB_AudioConfig_Impl(PluginInstance* instance) PPB_AudioConfig_Impl::~PPB_AudioConfig_Impl() { } -::ppapi::thunk::PPB_AudioConfig_API* PPB_AudioConfig_Impl::AsAudioConfig_API() { +::ppapi::thunk::PPB_AudioConfig_API* +PPB_AudioConfig_Impl::AsPPB_AudioConfig_API() { return this; } @@ -62,11 +63,11 @@ PPB_Audio_Impl::~PPB_Audio_Impl() { } } -::ppapi::thunk::PPB_Audio_API* PPB_Audio_Impl::AsAudio_API() { +::ppapi::thunk::PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { return this; } -::ppapi::thunk::PPB_AudioTrusted_API* PPB_Audio_Impl::AsAudioTrusted_API() { +::ppapi::thunk::PPB_AudioTrusted_API* PPB_Audio_Impl::AsPPB_AudioTrusted_API() { return this; } diff --git a/webkit/plugins/ppapi/ppb_audio_impl.h b/webkit/plugins/ppapi/ppb_audio_impl.h index 060b8bf..4909903 100644 --- a/webkit/plugins/ppapi/ppb_audio_impl.h +++ b/webkit/plugins/ppapi/ppb_audio_impl.h @@ -34,7 +34,7 @@ class PPB_AudioConfig_Impl : public Resource, virtual ~PPB_AudioConfig_Impl(); // ResourceObjectBase overrides. - virtual ::ppapi::thunk::PPB_AudioConfig_API* AsAudioConfig_API() OVERRIDE; + virtual ::ppapi::thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(PPB_AudioConfig_Impl); @@ -57,8 +57,8 @@ class PPB_Audio_Impl : public Resource, PPB_Audio_Callback user_callback, void* user_data); // ResourceObjectBase overrides. - virtual ::ppapi::thunk::PPB_Audio_API* AsAudio_API(); - virtual ::ppapi::thunk::PPB_AudioTrusted_API* AsAudioTrusted_API(); + virtual ::ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API(); + virtual ::ppapi::thunk::PPB_AudioTrusted_API* AsPPB_AudioTrusted_API(); // PPB_Audio_API implementation. virtual PP_Resource GetCurrentConfig() OVERRIDE; diff --git a/webkit/plugins/ppapi/ppb_broker_impl.cc b/webkit/plugins/ppapi/ppb_broker_impl.cc index 2da35d6..7d2aec0 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.cc +++ b/webkit/plugins/ppapi/ppb_broker_impl.cc @@ -61,7 +61,7 @@ PPB_Broker_Impl* PPB_Broker_Impl::AsPPB_Broker_Impl() { return this; } -PPB_Broker_API* PPB_Broker_Impl::AsBroker_API() { +PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() { return this; } diff --git a/webkit/plugins/ppapi/ppb_broker_impl.h b/webkit/plugins/ppapi/ppb_broker_impl.h index c569c1c..9ae920e 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.h +++ b/webkit/plugins/ppapi/ppb_broker_impl.h @@ -32,7 +32,7 @@ class PPB_Broker_Impl : public Resource, virtual PPB_Broker_Impl* AsPPB_Broker_Impl() OVERRIDE; // ResourceObjectBase override. - virtual ::ppapi::thunk::PPB_Broker_API* AsBroker_API() OVERRIDE; + virtual ::ppapi::thunk::PPB_Broker_API* AsPPB_Broker_API() OVERRIDE; // PPB_BrokerTrusted implementation. virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE; diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.cc b/webkit/plugins/ppapi/ppb_buffer_impl.cc index 182738f..39d3191 100644 --- a/webkit/plugins/ppapi/ppb_buffer_impl.cc +++ b/webkit/plugins/ppapi/ppb_buffer_impl.cc @@ -41,7 +41,7 @@ PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { return this; } -PPB_Buffer_API* PPB_Buffer_Impl::AsBuffer_API() { +PPB_Buffer_API* PPB_Buffer_Impl::AsPPB_Buffer_API() { return this; } diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.h b/webkit/plugins/ppapi/ppb_buffer_impl.h index f68c825..2a2743d 100644 --- a/webkit/plugins/ppapi/ppb_buffer_impl.h +++ b/webkit/plugins/ppapi/ppb_buffer_impl.h @@ -31,7 +31,7 @@ class PPB_Buffer_Impl : public Resource, uint32_t size() const { return size_; } // ResourceObjectBase overries. - virtual ::ppapi::thunk::PPB_Buffer_API* AsBuffer_API() OVERRIDE; + virtual ::ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE; // PPB_Buffer_API implementation. virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE; diff --git a/webkit/plugins/ppapi/ppb_char_set_impl.cc b/webkit/plugins/ppapi/ppb_char_set_impl.cc index fcabf2f..496e339 100644 --- a/webkit/plugins/ppapi/ppb_char_set_impl.cc +++ b/webkit/plugins/ppapi/ppb_char_set_impl.cc @@ -24,7 +24,7 @@ PPB_CharSet_Impl::PPB_CharSet_Impl(PluginInstance* instance) PPB_CharSet_Impl::~PPB_CharSet_Impl() { } -PPB_CharSet_FunctionAPI* PPB_CharSet_Impl::AsCharSet_FunctionAPI() { +PPB_CharSet_FunctionAPI* PPB_CharSet_Impl::AsPPB_CharSet_FunctionAPI() { return this; } diff --git a/webkit/plugins/ppapi/ppb_char_set_impl.h b/webkit/plugins/ppapi/ppb_char_set_impl.h index 6036dec..768ab8c 100644 --- a/webkit/plugins/ppapi/ppb_char_set_impl.h +++ b/webkit/plugins/ppapi/ppb_char_set_impl.h @@ -22,7 +22,7 @@ class PPB_CharSet_Impl : public ::ppapi::FunctionGroupBase, virtual ~PPB_CharSet_Impl(); // FunctionGroupBase overrides. - virtual ::ppapi::thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI(); + virtual ::ppapi::thunk::PPB_CharSet_FunctionAPI* AsPPB_CharSet_FunctionAPI(); // PPB_CharSet_FunctionAPI implementation. virtual char* UTF16ToCharSet(PP_Instance instance, diff --git a/webkit/plugins/ppapi/ppb_cursor_control_impl.cc b/webkit/plugins/ppapi/ppb_cursor_control_impl.cc index 4bfb081..3968dd4 100644 --- a/webkit/plugins/ppapi/ppb_cursor_control_impl.cc +++ b/webkit/plugins/ppapi/ppb_cursor_control_impl.cc @@ -28,7 +28,7 @@ PPB_CursorControl_Impl::~PPB_CursorControl_Impl() { } PPB_CursorControl_FunctionAPI* -PPB_CursorControl_Impl::AsCursorControl_FunctionAPI() { +PPB_CursorControl_Impl::AsPPB_CursorControl_FunctionAPI() { return this; } diff --git a/webkit/plugins/ppapi/ppb_cursor_control_impl.h b/webkit/plugins/ppapi/ppb_cursor_control_impl.h index f3b8a7e..6b1242e 100644 --- a/webkit/plugins/ppapi/ppb_cursor_control_impl.h +++ b/webkit/plugins/ppapi/ppb_cursor_control_impl.h @@ -24,7 +24,7 @@ class PPB_CursorControl_Impl // FunctionGroupBase overrides. virtual ::ppapi::thunk::PPB_CursorControl_FunctionAPI* - AsCursorControl_FunctionAPI() OVERRIDE; + AsPPB_CursorControl_FunctionAPI() OVERRIDE; // PPB_CursorControl_FunctionAPI implementation. virtual PP_Bool SetCursor(PP_Instance instance, diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc index 33ca825..cba21d5 100644 --- a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc +++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc @@ -9,6 +9,8 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/dev/ppb_directory_reader_dev.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_ref_api.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/file_callbacks.h" #include "webkit/plugins/ppapi/plugin_delegate.h" @@ -18,6 +20,10 @@ #include "webkit/plugins/ppapi/ppb_file_system_impl.h" #include "webkit/plugins/ppapi/resource_tracker.h" +using ::ppapi::thunk::EnterResourceNoLock; +using ::ppapi::thunk::PPB_DirectoryReader_API; +using ::ppapi::thunk::PPB_FileRef_API; + namespace webkit { namespace ppapi { @@ -43,38 +49,6 @@ FilePath::StringType UTF8StringToFilePathString(const std::string& str) { #endif } -PP_Resource Create(PP_Resource directory_ref_id) { - scoped_refptr<PPB_FileRef_Impl> directory_ref( - Resource::GetAs<PPB_FileRef_Impl>(directory_ref_id)); - if (!directory_ref) - return 0; - - PPB_DirectoryReader_Impl* reader = - new PPB_DirectoryReader_Impl(directory_ref); - return reader->GetReference(); -} - -PP_Bool IsDirectoryReader(PP_Resource resource) { - return BoolToPPBool(!!Resource::GetAs<PPB_DirectoryReader_Impl>(resource)); -} - -int32_t GetNextEntry(PP_Resource reader_id, - PP_DirectoryEntry_Dev* entry, - PP_CompletionCallback callback) { - scoped_refptr<PPB_DirectoryReader_Impl> reader( - Resource::GetAs<PPB_DirectoryReader_Impl>(reader_id)); - if (!reader) - return PP_ERROR_BADRESOURCE; - - return reader->GetNextEntry(entry, callback); -} - -const PPB_DirectoryReader_Dev ppb_directoryreader = { - &Create, - &IsDirectoryReader, - &GetNextEntry -}; - } // namespace PPB_DirectoryReader_Impl::PPB_DirectoryReader_Impl( @@ -88,8 +62,15 @@ PPB_DirectoryReader_Impl::PPB_DirectoryReader_Impl( PPB_DirectoryReader_Impl::~PPB_DirectoryReader_Impl() { } -const PPB_DirectoryReader_Dev* PPB_DirectoryReader_Impl::GetInterface() { - return &ppb_directoryreader; +// static +PP_Resource PPB_DirectoryReader_Impl::Create(PP_Resource directory_ref) { + EnterResourceNoLock<PPB_FileRef_API> enter(directory_ref, true); + if (enter.failed()) + return 0; + + PPB_DirectoryReader_Impl* reader = new PPB_DirectoryReader_Impl( + static_cast<PPB_FileRef_Impl*>(enter.object())); + return reader->GetReference(); } PPB_DirectoryReader_Impl* @@ -97,6 +78,10 @@ PPB_DirectoryReader_Impl::AsPPB_DirectoryReader_Impl() { return this; } +PPB_DirectoryReader_API* PPB_DirectoryReader_Impl::AsPPB_DirectoryReader_API() { + return this; +} + int32_t PPB_DirectoryReader_Impl::GetNextEntry( PP_DirectoryEntry_Dev* entry, PP_CompletionCallback callback) { @@ -109,7 +94,7 @@ int32_t PPB_DirectoryReader_Impl::GetNextEntry( return PP_OK; } - PluginInstance* instance = directory_ref_->GetFileSystem()->instance(); + PluginInstance* instance = directory_ref_->instance(); PP_Resource resource_id = GetReferenceNoAddRef(); DCHECK(resource_id != 0); if (!instance->delegate()->ReadDirectory( @@ -126,7 +111,7 @@ void PPB_DirectoryReader_Impl::AddNewEntries( const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { DCHECK(!entries.empty() || !has_more); has_more_ = has_more; - std::string dir_path = directory_ref_->GetPath(); + std::string dir_path = directory_ref_->virtual_path(); if (dir_path[dir_path.size() - 1] != '/') dir_path += '/'; FilePath::StringType dir_file_path = UTF8StringToFilePathString(dir_path); @@ -150,7 +135,7 @@ bool PPB_DirectoryReader_Impl::FillUpEntry() { if (entry_->file_ref) ResourceTracker::Get()->UnrefResource(entry_->file_ref); PPB_FileRef_Impl* file_ref = - new PPB_FileRef_Impl(instance(), directory_ref_->GetFileSystem(), + new PPB_FileRef_Impl(instance(), directory_ref_->file_system(), FilePathStringToUTF8String(dir_entry.name)); entry_->file_ref = file_ref->GetReference(); entry_->file_type = diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.h b/webkit/plugins/ppapi/ppb_directory_reader_impl.h index 6e6dfdf..67be4a5 100644 --- a/webkit/plugins/ppapi/ppb_directory_reader_impl.h +++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.h @@ -8,6 +8,7 @@ #include <queue> #include "base/file_util_proxy.h" +#include "ppapi/thunk/ppb_directory_reader_api.h" #include "webkit/plugins/ppapi/resource.h" struct PP_CompletionCallback; @@ -19,21 +20,25 @@ namespace ppapi { class PPB_FileRef_Impl; -class PPB_DirectoryReader_Impl : public Resource { +class PPB_DirectoryReader_Impl + : public Resource, + public ::ppapi::thunk::PPB_DirectoryReader_API { public: explicit PPB_DirectoryReader_Impl(PPB_FileRef_Impl* directory_ref); virtual ~PPB_DirectoryReader_Impl(); - // Returns a pointer to the interface implementing PPB_DirectoryReader that - // is exposed to the plugin. - static const PPB_DirectoryReader_Dev* GetInterface(); + static PP_Resource Create(PP_Resource directory_ref); // Resource overrides. - virtual PPB_DirectoryReader_Impl* AsPPB_DirectoryReader_Impl(); + virtual PPB_DirectoryReader_Impl* AsPPB_DirectoryReader_Impl() OVERRIDE; - // PPB_DirectoryReader implementation. - int32_t GetNextEntry(PP_DirectoryEntry_Dev* entry, - PP_CompletionCallback callback); + // ResourceObjectBase overrides. + virtual ::ppapi::thunk::PPB_DirectoryReader_API* AsPPB_DirectoryReader_API() + OVERRIDE; + + // PPB_DirectoryReader_API implementation. + virtual int32_t GetNextEntry(PP_DirectoryEntry_Dev* entry, + PP_CompletionCallback callback) OVERRIDE; void AddNewEntries(const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more); diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc index 817dcd5..3ce1489 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc @@ -25,6 +25,7 @@ #include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/glue/webkit_glue.h" +using ppapi::thunk::PPB_FileChooser_API; using WebKit::WebCString; using WebKit::WebFileChooserCompletion; using WebKit::WebFileChooserParams; @@ -36,53 +37,6 @@ namespace ppapi { namespace { -PP_Resource Create(PP_Instance instance_id, - const PP_FileChooserOptions_Dev* options) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return 0; - - if ((options->mode != PP_FILECHOOSERMODE_OPEN) && - (options->mode != PP_FILECHOOSERMODE_OPENMULTIPLE)) - return 0; - - PPB_FileChooser_Impl* chooser = new PPB_FileChooser_Impl(instance, options); - return chooser->GetReference(); -} - -PP_Bool IsFileChooser(PP_Resource resource) { - return BoolToPPBool(!!Resource::GetAs<PPB_FileChooser_Impl>(resource)); -} - -int32_t Show(PP_Resource chooser_id, PP_CompletionCallback callback) { - scoped_refptr<PPB_FileChooser_Impl> chooser( - Resource::GetAs<PPB_FileChooser_Impl>(chooser_id)); - if (!chooser) - return PP_ERROR_BADRESOURCE; - - return chooser->Show(callback); -} - -PP_Resource GetNextChosenFile(PP_Resource chooser_id) { - scoped_refptr<PPB_FileChooser_Impl> chooser( - Resource::GetAs<PPB_FileChooser_Impl>(chooser_id)); - if (!chooser) - return 0; - - scoped_refptr<PPB_FileRef_Impl> file_ref(chooser->GetNextChosenFile()); - if (!file_ref) - return 0; - - return file_ref->GetReference(); -} - -const PPB_FileChooser_Dev ppb_filechooser = { - &Create, - &IsFileChooser, - &Show, - &GetNextChosenFile -}; - class FileChooserCompletionImpl : public WebFileChooserCompletion { public: FileChooserCompletionImpl(PPB_FileChooser_Impl* file_chooser) @@ -120,14 +74,29 @@ PPB_FileChooser_Impl::~PPB_FileChooser_Impl() { } // static -const PPB_FileChooser_Dev* PPB_FileChooser_Impl::GetInterface() { - return &ppb_filechooser; +PP_Resource PPB_FileChooser_Impl::Create( + PP_Instance pp_instance, + const PP_FileChooserOptions_Dev* options) { + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); + if (!instance) + return 0; + + if ((options->mode != PP_FILECHOOSERMODE_OPEN) && + (options->mode != PP_FILECHOOSERMODE_OPENMULTIPLE)) + return 0; + + PPB_FileChooser_Impl* chooser = new PPB_FileChooser_Impl(instance, options); + return chooser->GetReference(); } PPB_FileChooser_Impl* PPB_FileChooser_Impl::AsPPB_FileChooser_Impl() { return this; } +PPB_FileChooser_API* PPB_FileChooser_Impl::AsPPB_FileChooser_API() { + return this; +} + void PPB_FileChooser_Impl::StoreChosenFiles( const std::vector<std::string>& files) { chosen_files_.clear(); @@ -176,7 +145,7 @@ void PPB_FileChooser_Impl::RunCallback(int32_t result) { callback->Run(result); // Will complete abortively if necessary. } -int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { +int32_t PPB_FileChooser_Impl::Show(PP_CompletionCallback callback) { int32_t rv = ValidateCallback(callback); if (rv != PP_OK) return rv; @@ -197,11 +166,11 @@ int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { return PP_OK_COMPLETIONPENDING; } -scoped_refptr<PPB_FileRef_Impl> PPB_FileChooser_Impl::GetNextChosenFile() { +PP_Resource PPB_FileChooser_Impl::GetNextChosenFile() { if (next_chosen_file_index_ >= chosen_files_.size()) - return NULL; + return 0; - return chosen_files_[next_chosen_file_index_++]; + return chosen_files_[next_chosen_file_index_++]->GetReference(); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.h b/webkit/plugins/ppapi/ppb_file_chooser_impl.h index 57d1d32..024970f 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.h +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.h @@ -10,6 +10,7 @@ #include "base/memory/ref_counted.h" #include "ppapi/c/dev/ppb_file_chooser_dev.h" +#include "ppapi/thunk/ppb_file_chooser_api.h" #include "webkit/plugins/ppapi/resource.h" struct PP_CompletionCallback; @@ -21,19 +22,22 @@ class PluginInstance; class PPB_FileRef_Impl; class TrackedCompletionCallback; -class PPB_FileChooser_Impl : public Resource { +class PPB_FileChooser_Impl : public Resource, + public ::ppapi::thunk::PPB_FileChooser_API { public: PPB_FileChooser_Impl(PluginInstance* instance, const PP_FileChooserOptions_Dev* options); virtual ~PPB_FileChooser_Impl(); - // Returns a pointer to the interface implementing PPB_FileChooser that is - // exposed to the plugin. - static const PPB_FileChooser_Dev* GetInterface(); + static PP_Resource Create(PP_Instance instance, + const PP_FileChooserOptions_Dev* options); // Resource overrides. virtual PPB_FileChooser_Impl* AsPPB_FileChooser_Impl(); + // ResourceObjectBase overrides. + virtual ::ppapi::thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; + // Stores the list of selected files. void StoreChosenFiles(const std::vector<std::string>& files); @@ -48,9 +52,9 @@ class PPB_FileChooser_Impl : public Resource { void RunCallback(int32_t result); - // PPB_FileChooser implementation. - int32_t Show(const PP_CompletionCallback& callback); - scoped_refptr<PPB_FileRef_Impl> GetNextChosenFile(); + // PPB_FileChooser_API implementation. + virtual int32_t Show(PP_CompletionCallback callback) OVERRIDE; + virtual PP_Resource GetNextChosenFile() OVERRIDE; private: PP_FileChooserMode_Dev mode_; diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.cc b/webkit/plugins/ppapi/ppb_file_io_impl.cc index 0989f1e..b68da1b 100644 --- a/webkit/plugins/ppapi/ppb_file_io_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_io_impl.cc @@ -15,6 +15,8 @@ #include "ppapi/c/dev/ppb_file_io_trusted_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_ref_api.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/file_type_conversions.h" #include "webkit/plugins/ppapi/plugin_module.h" @@ -22,163 +24,13 @@ #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/resource_tracker.h" +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_FileIO_API; +using ppapi::thunk::PPB_FileRef_API; + namespace webkit { namespace ppapi { -namespace { - -PP_Resource Create(PP_Instance instance_id) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return 0; - - PPB_FileIO_Impl* file_io = new PPB_FileIO_Impl(instance); - return file_io->GetReference(); -} - -PP_Bool IsFileIO(PP_Resource resource) { - return BoolToPPBool(!!Resource::GetAs<PPB_FileIO_Impl>(resource)); -} - -int32_t Open(PP_Resource file_io_id, - PP_Resource file_ref_id, - int32_t open_flags, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - - scoped_refptr<PPB_FileRef_Impl> file_ref( - Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); - if (!file_ref) - return PP_ERROR_BADRESOURCE; - - return file_io->Open(file_ref, open_flags, callback); -} - -int32_t Query(PP_Resource file_io_id, - PP_FileInfo_Dev* info, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - return file_io->Query(info, callback); -} - -int32_t Touch(PP_Resource file_io_id, - PP_Time last_access_time, - PP_Time last_modified_time, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - return file_io->Touch(last_access_time, last_modified_time, callback); -} - -int32_t Read(PP_Resource file_io_id, - int64_t offset, - char* buffer, - int32_t bytes_to_read, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - return file_io->Read(offset, buffer, bytes_to_read, callback); -} - -int32_t Write(PP_Resource file_io_id, - int64_t offset, - const char* buffer, - int32_t bytes_to_write, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - return file_io->Write(offset, buffer, bytes_to_write, callback); -} - -int32_t SetLength(PP_Resource file_io_id, - int64_t length, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - return file_io->SetLength(length, callback); -} - -int32_t Flush(PP_Resource file_io_id, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - return file_io->Flush(callback); -} - -void Close(PP_Resource file_io_id) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return; - file_io->Close(); -} - -const PPB_FileIO_Dev ppb_fileio = { - &Create, - &IsFileIO, - &Open, - &Query, - &Touch, - &Read, - &Write, - &SetLength, - &Flush, - &Close -}; - -int32_t GetOSFileDescriptor(PP_Resource file_io_id) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - return file_io->GetOSFileDescriptor(); -} - -int32_t WillWrite(PP_Resource file_io_id, - int64_t offset, - int32_t bytes_to_write, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - return file_io->WillWrite(offset, bytes_to_write, callback); -} - -int32_t WillSetLength(PP_Resource file_io_id, - int64_t length, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileIO_Impl> - file_io(Resource::GetAs<PPB_FileIO_Impl>(file_io_id)); - if (!file_io) - return PP_ERROR_BADRESOURCE; - return file_io->WillSetLength(length, callback); -} - -const PPB_FileIOTrusted_Dev ppb_fileiotrusted = { - &GetOSFileDescriptor, - &WillWrite, - &WillSetLength -}; - -} // namespace - PPB_FileIO_Impl::PPB_FileIO_Impl(PluginInstance* instance) : Resource(instance), ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), @@ -193,22 +45,26 @@ PPB_FileIO_Impl::~PPB_FileIO_Impl() { } // static -const PPB_FileIO_Dev* PPB_FileIO_Impl::GetInterface() { - return &ppb_fileio; -} - -// static -const PPB_FileIOTrusted_Dev* PPB_FileIO_Impl::GetTrustedInterface() { - return &ppb_fileiotrusted; +PP_Resource PPB_FileIO_Impl::Create(PP_Instance pp_instance) { + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); + if (!instance) + return 0; + PPB_FileIO_Impl* file_io = new PPB_FileIO_Impl(instance); + return file_io->GetReference(); } -PPB_FileIO_Impl* PPB_FileIO_Impl::AsPPB_FileIO_Impl() { +PPB_FileIO_API* PPB_FileIO_Impl::AsPPB_FileIO_API() { return this; } -int32_t PPB_FileIO_Impl::Open(PPB_FileRef_Impl* file_ref, +int32_t PPB_FileIO_Impl::Open(PP_Resource pp_file_ref, int32_t open_flags, PP_CompletionCallback callback) { + EnterResourceNoLock<PPB_FileRef_API> enter(pp_file_ref, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); + int32_t rv = CommonCallValidation(false, callback); if (rv != PP_OK) return rv; diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.h b/webkit/plugins/ppapi/ppb_file_io_impl.h index 621aa1e..32cd6a0 100644 --- a/webkit/plugins/ppapi/ppb_file_io_impl.h +++ b/webkit/plugins/ppapi/ppb_file_io_impl.h @@ -13,6 +13,7 @@ #include "base/platform_file.h" #include "ppapi/c/dev/pp_file_info_dev.h" #include "ppapi/c/pp_time.h" +#include "ppapi/thunk/ppb_file_io_api.h" #include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/resource.h" @@ -27,51 +28,44 @@ namespace ppapi { class PluginModule; class PPB_FileRef_Impl; -class PPB_FileIO_Impl : public Resource { +class PPB_FileIO_Impl : public Resource, + public ::ppapi::thunk::PPB_FileIO_API { public: explicit PPB_FileIO_Impl(PluginInstance* instance); virtual ~PPB_FileIO_Impl(); - // Returns a pointer to the interface implementing PPB_FileIO that is exposed - // to the plugin. - static const PPB_FileIO_Dev* GetInterface(); - - // Returns a pointer to the interface implementing PPB_FileIOTrusted that is - // exposed to the plugin. - static const PPB_FileIOTrusted_Dev* GetTrustedInterface(); - - // Resource overrides. - virtual PPB_FileIO_Impl* AsPPB_FileIO_Impl(); - - // PPB_FileIO implementation. - int32_t Open(PPB_FileRef_Impl* file_ref, - int32_t open_flags, - PP_CompletionCallback callback); - int32_t Query(PP_FileInfo_Dev* info, - PP_CompletionCallback callback); - int32_t Touch(PP_Time last_access_time, - PP_Time last_modified_time, - PP_CompletionCallback callback); - int32_t Read(int64_t offset, - char* buffer, - int32_t bytes_to_read, - PP_CompletionCallback callback); - int32_t Write(int64_t offset, - const char* buffer, - int32_t bytes_to_write, - PP_CompletionCallback callback); - int32_t SetLength(int64_t length, - PP_CompletionCallback callback); - int32_t Flush(PP_CompletionCallback callback); - void Close(); - - // PPB_FileIOTrusted implementation. - int32_t GetOSFileDescriptor(); - int32_t WillWrite(int64_t offset, - int32_t bytes_to_write, - PP_CompletionCallback callback); - int32_t WillSetLength(int64_t length, - PP_CompletionCallback callback); + static PP_Resource Create(PP_Instance instance); + + // ResourceObjectBase overrides. + virtual ::ppapi::thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE; + + // PPB_FileIO_API implementation. + virtual int32_t Open(PP_Resource file_ref, + int32_t open_flags, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t Query(PP_FileInfo_Dev* info, + 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 Read(int64_t offset, + char* buffer, + int32_t bytes_to_read, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t Write(int64_t offset, + const char* buffer, + int32_t bytes_to_write, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t SetLength(int64_t length, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE; + virtual void Close() OVERRIDE; + virtual int32_t GetOSFileDescriptor() OVERRIDE; + virtual int32_t WillWrite(int64_t offset, + int32_t bytes_to_write, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t WillSetLength(int64_t length, + PP_CompletionCallback callback) OVERRIDE; private: // Verifies: diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc index 8ab57e7..de31bfb 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc @@ -8,6 +8,8 @@ #include "base/utf_string_conversions.h" #include "googleurl/src/gurl.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_system_api.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/file_callbacks.h" #include "webkit/plugins/ppapi/plugin_delegate.h" @@ -17,6 +19,10 @@ #include "webkit/plugins/ppapi/ppb_file_system_impl.h" #include "webkit/plugins/ppapi/var.h" +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_FileRef_API; +using ppapi::thunk::PPB_FileSystem_API; + namespace webkit { namespace ppapi { @@ -41,192 +47,6 @@ void TrimTrailingSlash(std::string* path) { path->erase(path->size() - 1, 1); } -PP_Resource Create(PP_Resource file_system_id, const char* path) { - scoped_refptr<PPB_FileSystem_Impl> file_system( - Resource::GetAs<PPB_FileSystem_Impl>(file_system_id)); - if (!file_system) - return 0; - - if (!file_system->instance()) - return 0; - - std::string validated_path(path); - if (!IsValidLocalPath(validated_path)) - return 0; - TrimTrailingSlash(&validated_path); - - PPB_FileRef_Impl* file_ref = - new PPB_FileRef_Impl(file_system->instance(), - file_system, validated_path); - return file_ref->GetReference(); -} - -PP_Bool IsFileRef(PP_Resource resource) { - return BoolToPPBool(!!Resource::GetAs<PPB_FileRef_Impl>(resource)); -} - -PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref_id) { - scoped_refptr<PPB_FileRef_Impl> file_ref( - Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); - if (!file_ref) - return PP_FILESYSTEMTYPE_INVALID; - return file_ref->GetFileSystemType(); -} - -PP_Var GetName(PP_Resource file_ref_id) { - scoped_refptr<PPB_FileRef_Impl> file_ref( - Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); - if (!file_ref) - return PP_MakeUndefined(); - return StringVar::StringToPPVar(file_ref->instance()->module(), - file_ref->GetName()); -} - -PP_Var GetPath(PP_Resource file_ref_id) { - scoped_refptr<PPB_FileRef_Impl> file_ref( - Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); - if (!file_ref) - return PP_MakeUndefined(); - - if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) - return PP_MakeUndefined(); - - return StringVar::StringToPPVar(file_ref->instance()->module(), - file_ref->GetPath()); -} - -PP_Resource GetParent(PP_Resource file_ref_id) { - scoped_refptr<PPB_FileRef_Impl> file_ref( - Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); - if (!file_ref) - return 0; - - if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) - return 0; - - scoped_refptr<PPB_FileRef_Impl> parent_ref(file_ref->GetParent()); - if (!parent_ref) - return 0; - - return parent_ref->GetReference(); -} - -int32_t MakeDirectory(PP_Resource directory_ref_id, - PP_Bool make_ancestors, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileRef_Impl> directory_ref( - Resource::GetAs<PPB_FileRef_Impl>(directory_ref_id)); - if (!directory_ref) - return PP_ERROR_BADRESOURCE; - - scoped_refptr<PPB_FileSystem_Impl> file_system = - directory_ref->GetFileSystem(); - if (!file_system || !file_system->opened() || - (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) - return PP_ERROR_NOACCESS; - - PluginInstance* instance = file_system->instance(); - if (!instance->delegate()->MakeDirectory( - directory_ref->GetFileSystemURL(), PPBoolToBool(make_ancestors), - new FileCallbacks(instance->module()->AsWeakPtr(), directory_ref_id, - callback, NULL, NULL, NULL))) - return PP_ERROR_FAILED; - - return PP_OK_COMPLETIONPENDING; -} - -int32_t Touch(PP_Resource file_ref_id, - PP_Time last_access_time, - PP_Time last_modified_time, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileRef_Impl> file_ref( - Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); - if (!file_ref) - return PP_ERROR_BADRESOURCE; - - scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); - if (!file_system || !file_system->opened() || - (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) - return PP_ERROR_NOACCESS; - - PluginInstance* instance = file_system->instance(); - if (!instance->delegate()->Touch( - file_ref->GetFileSystemURL(), - base::Time::FromDoubleT(last_access_time), - base::Time::FromDoubleT(last_modified_time), - new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, - callback, NULL, NULL, NULL))) - return PP_ERROR_FAILED; - - return PP_OK_COMPLETIONPENDING; -} - -int32_t Delete(PP_Resource file_ref_id, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileRef_Impl> file_ref( - Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); - if (!file_ref) - return PP_ERROR_BADRESOURCE; - - scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); - if (!file_system || !file_system->opened() || - (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) - return PP_ERROR_NOACCESS; - - PluginInstance* instance = file_system->instance(); - if (!instance->delegate()->Delete( - file_ref->GetFileSystemURL(), - new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, - callback, NULL, NULL, NULL))) - return PP_ERROR_FAILED; - - return PP_OK_COMPLETIONPENDING; -} - -int32_t Rename(PP_Resource file_ref_id, - PP_Resource new_file_ref_id, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileRef_Impl> file_ref( - Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); - if (!file_ref) - return PP_ERROR_BADRESOURCE; - - scoped_refptr<PPB_FileRef_Impl> new_file_ref( - Resource::GetAs<PPB_FileRef_Impl>(new_file_ref_id)); - if (!new_file_ref) - return PP_ERROR_BADRESOURCE; - - scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); - if (!file_system || !file_system->opened() || - (file_system != new_file_ref->GetFileSystem()) || - (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) - return PP_ERROR_NOACCESS; - - // TODO(viettrungluu): Also cancel when the new file ref is destroyed? - // http://crbug.com/67624 - PluginInstance* instance = file_system->instance(); - if (!instance->delegate()->Rename( - file_ref->GetFileSystemURL(), new_file_ref->GetFileSystemURL(), - new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, - callback, NULL, NULL, NULL))) - return PP_ERROR_FAILED; - - return PP_OK_COMPLETIONPENDING; -} - -const PPB_FileRef_Dev ppb_fileref = { - &Create, - &IsFileRef, - &GetFileSystemType, - &GetName, - &GetPath, - &GetParent, - &MakeDirectory, - &Touch, - &Delete, - &Rename -}; - } // namespace PPB_FileRef_Impl::PPB_FileRef_Impl() @@ -254,41 +74,78 @@ PPB_FileRef_Impl::~PPB_FileRef_Impl() { } // static -const PPB_FileRef_Dev* PPB_FileRef_Impl::GetInterface() { - return &ppb_fileref; +PP_Resource PPB_FileRef_Impl::Create(PP_Resource pp_file_system, + const char* path) { + EnterResourceNoLock<PPB_FileSystem_API> enter(pp_file_system, true); + if (enter.failed()) + return 0; + + PPB_FileSystem_Impl* file_system = + static_cast<PPB_FileSystem_Impl*>(enter.object()); + if (!file_system->instance()) + return 0; + + std::string validated_path(path); + if (!IsValidLocalPath(validated_path)) + return 0; + TrimTrailingSlash(&validated_path); + + PPB_FileRef_Impl* file_ref = + new PPB_FileRef_Impl(file_system->instance(), + file_system, validated_path); + return file_ref->GetReference(); +} + +PPB_FileRef_API* PPB_FileRef_Impl::AsPPB_FileRef_API() { + return this; } PPB_FileRef_Impl* PPB_FileRef_Impl::AsPPB_FileRef_Impl() { return this; } -std::string PPB_FileRef_Impl::GetName() const { +PP_FileSystemType_Dev PPB_FileRef_Impl::GetFileSystemType() const { + // When the file ref exists but there's no explicit filesystem object + // associated with it, that means it's an "external" filesystem. + if (!file_system_) + return PP_FILESYSTEMTYPE_EXTERNAL; + return file_system_->type(); +} + +PP_Var PPB_FileRef_Impl::GetName() const { + std::string result; if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) { FilePath::StringType path = system_path_.value(); size_t pos = path.rfind(FilePath::kSeparators[0]); DCHECK(pos != FilePath::StringType::npos); #if defined(OS_WIN) - return WideToUTF8(path.substr(pos + 1)); + result = WideToUTF8(path.substr(pos + 1)); #elif defined(OS_POSIX) - return path.substr(pos + 1); + result = path.substr(pos + 1); #else #error "Unsupported platform." #endif + } else if (virtual_path_.size() == 1 && virtual_path_[0] == '/') { + result = virtual_path_; + } else { + // There should always be a leading slash at least! + size_t pos = virtual_path_.rfind('/'); + DCHECK(pos != std::string::npos); + result = virtual_path_.substr(pos + 1); } - if (virtual_path_.size() == 1 && virtual_path_[0] == '/') - return virtual_path_; - - // There should always be a leading slash at least! - size_t pos = virtual_path_.rfind('/'); - DCHECK(pos != std::string::npos); + return StringVar::StringToPPVar(instance()->module(), result); +} - return virtual_path_.substr(pos + 1); +PP_Var PPB_FileRef_Impl::GetPath() const { + if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) + return PP_MakeUndefined(); + return StringVar::StringToPPVar(instance()->module(), virtual_path_); } -scoped_refptr<PPB_FileRef_Impl> PPB_FileRef_Impl::GetParent() { +PP_Resource PPB_FileRef_Impl::GetParent() { if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) - return new PPB_FileRef_Impl(); + return 0; // There should always be a leading slash at least! size_t pos = virtual_path_.rfind('/'); @@ -299,26 +156,73 @@ scoped_refptr<PPB_FileRef_Impl> PPB_FileRef_Impl::GetParent() { pos++; std::string parent_path = virtual_path_.substr(0, pos); - PPB_FileRef_Impl* parent_ref = new PPB_FileRef_Impl(instance(), file_system_, - parent_path); - return parent_ref; + scoped_refptr<PPB_FileRef_Impl> parent_ref( + new PPB_FileRef_Impl(instance(), file_system_, parent_path)); + return parent_ref->GetReference(); } -scoped_refptr<PPB_FileSystem_Impl> PPB_FileRef_Impl::GetFileSystem() const { - return file_system_; +int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, + PP_CompletionCallback callback) { + if (!IsValidNonExternalFileSystem()) + return PP_ERROR_NOACCESS; + if (!instance()->delegate()->MakeDirectory( + GetFileSystemURL(), PP_ToBool(make_ancestors), + new FileCallbacks(instance()->module()->AsWeakPtr(), + GetReferenceNoAddRef(), callback, + NULL, NULL, NULL))) + return PP_ERROR_FAILED; + return PP_OK_COMPLETIONPENDING; } -PP_FileSystemType_Dev PPB_FileRef_Impl::GetFileSystemType() const { - // When the file ref exists but there's no explicit filesystem object - // associated with it, that means it's an "external" filesystem. - if (!file_system_) - return PP_FILESYSTEMTYPE_EXTERNAL; +int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, + PP_Time last_modified_time, + PP_CompletionCallback callback) { + if (!IsValidNonExternalFileSystem()) + return PP_ERROR_NOACCESS; + if (!instance()->delegate()->Touch( + GetFileSystemURL(), + base::Time::FromDoubleT(last_access_time), + base::Time::FromDoubleT(last_modified_time), + new FileCallbacks(instance()->module()->AsWeakPtr(), + GetReferenceNoAddRef(), callback, + NULL, NULL, NULL))) + return PP_ERROR_FAILED; + return PP_OK_COMPLETIONPENDING; +} - return file_system_->type(); +int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { + if (!IsValidNonExternalFileSystem()) + return PP_ERROR_NOACCESS; + if (!instance()->delegate()->Delete( + GetFileSystemURL(), + new FileCallbacks(instance()->module()->AsWeakPtr(), + GetReferenceNoAddRef(), callback, + NULL, NULL, NULL))) + return PP_ERROR_FAILED; + return PP_OK_COMPLETIONPENDING; } -std::string PPB_FileRef_Impl::GetPath() const { - return virtual_path_; +int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, + PP_CompletionCallback callback) { + EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + PPB_FileRef_Impl* new_file_ref = + static_cast<PPB_FileRef_Impl*>(enter.object()); + + if (!IsValidNonExternalFileSystem() || + file_system_.get() != new_file_ref->file_system_.get()) + return PP_ERROR_NOACCESS; + + // TODO(viettrungluu): Also cancel when the new file ref is destroyed? + // http://crbug.com/67624 + if (!instance()->delegate()->Rename( + GetFileSystemURL(), new_file_ref->GetFileSystemURL(), + new FileCallbacks(instance()->module()->AsWeakPtr(), + GetReferenceNoAddRef(), callback, + NULL, NULL, NULL))) + return PP_ERROR_FAILED; + return PP_OK_COMPLETIONPENDING; } FilePath PPB_FileRef_Impl::GetSystemPath() const { @@ -345,5 +249,10 @@ GURL PPB_FileRef_Impl::GetFileSystemURL() const { return GURL(file_system_->root_url().spec() + virtual_path_.substr(1)); } +bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { + return file_system_ && file_system_->opened() && + file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; +} + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.h b/webkit/plugins/ppapi/ppb_file_ref_impl.h index 234e150..a1406a3 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.h +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.h @@ -10,6 +10,7 @@ #include "base/file_path.h" #include "googleurl/src/gurl.h" #include "ppapi/c/dev/ppb_file_ref_dev.h" +#include "ppapi/thunk/ppb_file_ref_api.h" #include "webkit/plugins/ppapi/resource.h" namespace webkit { @@ -19,7 +20,8 @@ class PPB_FileSystem_Impl; class PluginInstance; class PluginModule; -class PPB_FileRef_Impl : public Resource { +class PPB_FileRef_Impl : public Resource, + public ::ppapi::thunk::PPB_FileRef_API { public: PPB_FileRef_Impl(); PPB_FileRef_Impl(PluginInstance* instance, @@ -29,27 +31,32 @@ class PPB_FileRef_Impl : public Resource { const FilePath& external_file_path); virtual ~PPB_FileRef_Impl(); - // Returns a pointer to the interface implementing PPB_FileRef that is - // exposed to the plugin. - static const PPB_FileRef_Dev* GetInterface(); + static PP_Resource Create(PP_Resource file_system, const char* path); // Resource overrides. virtual PPB_FileRef_Impl* AsPPB_FileRef_Impl(); - // PPB_FileRef implementation. - std::string GetName() const; - scoped_refptr<PPB_FileRef_Impl> GetParent(); - - // Returns the file system to which this PPB_FileRef_Impl belongs. - scoped_refptr<PPB_FileSystem_Impl> GetFileSystem() const; - - // Returns the type of the file system to which this PPB_FileRef_Impl belongs. - PP_FileSystemType_Dev GetFileSystemType() const; + // ResourceObjectBase overrides. + virtual ::ppapi::thunk::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; + + PPB_FileSystem_Impl* file_system() const { return file_system_.get(); } + const std::string& virtual_path() const { return virtual_path_; } // Returns the virtual path (i.e., the path that the pepper plugin sees) - // corresponding to this file. - std::string GetPath() const; - // Returns the system path corresponding to this file. FilePath GetSystemPath() const; @@ -57,6 +64,11 @@ class PPB_FileRef_Impl : public Resource { GURL GetFileSystemURL() const; private: + // Many mutation functions are allow only to non-external filesystems, This + // function returns true if the filesystem is opened and isn't external as an + // access check for these functions. + bool IsValidNonExternalFileSystem() const; + scoped_refptr<PPB_FileSystem_Impl> file_system_; std::string virtual_path_; // UTF-8 encoded FilePath system_path_; diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.cc b/webkit/plugins/ppapi/ppb_file_system_impl.cc index 0f4793c..6a8a80b 100644 --- a/webkit/plugins/ppapi/ppb_file_system_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_system_impl.cc @@ -21,12 +21,27 @@ #include "webkit/plugins/ppapi/resource.h" #include "webkit/plugins/ppapi/resource_tracker.h" +using ppapi::thunk::PPB_FileSystem_API; + namespace webkit { namespace ppapi { -namespace { +PPB_FileSystem_Impl::PPB_FileSystem_Impl(PluginInstance* instance, + PP_FileSystemType_Dev type) + : Resource(instance), + instance_(instance), + type_(type), + opened_(false), + called_open_(false) { + DCHECK(type_ != PP_FILESYSTEMTYPE_INVALID); +} + +PPB_FileSystem_Impl::~PPB_FileSystem_Impl() { +} -PP_Resource Create(PP_Instance instance, PP_FileSystemType_Dev type) { +// static +PP_Resource PPB_FileSystem_Impl::Create(PP_Instance instance, + PP_FileSystemType_Dev type) { PluginInstance* plugin_instance = ResourceTracker::Get()->GetInstance(instance); if (!plugin_instance) @@ -42,77 +57,38 @@ PP_Resource Create(PP_Instance instance, PP_FileSystemType_Dev type) { return file_system->GetReference(); } -PP_Bool IsFileSystem(PP_Resource resource) { - scoped_refptr<PPB_FileSystem_Impl> file_system( - Resource::GetAs<PPB_FileSystem_Impl>(resource)); - return BoolToPPBool(!!file_system.get()); +PPB_FileSystem_API* PPB_FileSystem_Impl::AsPPB_FileSystem_API() { + return this; } -int32_t Open(PP_Resource file_system_id, - int64 expected_size, - PP_CompletionCallback callback) { - scoped_refptr<PPB_FileSystem_Impl> file_system( - Resource::GetAs<PPB_FileSystem_Impl>(file_system_id)); - if (!file_system) - return PP_ERROR_BADRESOURCE; - +int32_t PPB_FileSystem_Impl::Open(int64_t expected_size, + PP_CompletionCallback callback) { // Should not allow multiple opens. - if (file_system->called_open()) + if (called_open_) return PP_ERROR_FAILED; - file_system->set_called_open(); + called_open_ = true; - if ((file_system->type() != PP_FILESYSTEMTYPE_LOCALPERSISTENT) && - (file_system->type() != PP_FILESYSTEMTYPE_LOCALTEMPORARY)) + if (type_ != PP_FILESYSTEMTYPE_LOCALPERSISTENT && + type_ != PP_FILESYSTEMTYPE_LOCALTEMPORARY) return PP_ERROR_FAILED; - PluginInstance* instance = file_system->instance(); fileapi::FileSystemType file_system_type = - (file_system->type() == PP_FILESYSTEMTYPE_LOCALTEMPORARY ? + (type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY ? fileapi::kFileSystemTypeTemporary : fileapi::kFileSystemTypePersistent); - if (!instance->delegate()->OpenFileSystem( - instance->container()->element().document().frame()->url(), + if (!instance()->delegate()->OpenFileSystem( + instance()->container()->element().document().frame()->url(), file_system_type, expected_size, - new FileCallbacks(instance->module()->AsWeakPtr(), file_system_id, - callback, NULL, file_system, NULL))) + new FileCallbacks(instance()->module()->AsWeakPtr(), + GetReferenceNoAddRef(), + callback, NULL, + scoped_refptr<PPB_FileSystem_Impl>(this), NULL))) return PP_ERROR_FAILED; - return PP_OK_COMPLETIONPENDING; } -PP_FileSystemType_Dev GetType(PP_Resource resource) { - scoped_refptr<PPB_FileSystem_Impl> file_system( - Resource::GetAs<PPB_FileSystem_Impl>(resource)); - if (!file_system) - return PP_FILESYSTEMTYPE_INVALID; - return file_system->type(); -} - -const PPB_FileSystem_Dev ppb_filesystem = { - &Create, - &IsFileSystem, - &Open, - &GetType -}; - -} // namespace - -PPB_FileSystem_Impl::PPB_FileSystem_Impl(PluginInstance* instance, - PP_FileSystemType_Dev type) - : Resource(instance), - instance_(instance), - type_(type), - opened_(false), - called_open_(false) { - DCHECK(type_ != PP_FILESYSTEMTYPE_INVALID); -} - -PPB_FileSystem_Impl* PPB_FileSystem_Impl::AsPPB_FileSystem_Impl() { - return this; -} - -const PPB_FileSystem_Dev* PPB_FileSystem_Impl::GetInterface() { - return &ppb_filesystem; +PP_FileSystemType_Dev PPB_FileSystem_Impl::GetType() { + return type_; } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.h b/webkit/plugins/ppapi/ppb_file_system_impl.h index b381f56..73f9019 100644 --- a/webkit/plugins/ppapi/ppb_file_system_impl.h +++ b/webkit/plugins/ppapi/ppb_file_system_impl.h @@ -6,8 +6,10 @@ #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_SYSTEM_IMPL_H_ #include "base/basictypes.h" +#include "base/compiler_specific.h" #include "googleurl/src/gurl.h" #include "ppapi/c/dev/pp_file_info_dev.h" +#include "ppapi/thunk/ppb_file_system_api.h" #include "webkit/plugins/ppapi/resource.h" struct PPB_FileSystem_Dev; @@ -17,14 +19,16 @@ namespace ppapi { class PluginInstance; -class PPB_FileSystem_Impl : public Resource { +class PPB_FileSystem_Impl : public Resource, + public ::ppapi::thunk::PPB_FileSystem_API { public: - // Returns a pointer to the interface implementing PPB_FileSystem that is - // exposed to the plugin. - static const PPB_FileSystem_Dev* GetInterface(); - PPB_FileSystem_Impl(PluginInstance* instance, PP_FileSystemType_Dev type); - virtual PPB_FileSystem_Impl* AsPPB_FileSystem_Impl(); + virtual ~PPB_FileSystem_Impl(); + + static PP_Resource Create(PP_Instance instance, PP_FileSystemType_Dev type); + + // ResourceObjectBase overrides. + virtual ::ppapi::thunk::PPB_FileSystem_API* AsPPB_FileSystem_API() OVERRIDE; PluginInstance* instance() { return instance_; } PP_FileSystemType_Dev type() { return type_; } @@ -32,8 +36,11 @@ class PPB_FileSystem_Impl : public Resource { void set_root_url(const GURL& root_url) { root_url_ = root_url; } bool opened() const { return opened_; } void set_opened(bool opened) { opened_ = opened; } - bool called_open() const { return called_open_; } - void set_called_open() { called_open_ = true; } + + // PPB_FileSystem_API implementation. + virtual int32_t Open(int64_t expected_size, + PP_CompletionCallback callback) OVERRIDE; + virtual PP_FileSystemType_Dev GetType() OVERRIDE; private: PluginInstance* instance_; diff --git a/webkit/plugins/ppapi/ppb_find_impl.cc b/webkit/plugins/ppapi/ppb_find_impl.cc new file mode 100644 index 0000000..d83bc19 --- /dev/null +++ b/webkit/plugins/ppapi/ppb_find_impl.cc @@ -0,0 +1,41 @@ +// 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 "webkit/plugins/ppapi/ppb_find_impl.h" + +#include "webkit/plugins/ppapi/plugin_delegate.h" +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" + +using ::ppapi::thunk::PPB_Find_FunctionAPI; + +namespace webkit { +namespace ppapi { + +PPB_Find_Impl::PPB_Find_Impl(PluginInstance* instance) : instance_(instance) { +} + +PPB_Find_Impl::~PPB_Find_Impl() { +} + +PPB_Find_FunctionAPI* PPB_Find_Impl::AsPPB_Find_FunctionAPI() { + return this; +} + +void PPB_Find_Impl::NumberOfFindResultsChanged(PP_Instance instance, + int32_t total, + PP_Bool final_result) { + DCHECK_NE(instance_->find_identifier(), -1); + instance_->delegate()->NumberOfFindResultsChanged( + instance_->find_identifier(), total, PP_ToBool(final_result)); +} + +void PPB_Find_Impl::SelectedFindResultChanged(PP_Instance instance, + int32_t index) { + DCHECK_NE(instance_->find_identifier(), -1); + instance_->delegate()->SelectedFindResultChanged( + instance_->find_identifier(), index); +} + +} // namespace ppapi +} // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_find_impl.h b/webkit/plugins/ppapi/ppb_find_impl.h new file mode 100644 index 0000000..b6675cd --- /dev/null +++ b/webkit/plugins/ppapi/ppb_find_impl.h @@ -0,0 +1,46 @@ +// 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 WEBKIT_PLUGINS_PPAPI_PPB_FIND_IMPL_H_ +#define WEBKIT_PLUGINS_PPAPI_PPB_FIND_IMPL_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/function_group_base.h" +#include "ppapi/thunk/ppb_find_api.h" + +namespace webkit { +namespace ppapi { + +class PluginInstance; + +// Some of the backend functionality of this class is implemented by the +// AudioImpl so it can be shared with the proxy. +class PPB_Find_Impl : public ::ppapi::FunctionGroupBase, + public ::ppapi::thunk::PPB_Find_FunctionAPI { + public: + PPB_Find_Impl(PluginInstance* instance); + virtual ~PPB_Find_Impl(); + + // FunctionBase overrides. + virtual ::ppapi::thunk::PPB_Find_FunctionAPI* AsPPB_Find_FunctionAPI() + OVERRIDE; + + // PPB_Find_API implementation. + virtual void NumberOfFindResultsChanged(PP_Instance instance, + int32_t total, + PP_Bool final_result) OVERRIDE; + virtual void SelectedFindResultChanged(PP_Instance instance, + int32_t index) OVERRIDE; + + private: + PluginInstance* instance_; + + DISALLOW_COPY_AND_ASSIGN(PPB_Find_Impl); +}; + +} // namespace ppapi +} // namespace webkit + +#endif // WEBKIT_PLUGINS_PPAPI_PPB_FIND_IMPL_H_ diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc index 6ff6928b..0da1b3a 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.cc +++ b/webkit/plugins/ppapi/ppb_font_impl.cc @@ -52,7 +52,7 @@ PPB_Font_Impl::PPB_Font_Impl(PluginInstance* instance, PPB_Font_Impl::~PPB_Font_Impl() { } -::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsFont_API() { +::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsPPB_Font_API() { return this; } diff --git a/webkit/plugins/ppapi/ppb_font_impl.h b/webkit/plugins/ppapi/ppb_font_impl.h index 2c8886e..23416ef 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.h +++ b/webkit/plugins/ppapi/ppb_font_impl.h @@ -28,7 +28,7 @@ class PPB_Font_Impl : public Resource, virtual ~PPB_Font_Impl(); // ResourceObjectBase. - virtual ::ppapi::thunk::PPB_Font_API* AsFont_API() OVERRIDE; + virtual ::ppapi::thunk::PPB_Font_API* AsPPB_Font_API() OVERRIDE; // Resource overrides. virtual PPB_Font_Impl* AsPPB_Font_Impl() OVERRIDE; diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc index 813ea0f..ff54442 100644 --- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc +++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc @@ -176,7 +176,8 @@ bool PPB_Graphics2D_Impl::Init(int width, int height, bool is_always_opaque) { return true; } -::ppapi::thunk::PPB_Graphics2D_API* PPB_Graphics2D_Impl::AsGraphics2D_API() { +::ppapi::thunk::PPB_Graphics2D_API* +PPB_Graphics2D_Impl::AsPPB_Graphics2D_API() { return this; } diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h index 66e3032..6739b60 100644 --- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h +++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h @@ -42,7 +42,7 @@ class PPB_Graphics2D_Impl bool is_always_opaque() const { return is_always_opaque_; } - virtual ::ppapi::thunk::PPB_Graphics2D_API* AsGraphics2D_API(); + virtual ::ppapi::thunk::PPB_Graphics2D_API* AsPPB_Graphics2D_API(); // Resource override. virtual PPB_Graphics2D_Impl* AsPPB_Graphics2D_Impl(); diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.cc b/webkit/plugins/ppapi/ppb_image_data_impl.cc index 2f722e0..1c621a4 100644 --- a/webkit/plugins/ppapi/ppb_image_data_impl.cc +++ b/webkit/plugins/ppapi/ppb_image_data_impl.cc @@ -62,7 +62,7 @@ const PPB_ImageDataTrusted* PPB_ImageData_Impl::GetTrustedInterface() { return &ppb_imagedata_trusted; } -::ppapi::thunk::PPB_ImageData_API* PPB_ImageData_Impl::AsImageData_API() { +::ppapi::thunk::PPB_ImageData_API* PPB_ImageData_Impl::AsPPB_ImageData_API() { return this; } diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.h b/webkit/plugins/ppapi/ppb_image_data_impl.h index 14a004d..096e54e 100644 --- a/webkit/plugins/ppapi/ppb_image_data_impl.h +++ b/webkit/plugins/ppapi/ppb_image_data_impl.h @@ -53,7 +53,7 @@ class PPB_ImageData_Impl : public Resource, static const PPB_ImageData* GetInterface(); static const PPB_ImageDataTrusted* GetTrustedInterface(); - virtual ::ppapi::thunk::PPB_ImageData_API* AsImageData_API(); + virtual ::ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API(); // Resource overrides. virtual PPB_ImageData_Impl* AsPPB_ImageData_Impl(); diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 6e4ef7d..11a1e5a 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -10,6 +10,11 @@ #include "webkit/plugins/ppapi/ppb_audio_impl.h" #include "webkit/plugins/ppapi/ppb_broker_impl.h" #include "webkit/plugins/ppapi/ppb_buffer_impl.h" +#include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" +#include "webkit/plugins/ppapi/ppb_file_chooser_impl.h" +#include "webkit/plugins/ppapi/ppb_file_io_impl.h" +#include "webkit/plugins/ppapi/ppb_file_ref_impl.h" +#include "webkit/plugins/ppapi/ppb_file_system_impl.h" #include "webkit/plugins/ppapi/ppb_font_impl.h" #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" @@ -25,7 +30,7 @@ ResourceCreationImpl::~ResourceCreationImpl() { } ::ppapi::thunk::ResourceCreationAPI* -ResourceCreationImpl::AsResourceCreation() { +ResourceCreationImpl::AsResourceCreationAPI() { return this; } @@ -75,6 +80,32 @@ PP_Resource ResourceCreationImpl::CreateBuffer(PP_Instance instance, return PPB_Buffer_Impl::Create(instance, size); } +PP_Resource ResourceCreationImpl::CreateDirectoryReader( + PP_Resource directory_ref) { + return PPB_DirectoryReader_Impl::Create(directory_ref); +} + +PP_Resource ResourceCreationImpl::CreateFileChooser( + PP_Instance instance, + const PP_FileChooserOptions_Dev* options) { + return PPB_FileChooser_Impl::Create(instance, options); +} + +PP_Resource ResourceCreationImpl::CreateFileIO(PP_Instance instance) { + return PPB_FileIO_Impl::Create(instance); +} + +PP_Resource ResourceCreationImpl::CreateFileRef(PP_Resource file_system, + const char* path) { + return PPB_FileRef_Impl::Create(file_system, path); +} + +PP_Resource ResourceCreationImpl::CreateFileSystem( + PP_Instance instance, + PP_FileSystemType_Dev type) { + return PPB_FileSystem_Impl::Create(instance, type); +} + PP_Resource ResourceCreationImpl::CreateFontObject( PP_Instance pp_instance, const PP_FontDescription_Dev* description) { diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index 9569620..c2550b3 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -22,7 +22,7 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, virtual ~ResourceCreationImpl(); // FunctionGroupBase implementation. - virtual ::ppapi::thunk::ResourceCreationAPI* AsResourceCreation(); + virtual ::ppapi::thunk::ResourceCreationAPI* AsResourceCreationAPI(); // ResourceCreationAPI implementation. virtual PP_Resource CreateAudio(PP_Instance instance, @@ -36,6 +36,15 @@ class ResourceCreationImpl : 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; diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc index 7e04f61..dc1d61e 100644 --- a/webkit/plugins/ppapi/resource_tracker.cc +++ b/webkit/plugins/ppapi/resource_tracker.cc @@ -17,6 +17,7 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_char_set_impl.h" #include "webkit/plugins/ppapi/ppb_cursor_control_impl.h" +#include "webkit/plugins/ppapi/ppb_find_impl.h" #include "webkit/plugins/ppapi/ppb_font_impl.h" #include "webkit/plugins/ppapi/resource.h" #include "webkit/plugins/ppapi/resource_creation_impl.h" @@ -277,6 +278,9 @@ uint32 ResourceTracker::GetLiveObjectsForInstance( case pp::proxy::INTERFACE_ID_PPB_CURSORCONTROL: proxy.reset(new PPB_CursorControl_Impl(instance)); break; + case pp::proxy::INTERFACE_ID_PPB_FIND: + proxy.reset(new PPB_Find_Impl(instance)); + break; case pp::proxy::INTERFACE_ID_PPB_FONT: proxy.reset(new PPB_Font_FunctionImpl(instance)); break; @@ -290,6 +294,13 @@ uint32 ResourceTracker::GetLiveObjectsForInstance( return proxy.get(); } +PP_Instance ResourceTracker::GetInstanceForResource(PP_Resource pp_resource) { + scoped_refptr<Resource> resource(GetResource(pp_resource)); + if (!resource.get()) + return 0; + return resource->instance()->pp_instance(); +} + scoped_refptr<Var> ResourceTracker::GetVar(int32 var_id) const { DLOG_IF(ERROR, !CheckIdType(var_id, PP_ID_TYPE_VAR)) << var_id << " is not a PP_Var ID."; diff --git a/webkit/plugins/ppapi/resource_tracker.h b/webkit/plugins/ppapi/resource_tracker.h index 2d008f9..d5618e6 100644 --- a/webkit/plugins/ppapi/resource_tracker.h +++ b/webkit/plugins/ppapi/resource_tracker.h @@ -59,10 +59,11 @@ class ResourceTracker : public ::ppapi::TrackerBase { // ResourceTrackerBase. virtual ::ppapi::ResourceObjectBase* GetResourceAPI( - PP_Resource res); + PP_Resource res) OVERRIDE; virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( PP_Instance pp_instance, - pp::proxy::InterfaceID id); + pp::proxy::InterfaceID id) OVERRIDE; + virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE; // PP_Vars ------------------------------------------------------------------- |