diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-13 04:00:33 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-13 04:00:33 +0000 |
commit | 37fe036a2c3e907a5790561e11292904426db144 (patch) | |
tree | 4b4c928830476c7450ffd5c69ca9f222ddbcfded /ppapi/proxy | |
parent | ad432d686c8529838448f6639130f1290db9d5a5 (diff) | |
download | chromium_src-37fe036a2c3e907a5790561e11292904426db144.zip chromium_src-37fe036a2c3e907a5790561e11292904426db144.tar.gz chromium_src-37fe036a2c3e907a5790561e11292904426db144.tar.bz2 |
Revert r100853, 100851. Win_shared build is broken.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
110 files changed, 2152 insertions, 1202 deletions
diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc index 8381c6a..d77c905 100644 --- a/ppapi/proxy/dispatcher.cc +++ b/ppapi/proxy/dispatcher.cc @@ -11,12 +11,209 @@ #include "base/compiler_specific.h" #include "base/logging.h" #include "base/memory/singleton.h" +#include "ppapi/c/dev/ppb_buffer_dev.h" +#include "ppapi/c/dev/ppb_char_set_dev.h" +#include "ppapi/c/dev/ppb_context_3d_dev.h" +#include "ppapi/c/dev/ppb_crypto_dev.h" +#include "ppapi/c/dev/ppb_cursor_control_dev.h" +#include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" +#include "ppapi/c/dev/ppb_font_dev.h" +#include "ppapi/c/dev/ppb_surface_3d_dev.h" +#include "ppapi/c/dev/ppb_testing_dev.h" +#include "ppapi/c/dev/ppb_url_util_dev.h" +#include "ppapi/c/dev/ppb_var_deprecated.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/ppb_audio.h" +#include "ppapi/c/ppb_audio_config.h" +#include "ppapi/c/ppb_core.h" +#include "ppapi/c/ppb_graphics_2d.h" +#include "ppapi/c/ppb_image_data.h" +#include "ppapi/c/ppb_instance.h" +#include "ppapi/c/ppb_opengles.h" +#include "ppapi/c/ppb_url_loader.h" +#include "ppapi/c/ppb_url_request_info.h" +#include "ppapi/c/ppb_url_response_info.h" +#include "ppapi/c/ppb_var.h" +#include "ppapi/c/ppp_instance.h" +#include "ppapi/c/private/ppb_flash.h" +#include "ppapi/c/private/ppb_flash_clipboard.h" +#include "ppapi/c/private/ppb_flash_file.h" +#include "ppapi/c/private/ppb_flash_menu.h" +#include "ppapi/c/private/ppb_flash_net_connector.h" +#include "ppapi/c/private/ppb_flash_tcp_socket.h" +#include "ppapi/c/private/ppb_pdf.h" +#include "ppapi/c/trusted/ppb_url_loader_trusted.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/ppb_audio_config_proxy.h" +#include "ppapi/proxy/ppb_audio_proxy.h" +#include "ppapi/proxy/ppb_broker_proxy.h" +#include "ppapi/proxy/ppb_buffer_proxy.h" +#include "ppapi/proxy/ppb_char_set_proxy.h" +#include "ppapi/proxy/ppb_console_proxy.h" +#include "ppapi/proxy/ppb_context_3d_proxy.h" +#include "ppapi/proxy/ppb_core_proxy.h" +#include "ppapi/proxy/ppb_crypto_proxy.h" +#include "ppapi/proxy/ppb_cursor_control_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_flash_clipboard_proxy.h" +#include "ppapi/proxy/ppb_flash_file_proxy.h" +#include "ppapi/proxy/ppb_flash_proxy.h" +#include "ppapi/proxy/ppb_flash_menu_proxy.h" +#include "ppapi/proxy/ppb_flash_net_connector_proxy.h" +#include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h" +#include "ppapi/proxy/ppb_font_proxy.h" +#include "ppapi/proxy/ppb_graphics_2d_proxy.h" +#include "ppapi/proxy/ppb_graphics_3d_proxy.h" +#include "ppapi/proxy/ppb_image_data_proxy.h" +#include "ppapi/proxy/ppb_input_event_proxy.h" +#include "ppapi/proxy/ppb_instance_proxy.h" +#include "ppapi/proxy/ppb_memory_proxy.h" +#include "ppapi/proxy/ppb_opengles2_proxy.h" +#include "ppapi/proxy/ppb_pdf_proxy.h" +#include "ppapi/proxy/ppb_surface_3d_proxy.h" +#include "ppapi/proxy/ppb_testing_proxy.h" +#include "ppapi/proxy/ppb_url_loader_proxy.h" +#include "ppapi/proxy/ppb_url_request_info_proxy.h" +#include "ppapi/proxy/ppb_url_response_info_proxy.h" +#include "ppapi/proxy/ppb_url_util_proxy.h" +#include "ppapi/proxy/ppb_var_deprecated_proxy.h" +#include "ppapi/proxy/ppb_var_proxy.h" +#include "ppapi/proxy/ppb_video_capture_proxy.h" +#include "ppapi/proxy/ppb_video_decoder_proxy.h" +#include "ppapi/proxy/ppp_class_proxy.h" +#include "ppapi/proxy/ppp_graphics_3d_proxy.h" +#include "ppapi/proxy/ppp_input_event_proxy.h" +#include "ppapi/proxy/ppp_instance_private_proxy.h" +#include "ppapi/proxy/ppp_instance_proxy.h" +#include "ppapi/proxy/ppp_messaging_proxy.h" +#include "ppapi/proxy/ppp_mouse_lock_proxy.h" +#include "ppapi/proxy/ppp_video_decoder_proxy.h" #include "ppapi/proxy/var_serialization_rules.h" namespace ppapi { namespace proxy { +namespace { + +struct InterfaceList { + InterfaceList(); + + static InterfaceList* GetInstance(); + + void AddPPP(const InterfaceProxy::Info* info); + void AddPPB(const InterfaceProxy::Info* info); + + typedef std::map<std::string, const InterfaceProxy::Info*> NameToInfo; + NameToInfo name_to_plugin_info_; + NameToInfo name_to_browser_info_; + + // Note that there can be multiple interface names mapping to the same ID. + // In this case, the ID will map to one of them. This is temporary while + // we're converting to the thunk system, when that is complete, we need to + // have a better way of handling multiple interface implemented by one + // proxy object. + const InterfaceProxy::Info* id_to_browser_info_[INTERFACE_ID_COUNT]; +}; + +InterfaceList::InterfaceList() { + memset(id_to_browser_info_, 0, sizeof(id_to_browser_info_)); + + // PPB (browser) interfaces. + AddPPB(PPB_AudioConfig_Proxy::GetInfo()); + AddPPB(PPB_Audio_Proxy::GetInfo()); + AddPPB(PPB_Broker_Proxy::GetInfo()); + AddPPB(PPB_Buffer_Proxy::GetInfo()); + AddPPB(PPB_CharSet_Proxy::GetInfo()); + AddPPB(PPB_Console_Proxy::GetInfo()); + AddPPB(PPB_Context3D_Proxy::GetInfo()); + AddPPB(PPB_Context3D_Proxy::GetTextureMappingInfo()); + AddPPB(PPB_Core_Proxy::GetInfo()); + AddPPB(PPB_Crypto_Proxy::GetInfo()); + AddPPB(PPB_CursorControl_Proxy::GetInfo()); + AddPPB(PPB_FileChooser_Proxy::GetInfo()); + AddPPB(PPB_FileChooser_Proxy::GetInfo0_4()); + AddPPB(PPB_FileRef_Proxy::GetInfo()); + AddPPB(PPB_FileSystem_Proxy::GetInfo()); + AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo()); + AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo()); + AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo()); + AddPPB(PPB_Flash_Menu_Proxy::GetInfo()); + AddPPB(PPB_Flash_Proxy::GetInfo()); + AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo()); + AddPPB(PPB_Font_Proxy::GetInfo()); + AddPPB(PPB_Graphics2D_Proxy::GetInfo()); + AddPPB(PPB_Graphics3D_Proxy::GetInfo()); + AddPPB(PPB_ImageData_Proxy::GetInfo()); + AddPPB(PPB_InputEvent_Proxy::GetInputEventInfo()); + AddPPB(PPB_InputEvent_Proxy::GetKeyboardInputEventInfo()); + AddPPB(PPB_InputEvent_Proxy::GetMouseInputEventInfo1_0()); + AddPPB(PPB_InputEvent_Proxy::GetMouseInputEventInfo1_1()); + AddPPB(PPB_InputEvent_Proxy::GetWheelInputEventInfo()); + AddPPB(PPB_Instance_Proxy::GetInfo0_5()); + AddPPB(PPB_Instance_Proxy::GetInfo1_0()); + AddPPB(PPB_Instance_Proxy::GetInfoFullscreen()); + AddPPB(PPB_Instance_Proxy::GetInfoMessaging()); + AddPPB(PPB_Instance_Proxy::GetInfoMouseLock()); + AddPPB(PPB_Instance_Proxy::GetInfoPrivate()); + AddPPB(PPB_Memory_Proxy::GetInfo()); + AddPPB(PPB_OpenGLES2_Proxy::GetInfo()); + AddPPB(PPB_PDF_Proxy::GetInfo()); + AddPPB(PPB_Surface3D_Proxy::GetInfo()); + AddPPB(PPB_Testing_Proxy::GetInfo()); + AddPPB(PPB_URLLoader_Proxy::GetInfo()); + AddPPB(PPB_URLLoader_Proxy::GetTrustedInfo()); + AddPPB(PPB_URLRequestInfo_Proxy::GetInfo()); + AddPPB(PPB_URLResponseInfo_Proxy::GetInfo()); + AddPPB(PPB_URLUtil_Proxy::GetInfo()); + AddPPB(PPB_Var_Deprecated_Proxy::GetInfo()); + AddPPB(PPB_Var_Proxy::GetInfo()); + AddPPB(PPB_VideoCapture_Proxy::GetInfo()); + AddPPB(PPB_VideoDecoder_Proxy::GetInfo()); + +#ifdef ENABLE_FLAPPER_HACKS + AddPPB(PPB_Flash_NetConnector_Proxy::GetInfo()); +#endif + + // PPP (plugin) interfaces. + AddPPP(PPP_Graphics3D_Proxy::GetInfo()); + AddPPP(PPP_InputEvent_Proxy::GetInfo()); + AddPPP(PPP_Instance_Private_Proxy::GetInfo()); + AddPPP(PPP_Instance_Proxy::GetInfo1_0()); + AddPPP(PPP_Messaging_Proxy::GetInfo()); + AddPPP(PPP_MouseLock_Proxy::GetInfo()); + AddPPP(PPP_VideoCapture_Proxy::GetInfo()); + AddPPP(PPP_VideoDecoder_Proxy::GetInfo()); +} + +void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { + DCHECK(name_to_plugin_info_.find(info->name) == + name_to_plugin_info_.end()); + DCHECK(info->id >= INTERFACE_ID_NONE && info->id < INTERFACE_ID_COUNT); + + name_to_plugin_info_[info->name] = info; +} + +void InterfaceList::AddPPB(const InterfaceProxy::Info* info) { + DCHECK(name_to_browser_info_.find(info->name) == + name_to_browser_info_.end()); + DCHECK(info->id >= INTERFACE_ID_NONE && info->id < INTERFACE_ID_COUNT); + DCHECK(info->id == INTERFACE_ID_NONE || + id_to_browser_info_[info->id] == NULL); + + name_to_browser_info_[std::string(info->name)] = info; + if (info->id != INTERFACE_ID_NONE) + id_to_browser_info_[info->id] = info; +} + +// static +InterfaceList* InterfaceList::GetInstance() { + return Singleton<InterfaceList>::get(); +} + +} // namespace + Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, GetInterfaceFunc local_get_interface) : ProxyChannel(remote_process_handle), @@ -28,32 +225,6 @@ Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, Dispatcher::~Dispatcher() { } -InterfaceProxy* Dispatcher::GetInterfaceProxy(InterfaceID id) { - InterfaceProxy* proxy = proxies_[id].get(); - if (!proxy) { - // Handle the first time for a given API by creating the proxy for it. - InterfaceProxy::Factory factory = - InterfaceList::GetInstance()->GetFactoryForID(id); - if (!factory) { - NOTREACHED(); - return NULL; - } - proxy = factory(this); - DCHECK(proxy); - proxies_[id].reset(proxy); - } - return proxy; -} - -base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() { - return delegate()->GetIPCMessageLoop(); -} - -void Dispatcher::AddIOThreadMessageFilter( - IPC::ChannelProxy::MessageFilter* filter) { - channel()->AddFilter(filter); -} - bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { // Control messages. if (msg.routing_id() == MSG_ROUTING_CONTROL) { @@ -65,19 +236,37 @@ bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { IPC_END_MESSAGE_MAP() return handled; } + return false; +} - if (msg.routing_id() <= 0 || msg.routing_id() >= INTERFACE_ID_COUNT) { - OnInvalidMessageReceived(); - return true; - } +// static +const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo( + const std::string& name) { + const InterfaceList* list = InterfaceList::GetInstance(); + InterfaceList::NameToInfo::const_iterator found = + list->name_to_browser_info_.find(name); + if (found == list->name_to_browser_info_.end()) + return NULL; + return found->second; +} - InterfaceProxy* proxy = GetInterfaceProxy( - static_cast<InterfaceID>(msg.routing_id())); - if (!proxy) { - NOTREACHED(); - return true; - } - return proxy->OnMessageReceived(msg); +// static +const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo(InterfaceID id) { + if (id <= 0 || id >= INTERFACE_ID_COUNT) + return NULL; + const InterfaceList* list = InterfaceList::GetInstance(); + return list->id_to_browser_info_[id]; +} + +// static +const InterfaceProxy::Info* Dispatcher::GetPPPInterfaceInfo( + const std::string& name) { + const InterfaceList* list = InterfaceList::GetInstance(); + InterfaceList::NameToInfo::const_iterator found = + list->name_to_plugin_info_.find(name); + if (found == list->name_to_plugin_info_.end()) + return NULL; + return found->second; } void Dispatcher::SetSerializationRules( @@ -85,7 +274,17 @@ void Dispatcher::SetSerializationRules( serialization_rules_.reset(var_serialization_rules); } -void Dispatcher::OnInvalidMessageReceived() { +const void* Dispatcher::GetLocalInterface(const char* interface_name) { + return local_get_interface_(interface_name); +} + +base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() { + return delegate()->GetIPCMessageLoop(); +} + +void Dispatcher::AddIOThreadMessageFilter( + IPC::ChannelProxy::MessageFilter* filter) { + channel()->AddFilter(filter); } } // namespace proxy diff --git a/ppapi/proxy/dispatcher.h b/ppapi/proxy/dispatcher.h index a48cff7..bf3e36f 100644 --- a/ppapi/proxy/dispatcher.h +++ b/ppapi/proxy/dispatcher.h @@ -17,7 +17,6 @@ #include "ppapi/proxy/callback_tracker.h" #include "ppapi/proxy/proxy_channel.h" #include "ppapi/proxy/interface_id.h" -#include "ppapi/proxy/interface_list.h" #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/plugin_var_tracker.h" @@ -58,10 +57,8 @@ class PPAPI_PROXY_EXPORT Dispatcher : public ProxyChannel { return serialization_rules_.get(); } - // Returns a non-owning pointer to the interface proxy for the given ID, or - // NULL if the ID isn't found. This will create the proxy if it hasn't been - // created so far. - InterfaceProxy* GetInterfaceProxy(InterfaceID id); + // Wrapper for calling the local GetInterface function. + const void* GetLocalInterface(const char* interface_name); // Returns the pointer to the IO thread for processing IPC messages. // TODO(brettw) remove this. It's a hack to support the Flash @@ -87,7 +84,14 @@ class PPAPI_PROXY_EXPORT Dispatcher : public ProxyChannel { return callback_tracker_; } - GetInterfaceFunc local_get_interface() const { return local_get_interface_; } + // Retrieves the information associated with the given interface, identified + // either by name or ID. Each function searches either PPP or PPB interfaces. + static const InterfaceProxy::Info* GetPPBInterfaceInfo( + const std::string& name); + static const InterfaceProxy::Info* GetPPBInterfaceInfo( + InterfaceID id); + static const InterfaceProxy::Info* GetPPPInterfaceInfo( + const std::string& name); protected: Dispatcher(base::ProcessHandle remote_process_handle, @@ -97,21 +101,11 @@ class PPAPI_PROXY_EXPORT Dispatcher : public ProxyChannel { // Takes ownership of the given pointer, which must be on the heap. void SetSerializationRules(VarSerializationRules* var_serialization_rules); - // Called when an invalid message is received from the remote site. The - // default implementation does nothing, derived classes can override. - virtual void OnInvalidMessageReceived(); - bool disallow_trusted_interfaces() const { return disallow_trusted_interfaces_; } private: - friend class HostDispatcherTest; - friend class PluginDispatcherTest; - - // Lists all lazily-created interface proxies. - scoped_ptr<InterfaceProxy> proxies_[INTERFACE_ID_COUNT]; - bool disallow_trusted_interfaces_; GetInterfaceFunc local_get_interface_; diff --git a/ppapi/proxy/enter_proxy.h b/ppapi/proxy/enter_proxy.h index d7bf7c2..6852780 100644 --- a/ppapi/proxy/enter_proxy.h +++ b/ppapi/proxy/enter_proxy.h @@ -13,11 +13,6 @@ #include "ppapi/thunk/enter.h" namespace ppapi { - -namespace thunk { -class ResourceCreationAPI; -} - namespace proxy { // Wrapper around EnterResourceNoLock that takes a host resource. This is used @@ -120,21 +115,6 @@ class EnterHostFromHostResourceForceCallback RunCallback(PP_ERROR_BADRESOURCE); } - // For callbacks that take two extra parameters as a closure. - template<class CallbackFactory, typename Method, typename A, typename B> - EnterHostFromHostResourceForceCallback( - const HostResource& host_resource, - CallbackFactory& factory, - Method method, - const A& a, - const B& b) - : EnterHostFromHostResource<ResourceT>(host_resource), - needs_running_(true), - callback_(factory.NewOptionalCallback(method, a, b)) { - if (this->failed()) - RunCallback(PP_ERROR_BADRESOURCE); - } - ~EnterHostFromHostResourceForceCallback() { if (needs_running_) { NOTREACHED() << "Should always call SetResult except in the " diff --git a/ppapi/proxy/host_dispatcher.cc b/ppapi/proxy/host_dispatcher.cc index a9f14f4..c5bf08f 100644 --- a/ppapi/proxy/host_dispatcher.cc +++ b/ppapi/proxy/host_dispatcher.cc @@ -11,7 +11,6 @@ #include "ppapi/c/private/ppb_proxy_private.h" #include "ppapi/c/ppb_var.h" #include "ppapi/proxy/host_var_serialization_rules.h" -#include "ppapi/proxy/interface_list.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/resource_creation_proxy.h" @@ -76,7 +75,7 @@ HostDispatcher::HostDispatcher(base::ProcessHandle remote_process_handle, SetSerializationRules(new HostVarSerializationRules(var_interface, module)); ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( - local_get_interface(PPB_PROXY_PRIVATE_INTERFACE)); + GetLocalInterface(PPB_PROXY_PRIVATE_INTERFACE)); DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; ppb_proxy_->SetReserveInstanceIDCallback(pp_module_, &ReserveInstanceID); @@ -157,7 +156,39 @@ bool HostDispatcher::OnMessageReceived(const IPC::Message& msg) { BoolRestorer restorer(&allow_plugin_reentrancy_); allow_plugin_reentrancy_ = false; - return Dispatcher::OnMessageReceived(msg); + // Handle common control messages. + if (Dispatcher::OnMessageReceived(msg)) + return true; + + if (msg.routing_id() <= 0 || msg.routing_id() >= INTERFACE_ID_COUNT) { + NOTREACHED(); + // TODO(brettw): kill the plugin if it starts sending invalid messages? + return true; + } + + // New-style function proxies. + // TODO(brettw) this is hacked in for the routing for the types we've + // implemented in this style so far. When everything is implemented in this + // style, this function should be cleaned up. + if (msg.routing_id() == INTERFACE_ID_RESOURCE_CREATION) { + ResourceCreationProxy proxy(this); + return proxy.OnMessageReceived(msg); + } + + InterfaceProxy* proxy = target_proxies_[msg.routing_id()].get(); + if (!proxy) { + // Autocreate any proxy objects to handle requests from the plugin. Since + // we always support all known PPB_* interfaces (modulo the trusted bit), + // there's very little checking necessary. + const InterfaceProxy::Info* info = GetPPBInterfaceInfo( + static_cast<InterfaceID>(msg.routing_id())); + if (!info || + (info->is_trusted && disallow_trusted_interfaces())) + return true; + proxy = CreatePPBInterfaceProxy(info); + } + + return proxy->OnMessageReceived(msg); } void HostDispatcher::OnChannelError() { @@ -167,35 +198,67 @@ void HostDispatcher::OnChannelError() { ppb_proxy_->PluginCrashed(pp_module()); } -const void* HostDispatcher::GetProxiedInterface(const std::string& iface_name) { - const void* proxied_interface = - InterfaceList::GetInstance()->GetInterfaceForPPP(iface_name); - if (!proxied_interface) - return NULL; // Don't have a proxy for this interface, don't query further. +const void* HostDispatcher::GetProxiedInterface( + const std::string& proxied_interface) { + // First see if we even have a proxy for this interface. + const InterfaceProxy::Info* info = GetPPPInterfaceInfo(proxied_interface); + if (!info) + return NULL; - PluginSupportedMap::iterator iter(plugin_supported_.find(iface_name)); - if (iter == plugin_supported_.end()) { + PluginIFSupportedMap::iterator iter(plugin_if_supported_.find( + proxied_interface)); + if (iter == plugin_if_supported_.end()) { // Need to query. Cache the result so we only do this once. bool supported = false; bool previous_reentrancy_value = allow_plugin_reentrancy_; allow_plugin_reentrancy_ = true; - Send(new PpapiMsg_SupportsInterface(iface_name, &supported)); + Send(new PpapiMsg_SupportsInterface(proxied_interface, &supported)); allow_plugin_reentrancy_ = previous_reentrancy_value; - std::pair<PluginSupportedMap::iterator, bool> iter_success_pair; - iter_success_pair = plugin_supported_.insert( - PluginSupportedMap::value_type(iface_name, supported)); + std::pair<PluginIFSupportedMap::iterator, bool> iter_success_pair; + iter_success_pair = plugin_if_supported_.insert( + PluginIFSupportedMap::value_type(proxied_interface, supported)); iter = iter_success_pair.first; } if (iter->second) - return proxied_interface; + return info->interface_ptr; return NULL; } -void HostDispatcher::OnInvalidMessageReceived() { - // TODO(brettw) bug 95345 kill the plugin when an invalid message is - // received. +InterfaceProxy* HostDispatcher::GetOrCreatePPBInterfaceProxy( + InterfaceID id) { + InterfaceProxy* proxy = target_proxies_[id].get(); + if (!proxy) { + const InterfaceProxy::Info* info = GetPPBInterfaceInfo(id); + if (!info) + return NULL; + + // Sanity check. This function won't normally be called for trusted + // interfaces, but in case somebody does this, we don't want to then give + // the plugin the ability to call that trusted interface (since the + // checking occurs at proxy-creation time). + if (info->is_trusted && disallow_trusted_interfaces()) + return NULL; + + proxy = CreatePPBInterfaceProxy(info); + } + return proxy; +} + +InterfaceProxy* HostDispatcher::CreatePPBInterfaceProxy( + const InterfaceProxy::Info* info) { + const void* local_interface = GetLocalInterface(info->name); + if (!local_interface) { + // This should always succeed since the browser should support the stuff + // the proxy does. If this happens, something is out of sync. + NOTREACHED(); + return NULL; + } + + InterfaceProxy* proxy = info->create_proxy(this, local_interface); + target_proxies_[info->id].reset(proxy); + return proxy; } // ScopedModuleReference ------------------------------------------------------- diff --git a/ppapi/proxy/host_dispatcher.h b/ppapi/proxy/host_dispatcher.h index 10fca5c..623aa26 100644 --- a/ppapi/proxy/host_dispatcher.h +++ b/ppapi/proxy/host_dispatcher.h @@ -32,6 +32,7 @@ struct Preferences; namespace proxy { +class InterfaceProxy; class VarSerialization; class PPAPI_PROXY_EXPORT HostDispatcher : public Dispatcher { @@ -79,11 +80,18 @@ class PPAPI_PROXY_EXPORT HostDispatcher : public Dispatcher { // if the plugin supports the given interface (with caching) and returns the // pointer to the proxied interface if it is supported. Returns NULL if the // given interface isn't supported by the plugin or the proxy. - const void* GetProxiedInterface(const std::string& iface_name); + const void* GetProxiedInterface(const std::string& proxied_interface); + + // Returns the proxy object associated with the given interface ID, creating + // it if necessary. This is used in cases where a proxy needs to access code + // in the proxy for another interface. It's assumed that the interface always + // exists, so this is only used for browser proxies. + // + // Will return NULL if an interface isn't supported. + InterfaceProxy* GetOrCreatePPBInterfaceProxy(InterfaceID id); // See the value below. Call this when processing a scripting message from - // the plugin that can be reentered. This is set to false at the beginning - // of processing of each message from the plugin. + // the plugin that can be reentered. void set_allow_plugin_reentrancy() { allow_plugin_reentrancy_ = true; } @@ -91,17 +99,28 @@ class PPAPI_PROXY_EXPORT HostDispatcher : public Dispatcher { // Returns the proxy interface for talking to the implementation. const PPB_Proxy_Private* ppb_proxy() const { return ppb_proxy_; } - protected: - // Overridden from Dispatcher. - virtual void OnInvalidMessageReceived(); - private: + friend class HostDispatcherTest; + + // Makes an instance of the given PPB interface proxy, storing it in the + // target_proxies_ array. An proxy for this interface must not exist yet. + InterfaceProxy* CreatePPBInterfaceProxy(const InterfaceProxy::Info* info); + PP_Module pp_module_; + typedef std::map<std::string, bool> PluginIFSupportedMap; // Maps interface name to whether that interface is supported. If an interface // name is not in the map, that implies that we haven't queried for it yet. - typedef base::hash_map<std::string, bool> PluginSupportedMap; - PluginSupportedMap plugin_supported_; + std::map<std::string, bool> plugin_if_supported_; + + // All target proxies currently created. These are ones that receive + // messages. They are created on demand when we receive messages. + scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; + + // Function proxies created for "new-style" FunctionGroups. + // TODO(brettw) this is in progress. It should be merged with the target + // proxies so there is one list to consult. + scoped_ptr<FunctionGroupBase> function_proxies_[INTERFACE_ID_COUNT]; // Guaranteed non-NULL. const PPB_Proxy_Private* ppb_proxy_; diff --git a/ppapi/proxy/host_dispatcher_unittest.cc b/ppapi/proxy/host_dispatcher_unittest.cc index 5ce8ba3..25dfa5c 100644 --- a/ppapi/proxy/host_dispatcher_unittest.cc +++ b/ppapi/proxy/host_dispatcher_unittest.cc @@ -17,7 +17,7 @@ class HostDispatcherTest : public HostProxyTest { HostDispatcherTest() {} bool HasTargetProxy(InterfaceID id) { - return !!host_dispatcher()->proxies_[id].get(); + return !!host_dispatcher()->target_proxies_[id].get(); } }; diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h index 3b43943..277f964 100644 --- a/ppapi/proxy/interface_id.h +++ b/ppapi/proxy/interface_id.h @@ -18,6 +18,7 @@ enum InterfaceID { INTERFACE_ID_PPB_BROKER, INTERFACE_ID_PPB_BUFFER, INTERFACE_ID_PPB_CHAR_SET, + INTERFACE_ID_PPB_CONSOLE, INTERFACE_ID_PPB_CONTEXT_3D, INTERFACE_ID_PPB_CORE, INTERFACE_ID_PPB_CRYPTO, @@ -36,15 +37,19 @@ enum InterfaceID { INTERFACE_ID_PPB_FONT, INTERFACE_ID_PPB_GRAPHICS_2D, INTERFACE_ID_PPB_GRAPHICS_3D, + INTERFACE_ID_PPB_IMAGE_DATA, INTERFACE_ID_PPB_INSTANCE, INTERFACE_ID_PPB_INSTANCE_PRIVATE, + INTERFACE_ID_PPB_MEMORY, INTERFACE_ID_PPB_OPENGLES2, INTERFACE_ID_PPB_PDF, INTERFACE_ID_PPB_SURFACE_3D, INTERFACE_ID_PPB_TESTING, INTERFACE_ID_PPB_URL_LOADER, + INTERFACE_ID_PPB_URL_REQUEST_INFO, INTERFACE_ID_PPB_URL_RESPONSE_INFO, INTERFACE_ID_PPB_URL_UTIL, + INTERFACE_ID_PPB_VAR, INTERFACE_ID_PPB_VAR_DEPRECATED, INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, INTERFACE_ID_PPB_VIDEO_DECODER_DEV, diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc deleted file mode 100644 index 0b386aa..0000000 --- a/ppapi/proxy/interface_list.cc +++ /dev/null @@ -1,296 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ppapi/proxy/interface_list.h" - -#include "base/memory/singleton.h" -#include "ppapi/c/dev/ppb_buffer_dev.h" -#include "ppapi/c/dev/ppb_char_set_dev.h" -#include "ppapi/c/dev/ppb_console_dev.h" -#include "ppapi/c/dev/ppb_context_3d_dev.h" -#include "ppapi/c/dev/ppb_crypto_dev.h" -#include "ppapi/c/dev/ppb_cursor_control_dev.h" -#include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" -#include "ppapi/c/dev/ppb_font_dev.h" -#include "ppapi/c/dev/ppb_memory_dev.h" -#include "ppapi/c/dev/ppb_mouse_lock_dev.h" -#include "ppapi/c/dev/ppb_surface_3d_dev.h" -#include "ppapi/c/dev/ppb_testing_dev.h" -#include "ppapi/c/dev/ppb_url_util_dev.h" -#include "ppapi/c/dev/ppb_var_deprecated.h" -#include "ppapi/c/dev/ppb_video_capture_dev.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/c/ppb_audio.h" -#include "ppapi/c/ppb_audio_config.h" -#include "ppapi/c/ppb_core.h" -#include "ppapi/c/ppb_file_ref.h" -#include "ppapi/c/ppb_file_system.h" -#include "ppapi/c/ppb_graphics_2d.h" -#include "ppapi/c/ppb_image_data.h" -#include "ppapi/c/ppb_input_event.h" -#include "ppapi/c/ppb_instance.h" -#include "ppapi/c/ppb_messaging.h" -#include "ppapi/c/ppb_opengles.h" -#include "ppapi/c/ppb_url_loader.h" -#include "ppapi/c/ppb_url_request_info.h" -#include "ppapi/c/ppb_url_response_info.h" -#include "ppapi/c/ppb_var.h" -#include "ppapi/c/ppp_instance.h" -#include "ppapi/c/private/ppb_flash.h" -#include "ppapi/c/private/ppb_flash_clipboard.h" -#include "ppapi/c/private/ppb_flash_file.h" -#include "ppapi/c/private/ppb_flash_menu.h" -#include "ppapi/c/private/ppb_flash_net_connector.h" -#include "ppapi/c/private/ppb_flash_tcp_socket.h" -#include "ppapi/c/private/ppb_pdf.h" -#include "ppapi/c/trusted/ppb_broker_trusted.h" -#include "ppapi/c/trusted/ppb_url_loader_trusted.h" -#include "ppapi/proxy/interface_proxy.h" -#include "ppapi/proxy/ppb_audio_proxy.h" -#include "ppapi/proxy/ppb_broker_proxy.h" -#include "ppapi/proxy/ppb_buffer_proxy.h" -#include "ppapi/proxy/ppb_char_set_proxy.h" -#include "ppapi/proxy/ppb_context_3d_proxy.h" -#include "ppapi/proxy/ppb_core_proxy.h" -#include "ppapi/proxy/ppb_crypto_proxy.h" -#include "ppapi/proxy/ppb_cursor_control_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_flash_clipboard_proxy.h" -#include "ppapi/proxy/ppb_flash_file_proxy.h" -#include "ppapi/proxy/ppb_flash_proxy.h" -#include "ppapi/proxy/ppb_flash_menu_proxy.h" -#include "ppapi/proxy/ppb_flash_net_connector_proxy.h" -#include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h" -#include "ppapi/proxy/ppb_font_proxy.h" -#include "ppapi/proxy/ppb_graphics_2d_proxy.h" -#include "ppapi/proxy/ppb_graphics_3d_proxy.h" -#include "ppapi/proxy/ppb_image_data_proxy.h" -#include "ppapi/proxy/ppb_instance_proxy.h" -#include "ppapi/proxy/ppb_memory_proxy.h" -#include "ppapi/proxy/ppp_mouse_lock_proxy.h" -#include "ppapi/proxy/ppb_pdf_proxy.h" -#include "ppapi/proxy/ppb_surface_3d_proxy.h" -#include "ppapi/proxy/ppb_testing_proxy.h" -#include "ppapi/proxy/ppb_url_loader_proxy.h" -#include "ppapi/proxy/ppb_url_response_info_proxy.h" -#include "ppapi/proxy/ppb_url_util_proxy.h" -#include "ppapi/proxy/ppb_var_deprecated_proxy.h" -#include "ppapi/proxy/ppb_var_proxy.h" -#include "ppapi/proxy/ppb_video_capture_proxy.h" -#include "ppapi/proxy/ppb_video_decoder_proxy.h" -#include "ppapi/proxy/ppp_class_proxy.h" -#include "ppapi/proxy/ppp_graphics_3d_proxy.h" -#include "ppapi/proxy/ppp_input_event_proxy.h" -#include "ppapi/proxy/ppp_instance_private_proxy.h" -#include "ppapi/proxy/ppp_instance_proxy.h" -#include "ppapi/proxy/ppp_messaging_proxy.h" -#include "ppapi/proxy/ppp_video_decoder_proxy.h" -#include "ppapi/proxy/resource_creation_proxy.h" -#include "ppapi/shared_impl/opengles2_impl.h" -#include "ppapi/thunk/thunk.h" - -// Helper to get the proxy name PPB_Foo_Proxy given the API name PPB_Foo. -#define PROXY_CLASS_NAME(api_name) api_name##_Proxy - -// Helper to get the interface ID PPB_Foo_Proxy::kInterfaceID given the API -// name PPB_Foo. -#define PROXY_INTERFACE_ID(api_name) PROXY_CLASS_NAME(api_name)::kInterfaceID - -// Helper to get the name of the factory function CreatePPB_Foo_Proxy given -// the API name PPB_Foo. -#define PROXY_FACTORY_NAME(api_name) Create##api_name##_Proxy - -// Helper to get the name of the thunk GetPPB_Foo_1_0_Thunk given the interface -// struct name PPB_Foo_1_0. -#define INTERFACE_THUNK_NAME(iface_struct) thunk::Get##iface_struct##_Thunk - -namespace ppapi { -namespace proxy { - -namespace { - -// The interface list has interfaces with no ID listed as "NoAPIName" which -// means there's no corresponding _Proxy object. Our macros expand this to -// NoAPIName_Proxy, and then they look for kInterfaceID inside it. -// -// This dummy class provides the correct definition for that interface ID, -// which is "NONE". -class NoAPIName_Proxy { - public: - static const InterfaceID kInterfaceID = INTERFACE_ID_NONE; -}; - -// Define factory functions for each interface type. These are of the form: -// InterfaceProxy* CreatePPB_URLLoader_Proxy(... -#define PROXIED_API(api_name) \ - InterfaceProxy* PROXY_FACTORY_NAME(api_name)(Dispatcher* dispatcher) { \ - return new PROXY_CLASS_NAME(api_name)(dispatcher); \ - } -#include "ppapi/thunk/interfaces_ppb_public_stable.h" -#include "ppapi/thunk/interfaces_ppb_public_dev.h" -#include "ppapi/thunk/interfaces_ppb_private.h" -#undef PROXIED_API - -} // namespace - -InterfaceList::InterfaceList() { - memset(id_to_factory_, 0, sizeof(id_to_factory_)); - - // Register the API factories for each of the API types. This calls AddProxy - // for each InterfaceProxy type we support. - #define PROXIED_API(api_name) \ - AddProxy(PROXY_INTERFACE_ID(api_name), &PROXY_FACTORY_NAME(api_name)); - - // Register each proxied interface by calling AddPPB for each supported - // interface. - #define PROXIED_IFACE(api_name, iface_str, iface_struct) \ - AddPPB(iface_str, PROXY_INTERFACE_ID(api_name), \ - INTERFACE_THUNK_NAME(iface_struct)()); - - #include "ppapi/thunk/interfaces_ppb_public_stable.h" - #include "ppapi/thunk/interfaces_ppb_public_dev.h" - #include "ppapi/thunk/interfaces_ppb_private.h" - - #undef PROXIED_API - #undef PROXIED_IFACE - - // New-style AddPPB not converted to the macros above. - AddPPB(PPB_CORE_INTERFACE, INTERFACE_ID_PPB_CORE, - PPB_Core_Proxy::GetPPB_Core_Interface()); - AddPPB(PPB_MEMORY_DEV_INTERFACE, INTERFACE_ID_NONE, - GetPPB_Memory_Interface()); - AddPPB(PPB_OPENGLES2_INTERFACE, INTERFACE_ID_NONE, - OpenGLES2Impl::GetInterface()); - AddPPB(PPB_VAR_INTERFACE, INTERFACE_ID_NONE, - GetPPB_Var_Interface()); - - // Manually add some special proxies. These don't have interfaces that they - // support, so aren't covered by the macros above, but have proxies for - // message routing. - AddProxy(INTERFACE_ID_RESOURCE_CREATION, &ResourceCreationProxy::Create); - AddProxy(INTERFACE_ID_PPP_CLASS, &PPP_Class_Proxy::Create); - - // PPB (browser) interfaces. - AddPPB(PPB_Crypto_Proxy::GetInfo()); - AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo()); - AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo()); - AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo()); - AddPPB(PPB_Flash_Menu_Proxy::GetInfo()); - AddPPB(PPB_Flash_Proxy::GetInfo()); - AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo()); - AddPPB(PPB_Instance_Proxy::GetInfoFullscreen()); - AddPPB(PPB_Instance_Proxy::GetInfoPrivate()); - AddPPB(PPB_PDF_Proxy::GetInfo()); - AddPPB(PPB_Testing_Proxy::GetInfo()); - AddPPB(PPB_URLLoader_Proxy::GetTrustedInfo()); - AddPPB(PPB_URLUtil_Proxy::GetInfo()); - AddPPB(PPB_Var_Deprecated_Proxy::GetInfo()); - -#ifdef ENABLE_FLAPPER_HACKS - AddPPB(PPB_Flash_NetConnector_Proxy::GetInfo()); -#endif - - // PPP (plugin) interfaces. - AddPPP(PPP_Graphics3D_Proxy::GetInfo()); - AddPPP(PPP_InputEvent_Proxy::GetInfo()); - AddPPP(PPP_Instance_Private_Proxy::GetInfo()); - AddPPP(PPP_Instance_Proxy::GetInfo1_0()); - AddPPP(PPP_Messaging_Proxy::GetInfo()); - AddPPP(PPP_MouseLock_Proxy::GetInfo()); - AddPPP(PPP_VideoCapture_Proxy::GetInfo()); - AddPPP(PPP_VideoDecoder_Proxy::GetInfo()); -} - -InterfaceList::~InterfaceList() { -} - -// static -InterfaceList* InterfaceList::GetInstance() { - return Singleton<InterfaceList>::get(); -} - -InterfaceID InterfaceList::GetIDForPPBInterface(const std::string& name) const { - NameToInterfaceInfoMap::const_iterator found = - name_to_browser_info_.find(name); - if (found == name_to_browser_info_.end()) - return INTERFACE_ID_NONE; - return found->second.id; -} - -InterfaceID InterfaceList::GetIDForPPPInterface(const std::string& name) const { - NameToInterfaceInfoMap::const_iterator found = - name_to_plugin_info_.find(name); - if (found == name_to_plugin_info_.end()) - return INTERFACE_ID_NONE; - return found->second.id; -} - -InterfaceProxy::Factory InterfaceList::GetFactoryForID(InterfaceID id) const { - int index = static_cast<int>(id); - COMPILE_ASSERT(INTERFACE_ID_NONE == 0, none_must_be_zero); - if (id <= 0 || id >= INTERFACE_ID_COUNT) - return NULL; - return id_to_factory_[index]; -} - -const void* InterfaceList::GetInterfaceForPPB(const std::string& name) const { - NameToInterfaceInfoMap::const_iterator found = - name_to_browser_info_.find(name); - if (found == name_to_browser_info_.end()) - return NULL; - return found->second.iface; -} - -const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { - NameToInterfaceInfoMap::const_iterator found = - name_to_plugin_info_.find(name); - if (found == name_to_plugin_info_.end()) - return NULL; - return found->second.iface; -} - -void InterfaceList::AddProxy(InterfaceID id, - InterfaceProxy::Factory factory) { - // For interfaces with no corresponding _Proxy objects, the macros will - // generate calls to this function with INTERFACE_ID_NONE. This means we - // should just skip adding a factory for these functions. - if (id == INTERFACE_ID_NONE) - return; - - // The factory should be an exact dupe of the one we already have if it - // has already been registered before. - int index = static_cast<int>(id); - DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory); - - id_to_factory_[index] = factory; -} - -void InterfaceList::AddPPB(const char* name, - InterfaceID id, - const void* iface) { - DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end()); - name_to_browser_info_[name] = InterfaceInfo(id, iface); -} - -void InterfaceList::AddPPP(const char* name, - InterfaceID id, - const void* iface) { - DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end()); - name_to_plugin_info_[name] = InterfaceInfo(id, iface); -} - -void InterfaceList::AddPPB(const InterfaceProxy::Info* info) { - AddProxy(info->id, info->create_proxy); - AddPPB(info->name, info->id, info->interface_ptr); -} - -void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { - AddProxy(info->id, info->create_proxy); - AddPPP(info->name, info->id, info->interface_ptr); -} - -} // namespace proxy -} // namespace ppapi diff --git a/ppapi/proxy/interface_list.h b/ppapi/proxy/interface_list.h deleted file mode 100644 index 0290af9..0000000 --- a/ppapi/proxy/interface_list.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PPAPI_PROXY_INTERFACE_LIST_H_ -#define PPAPI_PROXY_INTERFACE_LIST_H_ - -#include <map> -#include <string> - -#include "base/basictypes.h" -#include "ppapi/proxy/interface_proxy.h" - -namespace ppapi { -namespace proxy { - -class InterfaceList { - public: - InterfaceList(); - ~InterfaceList(); - - static InterfaceList* GetInstance(); - - // Looks up the ID for the given interface name. Returns INTERFACE_ID_NONE if - // the interface string is not found. - InterfaceID GetIDForPPBInterface(const std::string& name) const; - InterfaceID GetIDForPPPInterface(const std::string& name) const; - - // Looks up the factory function for the given ID. Returns NULL if not - // supported. - InterfaceProxy::Factory GetFactoryForID(InterfaceID id) const; - - // Returns the interface pointer for the given browser or plugin interface, - // or NULL if it's not supported. - const void* GetInterfaceForPPB(const std::string& name) const; - const void* GetInterfaceForPPP(const std::string& name) const; - - private: - struct InterfaceInfo { - InterfaceInfo() - : id(INTERFACE_ID_NONE), - iface(NULL) { - } - InterfaceInfo(InterfaceID in_id, const void* in_interface) - : id(in_id), - iface(in_interface) { - } - - InterfaceID id; - const void* iface; - }; - - typedef std::map<std::string, InterfaceInfo> NameToInterfaceInfoMap; - - void AddProxy(InterfaceID id, InterfaceProxy::Factory factory); - - void AddPPB(const char* name, InterfaceID id, const void* iface); - void AddPPP(const char* name, InterfaceID id, const void* iface); - - // Old-style add functions. These should be removed when the rest of the - // proxies are converted over to using the new system. - void AddPPB(const InterfaceProxy::Info* info); - void AddPPP(const InterfaceProxy::Info* info); - - NameToInterfaceInfoMap name_to_browser_info_; - NameToInterfaceInfoMap name_to_plugin_info_; - - InterfaceProxy::Factory id_to_factory_[INTERFACE_ID_COUNT]; - - DISALLOW_COPY_AND_ASSIGN(InterfaceList); -}; - -} // namespace proxy -} // namespace ppapi - -#endif // PPAPI_PROXY_INTERFACE_LIST_H_ - diff --git a/ppapi/proxy/interface_proxy.cc b/ppapi/proxy/interface_proxy.cc index 913821a..a474383 100644 --- a/ppapi/proxy/interface_proxy.cc +++ b/ppapi/proxy/interface_proxy.cc @@ -10,8 +10,10 @@ namespace ppapi { namespace proxy { -InterfaceProxy::InterfaceProxy(Dispatcher* dispatcher) - : dispatcher_(dispatcher) { +InterfaceProxy::InterfaceProxy(Dispatcher* dispatcher, + const void* target_interface) + : dispatcher_(dispatcher), + target_interface_(target_interface) { } InterfaceProxy::~InterfaceProxy() { diff --git a/ppapi/proxy/interface_proxy.h b/ppapi/proxy/interface_proxy.h index 795944b..1fed704 100644 --- a/ppapi/proxy/interface_proxy.h +++ b/ppapi/proxy/interface_proxy.h @@ -12,7 +12,6 @@ #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_var.h" #include "ppapi/proxy/interface_id.h" -#include "ppapi/shared_impl/function_group_base.h" namespace ppapi { namespace proxy { @@ -20,16 +19,13 @@ namespace proxy { class Dispatcher; class InterfaceProxy : public IPC::Channel::Listener, - public IPC::Message::Sender, - public FunctionGroupBase { + public IPC::Message::Sender { public: // Factory function type for interfaces. Ownership of the returned pointer // is transferred to the caller. - typedef InterfaceProxy* (*Factory)(Dispatcher* dispatcher); + typedef InterfaceProxy* (*Factory)(Dispatcher* dispatcher, + const void* target_interface); - // DEPRECATED: New classes should be registered directly in the interface - // list. This is kept around until we convert all the existing code. - // // Information about the interface. Each interface has a static function to // return its info, which allows either construction on the target side, and // getting the proxied interface on the source side (see dispatcher.h for @@ -47,6 +43,9 @@ class InterfaceProxy : public IPC::Channel::Listener, virtual ~InterfaceProxy(); + // The actual implementation of the given interface in the current process. + const void* target_interface() const { return target_interface_; } + Dispatcher* dispatcher() const { return dispatcher_; } // IPC::Message::Sender implementation. @@ -58,13 +57,19 @@ class InterfaceProxy : public IPC::Channel::Listener, protected: // Creates the given interface associated with the given dispatcher. The // dispatcher manages our lifetime. - InterfaceProxy(Dispatcher* dispatcher); + // + // The target interface pointer, when non-NULL, indicates that this is a + // target proxy (see dispatcher.h for a definition). In this case, the proxy + // will interpret this pointer to the actual implementation of the interface + // in the local process. + InterfaceProxy(Dispatcher* dispatcher, const void* target_interface); uint32 SendCallback(PP_CompletionCallback callback); PP_CompletionCallback ReceiveCallback(uint32 serialized_callback); private: Dispatcher* dispatcher_; + const void* target_interface_; }; } // namespace proxy diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index 7afd3d6..bb42fcb7 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -13,7 +13,6 @@ #include "ipc/ipc_sync_channel.h" #include "base/debug/trace_event.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/proxy/interface_list.h" #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/plugin_message_filter.h" #include "ppapi/proxy/plugin_resource_tracker.h" @@ -54,6 +53,11 @@ PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle, received_preferences_(false), plugin_dispatcher_id_(0) { SetSerializationRules(new PluginVarSerializationRules); + + // As a plugin, we always support the PPP_Class interface. There's no + // GetInterface call or name for it, so we insert it into our table now. + target_proxies_[INTERFACE_ID_PPP_CLASS].reset(new PPP_Class_Proxy(this)); + TrackerBase::Init(&PluginResourceTracker::GetTrackerBaseInstance); } @@ -79,19 +83,13 @@ PluginDispatcher* PluginDispatcher::GetForResource(const Resource* resource) { } // static -const void* PluginDispatcher::GetBrowserInterface(const char* interface_name) { - return InterfaceList::GetInstance()->GetInterfaceForPPB(interface_name); -} - -const void* PluginDispatcher::GetPluginInterface( - const std::string& interface_name) { - InterfaceMap::iterator found = plugin_interfaces_.find(interface_name); - if (found == plugin_interfaces_.end()) { - const void* ret = local_get_interface()(interface_name.c_str()); - plugin_interfaces_.insert(std::make_pair(interface_name, ret)); - return ret; - } - return found->second; +const void* PluginDispatcher::GetInterfaceFromDispatcher( + const char* dispatcher_interface) { + // All interfaces the plugin requests of the browser are "PPB". + const InterfaceProxy::Info* info = GetPPBInterfaceInfo(dispatcher_interface); + if (!info) + return NULL; + return info->interface_ptr; } bool PluginDispatcher::InitPluginWithChannel( @@ -133,18 +131,56 @@ bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) { TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived", "Class", IPC_MESSAGE_ID_CLASS(msg.type()), "Line", IPC_MESSAGE_ID_LINE(msg.type())); + // Handle common control messages. + if (Dispatcher::OnMessageReceived(msg)) + return true; + if (msg.routing_id() == MSG_ROUTING_CONTROL) { // Handle some plugin-specific control messages. bool handled = true; IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences) - IPC_MESSAGE_UNHANDLED(handled = false); IPC_END_MESSAGE_MAP() - if (handled) + return handled; + } + + if (msg.routing_id() <= 0 || msg.routing_id() >= INTERFACE_ID_COUNT) { + // Host is sending us garbage. Since it's supposed to be trusted, this + // isn't supposed to happen. Crash here in all builds in case the renderer + // is compromised. + CHECK(false); + return true; + } + + // There are two cases: + // + // * The first case is that the host is calling a PPP interface. It will + // always do a check for the interface before sending messages, and this + // will create the necessary interface proxy at that time. So when we + // actually receive a message, we know such a proxy will exist. + // + // * The second case is that the host is sending a response to the plugin + // side of a PPB interface (some, like the URL loader, have complex + // response messages). Since the host is trusted and not supposed to be + // doing silly things, we can just create a PPB proxy project on demand the + // first time it's needed. + + InterfaceProxy* proxy = target_proxies_[msg.routing_id()].get(); + if (!proxy) { + // Handle the first time the host calls a PPB reply interface by + // autocreating it. + const InterfaceProxy::Info* info = GetPPBInterfaceInfo( + static_cast<InterfaceID>(msg.routing_id())); + if (!info) { + NOTREACHED(); return true; + } + proxy = info->create_proxy(this, NULL); + target_proxies_[info->id].reset(proxy); } - return Dispatcher::OnMessageReceived(msg); + + return proxy->OnMessageReceived(msg); } void PluginDispatcher::OnChannelError() { @@ -202,7 +238,23 @@ WebKitForwarding* PluginDispatcher::GetWebKitForwarding() { } FunctionGroupBase* PluginDispatcher::GetFunctionAPI(InterfaceID id) { - return GetInterfaceProxy(id); + scoped_ptr<FunctionGroupBase >& proxy = function_proxies_[id]; + + if (proxy.get()) + return proxy.get(); + + if (id == INTERFACE_ID_PPB_CHAR_SET) + proxy.reset(new PPB_CharSet_Proxy(this, NULL)); + else if(id == INTERFACE_ID_PPB_CURSORCONTROL) + proxy.reset(new PPB_CursorControl_Proxy(this, NULL)); + else if (id == INTERFACE_ID_PPB_FONT) + proxy.reset(new PPB_Font_Proxy(this, NULL)); + else if (id == INTERFACE_ID_PPB_INSTANCE) + proxy.reset(new PPB_Instance_Proxy(this, NULL)); + else if (id == INTERFACE_ID_RESOURCE_CREATION) + proxy.reset(new ResourceCreationProxy(this)); + + return proxy.get(); } void PluginDispatcher::ForceFreeAllInstances() { @@ -226,7 +278,26 @@ void PluginDispatcher::ForceFreeAllInstances() { void PluginDispatcher::OnMsgSupportsInterface( const std::string& interface_name, bool* result) { - *result = !!GetPluginInterface(interface_name); + *result = false; + + // Setup a proxy for receiving the messages from this interface. + const InterfaceProxy::Info* info = GetPPPInterfaceInfo(interface_name); + if (!info) + return; // Interface not supported by proxy. + + // Check for a cached result. + if (target_proxies_[info->id].get()) { + *result = true; + return; + } + + // Query the plugin & cache the result. + const void* interface_functions = GetLocalInterface(interface_name.c_str()); + if (!interface_functions) + return; + target_proxies_[info->id].reset( + info->create_proxy(this, interface_functions)); + *result = true; } void PluginDispatcher::OnMsgSetPreferences(const Preferences& prefs) { diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h index 1a2f586..2238646 100644 --- a/ppapi/proxy/plugin_dispatcher.h +++ b/ppapi/proxy/plugin_dispatcher.h @@ -88,11 +88,8 @@ class PPAPI_PROXY_EXPORT PluginDispatcher : public Dispatcher { // object as a convenience. Returns NULL on failure. static PluginDispatcher* GetForResource(const Resource* resource); - // Implements the GetInterface function for the plugin to call to retrieve - // a browser interface. - static const void* GetBrowserInterface(const char* interface_name); - - const void* GetPluginInterface(const std::string& interface_name); + static const void* GetInterfaceFromDispatcher( + const char* dispatcher_interface); // You must call this function before anything else. Returns true on success. // The delegate pointer must outlive this class, ownership is not @@ -152,12 +149,14 @@ class PPAPI_PROXY_EXPORT PluginDispatcher : public Dispatcher { PluginDelegate* plugin_delegate_; - // Contains all the plugin interfaces we've queried. The mapped value will - // be the pointer to the interface pointer supplied by the plugin if it's - // supported, or NULL if it's not supported. This allows us to cache failures - // and not req-query if a plugin doesn't support the interface. - typedef base::hash_map<std::string, const void*> InterfaceMap; - InterfaceMap plugin_interfaces_; + // All target proxies currently created. These are ones that receive + // messages. + scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; + + // Function proxies created for "new-style" FunctionGroups. + // TODO(brettw) this is in progress. It should be merged with the target + // proxies so there is one list to consult. + scoped_ptr<FunctionGroupBase> function_proxies_[INTERFACE_ID_COUNT]; typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; InstanceDataMap instance_map_; diff --git a/ppapi/proxy/plugin_dispatcher_unittest.cc b/ppapi/proxy/plugin_dispatcher_unittest.cc index 8a32026..56f563b 100644 --- a/ppapi/proxy/plugin_dispatcher_unittest.cc +++ b/ppapi/proxy/plugin_dispatcher_unittest.cc @@ -53,7 +53,7 @@ class PluginDispatcherTest : public PluginProxyTest { PluginDispatcherTest() {} bool HasTargetProxy(InterfaceID id) { - return !!plugin_dispatcher()->proxies_[id].get(); + return !!plugin_dispatcher()->target_proxies_[id].get(); } }; @@ -64,6 +64,11 @@ TEST_F(PluginDispatcherTest, SupportsInterface) { // Sending a request for a random interface should fail. EXPECT_FALSE(SupportsInterface("Random interface")); + // Sending a request for a PPB interface should fail even though we've + // registered it as existing in the GetInterface function (the plugin proxy + // should only respond to PPP interfaces when asked if it supports them). + EXPECT_FALSE(SupportsInterface(PPB_AUDIO_INTERFACE)); + // Sending a request for a supported PPP interface should succeed. EXPECT_TRUE(SupportsInterface(PPP_INSTANCE_INTERFACE)); } diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index ac7992d..4611a4f 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -468,6 +468,17 @@ IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBBuffer_Create, ppapi::HostResource /* result_resource */, base::SharedMemoryHandle /* result_shm_handle */) +// PPB_Console. +IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBConsole_Log, + PP_Instance /* instance */, + int /* log_level */, + ppapi::proxy::SerializedVar /* value */) +IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBConsole_LogWithSource, + PP_Instance /* instance */, + int /* log_level */, + ppapi::proxy::SerializedVar /* soruce */, + ppapi::proxy::SerializedVar /* value */) + // PPB_Context3D. IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBContext3D_Create, PP_Instance /* instance */, @@ -813,15 +824,6 @@ IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBInstance_ExecuteScript, ppapi::proxy::SerializedVar /* script */, ppapi::proxy::SerializedVar /* out_exception */, ppapi::proxy::SerializedVar /* result */) -IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBInstance_Log, - PP_Instance /* instance */, - int /* log_level */, - ppapi::proxy::SerializedVar /* value */) -IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBInstance_LogWithSource, - PP_Instance /* instance */, - int /* log_level */, - ppapi::proxy::SerializedVar /* source */, - ppapi::proxy::SerializedVar /* value */) IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBInstance_SetFullscreen, PP_Instance /* instance */, PP_Bool /* fullscreen */, diff --git a/ppapi/proxy/ppb_audio_config_proxy.cc b/ppapi/proxy/ppb_audio_config_proxy.cc new file mode 100644 index 0000000..d578fd5 --- /dev/null +++ b/ppapi/proxy/ppb_audio_config_proxy.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/proxy/ppb_audio_config_proxy.h" + +#include "ppapi/c/ppb_audio_config.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/audio_config_impl.h" +#include "ppapi/thunk/thunk.h" + +namespace ppapi { +namespace proxy { + +namespace { + +InterfaceProxy* CreateAudioConfigProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_AudioConfig_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPB_AudioConfig_Proxy::PPB_AudioConfig_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_AudioConfig_Proxy::~PPB_AudioConfig_Proxy() { +} + +// static +const InterfaceProxy::Info* PPB_AudioConfig_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_AudioConfig_Thunk(), + PPB_AUDIO_CONFIG_INTERFACE, + INTERFACE_ID_PPB_AUDIO_CONFIG, + false, + &CreateAudioConfigProxy, + }; + return &info; +} + +bool PPB_AudioConfig_Proxy::OnMessageReceived(const IPC::Message& msg) { + // There are no IPC messages for this interface. + NOTREACHED(); + return false; +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/ppb_audio_config_proxy.h b/ppapi/proxy/ppb_audio_config_proxy.h new file mode 100644 index 0000000..d70d2db --- /dev/null +++ b/ppapi/proxy/ppb_audio_config_proxy.h @@ -0,0 +1,36 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_PPB_AUDIO_CONFIG_PROXY_H_ +#define PPAPI_PROXY_PPB_AUDIO_CONFIG_PROXY_H_ + +#include "base/basictypes.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/ppb_audio_config.h" +#include "ppapi/proxy/interface_proxy.h" + +struct PPB_AudioConfig; + +namespace ppapi { +namespace proxy { + +class PPB_AudioConfig_Proxy : public InterfaceProxy { + public: + PPB_AudioConfig_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_AudioConfig_Proxy(); + + static const Info* GetInfo(); + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg); + + private: + DISALLOW_COPY_AND_ASSIGN(PPB_AudioConfig_Proxy); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PPB_AUDIO_CONFIG_PROXY_H_ diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc index 453d7b0..139df10 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -116,6 +116,11 @@ int32_t Audio::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { namespace { +InterfaceProxy* CreateAudioProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Audio_Proxy(dispatcher, target_interface); +} + base::PlatformFile IntToPlatformFile(int32_t handle) { // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, // those casts are ugly. @@ -130,8 +135,9 @@ base::PlatformFile IntToPlatformFile(int32_t handle) { } // namespace -PPB_Audio_Proxy::PPB_Audio_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +PPB_Audio_Proxy::PPB_Audio_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } @@ -139,6 +145,18 @@ PPB_Audio_Proxy::~PPB_Audio_Proxy() { } // static +const InterfaceProxy::Info* PPB_Audio_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_Audio_Thunk(), + PPB_AUDIO_INTERFACE, + INTERFACE_ID_PPB_AUDIO, + false, + &CreateAudioProxy, + }; + return &info; +} + +// static PP_Resource PPB_Audio_Proxy::CreateProxyResource( PP_Instance instance_id, PP_Resource config_id, @@ -224,19 +242,16 @@ void PPB_Audio_Proxy::OnMsgCreate(PP_Instance instance_id, // Clean up the temporary audio config resource we made. const PPB_Core* core = static_cast<const PPB_Core*>( - dispatcher()->local_get_interface()(PPB_CORE_INTERFACE)); + dispatcher()->GetLocalInterface(PPB_CORE_INTERFACE)); core->ReleaseResource(audio_config_res); } void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id, bool play) { - EnterHostFromHostResource<PPB_Audio_API> enter(audio_id); - if (enter.failed()) - return; if (play) - enter.object()->StartPlayback(); + ppb_audio_target()->StartPlayback(audio_id.host_resource()); else - enter.object()->StopPlayback(); + ppb_audio_target()->StopPlayback(audio_id.host_resource()); } // Processed in the plugin (message from host). @@ -292,7 +307,7 @@ int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( base::SharedMemoryHandle* foreign_shared_memory_handle, uint32_t* shared_memory_length) { // Get the audio interface which will give us the handles. - EnterHostFromHostResource<PPB_Audio_API> enter(resource); + EnterResourceNoLock<PPB_Audio_API> enter(resource.host_resource(), false); if (enter.failed()) return PP_ERROR_NOINTERFACE; diff --git a/ppapi/proxy/ppb_audio_proxy.h b/ppapi/proxy/ppb_audio_proxy.h index b548e72..7948b9c 100644 --- a/ppapi/proxy/ppb_audio_proxy.h +++ b/ppapi/proxy/ppb_audio_proxy.h @@ -30,9 +30,11 @@ namespace proxy { class PPB_Audio_Proxy : public InterfaceProxy { public: - PPB_Audio_Proxy(Dispatcher* dispatcher); + PPB_Audio_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Audio_Proxy(); + static const Info* GetInfo(); + // Creates an Audio object in the plugin process. static PP_Resource CreateProxyResource(PP_Instance instance_id, PP_Resource config_id, @@ -40,11 +42,13 @@ class PPB_Audio_Proxy : public InterfaceProxy { void* user_data); + const PPB_Audio* ppb_audio_target() const { + return static_cast<const PPB_Audio*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_AUDIO; - private: // Plugin->renderer message handlers. void OnMsgCreate(PP_Instance instance_id, diff --git a/ppapi/proxy/ppb_broker_proxy.cc b/ppapi/proxy/ppb_broker_proxy.cc index ff06759..68ba8c0 100644 --- a/ppapi/proxy/ppb_broker_proxy.cc +++ b/ppapi/proxy/ppb_broker_proxy.cc @@ -11,7 +11,6 @@ #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/thunk/ppb_broker_api.h" #include "ppapi/thunk/enter.h" -#include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" using ppapi::thunk::PPB_Broker_API; @@ -41,6 +40,11 @@ int32_t PlatformFileToInt(base::PlatformFile handle) { #endif } +InterfaceProxy* CreateBrokerProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Broker_Proxy(dispatcher, target_interface); +} + } // namespace class Broker : public PPB_Broker_API, public Resource { @@ -143,8 +147,9 @@ void Broker::ConnectComplete(IPC::PlatformFileForTransit socket_handle, PP_RunAndClearCompletionCallback(¤t_connect_callback_, result); } -PPB_Broker_Proxy::PPB_Broker_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +PPB_Broker_Proxy::PPB_Broker_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) , callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)){ } @@ -152,6 +157,18 @@ PPB_Broker_Proxy::~PPB_Broker_Proxy() { } // static +const InterfaceProxy::Info* PPB_Broker_Proxy::GetInfo() { + static const Info info = { + ppapi::thunk::GetPPB_Broker_Thunk(), + PPB_BROKER_TRUSTED_INTERFACE, + INTERFACE_ID_PPB_BROKER, + true, + &CreateBrokerProxy, + }; + return &info; +} + +// static PP_Resource PPB_Broker_Proxy::CreateProxyResource(PP_Instance instance) { PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); if (!dispatcher) @@ -179,12 +196,9 @@ bool PPB_Broker_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_Broker_Proxy::OnMsgCreate(PP_Instance instance, HostResource* result_resource) { - thunk::EnterResourceCreation enter(instance); - if (enter.succeeded()) { - result_resource->SetHostResource( - instance, - enter.functions()->CreateBroker(instance)); - } + result_resource->SetHostResource( + instance, + ppb_broker_target()->CreateTrusted(instance)); } void PPB_Broker_Proxy::OnMsgConnect(const HostResource& broker) { @@ -226,9 +240,8 @@ void PPB_Broker_Proxy::ConnectCompleteInHost(int32_t result, IPC::InvalidPlatformFileForTransit(); if (result == PP_OK) { int32_t socket_handle = PlatformFileToInt(base::kInvalidPlatformFileValue); - EnterHostFromHostResource<PPB_Broker_API> enter(broker); - if (enter.succeeded()) - result = enter.object()->GetHandle(&socket_handle); + result = ppb_broker_target()->GetHandle(broker.host_resource(), + &socket_handle); DCHECK(result == PP_OK || socket_handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); diff --git a/ppapi/proxy/ppb_broker_proxy.h b/ppapi/proxy/ppb_broker_proxy.h index 54ff9de..e8c34e2 100644 --- a/ppapi/proxy/ppb_broker_proxy.h +++ b/ppapi/proxy/ppb_broker_proxy.h @@ -22,16 +22,20 @@ namespace proxy { class PPB_Broker_Proxy : public InterfaceProxy { public: - PPB_Broker_Proxy(Dispatcher* dispatcher); + PPB_Broker_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Broker_Proxy(); + static const Info* GetInfo(); + static PP_Resource CreateProxyResource(PP_Instance instance); + const PPB_BrokerTrusted* ppb_broker_target() const { + return static_cast<const PPB_BrokerTrusted*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_BROKER; - private: // Message handlers. void OnMsgCreate(PP_Instance instance, ppapi::HostResource* result_resource); diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc index 957108a..d9092fe 100644 --- a/ppapi/proxy/ppb_buffer_proxy.cc +++ b/ppapi/proxy/ppb_buffer_proxy.cc @@ -17,12 +17,20 @@ #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_buffer_trusted_api.h" -#include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" namespace ppapi { namespace proxy { +namespace { + +InterfaceProxy* CreateBufferProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Buffer_Proxy(dispatcher, target_interface); +} + +} // namespace + Buffer::Buffer(const HostResource& resource, const base::SharedMemoryHandle& shm_handle, uint32_t size) @@ -61,14 +69,27 @@ void Buffer::Unmap() { shm_.Unmap(); } -PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Buffer_Proxy::~PPB_Buffer_Proxy() { } // static +const InterfaceProxy::Info* PPB_Buffer_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_Buffer_Thunk(), + PPB_BUFFER_DEV_INTERFACE, + INTERFACE_ID_PPB_BUFFER, + false, + &CreateBufferProxy, + }; + return &info; +} + +// static PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, uint32_t size) { PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); @@ -114,15 +135,10 @@ void PPB_Buffer_Proxy::OnMsgCreate( HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); if (!dispatcher) return; - - thunk::EnterResourceCreation enter(instance); - if (enter.failed()) - return; - PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance, - size); + PP_Resource local_buffer_resource = + ppb_buffer_target()->Create(instance, size); if (local_buffer_resource == 0) return; - thunk::EnterResourceNoLock<thunk::PPB_BufferTrusted_API> trusted_buffer( local_buffer_resource, false); if (trusted_buffer.failed()) diff --git a/ppapi/proxy/ppb_buffer_proxy.h b/ppapi/proxy/ppb_buffer_proxy.h index 4105dcc..2c0b875 100644 --- a/ppapi/proxy/ppb_buffer_proxy.h +++ b/ppapi/proxy/ppb_buffer_proxy.h @@ -46,20 +46,24 @@ class Buffer : public thunk::PPB_Buffer_API, public Resource { class PPB_Buffer_Proxy : public InterfaceProxy { public: - PPB_Buffer_Proxy(Dispatcher* dispatcher); + PPB_Buffer_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Buffer_Proxy(); + static const Info* GetInfo(); + static PP_Resource CreateProxyResource(PP_Instance instance, uint32_t size); static PP_Resource AddProxyResource(const HostResource& resource, base::SharedMemoryHandle shm_handle, uint32_t size); + const PPB_Buffer_Dev* ppb_buffer_target() const { + return static_cast<const PPB_Buffer_Dev*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_BUFFER; - private: // Message handlers. void OnMsgCreate(PP_Instance instance, diff --git a/ppapi/proxy/ppb_char_set_proxy.cc b/ppapi/proxy/ppb_char_set_proxy.cc index 52610f3..f23626f 100644 --- a/ppapi/proxy/ppb_char_set_proxy.cc +++ b/ppapi/proxy/ppb_char_set_proxy.cc @@ -9,7 +9,6 @@ #include "ppapi/c/dev/ppb_memory_dev.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/ppb_memory_proxy.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/shared_impl/char_set_impl.h" #include "ppapi/thunk/enter.h" @@ -18,13 +17,40 @@ namespace ppapi { namespace proxy { -PPB_CharSet_Proxy::PPB_CharSet_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +namespace { + +const PPB_Memory_Dev* GetMemoryDevInterface() { + return static_cast<const PPB_Memory_Dev*>( + PluginDispatcher::GetInterfaceFromDispatcher(PPB_MEMORY_DEV_INTERFACE)); +} + +InterfaceProxy* CreateCharSetProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_CharSet_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPB_CharSet_Proxy::PPB_CharSet_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_CharSet_Proxy::~PPB_CharSet_Proxy() { } +// static +const InterfaceProxy::Info* PPB_CharSet_Proxy::GetInfo() { + static const Info info = { + ppapi::thunk::GetPPB_CharSet_Thunk(), + PPB_CHAR_SET_DEV_INTERFACE, + INTERFACE_ID_PPB_CHAR_SET, + false, + &CreateCharSetProxy, + }; + return &info; +} + ppapi::thunk::PPB_CharSet_FunctionAPI* PPB_CharSet_Proxy::AsPPB_CharSet_FunctionAPI() { return this; @@ -37,8 +63,8 @@ char* PPB_CharSet_Proxy::UTF16ToCharSet( PP_CharSet_ConversionError on_error, uint32_t* output_length) { return ppapi::CharSetImpl::UTF16ToCharSet( - GetPPB_Memory_Interface(), utf16, utf16_len, - output_char_set, on_error, output_length); + GetMemoryDevInterface(), utf16, utf16_len, output_char_set, on_error, + output_length); } uint16_t* PPB_CharSet_Proxy::CharSetToUTF16( @@ -48,8 +74,8 @@ uint16_t* PPB_CharSet_Proxy::CharSetToUTF16( PP_CharSet_ConversionError on_error, uint32_t* output_length) { return ppapi::CharSetImpl::CharSetToUTF16( - GetPPB_Memory_Interface(), input, input_len, - input_char_set, on_error, output_length); + GetMemoryDevInterface(), input, input_len, input_char_set, on_error, + output_length); } PP_Var PPB_CharSet_Proxy::GetDefaultCharSet(PP_Instance instance) { diff --git a/ppapi/proxy/ppb_char_set_proxy.h b/ppapi/proxy/ppb_char_set_proxy.h index 39ddc7b..af5cdc0 100644 --- a/ppapi/proxy/ppb_char_set_proxy.h +++ b/ppapi/proxy/ppb_char_set_proxy.h @@ -19,12 +19,15 @@ namespace proxy { class SerializedVarReturnValue; -class PPB_CharSet_Proxy : public InterfaceProxy, - public ppapi::thunk::PPB_CharSet_FunctionAPI { +class PPB_CharSet_Proxy : public ppapi::FunctionGroupBase, + public ppapi::thunk::PPB_CharSet_FunctionAPI, + public InterfaceProxy { public: - PPB_CharSet_Proxy(Dispatcher* dispatcher); + PPB_CharSet_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_CharSet_Proxy(); + static const Info* GetInfo(); + // FunctionGroupBase overrides. virtual ppapi::thunk::PPB_CharSet_FunctionAPI* AsPPB_CharSet_FunctionAPI() OVERRIDE; @@ -45,8 +48,6 @@ class PPB_CharSet_Proxy : public InterfaceProxy, // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_CHAR_SET; - private: void OnMsgGetDefaultCharSet(PP_Instance instance, SerializedVarReturnValue result); diff --git a/ppapi/proxy/ppb_console_proxy.cc b/ppapi/proxy/ppb_console_proxy.cc new file mode 100644 index 0000000..3745a77 --- /dev/null +++ b/ppapi/proxy/ppb_console_proxy.cc @@ -0,0 +1,103 @@ +// 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/proxy/ppb_console_proxy.h" + +#include "ppapi/c/dev/ppb_console_dev.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/ppapi_messages.h" + +namespace ppapi { +namespace proxy { + +namespace { + +void Log(PP_Instance instance, PP_LogLevel_Dev level, PP_Var value) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return; + dispatcher->Send(new PpapiHostMsg_PPBConsole_Log( + INTERFACE_ID_PPB_CONSOLE, instance, static_cast<int>(level), + SerializedVarSendInput(dispatcher, value))); +} + +void LogWithSource(PP_Instance instance, + PP_LogLevel_Dev level, + const PP_Var source, + const PP_Var value) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return; + dispatcher->Send(new PpapiHostMsg_PPBConsole_LogWithSource( + INTERFACE_ID_PPB_CONSOLE, instance, static_cast<int>(level), + SerializedVarSendInput(dispatcher, source), + SerializedVarSendInput(dispatcher, value))); +} + +const PPB_Console_Dev console_interface = { + &Log, + &LogWithSource +}; + +InterfaceProxy* CreateConsoleProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Console_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPB_Console_Proxy::PPB_Console_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_Console_Proxy::~PPB_Console_Proxy() { +} + +// static +const InterfaceProxy::Info* PPB_Console_Proxy::GetInfo() { + static const Info info = { + &console_interface, + PPB_CONSOLE_DEV_INTERFACE, + INTERFACE_ID_PPB_CONSOLE, + false, + &CreateConsoleProxy, + }; + return &info; +} + +bool PPB_Console_Proxy::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(PPB_Console_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBConsole_Log, + OnMsgLog) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBConsole_LogWithSource, + OnMsgLogWithSource) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void PPB_Console_Proxy::OnMsgLog(PP_Instance instance, + int log_level, + SerializedVarReceiveInput value) { + ppb_console_target()->Log(instance, + static_cast<PP_LogLevel_Dev>(log_level), + value.Get(dispatcher())); +} + +void PPB_Console_Proxy::OnMsgLogWithSource(PP_Instance instance, + int log_level, + SerializedVarReceiveInput source, + SerializedVarReceiveInput value) { + ppb_console_target()->LogWithSource( + instance, + static_cast<PP_LogLevel_Dev>(log_level), + source.Get(dispatcher()), + value.Get(dispatcher())); +} + +} // namespace proxy +} // namespace ppapi + diff --git a/ppapi/proxy/ppb_console_proxy.h b/ppapi/proxy/ppb_console_proxy.h new file mode 100644 index 0000000..33c1d2b --- /dev/null +++ b/ppapi/proxy/ppb_console_proxy.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_PROXY_PPB_CONSOLE_PROXY_H_ +#define PPAPI_PROXY_PPB_CONSOLE_PROXY_H_ + +#include "base/basictypes.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/proxy/interface_proxy.h" +#include "ppapi/proxy/serialized_var.h" + +struct PPB_Console_Dev; + +namespace ppapi { +namespace proxy { + +class PPB_Console_Proxy : public InterfaceProxy { + public: + PPB_Console_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_Console_Proxy(); + + static const Info* GetInfo(); + + const PPB_Console_Dev* ppb_console_target() const { + return static_cast<const PPB_Console_Dev*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg); + + private: + // Message handlers. + void OnMsgLog(PP_Instance instance, + int log_level, + SerializedVarReceiveInput value); + void OnMsgLogWithSource(PP_Instance instance, + int log_level, + SerializedVarReceiveInput source, + SerializedVarReceiveInput value); + + DISALLOW_COPY_AND_ASSIGN(PPB_Console_Proxy); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PPB_CONSOLE_PROXY_H_ diff --git a/ppapi/proxy/ppb_context_3d_proxy.cc b/ppapi/proxy/ppb_context_3d_proxy.cc index 460c922..26ad740 100644 --- a/ppapi/proxy/ppb_context_3d_proxy.cc +++ b/ppapi/proxy/ppb_context_3d_proxy.cc @@ -68,6 +68,11 @@ gpu::CommandBuffer::State GPUStateFromPPState( const int32 kCommandBufferSize = 1024 * 1024; const int32 kTransferBufferSize = 1024 * 1024; +InterfaceProxy* CreateContext3DProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Context3D_Proxy(dispatcher, target_interface); +} + } // namespace class PepperCommandBuffer : public gpu::CommandBuffer { @@ -516,14 +521,39 @@ gpu::gles2::GLES2Implementation* Context3D::GetGLES2Impl() { // PPB_Context3D_Proxy --------------------------------------------------------- -PPB_Context3D_Proxy::PPB_Context3D_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +PPB_Context3D_Proxy::PPB_Context3D_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Context3D_Proxy::~PPB_Context3D_Proxy() { } // static +const InterfaceProxy::Info* PPB_Context3D_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_Context3D_Thunk(), + PPB_CONTEXT_3D_DEV_INTERFACE, + INTERFACE_ID_PPB_CONTEXT_3D, + false, + &CreateContext3DProxy, + }; + return &info; +} + +// static +const InterfaceProxy::Info* PPB_Context3D_Proxy::GetTextureMappingInfo() { + static const Info info = { + thunk::GetPPB_GLESChromiumTextureMapping_Thunk(), + PPB_GLES_CHROMIUM_TEXTURE_MAPPING_DEV_INTERFACE, + INTERFACE_ID_NONE, // CONTEXT_3D is the canonical one. + false, + &CreateContext3DProxy, + }; + return &info; +} + +// static PP_Resource PPB_Context3D_Proxy::Create(PP_Instance instance, PP_Config3D_Dev config, PP_Resource share_context, @@ -591,7 +621,7 @@ void PPB_Context3D_Proxy::OnMsgCreate(PP_Instance instance, HostResource* result) { if (attribs.empty() || attribs.back() != 0) return; // Bad message. - thunk::EnterResourceCreation enter(instance); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); if (enter.succeeded()) { result->SetHostResource( instance, diff --git a/ppapi/proxy/ppb_context_3d_proxy.h b/ppapi/proxy/ppb_context_3d_proxy.h index 9670f3a..a24a78d 100644 --- a/ppapi/proxy/ppb_context_3d_proxy.h +++ b/ppapi/proxy/ppb_context_3d_proxy.h @@ -94,9 +94,12 @@ class Context3D : public Resource, public thunk::PPB_Context3D_API { class PPB_Context3D_Proxy : public InterfaceProxy { public: - PPB_Context3D_Proxy(Dispatcher* dispatcher); + PPB_Context3D_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Context3D_Proxy(); + static const Info* GetInfo(); + static const Info* GetTextureMappingInfo(); + static PP_Resource Create(PP_Instance instance, PP_Config3D_Dev config, PP_Resource share_context, @@ -105,8 +108,6 @@ class PPB_Context3D_Proxy : public InterfaceProxy { // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_CONTEXT_3D; - private: void OnMsgCreate(PP_Instance instance, PP_Config3D_Dev config, diff --git a/ppapi/proxy/ppb_core_proxy.cc b/ppapi/proxy/ppb_core_proxy.cc index d3d17c0..83eea37 100644 --- a/ppapi/proxy/ppb_core_proxy.cc +++ b/ppapi/proxy/ppb_core_proxy.cc @@ -75,23 +75,31 @@ const PPB_Core core_interface = { &IsMainThread }; +InterfaceProxy* CreateCoreProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Core_Proxy(dispatcher, target_interface); +} + } // namespace -PPB_Core_Proxy::PPB_Core_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_core_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_core_impl_ = static_cast<const PPB_Core*>( - dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); - } +PPB_Core_Proxy::PPB_Core_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Core_Proxy::~PPB_Core_Proxy() { } // static -const PPB_Core* PPB_Core_Proxy::GetPPB_Core_Interface() { - return &core_interface; +const InterfaceProxy::Info* PPB_Core_Proxy::GetInfo() { + static const Info info = { + &core_interface, + PPB_CORE_INTERFACE, + INTERFACE_ID_PPB_CORE, + false, + &CreateCoreProxy, + }; + return &info; } bool PPB_Core_Proxy::OnMessageReceived(const IPC::Message& msg) { @@ -108,11 +116,11 @@ bool PPB_Core_Proxy::OnMessageReceived(const IPC::Message& msg) { } void PPB_Core_Proxy::OnMsgAddRefResource(const HostResource& resource) { - ppb_core_impl_->AddRefResource(resource.host_resource()); + ppb_core_target()->AddRefResource(resource.host_resource()); } void PPB_Core_Proxy::OnMsgReleaseResource(const HostResource& resource) { - ppb_core_impl_->ReleaseResource(resource.host_resource()); + ppb_core_target()->ReleaseResource(resource.host_resource()); } } // namespace proxy diff --git a/ppapi/proxy/ppb_core_proxy.h b/ppapi/proxy/ppb_core_proxy.h index 950e5e8..1963e71 100644 --- a/ppapi/proxy/ppb_core_proxy.h +++ b/ppapi/proxy/ppb_core_proxy.h @@ -8,7 +8,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_var.h" -#include "ppapi/c/ppb_core.h" #include "ppapi/proxy/interface_proxy.h" #include "ppapi/shared_impl/host_resource.h" @@ -19,25 +18,22 @@ namespace proxy { class PPB_Core_Proxy : public InterfaceProxy { public: - PPB_Core_Proxy(Dispatcher* dispatcher); + PPB_Core_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Core_Proxy(); - static const PPB_Core* GetPPB_Core_Interface(); + static const Info* GetInfo(); + + const PPB_Core* ppb_core_target() const { + return reinterpret_cast<const PPB_Core*>(target_interface()); + } // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_CORE; - private: // Message handlers. void OnMsgAddRefResource(const ppapi::HostResource& resource); void OnMsgReleaseResource(const ppapi::HostResource& resource); - - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_Core* ppb_core_impl_; }; } // namespace proxy diff --git a/ppapi/proxy/ppb_crypto_proxy.cc b/ppapi/proxy/ppb_crypto_proxy.cc index e80e17a..c534864 100644 --- a/ppapi/proxy/ppb_crypto_proxy.cc +++ b/ppapi/proxy/ppb_crypto_proxy.cc @@ -17,14 +17,16 @@ const PPB_Crypto_Dev crypto_interface = { &ppapi::CryptoImpl::GetRandomBytes }; -InterfaceProxy* CreateCryptoProxy(Dispatcher* dispatcher) { - return new PPB_Crypto_Proxy(dispatcher); +InterfaceProxy* CreateCryptoProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Crypto_Proxy(dispatcher, target_interface); } } // namespace -PPB_Crypto_Proxy::PPB_Crypto_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +PPB_Crypto_Proxy::PPB_Crypto_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { NOTREACHED(); // See comment in the header file. } diff --git a/ppapi/proxy/ppb_crypto_proxy.h b/ppapi/proxy/ppb_crypto_proxy.h index 8e343a8..3ad77c9 100644 --- a/ppapi/proxy/ppb_crypto_proxy.h +++ b/ppapi/proxy/ppb_crypto_proxy.h @@ -16,7 +16,7 @@ class PPB_Crypto_Proxy : public InterfaceProxy { // function that's implemented entirely within the plugin. However, we need // to support this so the machinery for automatically handling interfaces // works. As a result, this constructor will assert if it's actually used. - PPB_Crypto_Proxy(Dispatcher* dispatcher); + PPB_Crypto_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Crypto_Proxy(); static const Info* GetInfo(); diff --git a/ppapi/proxy/ppb_cursor_control_proxy.cc b/ppapi/proxy/ppb_cursor_control_proxy.cc index a0b0ee8..5366ea0 100644 --- a/ppapi/proxy/ppb_cursor_control_proxy.cc +++ b/ppapi/proxy/ppb_cursor_control_proxy.cc @@ -18,13 +18,35 @@ using ppapi::thunk::PPB_CursorControl_FunctionAPI; namespace ppapi { namespace proxy { -PPB_CursorControl_Proxy::PPB_CursorControl_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +namespace { + +InterfaceProxy* CreateCursorControlProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_CursorControl_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPB_CursorControl_Proxy::PPB_CursorControl_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_CursorControl_Proxy::~PPB_CursorControl_Proxy() { } +// static +const InterfaceProxy::Info* PPB_CursorControl_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_CursorControl_Thunk(), + PPB_CURSOR_CONTROL_DEV_INTERFACE, + INTERFACE_ID_PPB_CURSORCONTROL, + false, + &CreateCursorControlProxy, + }; + return &info; +} + ppapi::thunk::PPB_CursorControl_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 6c42c9b..027dbfe 100644 --- a/ppapi/proxy/ppb_cursor_control_proxy.h +++ b/ppapi/proxy/ppb_cursor_control_proxy.h @@ -21,12 +21,15 @@ namespace ppapi { namespace proxy { class PPB_CursorControl_Proxy - : public InterfaceProxy, - public ppapi::thunk::PPB_CursorControl_FunctionAPI { + : public ppapi::FunctionGroupBase, + public ppapi::thunk::PPB_CursorControl_FunctionAPI, + public InterfaceProxy { public: - PPB_CursorControl_Proxy(Dispatcher* dispatcher); + PPB_CursorControl_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_CursorControl_Proxy(); + static const Info* GetInfo(); + // FunctionGroupBase overrides. ppapi::thunk::PPB_CursorControl_FunctionAPI* AsPPB_CursorControl_FunctionAPI() OVERRIDE; @@ -44,8 +47,6 @@ class PPB_CursorControl_Proxy // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_CURSORCONTROL; - private: // Message handlers. void OnMsgSetCursor(PP_Instance instance, diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc index 73f7a6a..f13ea86 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -16,7 +16,6 @@ #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/shared_impl/var.h" -#include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" using ppapi::thunk::PPB_FileChooser_API; @@ -119,14 +118,77 @@ void FileChooser::ChooseComplete( // DANGER: May delete |this|! } -PPB_FileChooser_Proxy::PPB_FileChooser_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +namespace { + +PP_Resource Create0_4(PP_Instance instance, + const PP_FileChooserOptions_0_4_Dev* options) { + PP_Var accept_var = PP_MakeUndefined(); + if (options->accept_mime_types) + accept_var = StringVar::StringToPPVar(0, options->accept_mime_types); + PP_Resource result = thunk::GetPPB_FileChooser_Thunk()->Create( + instance, options->mode, accept_var); + if (accept_var.type == PP_VARTYPE_STRING) + PluginResourceTracker::GetInstance()->var_tracker().ReleaseVar(accept_var); + return result; +} + +PP_Bool IsFileChooser0_4(PP_Resource resource) { + return thunk::GetPPB_FileChooser_Thunk()->IsFileChooser(resource); +} + +int32_t Show0_4(PP_Resource chooser, PP_CompletionCallback callback) { + return thunk::GetPPB_FileChooser_Thunk()->Show(chooser, callback); +} + +PP_Resource GetNextChosenFile0_4(PP_Resource chooser) { + return thunk::GetPPB_FileChooser_Thunk()->GetNextChosenFile(chooser); +} + +PPB_FileChooser_0_4_Dev file_chooser_0_4_interface = { + &Create0_4, + &IsFileChooser0_4, + &Show0_4, + &GetNextChosenFile0_4 +}; + +InterfaceProxy* CreateFileChooserProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_FileChooser_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPB_FileChooser_Proxy::PPB_FileChooser_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() { } +const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_FileChooser_Thunk(), + PPB_FILECHOOSER_DEV_INTERFACE, + INTERFACE_ID_PPB_FILE_CHOOSER, + false, + &CreateFileChooserProxy, + }; + return &info; +} + +const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo0_4() { + static const Info info = { + &file_chooser_0_4_interface, + PPB_FILECHOOSER_DEV_INTERFACE_0_4, + INTERFACE_ID_NONE, + false, + &CreateFileChooserProxy, + }; + return &info; +} + // static PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( PP_Instance instance, @@ -167,12 +229,9 @@ void PPB_FileChooser_Proxy::OnMsgCreate( int mode, SerializedVarReceiveInput accept_mime_types, HostResource* result) { - thunk::EnterResourceCreation enter(instance); - if (enter.succeeded()) { - result->SetHostResource(instance, enter.functions()->CreateFileChooser( - instance, static_cast<PP_FileChooserMode_Dev>(mode), - accept_mime_types.Get(dispatcher()))); - } + result->SetHostResource(instance, ppb_file_chooser_target()->Create( + instance, static_cast<PP_FileChooserMode_Dev>(mode), + accept_mime_types.Get(dispatcher()))); } void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) { @@ -196,16 +255,19 @@ void PPB_FileChooser_Proxy::OnMsgChooseComplete( void PPB_FileChooser_Proxy::OnShowCallback(int32_t result, const HostResource& chooser) { - EnterHostFromHostResource<PPB_FileChooser_API> enter(chooser); - std::vector<PPB_FileRef_CreateInfo> files; - if (enter.succeeded() && result == PP_OK) { + if (result == PP_OK) { + // Jump through some hoops to get the FileRef proxy. Since we know we're + // in the host at this point, we can ask the host dispatcher for it. + DCHECK(!dispatcher()->IsPlugin()); + HostDispatcher* host_disp = static_cast<HostDispatcher*>(dispatcher()); PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>( - dispatcher()->GetInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); + host_disp->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); // Convert the returned files to the serialized info. while (PP_Resource cur_file_resource = - enter.object()->GetNextChosenFile()) { + ppb_file_chooser_target()->GetNextChosenFile( + chooser.host_resource())) { PPB_FileRef_CreateInfo cur_create_info; file_ref_proxy->SerializeFileRef(cur_file_resource, &cur_create_info); files.push_back(cur_create_info); diff --git a/ppapi/proxy/ppb_file_chooser_proxy.h b/ppapi/proxy/ppb_file_chooser_proxy.h index f1dcd95..4f3bc84 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.h +++ b/ppapi/proxy/ppb_file_chooser_proxy.h @@ -28,19 +28,24 @@ class SerializedVarReceiveInput; class PPB_FileChooser_Proxy : public InterfaceProxy { public: - PPB_FileChooser_Proxy(Dispatcher* dispatcher); + PPB_FileChooser_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_FileChooser_Proxy(); + static const Info* GetInfo(); + static const Info* GetInfo0_4(); + static PP_Resource CreateProxyResource( PP_Instance instance, PP_FileChooserMode_Dev mode, const PP_Var& accept_mime_types); + const PPB_FileChooser_Dev* ppb_file_chooser_target() const { + return static_cast<const PPB_FileChooser_Dev*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_FILE_CHOOSER; - private: // Plugin -> host message handlers. void OnMsgCreate(PP_Instance instance, diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc index 49a1131..0cf26bd 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.cc +++ b/ppapi/proxy/ppb_file_ref_proxy.cc @@ -24,6 +24,15 @@ using ppapi::thunk::ResourceCreationAPI; namespace ppapi { namespace proxy { +namespace { + +InterfaceProxy* CreateFileRefProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_FileRef_Proxy(dispatcher, target_interface); +} + +} // namespace + class FileRef : public FileRefImpl { public: explicit FileRef(const PPB_FileRef_CreateInfo& info); @@ -102,13 +111,25 @@ int32_t FileRef::Rename(PP_Resource new_file_ref, return PP_OK_COMPLETIONPENDING; } -PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { } +const InterfaceProxy::Info* PPB_FileRef_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_FileRef_Thunk(), + PPB_FILEREF_INTERFACE, + INTERFACE_ID_PPB_FILE_REF, + false, + &CreateFileRefProxy, + }; + return &info; +} + // static PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Resource file_system, const char* path) { @@ -158,7 +179,7 @@ PP_Resource PPB_FileRef_Proxy::DeserializeFileRef( void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system, const std::string& path, PPB_FileRef_CreateInfo* result) { - thunk::EnterResourceCreation enter(file_system.instance()); + EnterFunctionNoLock<ResourceCreationAPI> enter(file_system.instance(), true); if (enter.failed()) return; PP_Resource resource = enter.functions()->CreateFileRef( diff --git a/ppapi/proxy/ppb_file_ref_proxy.h b/ppapi/proxy/ppb_file_ref_proxy.h index 6133c1a..1241343 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.h +++ b/ppapi/proxy/ppb_file_ref_proxy.h @@ -24,9 +24,11 @@ namespace proxy { class PPB_FileRef_Proxy : public InterfaceProxy { public: - PPB_FileRef_Proxy(Dispatcher* dispatcher); + PPB_FileRef_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_FileRef_Proxy(); + static const Info* GetInfo(); + static PP_Resource CreateProxyResource(PP_Resource file_system, const char* path); @@ -55,8 +57,6 @@ class PPB_FileRef_Proxy : public InterfaceProxy { static PP_Resource DeserializeFileRef( const PPB_FileRef_CreateInfo& serialized); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_FILE_REF; - private: // Message handlers. void OnMsgCreate(const ppapi::HostResource& file_system, diff --git a/ppapi/proxy/ppb_file_system_proxy.cc b/ppapi/proxy/ppb_file_system_proxy.cc index 8fc7b55..899c51f 100644 --- a/ppapi/proxy/ppb_file_system_proxy.cc +++ b/ppapi/proxy/ppb_file_system_proxy.cc @@ -27,8 +27,9 @@ namespace proxy { namespace { -InterfaceProxy* CreateFileSystemProxy(Dispatcher* dispatcher) { - return new PPB_FileSystem_Proxy(dispatcher); +InterfaceProxy* CreateFileSystemProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_FileSystem_Proxy(dispatcher, target_interface); } } // namespace @@ -109,8 +110,9 @@ void FileSystem::OpenComplete(int32_t result) { PP_RunAndClearCompletionCallback(¤t_open_callback_, result); } -PPB_FileSystem_Proxy::PPB_FileSystem_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +PPB_FileSystem_Proxy::PPB_FileSystem_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } @@ -158,7 +160,7 @@ bool PPB_FileSystem_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_FileSystem_Proxy::OnMsgCreate(PP_Instance instance, int type, HostResource* result) { - thunk::EnterResourceCreation enter(instance); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); if (enter.failed()) return; PP_Resource resource = enter.functions()->CreateFileSystem( diff --git a/ppapi/proxy/ppb_file_system_proxy.h b/ppapi/proxy/ppb_file_system_proxy.h index 5573cce..b83fb992 100644 --- a/ppapi/proxy/ppb_file_system_proxy.h +++ b/ppapi/proxy/ppb_file_system_proxy.h @@ -26,7 +26,7 @@ namespace proxy { class PPB_FileSystem_Proxy : public InterfaceProxy { public: - PPB_FileSystem_Proxy(Dispatcher* dispatcher); + PPB_FileSystem_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_FileSystem_Proxy(); static const Info* GetInfo(); @@ -37,8 +37,6 @@ class PPB_FileSystem_Proxy : public InterfaceProxy { // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_FILE_SYSTEM; - private: // Message handlers. void OnMsgCreate(PP_Instance instance, diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.cc b/ppapi/proxy/ppb_flash_clipboard_proxy.cc index 18918fc..38e3e5b 100644 --- a/ppapi/proxy/ppb_flash_clipboard_proxy.cc +++ b/ppapi/proxy/ppb_flash_clipboard_proxy.cc @@ -88,19 +88,16 @@ const PPB_Flash_Clipboard flash_clipboard_interface = { &WritePlainText }; -InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher) { - return new PPB_Flash_Clipboard_Proxy(dispatcher); +InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Flash_Clipboard_Proxy(dispatcher, target_interface); } } // namespace -PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_flash_clipboard_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_flash_clipboard_impl_ = static_cast<const PPB_Flash_Clipboard*>( - dispatcher->local_get_interface()(PPB_FLASH_CLIPBOARD_INTERFACE)); - } +PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy( + Dispatcher* dispatcher, const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() { @@ -137,7 +134,7 @@ void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( int clipboard_type, int format, bool* result) { - *result = PP_ToBool(ppb_flash_clipboard_impl_->IsFormatAvailable( + *result = PP_ToBool(ppb_flash_clipboard_target()->IsFormatAvailable( instance_id, static_cast<PP_Flash_Clipboard_Type>(clipboard_type), static_cast<PP_Flash_Clipboard_Format>(format))); @@ -148,7 +145,7 @@ void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( int clipboard_type, SerializedVarReturnValue result) { result.Return(dispatcher(), - ppb_flash_clipboard_impl_->ReadPlainText( + ppb_flash_clipboard_target()->ReadPlainText( instance_id, static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); } @@ -157,7 +154,7 @@ void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( PP_Instance instance_id, int clipboard_type, SerializedVarReceiveInput text) { - int32_t result = ppb_flash_clipboard_impl_->WritePlainText( + int32_t result = ppb_flash_clipboard_target()->WritePlainText( instance_id, static_cast<PP_Flash_Clipboard_Type>(clipboard_type), text.Get(dispatcher())); diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.h b/ppapi/proxy/ppb_flash_clipboard_proxy.h index 8d7a7b5..e0a1acf 100644 --- a/ppapi/proxy/ppb_flash_clipboard_proxy.h +++ b/ppapi/proxy/ppb_flash_clipboard_proxy.h @@ -18,11 +18,16 @@ class SerializedVarReturnValue; class PPB_Flash_Clipboard_Proxy : public InterfaceProxy { public: - PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher); + PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher, + const void* target_interface); virtual ~PPB_Flash_Clipboard_Proxy(); static const Info* GetInfo(); + const PPB_Flash_Clipboard* ppb_flash_clipboard_target() const { + return reinterpret_cast<const PPB_Flash_Clipboard*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -38,11 +43,6 @@ class PPB_Flash_Clipboard_Proxy : public InterfaceProxy { void OnMsgWritePlainText(PP_Instance instance_id, int clipboard_type, SerializedVarReceiveInput text); - - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_Flash_Clipboard* ppb_flash_clipboard_impl_; }; } // namespace proxy diff --git a/ppapi/proxy/ppb_flash_file_proxy.cc b/ppapi/proxy/ppb_flash_file_proxy.cc index 5f7ef23..138f990 100644 --- a/ppapi/proxy/ppb_flash_file_proxy.cc +++ b/ppapi/proxy/ppb_flash_file_proxy.cc @@ -501,22 +501,17 @@ const PPB_Flash_File_ModuleLocal flash_file_modulelocal_interface = { &FreeDirContents, }; -InterfaceProxy* CreateFlashFileModuleLocalProxy(Dispatcher* dispatcher) { - return new PPB_Flash_File_ModuleLocal_Proxy(dispatcher); +InterfaceProxy* CreateFlashFileModuleLocalProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Flash_File_ModuleLocal_Proxy(dispatcher, target_interface); } } // namespace PPB_Flash_File_ModuleLocal_Proxy::PPB_Flash_File_ModuleLocal_Proxy( - Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_flash_file_module_local_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_flash_file_module_local_impl_ = - static_cast<const PPB_Flash_File_ModuleLocal*>( - dispatcher->local_get_interface()( - PPB_FLASH_FILE_MODULELOCAL_INTERFACE)); - } + Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Flash_File_ModuleLocal_Proxy::~PPB_Flash_File_ModuleLocal_Proxy() { @@ -563,8 +558,8 @@ void PPB_Flash_File_ModuleLocal_Proxy::OnMsgOpenFile( IPC::PlatformFileForTransit* file_handle, int32_t* result) { base::PlatformFile file; - *result = ppb_flash_file_module_local_impl_->OpenFile( - instance, path.c_str(), mode, &file); + *result = ppb_flash_file_module_local_target()-> + OpenFile(instance, path.c_str(), mode, &file); *file_handle = PlatformFileToPlatformFileForTransit( dispatcher(), result, file); } @@ -574,8 +569,8 @@ void PPB_Flash_File_ModuleLocal_Proxy::OnMsgRenameFile( const std::string& from_path, const std::string& to_path, int32_t* result) { - *result = ppb_flash_file_module_local_impl_->RenameFile( - instance, from_path.c_str(), to_path.c_str()); + *result = ppb_flash_file_module_local_target()-> + RenameFile(instance, from_path.c_str(), to_path.c_str()); } void PPB_Flash_File_ModuleLocal_Proxy::OnMsgDeleteFileOrDir( @@ -583,23 +578,23 @@ void PPB_Flash_File_ModuleLocal_Proxy::OnMsgDeleteFileOrDir( const std::string& path, PP_Bool recursive, int32_t* result) { - *result = ppb_flash_file_module_local_impl_->DeleteFileOrDir( - instance, path.c_str(), recursive); + *result = ppb_flash_file_module_local_target()-> + DeleteFileOrDir(instance, path.c_str(), recursive); } void PPB_Flash_File_ModuleLocal_Proxy::OnMsgCreateDir(PP_Instance instance, const std::string& path, int32_t* result) { - *result = ppb_flash_file_module_local_impl_->CreateDir( - instance, path.c_str()); + *result = ppb_flash_file_module_local_target()-> + CreateDir(instance, path.c_str()); } void PPB_Flash_File_ModuleLocal_Proxy::OnMsgQueryFile(PP_Instance instance, const std::string& path, PP_FileInfo* info, int32_t* result) { - *result = ppb_flash_file_module_local_impl_->QueryFile( - instance, path.c_str(), info); + *result = ppb_flash_file_module_local_target()-> + QueryFile(instance, path.c_str(), info); } void PPB_Flash_File_ModuleLocal_Proxy::OnMsgGetDirContents( @@ -608,8 +603,8 @@ void PPB_Flash_File_ModuleLocal_Proxy::OnMsgGetDirContents( std::vector<SerializedDirEntry>* entries, int32_t* result) { PP_DirContents_Dev* contents = NULL; - *result = ppb_flash_file_module_local_impl_->GetDirContents( - instance, path.c_str(), &contents); + *result = ppb_flash_file_module_local_target()-> + GetDirContents(instance, path.c_str(), &contents); if (*result != PP_OK) return; @@ -619,7 +614,7 @@ void PPB_Flash_File_ModuleLocal_Proxy::OnMsgGetDirContents( (*entries)[i].name.assign(contents->entries[i].name); (*entries)[i].is_dir = PP_ToBool(contents->entries[i].is_dir); } - ppb_flash_file_module_local_impl_->FreeDirContents(instance, contents); + ppb_flash_file_module_local_target()->FreeDirContents(instance, contents); } // PPB_Flash_File_FileRef ------------------------------------------------------ @@ -670,20 +665,17 @@ const PPB_Flash_File_FileRef flash_file_fileref_interface = { &QueryFileRefFile, }; -InterfaceProxy* CreateFlashFileFileRefProxy(Dispatcher* dispatcher) { - return new PPB_Flash_File_FileRef_Proxy(dispatcher); +InterfaceProxy* CreateFlashFileFileRefProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Flash_File_FileRef_Proxy(dispatcher, target_interface); } } // namespace PPB_Flash_File_FileRef_Proxy::PPB_Flash_File_FileRef_Proxy( - Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_flash_file_fileref_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_flash_file_fileref_impl_ = static_cast<const PPB_Flash_File_FileRef*>( - dispatcher->local_get_interface()(PPB_FLASH_FILE_FILEREF_INTERFACE)); - } + Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Flash_File_FileRef_Proxy::~PPB_Flash_File_FileRef_Proxy() { @@ -721,8 +713,8 @@ void PPB_Flash_File_FileRef_Proxy::OnMsgOpenFile( IPC::PlatformFileForTransit* file_handle, int32_t* result) { base::PlatformFile file; - *result = ppb_flash_file_fileref_impl_->OpenFile( - host_resource.host_resource(), mode, &file); + *result = ppb_flash_file_module_local_target()-> + OpenFile(host_resource.host_resource(), mode, &file); *file_handle = PlatformFileToPlatformFileForTransit( dispatcher(), result, file); } @@ -731,8 +723,8 @@ void PPB_Flash_File_FileRef_Proxy::OnMsgQueryFile( const HostResource& host_resource, PP_FileInfo* info, int32_t* result) { - *result = ppb_flash_file_fileref_impl_->QueryFile( - host_resource.host_resource(), info); + *result = ppb_flash_file_module_local_target()-> + QueryFile(host_resource.host_resource(), info); } } // namespace proxy diff --git a/ppapi/proxy/ppb_flash_file_proxy.h b/ppapi/proxy/ppb_flash_file_proxy.h index b0ebb63..ee8d05d 100644 --- a/ppapi/proxy/ppb_flash_file_proxy.h +++ b/ppapi/proxy/ppb_flash_file_proxy.h @@ -27,11 +27,16 @@ struct SerializedDirEntry; class PPB_Flash_File_ModuleLocal_Proxy : public InterfaceProxy { public: - PPB_Flash_File_ModuleLocal_Proxy(Dispatcher* dispatcher); + PPB_Flash_File_ModuleLocal_Proxy(Dispatcher* dispatcher, + const void* target_interface); virtual ~PPB_Flash_File_ModuleLocal_Proxy(); static const Info* GetInfo(); + const PPB_Flash_File_ModuleLocal* ppb_flash_file_module_local_target() const { + return static_cast<const PPB_Flash_File_ModuleLocal*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -61,22 +66,20 @@ class PPB_Flash_File_ModuleLocal_Proxy : public InterfaceProxy { const std::string& path, std::vector<SerializedDirEntry>* entries, int32_t* result); - - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_Flash_File_ModuleLocal* ppb_flash_file_module_local_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPB_Flash_File_ModuleLocal_Proxy); }; class PPB_Flash_File_FileRef_Proxy : public InterfaceProxy { public: - PPB_Flash_File_FileRef_Proxy(Dispatcher* dispatcher); + PPB_Flash_File_FileRef_Proxy(Dispatcher* dispatcher, + const void* target_interface); virtual ~PPB_Flash_File_FileRef_Proxy(); static const Info* GetInfo(); + const PPB_Flash_File_FileRef* ppb_flash_file_module_local_target() const { + return static_cast<const PPB_Flash_File_FileRef*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -89,13 +92,6 @@ class PPB_Flash_File_FileRef_Proxy : public InterfaceProxy { void OnMsgQueryFile(const ppapi::HostResource& host_resource, PP_FileInfo* info, int32_t* result); - - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_Flash_File_FileRef* ppb_flash_file_fileref_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPB_Flash_File_FileRef_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppb_flash_menu_proxy.cc b/ppapi/proxy/ppb_flash_menu_proxy.cc index fad5689..5f6ff05 100644 --- a/ppapi/proxy/ppb_flash_menu_proxy.cc +++ b/ppapi/proxy/ppb_flash_menu_proxy.cc @@ -77,14 +77,16 @@ void FlashMenu::ShowACK(int32_t selected_id, int32_t result) { namespace { -InterfaceProxy* CreateFlashMenuProxy(Dispatcher* dispatcher) { - return new PPB_Flash_Menu_Proxy(dispatcher); +InterfaceProxy* CreateFlashMenuProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Flash_Menu_Proxy(dispatcher, target_interface); } } // namespace -PPB_Flash_Menu_Proxy::PPB_Flash_Menu_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +PPB_Flash_Menu_Proxy::PPB_Flash_Menu_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } @@ -142,7 +144,7 @@ bool PPB_Flash_Menu_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_Flash_Menu_Proxy::OnMsgCreate(PP_Instance instance, const SerializedFlashMenu& menu_data, HostResource* result) { - thunk::EnterResourceCreation enter(instance); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); if (enter.succeeded()) { result->SetHostResource( instance, diff --git a/ppapi/proxy/ppb_flash_menu_proxy.h b/ppapi/proxy/ppb_flash_menu_proxy.h index 51a4dc6..869a7d6 100644 --- a/ppapi/proxy/ppb_flash_menu_proxy.h +++ b/ppapi/proxy/ppb_flash_menu_proxy.h @@ -22,7 +22,7 @@ class SerializedFlashMenu; class PPB_Flash_Menu_Proxy : public InterfaceProxy { public: - PPB_Flash_Menu_Proxy(Dispatcher* dispatcher); + PPB_Flash_Menu_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Flash_Menu_Proxy(); static const Info* GetInfo(); diff --git a/ppapi/proxy/ppb_flash_net_connector_proxy.cc b/ppapi/proxy/ppb_flash_net_connector_proxy.cc index 323059e..44f856e 100644 --- a/ppapi/proxy/ppb_flash_net_connector_proxy.cc +++ b/ppapi/proxy/ppb_flash_net_connector_proxy.cc @@ -189,15 +189,16 @@ struct PPB_Flash_NetConnector_Proxy::ConnectCallbackInfo { namespace { -InterfaceProxy* CreateFlashNetConnectorProxy(Dispatcher* dispatcher) { - return new PPB_Flash_NetConnector_Proxy(dispatcher); +InterfaceProxy* CreateFlashNetConnectorProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Flash_NetConnector_Proxy(dispatcher, target_interface); } } // namespace PPB_Flash_NetConnector_Proxy::PPB_Flash_NetConnector_Proxy( - Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), + Dispatcher* dispatcher, const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } @@ -249,7 +250,7 @@ bool PPB_Flash_NetConnector_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_Flash_NetConnector_Proxy::OnMsgCreate(PP_Instance instance, HostResource* result) { - thunk::EnterResourceCreation enter(instance); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); if (enter.succeeded()) { result->SetHostResource( instance, diff --git a/ppapi/proxy/ppb_flash_net_connector_proxy.h b/ppapi/proxy/ppb_flash_net_connector_proxy.h index 4ac6c5d..191b350 100644 --- a/ppapi/proxy/ppb_flash_net_connector_proxy.h +++ b/ppapi/proxy/ppb_flash_net_connector_proxy.h @@ -22,7 +22,8 @@ namespace proxy { class PPB_Flash_NetConnector_Proxy : public InterfaceProxy { public: - PPB_Flash_NetConnector_Proxy(Dispatcher* dispatcher); + PPB_Flash_NetConnector_Proxy(Dispatcher* dispatcher, + const void* target_interface); virtual ~PPB_Flash_NetConnector_Proxy(); static const Info* GetInfo(); diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc index 1faae86..c551ace 100644 --- a/ppapi/proxy/ppb_flash_proxy.cc +++ b/ppapi/proxy/ppb_flash_proxy.cc @@ -20,7 +20,6 @@ #include "ppapi/proxy/serialized_var.h" #include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/scoped_pp_resource.h" -#include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_url_request_info_api.h" #include "ppapi/thunk/resource_creation_api.h" @@ -153,8 +152,12 @@ double GetLocalTimeZoneOffset(PP_Instance instance, PP_Time t) { } PP_Var GetCommandLineArgs(PP_Module pp_module) { + const PPB_Var_Deprecated* var_deprecated = + static_cast<const PPB_Var_Deprecated*>( + PluginDispatcher::GetInterfaceFromDispatcher( + PPB_VAR_DEPRECATED_INTERFACE)); std::string args = ProxyModule::GetInstance()->GetFlashCommandLineArgs(); - return StringVar::StringToPPVar(pp_module, args); + return var_deprecated->VarFromUtf8(pp_module, args.data(), args.length()); } const PPB_Flash flash_interface = { @@ -168,18 +171,16 @@ const PPB_Flash flash_interface = { &GetCommandLineArgs }; -InterfaceProxy* CreateFlashProxy(Dispatcher* dispatcher) { - return new PPB_Flash_Proxy(dispatcher); +InterfaceProxy* CreateFlashProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Flash_Proxy(dispatcher, target_interface); } } // namespace -PPB_Flash_Proxy::PPB_Flash_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_flash_impl_(NULL) { - if (!dispatcher->IsPlugin()) - ppb_flash_impl_ = static_cast<const PPB_Flash*>( - dispatcher->local_get_interface()(PPB_FLASH_INTERFACE)); +PPB_Flash_Proxy::PPB_Flash_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Flash_Proxy::~PPB_Flash_Proxy() { @@ -227,7 +228,7 @@ bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_Flash_Proxy::OnMsgSetInstanceAlwaysOnTop( PP_Instance instance, PP_Bool on_top) { - ppb_flash_impl_->SetInstanceAlwaysOnTop(instance, on_top); + ppb_flash_target()->SetInstanceAlwaysOnTop(instance, on_top); } void PPB_Flash_Proxy::OnMsgDrawGlyphs(const PPBFlash_DrawGlyphs_Params& params, @@ -241,7 +242,7 @@ void PPB_Flash_Proxy::OnMsgDrawGlyphs(const PPBFlash_DrawGlyphs_Params& params, params.glyph_indices.empty()) return; - *result = ppb_flash_impl_->DrawGlyphs( + *result = ppb_flash_target()->DrawGlyphs( 0, // Unused instance param. params.image_data.host_resource(), &font_desc, params.color, params.position, params.clip, @@ -254,7 +255,7 @@ void PPB_Flash_Proxy::OnMsgDrawGlyphs(const PPBFlash_DrawGlyphs_Params& params, void PPB_Flash_Proxy::OnMsgGetProxyForURL(PP_Instance instance, const std::string& url, SerializedVarReturnValue result) { - result.Return(dispatcher(), ppb_flash_impl_->GetProxyForURL( + result.Return(dispatcher(), ppb_flash_target()->GetProxyForURL( instance, url.c_str())); } @@ -291,23 +292,23 @@ void PPB_Flash_Proxy::OnMsgNavigate(PP_Instance instance, ScopedPPResource::PassRef(), enter.functions()->CreateURLRequestInfo(instance, data)); - *result = ppb_flash_impl_->Navigate(request_resource, - target.c_str(), - from_user_action); + *result = ppb_flash_target()->Navigate(request_resource, + target.c_str(), + from_user_action); } void PPB_Flash_Proxy::OnMsgRunMessageLoop(PP_Instance instance) { - ppb_flash_impl_->RunMessageLoop(instance); + ppb_flash_target()->RunMessageLoop(instance); } void PPB_Flash_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) { - ppb_flash_impl_->QuitMessageLoop(instance); + ppb_flash_target()->QuitMessageLoop(instance); } void PPB_Flash_Proxy::OnMsgGetLocalTimeZoneOffset(PP_Instance instance, PP_Time t, double* result) { - *result = ppb_flash_impl_->GetLocalTimeZoneOffset(instance, t); + *result = ppb_flash_target()->GetLocalTimeZoneOffset(instance, t); } } // namespace proxy diff --git a/ppapi/proxy/ppb_flash_proxy.h b/ppapi/proxy/ppb_flash_proxy.h index 8bb15eb..f893ce2 100644 --- a/ppapi/proxy/ppb_flash_proxy.h +++ b/ppapi/proxy/ppb_flash_proxy.h @@ -29,11 +29,15 @@ class SerializedVarReturnValue; class PPB_Flash_Proxy : public InterfaceProxy { public: - PPB_Flash_Proxy(Dispatcher* dispatcher); + PPB_Flash_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Flash_Proxy(); static const Info* GetInfo(); + const PPB_Flash* ppb_flash_target() const { + return static_cast<const PPB_Flash*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -55,13 +59,6 @@ class PPB_Flash_Proxy : public InterfaceProxy { void OnMsgQuitMessageLoop(PP_Instance instance); void OnMsgGetLocalTimeZoneOffset(PP_Instance instance, PP_Time t, double* result); - - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_Flash* ppb_flash_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc b/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc index 7ff2ce3..12d40b7 100644 --- a/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc +++ b/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc @@ -49,8 +49,9 @@ class AbortCallbackTask : public Task { PP_CompletionCallback callback_; }; -InterfaceProxy* CreateFlashTCPSocketProxy(Dispatcher* dispatcher) { - return new PPB_Flash_TCPSocket_Proxy(dispatcher); +InterfaceProxy* CreateFlashTCPSocketProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Flash_TCPSocket_Proxy(dispatcher, target_interface); } } // namespace @@ -388,8 +389,10 @@ void FlashTCPSocket::PostAbortAndClearIfNecessary( } } -PPB_Flash_TCPSocket_Proxy::PPB_Flash_TCPSocket_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +PPB_Flash_TCPSocket_Proxy::PPB_Flash_TCPSocket_Proxy( + Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Flash_TCPSocket_Proxy::~PPB_Flash_TCPSocket_Proxy() { diff --git a/ppapi/proxy/ppb_flash_tcp_socket_proxy.h b/ppapi/proxy/ppb_flash_tcp_socket_proxy.h index 925a4ae..831a8cc 100644 --- a/ppapi/proxy/ppb_flash_tcp_socket_proxy.h +++ b/ppapi/proxy/ppb_flash_tcp_socket_proxy.h @@ -26,7 +26,8 @@ PPAPI_PROXY_EXPORT extern const int32_t kFlashTCPSocketMaxWriteSize; class PPB_Flash_TCPSocket_Proxy : public InterfaceProxy { public: - PPB_Flash_TCPSocket_Proxy(Dispatcher* dispatcher); + PPB_Flash_TCPSocket_Proxy(Dispatcher* dispatcher, + const void* target_interface); virtual ~PPB_Flash_TCPSocket_Proxy(); static const Info* GetInfo(); diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc index b6ef2db..3c42ecd 100644 --- a/ppapi/proxy/ppb_font_proxy.cc +++ b/ppapi/proxy/ppb_font_proxy.cc @@ -40,15 +40,33 @@ bool PPTextRunToTextRun(const PP_TextRun_Dev* run, return true; } +InterfaceProxy* CreateFontProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Font_Proxy(dispatcher, target_interface); +} + } // namespace -PPB_Font_Proxy::PPB_Font_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +PPB_Font_Proxy::PPB_Font_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Font_Proxy::~PPB_Font_Proxy() { } +// static +const InterfaceProxy::Info* PPB_Font_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_Font_Thunk(), + PPB_FONT_DEV_INTERFACE, + INTERFACE_ID_PPB_FONT, + false, + &CreateFontProxy, + }; + return &info; +} + PPB_Font_FunctionAPI* PPB_Font_Proxy::AsPPB_Font_FunctionAPI() { return this; } diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h index d7af485..c9807e2 100644 --- a/ppapi/proxy/ppb_font_proxy.h +++ b/ppapi/proxy/ppb_font_proxy.h @@ -21,12 +21,15 @@ namespace proxy { class SerializedVarReturnValue; -class PPB_Font_Proxy : public InterfaceProxy, - public ppapi::thunk::PPB_Font_FunctionAPI { +class PPB_Font_Proxy : public ppapi::FunctionGroupBase, + public ppapi::thunk::PPB_Font_FunctionAPI, + public InterfaceProxy { public: - PPB_Font_Proxy(Dispatcher* dispatcher); + PPB_Font_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Font_Proxy(); + static const Info* GetInfo(); + // FunctionGroupBase overrides. virtual ppapi::thunk::PPB_Font_FunctionAPI* AsPPB_Font_FunctionAPI() OVERRIDE; @@ -36,8 +39,6 @@ class PPB_Font_Proxy : public InterfaceProxy, // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_FONT; - private: DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy); }; diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc index 232e1fe..a855cfd 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc @@ -24,6 +24,15 @@ using ppapi::thunk::PPB_Graphics2D_API; namespace ppapi { namespace proxy { +namespace { + +InterfaceProxy* CreateGraphics2DProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Graphics2D_Proxy(dispatcher, target_interface); +} + +} // namespace + class Graphics2D : public Resource, public thunk::PPB_Graphics2D_API { public: Graphics2D(const HostResource& host_resource, @@ -139,8 +148,9 @@ void Graphics2D::FlushACK(int32_t result_code) { PP_RunAndClearCompletionCallback(¤t_flush_callback_, result_code); } -PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } @@ -148,6 +158,18 @@ PPB_Graphics2D_Proxy::~PPB_Graphics2D_Proxy() { } // static +const InterfaceProxy::Info* PPB_Graphics2D_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_Graphics2D_Thunk(), + PPB_GRAPHICS_2D_INTERFACE, + INTERFACE_ID_PPB_GRAPHICS_2D, + false, + &CreateGraphics2DProxy, + }; + return &info; +} + +// static PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource( PP_Instance instance, const PP_Size& size, diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.h b/ppapi/proxy/ppb_graphics_2d_proxy.h index 59b4b1b..cd4c55f 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.h +++ b/ppapi/proxy/ppb_graphics_2d_proxy.h @@ -26,18 +26,22 @@ namespace proxy { class PPB_Graphics2D_Proxy : public InterfaceProxy { public: - PPB_Graphics2D_Proxy(Dispatcher* dispatcher); + PPB_Graphics2D_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Graphics2D_Proxy(); + 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()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_GRAPHICS_2D; - private: // Plugin->renderer message handlers. void OnMsgPaintImageData(const ppapi::HostResource& graphics_2d, @@ -63,8 +67,6 @@ class PPB_Graphics2D_Proxy : public InterfaceProxy { pp::CompletionCallbackFactory<PPB_Graphics2D_Proxy, ProxyNonThreadSafeRefCount> callback_factory_; - - DISALLOW_COPY_AND_ASSIGN(PPB_Graphics2D_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.cc b/ppapi/proxy/ppb_graphics_3d_proxy.cc index e184ef0..31d9ccb 100644 --- a/ppapi/proxy/ppb_graphics_3d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_3d_proxy.cc @@ -316,6 +316,10 @@ gpu::CommandBuffer::State GPUStateFromPPState( return state; } +InterfaceProxy* CreateGraphics3DProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Graphics3D_Proxy(dispatcher, target_interface); +} } // namespace Graphics3D::Graphics3D(const HostResource& resource) @@ -391,8 +395,9 @@ int32 Graphics3D::DoSwapBuffers() { return PP_OK_COMPLETIONPENDING; } -PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } @@ -400,6 +405,18 @@ PPB_Graphics3D_Proxy::~PPB_Graphics3D_Proxy() { } // static +const InterfaceProxy::Info* PPB_Graphics3D_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_Graphics3D_Thunk(), + PPB_GRAPHICS_3D_INTERFACE, + INTERFACE_ID_PPB_GRAPHICS_3D, + false, + &CreateGraphics3DProxy, + }; + return &info; +} + +// static PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource( PP_Instance instance, PP_Resource share_context, @@ -473,7 +490,7 @@ void PPB_Graphics3D_Proxy::OnMsgCreate(PP_Instance instance, if (attribs.empty() || attribs.back() != PP_GRAPHICS3DATTRIB_NONE) return; // Bad message. - thunk::EnterResourceCreation enter(instance); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); if (enter.succeeded()) { result->SetHostResource( instance, diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.h b/ppapi/proxy/ppb_graphics_3d_proxy.h index ef2b70b..4fd97a2 100644 --- a/ppapi/proxy/ppb_graphics_3d_proxy.h +++ b/ppapi/proxy/ppb_graphics_3d_proxy.h @@ -63,18 +63,22 @@ class Graphics3D : public Resource, public Graphics3DImpl { class PPB_Graphics3D_Proxy : public InterfaceProxy { public: - PPB_Graphics3D_Proxy(Dispatcher* dispatcher); + PPB_Graphics3D_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Graphics3D_Proxy(); + static const Info* GetInfo(); + static PP_Resource CreateProxyResource(PP_Instance instance, PP_Resource share_context, const int32_t* attrib_list); + const PPB_Graphics3D* ppb_graphics_3d_target() const { + return static_cast<const PPB_Graphics3D*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_GRAPHICS_3D; - private: void OnMsgCreate(PP_Instance instance, const std::vector<int32_t>& attribs, diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc index 32c24a9..0f96b99 100644 --- a/ppapi/proxy/ppb_image_data_proxy.cc +++ b/ppapi/proxy/ppb_image_data_proxy.cc @@ -25,6 +25,43 @@ namespace ppapi { namespace proxy { +namespace { + +InterfaceProxy* CreateImageDataProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_ImageData_Proxy(dispatcher, target_interface); +} + +} // namespace + +// PPB_ImageData_Proxy --------------------------------------------------------- + +PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_ImageData_Proxy::~PPB_ImageData_Proxy() { +} + +// static +const InterfaceProxy::Info* PPB_ImageData_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_ImageData_Thunk(), + PPB_IMAGEDATA_INTERFACE, + INTERFACE_ID_PPB_IMAGE_DATA, + false, + &CreateImageDataProxy, + }; + return &info; +} + +bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) { + return false; +} + +// ImageData ------------------------------------------------------------------- + ImageData::ImageData(const HostResource& resource, const PP_ImageDataDesc& desc, ImageHandle handle) diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h index 6cf4910..1b96917 100644 --- a/ppapi/proxy/ppb_image_data_proxy.h +++ b/ppapi/proxy/ppb_image_data_proxy.h @@ -32,6 +32,21 @@ class HostResource; namespace proxy { +class PPB_ImageData_Proxy : public InterfaceProxy { + public: + PPB_ImageData_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_ImageData_Proxy(); + + static const Info* GetInfo(); + + const PPB_ImageData* ppb_image_data_target() const { + return static_cast<const PPB_ImageData*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg); +}; + class ImageData : public ppapi::Resource, public ppapi::thunk::PPB_ImageData_API, public ppapi::ImageDataImpl { diff --git a/ppapi/proxy/ppb_input_event_proxy.cc b/ppapi/proxy/ppb_input_event_proxy.cc new file mode 100644 index 0000000..655b10d --- /dev/null +++ b/ppapi/proxy/ppb_input_event_proxy.cc @@ -0,0 +1,105 @@ +// 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/proxy/ppb_input_event_proxy.h" + +#include "ppapi/c/ppb_audio_config.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_var_tracker.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/input_event_impl.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/thunk/thunk.h" + +using ppapi::thunk::PPB_InputEvent_API; + +namespace ppapi { +namespace proxy { + +namespace { + +InterfaceProxy* CreateInputEventProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_InputEvent_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPB_InputEvent_Proxy::PPB_InputEvent_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_InputEvent_Proxy::~PPB_InputEvent_Proxy() { +} + +// static +const InterfaceProxy::Info* PPB_InputEvent_Proxy::GetInputEventInfo() { + static const Info info = { + thunk::GetPPB_InputEvent_Thunk(), + PPB_INPUT_EVENT_INTERFACE, + INTERFACE_ID_NONE, + false, + &CreateInputEventProxy, + }; + return &info; +} + +// static +const InterfaceProxy::Info* PPB_InputEvent_Proxy::GetKeyboardInputEventInfo() { + static const Info info = { + thunk::GetPPB_KeyboardInputEvent_Thunk(), + PPB_KEYBOARD_INPUT_EVENT_INTERFACE, + INTERFACE_ID_NONE, + false, + &CreateInputEventProxy, + }; + return &info; +} + +// static +const InterfaceProxy::Info* PPB_InputEvent_Proxy::GetMouseInputEventInfo1_0() { + static const Info info = { + thunk::GetPPB_MouseInputEvent_1_0_Thunk(), + PPB_MOUSE_INPUT_EVENT_INTERFACE_1_0, + INTERFACE_ID_NONE, + false, + &CreateInputEventProxy, + }; + return &info; +} + +// static +const InterfaceProxy::Info* PPB_InputEvent_Proxy::GetMouseInputEventInfo1_1() { + static const Info info = { + thunk::GetPPB_MouseInputEvent_1_1_Thunk(), + PPB_MOUSE_INPUT_EVENT_INTERFACE_1_1, + INTERFACE_ID_NONE, + false, + &CreateInputEventProxy, + }; + return &info; +} + +// static +const InterfaceProxy::Info* PPB_InputEvent_Proxy::GetWheelInputEventInfo() { + static const Info info = { + thunk::GetPPB_WheelInputEvent_Thunk(), + PPB_WHEEL_INPUT_EVENT_INTERFACE, + INTERFACE_ID_NONE, + false, + &CreateInputEventProxy, + }; + return &info; +} + +bool PPB_InputEvent_Proxy::OnMessageReceived(const IPC::Message& msg) { + // There are no IPC messages for this interface. + NOTREACHED(); + return false; +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/ppb_input_event_proxy.h b/ppapi/proxy/ppb_input_event_proxy.h new file mode 100644 index 0000000..5e60acb --- /dev/null +++ b/ppapi/proxy/ppb_input_event_proxy.h @@ -0,0 +1,40 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_PPB_INPUT_EVENT_PROXY_H_ +#define PPAPI_PROXY_PPB_INPUT_EVENT_PROXY_H_ + +#include "base/basictypes.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/proxy/interface_proxy.h" +#include "ppapi/shared_impl/input_event_impl.h" + +namespace ppapi { + +struct InputEventData; + +namespace proxy { + +class PPB_InputEvent_Proxy : public InterfaceProxy { + public: + PPB_InputEvent_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_InputEvent_Proxy(); + + static const Info* GetInputEventInfo(); + static const Info* GetKeyboardInputEventInfo(); + static const Info* GetMouseInputEventInfo1_0(); + static const Info* GetMouseInputEventInfo1_1(); + static const Info* GetWheelInputEventInfo(); + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg); + + private: + DISALLOW_COPY_AND_ASSIGN(PPB_InputEvent_Proxy); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PPB_INPUT_EVENT_PROXY_H_ diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index 5dcf713..10464c6 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -32,22 +32,70 @@ namespace proxy { namespace { -typedef EnterFunctionNoLock<PPB_Instance_FunctionAPI> EnterInstanceNoLock; - -InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher) { - return new PPB_Instance_Proxy(dispatcher); +InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Instance_Proxy(dispatcher, target_interface); } } // namespace -PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +PPB_Instance_Proxy::PPB_Instance_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Instance_Proxy::~PPB_Instance_Proxy() { } // static +const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfo0_5() { + static const Info info = { + ppapi::thunk::GetPPB_Instance_1_0_Thunk(), + PPB_INSTANCE_INTERFACE_0_5, + INTERFACE_ID_NONE, // 1_0 is the canonical one. + false, + &CreateInstanceProxy, + }; + return &info; +} + +// static +const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfo1_0() { + static const Info info = { + ppapi::thunk::GetPPB_Instance_1_0_Thunk(), + PPB_INSTANCE_INTERFACE_1_0, + INTERFACE_ID_PPB_INSTANCE, + false, + &CreateInstanceProxy, + }; + return &info; +} + +// static +const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoMessaging() { + static const Info info = { + ppapi::thunk::GetPPB_Messaging_Thunk(), + PPB_MESSAGING_INTERFACE, + INTERFACE_ID_NONE, // 1_0 is the canonical one. + false, + &CreateInstanceProxy, + }; + return &info; +} + +// static +const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoMouseLock() { + static const Info info = { + ppapi::thunk::GetPPB_MouseLock_Thunk(), + PPB_MOUSELOCK_DEV_INTERFACE, + INTERFACE_ID_NONE, // 1_0 is the canonical one. + false, + &CreateInstanceProxy, + }; + return &info; +} + +// static const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoPrivate() { static const Info info = { ppapi::thunk::GetPPB_Instance_Private_Thunk(), @@ -90,10 +138,6 @@ bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { OnMsgIsFullFrame) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ExecuteScript, OnMsgExecuteScript) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_Log, - OnMsgLog) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LogWithSource, - OnMsgLogWithSource) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_PostMessage, OnMsgPostMessage) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_SetFullscreen, @@ -165,24 +209,6 @@ PP_Var PPB_Instance_Proxy::ExecuteScript(PP_Instance instance, return result.Return(dispatcher()); } -void PPB_Instance_Proxy::Log(PP_Instance instance, - int log_level, - PP_Var value) { - dispatcher()->Send(new PpapiHostMsg_PPBInstance_Log( - INTERFACE_ID_PPB_INSTANCE, instance, static_cast<int>(log_level), - SerializedVarSendInput(dispatcher(), value))); -} - -void PPB_Instance_Proxy::LogWithSource(PP_Instance instance, - int log_level, - PP_Var source, - PP_Var value) { - dispatcher()->Send(new PpapiHostMsg_PPBInstance_LogWithSource( - INTERFACE_ID_PPB_INSTANCE, instance, static_cast<int>(log_level), - SerializedVarSendInput(dispatcher(), source), - SerializedVarSendInput(dispatcher(), value))); -} - PP_Bool PPB_Instance_Proxy::IsFullscreen(PP_Instance instance) { InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> GetInstanceData(instance); @@ -279,7 +305,7 @@ void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) { void PPB_Instance_Proxy::OnMsgGetWindowObject( PP_Instance instance, SerializedVarReturnValue result) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.succeeded()) result.Return(dispatcher(), enter.functions()->GetWindowObject(instance)); } @@ -287,7 +313,7 @@ void PPB_Instance_Proxy::OnMsgGetWindowObject( void PPB_Instance_Proxy::OnMsgGetOwnerElementObject( PP_Instance instance, SerializedVarReturnValue result) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.succeeded()) { result.Return(dispatcher(), enter.functions()->GetOwnerElementObject(instance)); @@ -297,7 +323,7 @@ void PPB_Instance_Proxy::OnMsgGetOwnerElementObject( void PPB_Instance_Proxy::OnMsgBindGraphics(PP_Instance instance, const HostResource& device, PP_Bool* result) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.succeeded()) { *result = enter.functions()->BindGraphics(instance, device.host_resource()); @@ -306,7 +332,7 @@ void PPB_Instance_Proxy::OnMsgBindGraphics(PP_Instance instance, void PPB_Instance_Proxy::OnMsgIsFullFrame(PP_Instance instance, PP_Bool* result) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.succeeded()) *result = enter.functions()->IsFullFrame(instance); } @@ -316,7 +342,7 @@ void PPB_Instance_Proxy::OnMsgExecuteScript( SerializedVarReceiveInput script, SerializedVarOutParam out_exception, SerializedVarReturnValue result) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.failed()) return; @@ -331,30 +357,10 @@ void PPB_Instance_Proxy::OnMsgExecuteScript( out_exception.OutParam(dispatcher()))); } -void PPB_Instance_Proxy::OnMsgLog(PP_Instance instance, - int log_level, - SerializedVarReceiveInput value) { - EnterInstanceNoLock enter(instance, false); - if (enter.succeeded()) - enter.functions()->Log(instance, log_level, value.Get(dispatcher())); -} - -void PPB_Instance_Proxy::OnMsgLogWithSource(PP_Instance instance, - int log_level, - SerializedVarReceiveInput source, - SerializedVarReceiveInput value) { - EnterInstanceNoLock enter(instance, false); - if (enter.succeeded()) { - enter.functions()->LogWithSource(instance, log_level, - source.Get(dispatcher()), - value.Get(dispatcher())); - } -} - void PPB_Instance_Proxy::OnMsgSetFullscreen(PP_Instance instance, PP_Bool fullscreen, PP_Bool* result) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.succeeded()) *result = enter.functions()->SetFullscreen(instance, fullscreen); } @@ -362,7 +368,7 @@ void PPB_Instance_Proxy::OnMsgSetFullscreen(PP_Instance instance, void PPB_Instance_Proxy::OnMsgGetScreenSize(PP_Instance instance, PP_Bool* result, PP_Size* size) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.succeeded()) *result = enter.functions()->GetScreenSize(instance, size); } @@ -370,7 +376,7 @@ void PPB_Instance_Proxy::OnMsgGetScreenSize(PP_Instance instance, void PPB_Instance_Proxy::OnMsgRequestInputEvents(PP_Instance instance, bool is_filtering, uint32_t event_classes) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.succeeded()) { if (is_filtering) enter.functions()->RequestFilteringInputEvents(instance, event_classes); @@ -381,14 +387,14 @@ void PPB_Instance_Proxy::OnMsgRequestInputEvents(PP_Instance instance, void PPB_Instance_Proxy::OnMsgClearInputEvents(PP_Instance instance, uint32_t event_classes) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.succeeded()) enter.functions()->ClearInputEventRequest(instance, event_classes); } void PPB_Instance_Proxy::OnMsgPostMessage(PP_Instance instance, SerializedVarReceiveInput message) { - EnterInstanceNoLock enter(instance, false); + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, false); if (enter.succeeded()) enter.functions()->PostMessage(instance, message.Get(dispatcher())); } diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index 4199912..d0ec32b 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -23,11 +23,16 @@ class SerializedVarReturnValue; class PPB_Instance_Proxy : public InterfaceProxy, public ppapi::InstanceImpl, + public ppapi::FunctionGroupBase, public ppapi::thunk::PPB_Instance_FunctionAPI { public: - PPB_Instance_Proxy(Dispatcher* dispatcher); + PPB_Instance_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Instance_Proxy(); + static const Info* GetInfo0_5(); + static const Info* GetInfo1_0(); + static const Info* GetInfoMessaging(); + static const Info* GetInfoMouseLock(); static const Info* GetInfoPrivate(); static const Info* GetInfoFullscreen(); @@ -46,13 +51,6 @@ class PPB_Instance_Proxy : public InterfaceProxy, virtual PP_Var ExecuteScript(PP_Instance instance, PP_Var script, PP_Var* exception) OVERRIDE; - virtual void Log(PP_Instance instance, - int log_level, - PP_Var value) OVERRIDE; - virtual void LogWithSource(PP_Instance instance, - int log_level, - PP_Var source, - PP_Var value) OVERRIDE; virtual PP_Bool IsFullscreen(PP_Instance instance) OVERRIDE; virtual PP_Bool SetFullscreen(PP_Instance instance, PP_Bool fullscreen) OVERRIDE; @@ -73,8 +71,6 @@ class PPB_Instance_Proxy : public InterfaceProxy, PP_CompletionCallback callback) OVERRIDE; virtual void UnlockMouse(PP_Instance instance) OVERRIDE; - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_INSTANCE; - private: // Message handlers. void OnMsgGetWindowObject(PP_Instance instance, @@ -89,13 +85,6 @@ class PPB_Instance_Proxy : public InterfaceProxy, SerializedVarReceiveInput script, SerializedVarOutParam out_exception, SerializedVarReturnValue result); - void OnMsgLog(PP_Instance instance, - int log_level, - SerializedVarReceiveInput value); - void OnMsgLogWithSource(PP_Instance instance, - int log_level, - SerializedVarReceiveInput source, - SerializedVarReceiveInput value); void OnMsgSetFullscreen(PP_Instance instance, PP_Bool fullscreen, PP_Bool* result); diff --git a/ppapi/proxy/ppb_memory_proxy.cc b/ppapi/proxy/ppb_memory_proxy.cc index 88da6b2..ec3fc03 100644 --- a/ppapi/proxy/ppb_memory_proxy.cc +++ b/ppapi/proxy/ppb_memory_proxy.cc @@ -27,10 +27,37 @@ const PPB_Memory_Dev memory_dev_interface = { &MemFree }; +InterfaceProxy* CreateMemoryProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Memory_Proxy(dispatcher, target_interface); +} + } // namespace -const PPB_Memory_Dev* GetPPB_Memory_Interface() { - return &memory_dev_interface; +PPB_Memory_Proxy::PPB_Memory_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_Memory_Proxy::~PPB_Memory_Proxy() { +} + +// static +const InterfaceProxy::Info* PPB_Memory_Proxy::GetInfo() { + static const Info info = { + &memory_dev_interface, + PPB_MEMORY_DEV_INTERFACE, + INTERFACE_ID_PPB_MEMORY, + false, + &CreateMemoryProxy, + }; + return &info; +} + +bool PPB_Memory_Proxy::OnMessageReceived(const IPC::Message& msg) { + // All PPB_Memory_Dev calls are handled locally; there is no need to send or + // receive messages here. + return false; } } // namespace proxy diff --git a/ppapi/proxy/ppb_memory_proxy.h b/ppapi/proxy/ppb_memory_proxy.h index fd7d5d2..6666ede 100644 --- a/ppapi/proxy/ppb_memory_proxy.h +++ b/ppapi/proxy/ppb_memory_proxy.h @@ -12,7 +12,23 @@ struct PPB_Memory_Dev; namespace ppapi { namespace proxy { -const PPB_Memory_Dev* GetPPB_Memory_Interface(); +class PPB_Memory_Proxy : public InterfaceProxy { + public: + PPB_Memory_Proxy(Dispatcher* dispatcher, + const void* target_interface); + virtual ~PPB_Memory_Proxy(); + + static const Info* GetInfo(); + + const PPB_Memory_Dev* ppb_memory_target() const { + return static_cast<const PPB_Memory_Dev*>(target_interface()); + } + + // InterfaceProxy implementation. In this case, no messages are sent or + // received, so this always returns false. + virtual bool OnMessageReceived(const IPC::Message& msg); + +}; } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/ppb_opengles2_proxy.cc b/ppapi/proxy/ppb_opengles2_proxy.cc new file mode 100644 index 0000000..9516678 --- /dev/null +++ b/ppapi/proxy/ppb_opengles2_proxy.cc @@ -0,0 +1,44 @@ +// 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/proxy/ppb_opengles2_proxy.h" + +#include "ppapi/shared_impl/opengles2_impl.h" + +namespace ppapi { +namespace proxy { + +namespace { +InterfaceProxy* CreateOpenGLES2Proxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_OpenGLES2_Proxy(dispatcher, target_interface); +} +} // namespace + +PPB_OpenGLES2_Proxy::PPB_OpenGLES2_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_OpenGLES2_Proxy::~PPB_OpenGLES2_Proxy() { +} + +// static +const InterfaceProxy::Info* PPB_OpenGLES2_Proxy::GetInfo() { + static const Info info = { + ppapi::OpenGLES2Impl::GetInterface(), + PPB_OPENGLES2_INTERFACE, + INTERFACE_ID_PPB_OPENGLES2, + false, + &CreateOpenGLES2Proxy, + }; + return &info; +} + +bool PPB_OpenGLES2_Proxy::OnMessageReceived(const IPC::Message& msg) { + return false; +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/ppb_opengles2_proxy.h b/ppapi/proxy/ppb_opengles2_proxy.h new file mode 100644 index 0000000..c424ae8 --- /dev/null +++ b/ppapi/proxy/ppb_opengles2_proxy.h @@ -0,0 +1,33 @@ +// 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_PPB_OPENGLES2_PROXY_H_ +#define PPAPI_PPB_OPENGLES2_PROXY_H_ + +#include "ppapi/proxy/interface_proxy.h" + +struct PPB_OpenGLES2_Dev; + +namespace ppapi { +namespace proxy { + +class PPB_OpenGLES2_Proxy : public InterfaceProxy { + public: + PPB_OpenGLES2_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_OpenGLES2_Proxy(); + + static const Info* GetInfo(); + + const PPB_OpenGLES2_Dev* ppb_opengles2_target() const { + return reinterpret_cast<const PPB_OpenGLES2_Dev*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PPB_OPENGLES2_PROXY_H_ diff --git a/ppapi/proxy/ppb_pdf_proxy.cc b/ppapi/proxy/ppb_pdf_proxy.cc index 874e487..dcf3358 100644 --- a/ppapi/proxy/ppb_pdf_proxy.cc +++ b/ppapi/proxy/ppb_pdf_proxy.cc @@ -118,19 +118,16 @@ const PPB_PDF pdf_interface = { &GetFontTableForPrivateFontFile, }; -InterfaceProxy* CreatePDFProxy(Dispatcher* dispatcher) { - return new PPB_PDF_Proxy(dispatcher); +InterfaceProxy* CreatePDFProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_PDF_Proxy(dispatcher, target_interface); } } // namespace -PPB_PDF_Proxy::PPB_PDF_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_pdf_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_pdf_impl_ = static_cast<const PPB_PDF*>( - dispatcher->local_get_interface()(PPB_PDF_INTERFACE)); - } +PPB_PDF_Proxy::PPB_PDF_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_PDF_Proxy::~PPB_PDF_Proxy() { @@ -169,7 +166,7 @@ void PPB_PDF_Proxy::OnMsgGetFontFileWithFallback( PP_FontDescription_Dev desc; in_desc.SetToPPFontDescription(dispatcher(), &desc, false); result->SetHostResource(instance, - ppb_pdf_impl_->GetFontFileWithFallback( + ppb_pdf_target()->GetFontFileWithFallback( instance, &desc, static_cast<PP_PrivateFontCharset>(charset))); } @@ -180,12 +177,12 @@ void PPB_PDF_Proxy::OnMsgGetFontTableForPrivateFontFile( // TODO(brettw): It would be nice not to copy here. At least on Linux, // we can map the font file into shared memory and read it that way. uint32_t table_length = 0; - if (!ppb_pdf_impl_->GetFontTableForPrivateFontFile( + if (!ppb_pdf_target()->GetFontTableForPrivateFontFile( font_file.host_resource(), table, NULL, &table_length)) return; result->resize(table_length); - ppb_pdf_impl_->GetFontTableForPrivateFontFile(font_file.host_resource(), + ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file.host_resource(), table, const_cast<char*>(result->c_str()), &table_length); } diff --git a/ppapi/proxy/ppb_pdf_proxy.h b/ppapi/proxy/ppb_pdf_proxy.h index 7ad012d..27ab6c4 100644 --- a/ppapi/proxy/ppb_pdf_proxy.h +++ b/ppapi/proxy/ppb_pdf_proxy.h @@ -18,11 +18,15 @@ struct SerializedFontDescription; class PPB_PDF_Proxy : public InterfaceProxy { public: - PPB_PDF_Proxy(Dispatcher* dispatcher); + PPB_PDF_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_PDF_Proxy(); static const Info* GetInfo(); + const PPB_PDF* ppb_pdf_target() const { + return static_cast<const PPB_PDF*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -35,11 +39,6 @@ class PPB_PDF_Proxy : public InterfaceProxy { void OnMsgGetFontTableForPrivateFontFile(const ppapi::HostResource& font_file, uint32_t table, std::string* result); - - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_PDF* ppb_pdf_impl_; }; } // namespace proxy diff --git a/ppapi/proxy/ppb_surface_3d_proxy.cc b/ppapi/proxy/ppb_surface_3d_proxy.cc index 70809da..23348fc 100644 --- a/ppapi/proxy/ppb_surface_3d_proxy.cc +++ b/ppapi/proxy/ppb_surface_3d_proxy.cc @@ -25,8 +25,9 @@ namespace proxy { namespace { -InterfaceProxy* CreateSurface3DProxy(Dispatcher* dispatcher) { - return new PPB_Surface3D_Proxy(dispatcher); +InterfaceProxy* CreateSurface3DProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Surface3D_Proxy(dispatcher, target_interface); } } // namespace @@ -87,8 +88,9 @@ void Surface3D::SwapBuffersACK(int32_t pp_error) { // PPB_Surface3D_Proxy --------------------------------------------------------- -PPB_Surface3D_Proxy::PPB_Surface3D_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +PPB_Surface3D_Proxy::PPB_Surface3D_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } @@ -98,7 +100,7 @@ PPB_Surface3D_Proxy::~PPB_Surface3D_Proxy() { // static const InterfaceProxy::Info* PPB_Surface3D_Proxy::GetInfo() { static const Info info = { - thunk::GetPPB_Surface3D_Dev_Thunk(), + thunk::GetPPB_Surface3D_Thunk(), PPB_SURFACE_3D_DEV_INTERFACE, INTERFACE_ID_PPB_SURFACE_3D, false, @@ -160,7 +162,7 @@ void PPB_Surface3D_Proxy::OnMsgCreate(PP_Instance instance, attribs.back() != PP_GRAPHICS3DATTRIB_NONE) return; // Bad message. - thunk::EnterResourceCreation enter(instance); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); if (enter.succeeded()) { result->SetHostResource( instance, diff --git a/ppapi/proxy/ppb_surface_3d_proxy.h b/ppapi/proxy/ppb_surface_3d_proxy.h index be8ce34..ce7e8b6 100644 --- a/ppapi/proxy/ppb_surface_3d_proxy.h +++ b/ppapi/proxy/ppb_surface_3d_proxy.h @@ -63,7 +63,7 @@ class Surface3D : public ppapi::Resource, class PPB_Surface3D_Proxy : public InterfaceProxy { public: - PPB_Surface3D_Proxy(Dispatcher* dispatcher); + PPB_Surface3D_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Surface3D_Proxy(); static const Info* GetInfo(); @@ -75,8 +75,6 @@ class PPB_Surface3D_Proxy : public InterfaceProxy { // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_SURFACE_3D; - private: // Message handlers. void OnMsgCreate(PP_Instance instance, diff --git a/ppapi/proxy/ppb_testing_proxy.cc b/ppapi/proxy/ppb_testing_proxy.cc index 836e1cf..564f68f 100644 --- a/ppapi/proxy/ppb_testing_proxy.cc +++ b/ppapi/proxy/ppb_testing_proxy.cc @@ -75,19 +75,16 @@ const PPB_Testing_Dev testing_interface = { &IsOutOfProcess }; -InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) { - return new PPB_Testing_Proxy(dispatcher); +InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Testing_Proxy(dispatcher, target_interface); } } // namespace -PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_testing_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_testing_impl_ = static_cast<const PPB_Testing_Dev*>( - dispatcher->local_get_interface()(PPB_TESTING_DEV_INTERFACE)); - } +PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_Testing_Proxy::~PPB_Testing_Proxy() { @@ -122,21 +119,21 @@ void PPB_Testing_Proxy::OnMsgReadImageData( const HostResource& image, const PP_Point& top_left, PP_Bool* result) { - *result = ppb_testing_impl_->ReadImageData( + *result = ppb_testing_target()->ReadImageData( device_context_2d.host_resource(), image.host_resource(), &top_left); } void PPB_Testing_Proxy::OnMsgRunMessageLoop(PP_Instance instance) { - ppb_testing_impl_->RunMessageLoop(instance); + ppb_testing_target()->RunMessageLoop(instance); } void PPB_Testing_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) { - ppb_testing_impl_->QuitMessageLoop(instance); + ppb_testing_target()->QuitMessageLoop(instance); } void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance, uint32_t* result) { - *result = ppb_testing_impl_->GetLiveObjectsForInstance(instance); + *result = ppb_testing_target()->GetLiveObjectsForInstance(instance); } } // namespace proxy diff --git a/ppapi/proxy/ppb_testing_proxy.h b/ppapi/proxy/ppb_testing_proxy.h index eaf5fb3..c07f6a9 100644 --- a/ppapi/proxy/ppb_testing_proxy.h +++ b/ppapi/proxy/ppb_testing_proxy.h @@ -19,11 +19,15 @@ namespace proxy { class PPB_Testing_Proxy : public InterfaceProxy { public: - PPB_Testing_Proxy(Dispatcher* dispatcher); + PPB_Testing_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_Testing_Proxy(); static const Info* GetInfo(); + const PPB_Testing_Dev* ppb_testing_target() const { + return static_cast<const PPB_Testing_Dev*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -37,11 +41,6 @@ class PPB_Testing_Proxy : public InterfaceProxy { void OnMsgQuitMessageLoop(PP_Instance instance); void OnMsgGetLiveObjectsForInstance(PP_Instance instance, uint32_t* result); - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_Testing_Dev* ppb_testing_impl_; - DISALLOW_COPY_AND_ASSIGN(PPB_Testing_Proxy); }; diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc index ce4bc62..e6ef68e 100644 --- a/ppapi/proxy/ppb_url_loader_proxy.cc +++ b/ppapi/proxy/ppb_url_loader_proxy.cc @@ -70,8 +70,9 @@ void UpdateResourceLoadStatus(PP_Instance pp_instance, INTERFACE_ID_PPB_URL_LOADER, params)); } -InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher) { - return new PPB_URLLoader_Proxy(dispatcher); +InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_URLLoader_Proxy(dispatcher, target_interface); } } // namespace @@ -345,8 +346,9 @@ struct PPB_URLLoader_Proxy::ReadCallbackInfo { std::string read_buffer; }; -PPB_URLLoader_Proxy::PPB_URLLoader_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +PPB_URLLoader_Proxy::PPB_URLLoader_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), host_urlloader_trusted_interface_(NULL) { } @@ -361,6 +363,18 @@ PP_Resource PPB_URLLoader_Proxy::TrackPluginResource( } // static +const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_URLLoader_Thunk(), + PPB_URLLOADER_INTERFACE, + INTERFACE_ID_PPB_URL_LOADER, + false, + &CreateURLLoaderProxy, + }; + return &info; +} + +// static const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetTrustedInfo() { static const Info info = { thunk::GetPPB_URLLoaderTrusted_Thunk(), @@ -429,7 +443,7 @@ void PPB_URLLoader_Proxy::PrepareURLLoaderForSendingToPlugin( void PPB_URLLoader_Proxy::OnMsgCreate(PP_Instance instance, HostResource* result) { - thunk::EnterResourceCreation enter(instance); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); if (enter.succeeded()) { result->SetHostResource(instance, enter.functions()->CreateURLLoader(instance)); @@ -442,7 +456,8 @@ void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, uint32_t serialized_callback) { // Have to be careful to always issue the callback, so don't return early. EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); - thunk::EnterResourceCreation enter_creation(loader.instance()); + EnterFunctionNoLock<ResourceCreationAPI> enter_creation( + loader.instance(), true); PP_CompletionCallback callback = ReceiveCallback(serialized_callback); diff --git a/ppapi/proxy/ppb_url_loader_proxy.h b/ppapi/proxy/ppb_url_loader_proxy.h index defae9b..17825f1 100644 --- a/ppapi/proxy/ppb_url_loader_proxy.h +++ b/ppapi/proxy/ppb_url_loader_proxy.h @@ -29,9 +29,10 @@ struct PPBURLLoader_UpdateProgress_Params; class PPB_URLLoader_Proxy : public InterfaceProxy { public: - PPB_URLLoader_Proxy(Dispatcher* dispatcher); + PPB_URLLoader_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_URLLoader_Proxy(); + static const Info* GetInfo(); static const Info* GetTrustedInfo(); static PP_Resource CreateProxyResource(PP_Instance instance); @@ -43,6 +44,10 @@ class PPB_URLLoader_Proxy : public InterfaceProxy { static PP_Resource TrackPluginResource( const ppapi::HostResource& url_loader_resource); + const PPB_URLLoader* ppb_url_loader_target() const { + return reinterpret_cast<const PPB_URLLoader*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -52,8 +57,6 @@ class PPB_URLLoader_Proxy : public InterfaceProxy { // time you're sending a new URLLoader that the plugin hasn't seen yet. void PrepareURLLoaderForSendingToPlugin(PP_Resource resource); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_URL_LOADER; - private: // Data associated with callbacks for ReadResponseBody. struct ReadCallbackInfo; diff --git a/ppapi/proxy/ppb_url_request_info_proxy.cc b/ppapi/proxy/ppb_url_request_info_proxy.cc new file mode 100644 index 0000000..e5861f0 --- /dev/null +++ b/ppapi/proxy/ppb_url_request_info_proxy.cc @@ -0,0 +1,50 @@ +// 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/proxy/ppb_url_request_info_proxy.h" + +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/shared_impl/url_request_info_impl.h" +#include "ppapi/thunk/thunk.h" + +namespace ppapi { +namespace proxy { + +namespace { + +InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_URLRequestInfo_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPB_URLRequestInfo_Proxy::PPB_URLRequestInfo_Proxy( + Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_URLRequestInfo_Proxy::~PPB_URLRequestInfo_Proxy() { +} + +// static +const InterfaceProxy::Info* PPB_URLRequestInfo_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_URLRequestInfo_Thunk(), + PPB_URLREQUESTINFO_INTERFACE, + INTERFACE_ID_PPB_URL_REQUEST_INFO, + false, + &CreateURLRequestInfoProxy, + }; + return &info; +} + +bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { + // No messages to handle. + return false; +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/ppb_url_request_info_proxy.h b/ppapi/proxy/ppb_url_request_info_proxy.h new file mode 100644 index 0000000..6242bf8 --- /dev/null +++ b/ppapi/proxy/ppb_url_request_info_proxy.h @@ -0,0 +1,36 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_PPB_URL_REQUEST_INFO_PROXY_H_ +#define PPAPI_PROXY_PPB_URL_REQUEST_INFO_PROXY_H_ + +#include "base/basictypes.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/proxy/interface_proxy.h" + +namespace ppapi { + +struct PPB_URLRequestInfo_Data; + +namespace proxy { + +class PPB_URLRequestInfo_Proxy : public InterfaceProxy { + public: + PPB_URLRequestInfo_Proxy(Dispatcher* dispatcher, + const void* target_interface); + virtual ~PPB_URLRequestInfo_Proxy(); + + static const Info* GetInfo(); + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg); + + private: + DISALLOW_COPY_AND_ASSIGN(PPB_URLRequestInfo_Proxy); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PPB_URL_REQUEST_INFO_PROXY_H_ diff --git a/ppapi/proxy/ppb_url_response_info_proxy.cc b/ppapi/proxy/ppb_url_response_info_proxy.cc index ace317c..3801e5f 100644 --- a/ppapi/proxy/ppb_url_response_info_proxy.cc +++ b/ppapi/proxy/ppb_url_response_info_proxy.cc @@ -20,6 +20,15 @@ using ppapi::thunk::PPB_URLResponseInfo_API; namespace ppapi { namespace proxy { +namespace { + +InterfaceProxy* CreateURLResponseInfoProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_URLResponseInfo_Proxy(dispatcher, target_interface); +} + +} // namespace + // URLResponseInfo ------------------------------------------------------------- class URLResponseInfo : public Resource, public PPB_URLResponseInfo_API { @@ -71,14 +80,28 @@ PP_Resource URLResponseInfo::GetBodyAsFileRef() { // PPB_URLResponseInfo_Proxy --------------------------------------------------- -PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy( + Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() { } // static +const InterfaceProxy::Info* PPB_URLResponseInfo_Proxy::GetInfo() { + static const Info info = { + ppapi::thunk::GetPPB_URLResponseInfo_Thunk(), + PPB_URLRESPONSEINFO_INTERFACE, + INTERFACE_ID_PPB_URL_RESPONSE_INFO, + false, + &CreateURLResponseInfoProxy, + }; + return &info; +} + +// static PP_Resource PPB_URLResponseInfo_Proxy::CreateResponseForResource( const HostResource& resource) { return (new URLResponseInfo(resource))->GetReference(); @@ -119,8 +142,10 @@ void PPB_URLResponseInfo_Proxy::OnMsgGetBodyAsFileRef( file_ref = enter.object()->GetBodyAsFileRef(); // Use the FileRef proxy to serialize. + DCHECK(!dispatcher()->IsPlugin()); + HostDispatcher* host_disp = static_cast<HostDispatcher*>(dispatcher()); PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>( - dispatcher()->GetInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); + host_disp->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); file_ref_proxy->SerializeFileRef(file_ref, result); } diff --git a/ppapi/proxy/ppb_url_response_info_proxy.h b/ppapi/proxy/ppb_url_response_info_proxy.h index 8f97a53..a81549d 100644 --- a/ppapi/proxy/ppb_url_response_info_proxy.h +++ b/ppapi/proxy/ppb_url_response_info_proxy.h @@ -24,9 +24,12 @@ class SerializedVarReturnValue; class PPB_URLResponseInfo_Proxy : public InterfaceProxy { public: - PPB_URLResponseInfo_Proxy(Dispatcher* dispatcher); + PPB_URLResponseInfo_Proxy(Dispatcher* dispatcher, + const void* target_interface); virtual ~PPB_URLResponseInfo_Proxy(); + static const Info* GetInfo(); + // URLResponseInfo objects are actually created and returned by the // URLLoader. This function allows the URLLoader to convert a new // HostResource representing a response info to a properly tracked @@ -38,8 +41,6 @@ class PPB_URLResponseInfo_Proxy : public InterfaceProxy { // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_URL_RESPONSE_INFO; - private: // Message handlers. void OnMsgGetProperty(const ppapi::HostResource& response, diff --git a/ppapi/proxy/ppb_url_util_proxy.cc b/ppapi/proxy/ppb_url_util_proxy.cc index b3cea08..a202038 100644 --- a/ppapi/proxy/ppb_url_util_proxy.cc +++ b/ppapi/proxy/ppb_url_util_proxy.cc @@ -129,19 +129,16 @@ const PPB_URLUtil_Dev url_util_interface = { &GetPluginInstanceURL }; -InterfaceProxy* CreateURLUtilProxy(Dispatcher* dispatcher) { - return new PPB_URLUtil_Proxy(dispatcher); +InterfaceProxy* CreateURLUtilProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_URLUtil_Proxy(dispatcher, target_interface); } } // namespace -PPB_URLUtil_Proxy::PPB_URLUtil_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_url_util_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_url_util_impl_ = static_cast<const PPB_URLUtil_Dev*>( - dispatcher->local_get_interface()(PPB_URLUTIL_DEV_INTERFACE)); - } +PPB_URLUtil_Proxy::PPB_URLUtil_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_URLUtil_Proxy::~PPB_URLUtil_Proxy() { @@ -182,34 +179,34 @@ void PPB_URLUtil_Proxy::OnMsgResolveRelativeToDocument( SerializedVarReceiveInput relative, SerializedVarReturnValue result) { result.Return(dispatcher(), - ppb_url_util_impl_->ResolveRelativeToDocument( + ppb_url_util_target()->ResolveRelativeToDocument( instance, relative.Get(dispatcher()), NULL)); } void PPB_URLUtil_Proxy::OnMsgDocumentCanRequest(PP_Instance instance, SerializedVarReceiveInput url, PP_Bool* result) { - *result = ppb_url_util_impl_->DocumentCanRequest(instance, - url.Get(dispatcher())); + *result = ppb_url_util_target()->DocumentCanRequest(instance, + url.Get(dispatcher())); } void PPB_URLUtil_Proxy::OnMsgDocumentCanAccessDocument(PP_Instance active, PP_Instance target, PP_Bool* result) { - *result = ppb_url_util_impl_->DocumentCanAccessDocument( + *result = ppb_url_util_target()->DocumentCanAccessDocument( active, target); } void PPB_URLUtil_Proxy::OnMsgGetDocumentURL(PP_Instance instance, SerializedVarReturnValue result) { result.Return(dispatcher(), - ppb_url_util_impl_->GetDocumentURL(instance, NULL)); + ppb_url_util_target()->GetDocumentURL(instance, NULL)); } void PPB_URLUtil_Proxy::OnMsgGetPluginInstanceURL( PP_Instance instance, SerializedVarReturnValue result) { result.Return(dispatcher(), - ppb_url_util_impl_->GetPluginInstanceURL(instance, NULL)); + ppb_url_util_target()->GetPluginInstanceURL(instance, NULL)); } } // namespace proxy diff --git a/ppapi/proxy/ppb_url_util_proxy.h b/ppapi/proxy/ppb_url_util_proxy.h index 0571377..2c6cb40 100644 --- a/ppapi/proxy/ppb_url_util_proxy.h +++ b/ppapi/proxy/ppb_url_util_proxy.h @@ -16,11 +16,15 @@ namespace proxy { class PPB_URLUtil_Proxy : public InterfaceProxy { public: - PPB_URLUtil_Proxy(Dispatcher* dispatcher); + PPB_URLUtil_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_URLUtil_Proxy(); static const Info* GetInfo(); + const PPB_URLUtil_Dev* ppb_url_util_target() const { + return static_cast<const PPB_URLUtil_Dev*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -40,11 +44,6 @@ class PPB_URLUtil_Proxy : public InterfaceProxy { void OnMsgGetPluginInstanceURL(PP_Instance instance, SerializedVarReturnValue result); - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_URLUtil_Dev* ppb_url_util_impl_; - DISALLOW_COPY_AND_ASSIGN(PPB_URLUtil_Proxy); }; diff --git a/ppapi/proxy/ppb_var_deprecated_proxy.cc b/ppapi/proxy/ppb_var_deprecated_proxy.cc index 1850dc0f..396e50e 100644 --- a/ppapi/proxy/ppb_var_deprecated_proxy.cc +++ b/ppapi/proxy/ppb_var_deprecated_proxy.cc @@ -288,21 +288,18 @@ const PPB_Var_Deprecated var_deprecated_interface = { &CreateObject }; -InterfaceProxy* CreateVarDeprecatedProxy(Dispatcher* dispatcher) { - return new PPB_Var_Deprecated_Proxy(dispatcher ); +InterfaceProxy* CreateVarDeprecatedProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Var_Deprecated_Proxy(dispatcher, target_interface); } } // namespace PPB_Var_Deprecated_Proxy::PPB_Var_Deprecated_Proxy( - Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), - ppb_var_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_var_impl_ = static_cast<const PPB_Var_Deprecated*>( - dispatcher->local_get_interface()(PPB_VAR_DEPRECATED_INTERFACE)); - } + Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), + task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } PPB_Var_Deprecated_Proxy::~PPB_Var_Deprecated_Proxy() { @@ -363,7 +360,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgAddRefObject(int64 object_id, PP_Var var; var.type = PP_VARTYPE_OBJECT; var.value.as_id = object_id; - ppb_var_impl_->AddRef(var); + ppb_var_target()->AddRef(var); } void PPB_Var_Deprecated_Proxy::OnMsgReleaseObject(int64 object_id) { @@ -396,7 +393,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgHasProperty( SerializedVarOutParam exception, PP_Bool* result) { SetAllowPluginReentrancy(); - *result = PP_FromBool(ppb_var_impl_->HasProperty( + *result = PP_FromBool(ppb_var_target()->HasProperty( var.Get(dispatcher()), name.Get(dispatcher()), exception.OutParam(dispatcher()))); @@ -408,7 +405,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgHasMethodDeprecated( SerializedVarOutParam exception, PP_Bool* result) { SetAllowPluginReentrancy(); - *result = PP_FromBool(ppb_var_impl_->HasMethod( + *result = PP_FromBool(ppb_var_target()->HasMethod( var.Get(dispatcher()), name.Get(dispatcher()), exception.OutParam(dispatcher()))); @@ -420,7 +417,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgGetProperty( SerializedVarOutParam exception, SerializedVarReturnValue result) { SetAllowPluginReentrancy(); - result.Return(dispatcher(), ppb_var_impl_->GetProperty( + result.Return(dispatcher(), ppb_var_target()->GetProperty( var.Get(dispatcher()), name.Get(dispatcher()), exception.OutParam(dispatcher()))); } @@ -430,7 +427,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgEnumerateProperties( SerializedVarVectorOutParam props, SerializedVarOutParam exception) { SetAllowPluginReentrancy(); - ppb_var_impl_->GetAllPropertyNames(var.Get(dispatcher()), + ppb_var_target()->GetAllPropertyNames(var.Get(dispatcher()), props.CountOutParam(), props.ArrayOutParam(dispatcher()), exception.OutParam(dispatcher())); } @@ -441,7 +438,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgSetPropertyDeprecated( SerializedVarReceiveInput value, SerializedVarOutParam exception) { SetAllowPluginReentrancy(); - ppb_var_impl_->SetProperty(var.Get(dispatcher()), + ppb_var_target()->SetProperty(var.Get(dispatcher()), name.Get(dispatcher()), value.Get(dispatcher()), exception.OutParam(dispatcher())); @@ -453,7 +450,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgDeleteProperty( SerializedVarOutParam exception, PP_Bool* result) { SetAllowPluginReentrancy(); - ppb_var_impl_->RemoveProperty(var.Get(dispatcher()), + ppb_var_target()->RemoveProperty(var.Get(dispatcher()), name.Get(dispatcher()), exception.OutParam(dispatcher())); // This deprecated function doesn't actually return a value, but we re-use @@ -470,7 +467,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgCallDeprecated( SetAllowPluginReentrancy(); uint32_t arg_count = 0; PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); - result.Return(dispatcher(), ppb_var_impl_->Call( + result.Return(dispatcher(), ppb_var_target()->Call( object.Get(dispatcher()), method_name.Get(dispatcher()), arg_count, args, @@ -485,7 +482,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgConstruct( SetAllowPluginReentrancy(); uint32_t arg_count = 0; PP_Var* args = arg_vector.Get(dispatcher(), &arg_count); - result.Return(dispatcher(), ppb_var_impl_->Construct( + result.Return(dispatcher(), ppb_var_target()->Construct( var.Get(dispatcher()), arg_count, args, exception.OutParam(dispatcher()))); } @@ -505,7 +502,7 @@ void PPB_Var_Deprecated_Proxy::OnMsgCreateObjectDeprecated( SerializedVarReturnValue result) { SetAllowPluginReentrancy(); result.Return(dispatcher(), PPP_Class_Proxy::CreateProxiedObject( - ppb_var_impl_, dispatcher(), instance, ppp_class, class_data)); + ppb_var_target(), dispatcher(), instance, ppp_class, class_data)); } void PPB_Var_Deprecated_Proxy::SetAllowPluginReentrancy() { @@ -519,7 +516,7 @@ void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64 object_id) { PP_Var var; var.type = PP_VARTYPE_OBJECT; var.value.as_id = object_id; - ppb_var_impl_->Release(var); + ppb_var_target()->Release(var); } } // namespace proxy diff --git a/ppapi/proxy/ppb_var_deprecated_proxy.h b/ppapi/proxy/ppb_var_deprecated_proxy.h index ac8c1fd..d1a45a0 100644 --- a/ppapi/proxy/ppb_var_deprecated_proxy.h +++ b/ppapi/proxy/ppb_var_deprecated_proxy.h @@ -26,11 +26,16 @@ class SerializedVarReturnValue; class PPB_Var_Deprecated_Proxy : public InterfaceProxy { public: - PPB_Var_Deprecated_Proxy(Dispatcher* dispatcher); + PPB_Var_Deprecated_Proxy(Dispatcher* dispatcher, + const void* target_interface); virtual ~PPB_Var_Deprecated_Proxy(); static const Info* GetInfo(); + const PPB_Var_Deprecated* ppb_var_target() const { + return static_cast<const PPB_Var_Deprecated*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -91,10 +96,6 @@ class PPB_Var_Deprecated_Proxy : public InterfaceProxy { void DoReleaseObject(int64 object_id); ScopedRunnableMethodFactory<PPB_Var_Deprecated_Proxy> task_factory_; - - const PPB_Var_Deprecated* ppb_var_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPB_Var_Deprecated_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppb_var_proxy.cc b/ppapi/proxy/ppb_var_proxy.cc index 4ee6cc1..765deef 100644 --- a/ppapi/proxy/ppb_var_proxy.cc +++ b/ppapi/proxy/ppb_var_proxy.cc @@ -46,10 +46,37 @@ const PPB_Var var_interface = { &VarToUtf8 }; +InterfaceProxy* CreateVarProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Var_Proxy(dispatcher, target_interface); +} + } // namespace -const PPB_Var* GetPPB_Var_Interface() { - return &var_interface; +PPB_Var_Proxy::PPB_Var_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_Var_Proxy::~PPB_Var_Proxy() { +} + +// static +const InterfaceProxy::Info* PPB_Var_Proxy::GetInfo() { + static const Info info = { + &var_interface, + PPB_VAR_INTERFACE, + INTERFACE_ID_PPB_VAR, + false, + &CreateVarProxy, + }; + return &info; +} + +bool PPB_Var_Proxy::OnMessageReceived(const IPC::Message& msg) { + // All PPB_Var calls are handled locally; there is no need to send or receive + // messages here. + return false; } } // namespace proxy diff --git a/ppapi/proxy/ppb_var_proxy.h b/ppapi/proxy/ppb_var_proxy.h index 465042b9..6e060b9 100644 --- a/ppapi/proxy/ppb_var_proxy.h +++ b/ppapi/proxy/ppb_var_proxy.h @@ -5,7 +5,6 @@ #ifndef PPAPI_PPB_VAR_PROXY_H_ #define PPAPI_PPB_VAR_PROXY_H_ -#include "ppapi/proxy/ppapi_proxy_export.h" #include "ppapi/proxy/interface_proxy.h" struct PPB_Var; @@ -13,9 +12,23 @@ struct PPB_Var; namespace ppapi { namespace proxy { -// Returns a pointer to the plugin-specific implementation of PPB_Var. -// There is no proxy object since this is implemented entirely in-process. -PPAPI_PROXY_EXPORT const PPB_Var* GetPPB_Var_Interface(); +class PPB_Var_Proxy : public InterfaceProxy { + public: + PPB_Var_Proxy(Dispatcher* dispatcher, + const void* target_interface); + virtual ~PPB_Var_Proxy(); + + static const Info* GetInfo(); + + const PPB_Var* ppb_var_target() const { + return static_cast<const PPB_Var*>(target_interface()); + } + + // InterfaceProxy implementation. In this case, no messages are sent or + // received, so this always returns false. + virtual bool OnMessageReceived(const IPC::Message& msg); + +}; } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/ppb_var_unittest.cc b/ppapi/proxy/ppb_var_unittest.cc index 79abf39..485b599 100644 --- a/ppapi/proxy/ppb_var_unittest.cc +++ b/ppapi/proxy/ppb_var_unittest.cc @@ -9,7 +9,6 @@ #include "ppapi/c/pp_var.h" #include "ppapi/c/ppb_var.h" #include "ppapi/proxy/ppapi_proxy_test.h" -#include "ppapi/proxy/ppb_var_proxy.h" // TODO(dmichael): Make PPB_Var_Proxy and PluginResourceTracker thread-safe and // add thread-safety tests here. @@ -31,7 +30,8 @@ class PPB_VarTest : public PluginProxyTest { }; TEST_F(PPB_VarTest, Strings) { - const PPB_Var* ppb_var = GetPPB_Var_Interface(); + const PPB_Var* ppb_var = static_cast<const PPB_Var*>( + plugin_dispatcher()->GetInterfaceFromDispatcher(PPB_VAR_INTERFACE)); // Make a vector of strings, where the value of test_strings[i] is "i". const int kNumStrings = 5; diff --git a/ppapi/proxy/ppb_video_capture_proxy.cc b/ppapi/proxy/ppb_video_capture_proxy.cc index 9f40c1f..cae0b22 100644 --- a/ppapi/proxy/ppb_video_capture_proxy.cc +++ b/ppapi/proxy/ppb_video_capture_proxy.cc @@ -21,7 +21,6 @@ #include "ppapi/thunk/ppb_buffer_api.h" #include "ppapi/thunk/ppb_buffer_trusted_api.h" #include "ppapi/thunk/ppb_video_capture_api.h" -#include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" using ppapi::thunk::EnterResourceNoLock; @@ -34,8 +33,14 @@ namespace proxy { namespace { -InterfaceProxy* CreatePPPVideoCaptureProxy(Dispatcher* dispatcher) { - return new PPP_VideoCapture_Proxy(dispatcher); +InterfaceProxy* CreatePPBVideoCaptureProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_VideoCapture_Proxy(dispatcher, target_interface); +} + +InterfaceProxy* CreatePPPVideoCaptureProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPP_VideoCapture_Proxy(dispatcher, target_interface); } void OnDeviceInfo(PP_Instance instance, @@ -52,7 +57,7 @@ void OnDeviceInfo(PP_Instance instance, host_resource.SetHostResource(instance, resource); std::vector<PPPVideoCapture_Buffer> buffers(buffer_count); const PPB_Core* core = static_cast<const PPB_Core*>( - dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); + dispatcher->GetLocalInterface(PPB_CORE_INTERFACE)); DCHECK(core); for (uint32_t i = 0; i < buffer_count; ++i) { // We need to take a ref on the resource now. The browser may drop @@ -260,14 +265,27 @@ ppapi::thunk::PPB_VideoCapture_API* VideoCapture::AsPPB_VideoCapture_API() { return this; } -PPB_VideoCapture_Proxy::PPB_VideoCapture_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { +PPB_VideoCapture_Proxy::PPB_VideoCapture_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPB_VideoCapture_Proxy::~PPB_VideoCapture_Proxy() { } // static +const InterfaceProxy::Info* PPB_VideoCapture_Proxy::GetInfo() { + static const Info info = { + ppapi::thunk::GetPPB_VideoCapture_Thunk(), + PPB_VIDEO_CAPTURE_DEV_INTERFACE, + INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, + false, + &CreatePPBVideoCaptureProxy, + }; + return &info; +} + +// static PP_Resource PPB_VideoCapture_Proxy::CreateProxyResource(PP_Instance instance) { PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); if (!dispatcher) @@ -299,12 +317,11 @@ bool PPB_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_VideoCapture_Proxy::OnMsgCreate(PP_Instance instance, HostResource* result_resource) { - thunk::EnterResourceCreation enter(instance); - if (enter.succeeded()) { - result_resource->SetHostResource( - instance, - enter.functions()->CreateVideoCapture(instance)); - } + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); + if (!dispatcher) + return; + PP_Resource resource = ppb_video_capture_target()->Create(instance); + result_resource->SetHostResource(instance, resource); } void PPB_VideoCapture_Proxy::OnMsgStartCapture( @@ -329,13 +346,9 @@ void PPB_VideoCapture_Proxy::OnMsgStopCapture(const HostResource& resource) { enter.object()->StopCapture(); } -PPP_VideoCapture_Proxy::PPP_VideoCapture_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppp_video_capture_impl_(NULL) { - if (dispatcher->IsPlugin()) { - ppp_video_capture_impl_ = static_cast<const PPP_VideoCapture_Dev*>( - dispatcher->local_get_interface()(PPP_VIDEO_CAPTURE_DEV_INTERFACE)); - } +PPP_VideoCapture_Proxy::PPP_VideoCapture_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPP_VideoCapture_Proxy::~PPP_VideoCapture_Proxy() { @@ -375,7 +388,7 @@ void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo( EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); - if (!resource || !ppp_video_capture_impl_ || enter.failed()) + if (!resource || !ppp_video_capture_target() || enter.failed()) return; scoped_array<PP_Resource> resources(new PP_Resource[buffers.size()]); @@ -387,7 +400,7 @@ void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo( buffers[i].size); } static_cast<VideoCapture*>(enter.object())->SetBufferCount(buffers.size()); - ppp_video_capture_impl_->OnDeviceInfo( + ppp_video_capture_target()->OnDeviceInfo( host_resource.instance(), resource, &info, @@ -402,12 +415,12 @@ void PPP_VideoCapture_Proxy::OnMsgOnStatus(const HostResource& host_resource, EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); - if (!resource || !ppp_video_capture_impl_ || enter.failed()) + if (!resource || !ppp_video_capture_target() || enter.failed()) return; if (!static_cast<VideoCapture*>(enter.object())->OnStatus(status)) return; - ppp_video_capture_impl_->OnStatus( + ppp_video_capture_target()->OnStatus( host_resource.instance(), resource, status); } @@ -416,11 +429,11 @@ void PPP_VideoCapture_Proxy::OnMsgOnError(const HostResource& host_resource, EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); - if (!resource || !ppp_video_capture_impl_ || enter.failed()) + if (!resource || !ppp_video_capture_target() || enter.failed()) return; static_cast<VideoCapture*>(enter.object())->set_status( PP_VIDEO_CAPTURE_STATUS_STOPPED); - ppp_video_capture_impl_->OnError( + ppp_video_capture_target()->OnError( host_resource.instance(), resource, error_code); } @@ -429,10 +442,10 @@ void PPP_VideoCapture_Proxy::OnMsgOnBufferReady( EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); - if (!resource || !ppp_video_capture_impl_ || enter.failed()) + if (!resource || !ppp_video_capture_target() || enter.failed()) return; static_cast<VideoCapture*>(enter.object())->SetBufferInUse(buffer); - ppp_video_capture_impl_->OnBufferReady( + ppp_video_capture_target()->OnBufferReady( host_resource.instance(), resource, buffer); } diff --git a/ppapi/proxy/ppb_video_capture_proxy.h b/ppapi/proxy/ppb_video_capture_proxy.h index 5695579..e882700 100644 --- a/ppapi/proxy/ppb_video_capture_proxy.h +++ b/ppapi/proxy/ppb_video_capture_proxy.h @@ -21,16 +21,20 @@ namespace proxy { class PPB_VideoCapture_Proxy : public InterfaceProxy { public: - PPB_VideoCapture_Proxy(Dispatcher* dispatcher); + PPB_VideoCapture_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_VideoCapture_Proxy(); + static const Info* GetInfo(); + static PP_Resource CreateProxyResource(PP_Instance instance); + const PPB_VideoCapture_Dev* ppb_video_capture_target() const { + return static_cast<const PPB_VideoCapture_Dev*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV; - private: // Message handlers. void OnMsgCreate(PP_Instance instance, ppapi::HostResource* result_resource); @@ -40,22 +44,22 @@ class PPB_VideoCapture_Proxy : public InterfaceProxy { void OnMsgReuseBuffer(const ppapi::HostResource& resource, uint32_t buffer); void OnMsgStopCapture(const ppapi::HostResource& resource); - - DISALLOW_COPY_AND_ASSIGN(PPB_VideoCapture_Proxy); }; class PPP_VideoCapture_Proxy : public InterfaceProxy { public: - PPP_VideoCapture_Proxy(Dispatcher* dispatcher); + PPP_VideoCapture_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPP_VideoCapture_Proxy(); static const Info* GetInfo(); + const PPP_VideoCapture_Dev* ppp_video_capture_target() const { + return static_cast<const PPP_VideoCapture_Dev*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPP_VIDEO_CAPTURE_DEV; - private: // Message handlers. void OnMsgOnDeviceInfo(const ppapi::HostResource& video_capture, @@ -67,13 +71,6 @@ class PPP_VideoCapture_Proxy : public InterfaceProxy { uint32_t error_code); void OnMsgOnBufferReady(const ppapi::HostResource& video_capture, uint32_t buffer); - - // When this proxy is in the plugin side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the host, this value is always NULL. - const PPP_VideoCapture_Dev* ppp_video_capture_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPP_VideoCapture_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppb_video_decoder_proxy.cc b/ppapi/proxy/ppb_video_decoder_proxy.cc index 023b8c9..f9e4379 100644 --- a/ppapi/proxy/ppb_video_decoder_proxy.cc +++ b/ppapi/proxy/ppb_video_decoder_proxy.cc @@ -154,14 +154,36 @@ void VideoDecoder::EndOfBitstreamACK( RunBitstreamBufferCallback(bitstream_buffer_id, result); } -PPB_VideoDecoder_Proxy::PPB_VideoDecoder_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), +namespace { + +InterfaceProxy* CreateVideoDecoderProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_VideoDecoder_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPB_VideoDecoder_Proxy::PPB_VideoDecoder_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } PPB_VideoDecoder_Proxy::~PPB_VideoDecoder_Proxy() { } +// static +const InterfaceProxy::Info* PPB_VideoDecoder_Proxy::GetInfo() { + static const Info info = { + thunk::GetPPB_VideoDecoder_Thunk(), + PPB_VIDEODECODER_DEV_INTERFACE, + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, + false, + &CreateVideoDecoderProxy, + }; + return &info; +} + bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_VideoDecoder_Proxy, msg) @@ -230,7 +252,8 @@ void PPB_VideoDecoder_Proxy::OnMsgCreate( PP_Instance instance, const HostResource& graphics_context, PP_VideoDecoder_Profile profile, HostResource* result) { - thunk::EnterResourceCreation resource_creation(instance); + thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation(instance, + true); if (resource_creation.failed()) return; @@ -243,52 +266,46 @@ void PPB_VideoDecoder_Proxy::OnMsgCreate( void PPB_VideoDecoder_Proxy::OnMsgDecode( const HostResource& decoder, const HostResource& buffer, int32 id, int32 size) { - EnterHostFromHostResourceForceCallback<PPB_VideoDecoder_API> enter( - decoder, callback_factory_, + pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( &PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin, decoder, id); - if (enter.failed()) - return; + PP_VideoBitstreamBuffer_Dev bitstream = { id, buffer.host_resource(), size }; - enter.SetResult(enter.object()->Decode(&bitstream, enter.callback())); + ppb_video_decoder_target()->Decode( + decoder.host_resource(), &bitstream, callback.pp_completion_callback()); } void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers( const HostResource& decoder, const std::vector<PP_PictureBuffer_Dev>& buffers) { - EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder); - if (enter.succeeded() && !buffers.empty()) { - const PP_PictureBuffer_Dev* buffer_array = &buffers.front(); - enter.object()->AssignPictureBuffers(buffers.size(), buffer_array); - } + DCHECK(!buffers.empty()); + const PP_PictureBuffer_Dev* buffer_array = &buffers.front(); + + ppb_video_decoder_target()->AssignPictureBuffers( + decoder.host_resource(), buffers.size(), buffer_array); } void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer( const HostResource& decoder, int32 picture_buffer_id) { - EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder); - if (enter.succeeded()) - enter.object()->ReusePictureBuffer(picture_buffer_id); + ppb_video_decoder_target()->ReusePictureBuffer( + decoder.host_resource(), picture_buffer_id); } void PPB_VideoDecoder_Proxy::OnMsgFlush(const HostResource& decoder) { - EnterHostFromHostResourceForceCallback<PPB_VideoDecoder_API> enter( - decoder, callback_factory_, + pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( &PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin, decoder); - if (enter.succeeded()) - enter.SetResult(enter.object()->Flush(enter.callback())); + ppb_video_decoder_target()->Flush( + decoder.host_resource(), callback.pp_completion_callback()); } void PPB_VideoDecoder_Proxy::OnMsgReset(const HostResource& decoder) { - EnterHostFromHostResourceForceCallback<PPB_VideoDecoder_API> enter( - decoder, callback_factory_, + pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( &PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin, decoder); - if (enter.succeeded()) - enter.SetResult(enter.object()->Reset(enter.callback())); + ppb_video_decoder_target()->Reset( + decoder.host_resource(), callback.pp_completion_callback()); } void PPB_VideoDecoder_Proxy::OnMsgDestroy(const HostResource& decoder) { - EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder); - if (enter.succeeded()) - enter.object()->Destroy(); + ppb_video_decoder_target()->Destroy(decoder.host_resource()); } void PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin( diff --git a/ppapi/proxy/ppb_video_decoder_proxy.h b/ppapi/proxy/ppb_video_decoder_proxy.h index 32d1ec6..b34cb22 100644 --- a/ppapi/proxy/ppb_video_decoder_proxy.h +++ b/ppapi/proxy/ppb_video_decoder_proxy.h @@ -17,9 +17,11 @@ namespace proxy { class PPB_VideoDecoder_Proxy : public InterfaceProxy { public: - PPB_VideoDecoder_Proxy(Dispatcher* dispatcher); + PPB_VideoDecoder_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_VideoDecoder_Proxy(); + static const Info* GetInfo(); + // Creates a VideoDecoder object in the plugin process. static PP_Resource CreateProxyResource( PP_Instance instance, @@ -29,7 +31,9 @@ class PPB_VideoDecoder_Proxy : public InterfaceProxy { // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); - static const InterfaceID kInterfaceID = INTERFACE_ID_PPB_VIDEO_DECODER_DEV; + const PPB_VideoDecoder_Dev* ppb_video_decoder_target() const { + return static_cast<const PPB_VideoDecoder_Dev*>(target_interface()); + } private: // Message handlers in the renderer process to receive messages from the diff --git a/ppapi/proxy/ppp_class_proxy.cc b/ppapi/proxy/ppp_class_proxy.cc index 9a616f42..8ab109f 100644 --- a/ppapi/proxy/ppp_class_proxy.cc +++ b/ppapi/proxy/ppp_class_proxy.cc @@ -175,18 +175,13 @@ void* ToUserData(int64 value) { // PPP_Class_Proxy ------------------------------------------------------------- PPP_Class_Proxy::PPP_Class_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { + : InterfaceProxy(dispatcher, NULL) { } PPP_Class_Proxy::~PPP_Class_Proxy() { } // static -InterfaceProxy* PPP_Class_Proxy::Create(Dispatcher* dispatcher) { - return new PPP_Class_Proxy(dispatcher); -} - -// static PP_Var PPP_Class_Proxy::CreateProxiedObject(const PPB_Var_Deprecated* var, Dispatcher* dispatcher, PP_Module module_id, diff --git a/ppapi/proxy/ppp_class_proxy.h b/ppapi/proxy/ppp_class_proxy.h index 299c3ec..ce93770 100644 --- a/ppapi/proxy/ppp_class_proxy.h +++ b/ppapi/proxy/ppp_class_proxy.h @@ -31,10 +31,6 @@ class PPP_Class_Proxy : public InterfaceProxy { PPP_Class_Proxy(Dispatcher* dispatcher); virtual ~PPP_Class_Proxy(); - // Factory function used for registration (normal code can just use the - // constructor). - static InterfaceProxy* Create(Dispatcher* dispatcher); - // Creates a proxied object in the browser process. This takes the browser's // PPB_Var_Deprecated interface to use to create the object. The class and static PP_Var CreateProxiedObject(const PPB_Var_Deprecated* var, diff --git a/ppapi/proxy/ppp_graphics_3d_proxy.cc b/ppapi/proxy/ppp_graphics_3d_proxy.cc index 3cac4646..a477227 100644 --- a/ppapi/proxy/ppp_graphics_3d_proxy.cc +++ b/ppapi/proxy/ppp_graphics_3d_proxy.cc @@ -24,19 +24,16 @@ static const PPP_Graphics3D graphics_3d_interface = { &ContextLost }; -InterfaceProxy* CreateGraphics3DProxy(Dispatcher* dispatcher) { - return new PPP_Graphics3D_Proxy(dispatcher); +InterfaceProxy* CreateGraphics3DProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPP_Graphics3D_Proxy(dispatcher, target_interface); } } // namespace -PPP_Graphics3D_Proxy::PPP_Graphics3D_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppp_graphics_3d_impl_(NULL) { - if (dispatcher->IsPlugin()) { - ppp_graphics_3d_impl_ = static_cast<const PPP_Graphics3D*>( - dispatcher->local_get_interface()(PPP_GRAPHICS_3D_INTERFACE)); - } +PPP_Graphics3D_Proxy::PPP_Graphics3D_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPP_Graphics3D_Proxy::~PPP_Graphics3D_Proxy() { @@ -65,8 +62,8 @@ bool PPP_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { } void PPP_Graphics3D_Proxy::OnMsgContextLost(PP_Instance instance) { - if (ppp_graphics_3d_impl_) - ppp_graphics_3d_impl_->Graphics3DContextLost(instance); + if (ppp_graphics_3d_target()) + ppp_graphics_3d_target()->Graphics3DContextLost(instance); } } // namespace proxy diff --git a/ppapi/proxy/ppp_graphics_3d_proxy.h b/ppapi/proxy/ppp_graphics_3d_proxy.h index e340424..eb3d3b0 100644 --- a/ppapi/proxy/ppp_graphics_3d_proxy.h +++ b/ppapi/proxy/ppp_graphics_3d_proxy.h @@ -16,24 +16,21 @@ namespace proxy { class PPP_Graphics3D_Proxy : public InterfaceProxy { public: - PPP_Graphics3D_Proxy(Dispatcher* dispatcher); + PPP_Graphics3D_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPP_Graphics3D_Proxy(); static const Info* GetInfo(); + const PPP_Graphics3D* ppp_graphics_3d_target() const { + return reinterpret_cast<const PPP_Graphics3D*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); private: // Message handlers. void OnMsgContextLost(PP_Instance instance); - - // When this proxy is in the plugin side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the host, this value is always NULL. - const PPP_Graphics3D* ppp_graphics_3d_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPP_Graphics3D_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppp_input_event_proxy.cc b/ppapi/proxy/ppp_input_event_proxy.cc index 7d72dfe..a8843f5 100644 --- a/ppapi/proxy/ppp_input_event_proxy.cc +++ b/ppapi/proxy/ppp_input_event_proxy.cc @@ -11,6 +11,7 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/ppb_input_event_proxy.h" #include "ppapi/shared_impl/input_event_impl.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_input_event_api.h" @@ -52,19 +53,16 @@ static const PPP_InputEvent input_event_interface = { &HandleInputEvent }; -InterfaceProxy* CreateInputEventProxy(Dispatcher* dispatcher) { - return new PPP_InputEvent_Proxy(dispatcher); +InterfaceProxy* CreateInputEventProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPP_InputEvent_Proxy(dispatcher, target_interface); } } // namespace -PPP_InputEvent_Proxy::PPP_InputEvent_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppp_input_event_impl_(NULL) { - if (dispatcher->IsPlugin()) { - ppp_input_event_impl_ = static_cast<const PPP_InputEvent*>( - dispatcher->local_get_interface()(PPP_INPUT_EVENT_INTERFACE)); - } +PPP_InputEvent_Proxy::PPP_InputEvent_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPP_InputEvent_Proxy::~PPP_InputEvent_Proxy() { @@ -98,7 +96,7 @@ void PPP_InputEvent_Proxy::OnMsgHandleInputEvent(PP_Instance instance, const InputEventData& data) { scoped_refptr<InputEventImpl> resource(new InputEventImpl( InputEventImpl::InitAsProxy(), instance, data)); - ppp_input_event_impl_->HandleInputEvent(instance, resource->pp_resource()); + ppp_input_event_target()->HandleInputEvent(instance, resource->pp_resource()); } void PPP_InputEvent_Proxy::OnMsgHandleFilteredInputEvent( @@ -107,8 +105,8 @@ void PPP_InputEvent_Proxy::OnMsgHandleFilteredInputEvent( PP_Bool* result) { scoped_refptr<InputEventImpl> resource(new InputEventImpl( InputEventImpl::InitAsProxy(), instance, data)); - *result = ppp_input_event_impl_->HandleInputEvent(instance, - resource->pp_resource()); + *result = ppp_input_event_target()->HandleInputEvent(instance, + resource->pp_resource()); } } // namespace proxy diff --git a/ppapi/proxy/ppp_input_event_proxy.h b/ppapi/proxy/ppp_input_event_proxy.h index ffe5e868..e286250 100644 --- a/ppapi/proxy/ppp_input_event_proxy.h +++ b/ppapi/proxy/ppp_input_event_proxy.h @@ -18,11 +18,15 @@ namespace proxy { class PPP_InputEvent_Proxy : public InterfaceProxy { public: - PPP_InputEvent_Proxy(Dispatcher* dispatcher); + PPP_InputEvent_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPP_InputEvent_Proxy(); static const Info* GetInfo(); + const PPP_InputEvent* ppp_input_event_target() const { + return static_cast<const PPP_InputEvent*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -33,13 +37,6 @@ class PPP_InputEvent_Proxy : public InterfaceProxy { void OnMsgHandleFilteredInputEvent(PP_Instance instance, const ppapi::InputEventData& data, PP_Bool* result); - - // When this proxy is in the plugin side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the host, this value is always NULL. - const PPP_InputEvent* ppp_input_event_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPP_InputEvent_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppp_instance_private_proxy.cc b/ppapi/proxy/ppp_instance_private_proxy.cc index 82057a6..4ecd6a6 100644 --- a/ppapi/proxy/ppp_instance_private_proxy.cc +++ b/ppapi/proxy/ppp_instance_private_proxy.cc @@ -30,19 +30,16 @@ static const PPP_Instance_Private instance_private_interface = { &GetInstanceObject }; -InterfaceProxy* CreateInstancePrivateProxy(Dispatcher* dispatcher) { - return new PPP_Instance_Private_Proxy(dispatcher); +InterfaceProxy* CreateInstancePrivateProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPP_Instance_Private_Proxy(dispatcher, target_interface); } } // namespace -PPP_Instance_Private_Proxy::PPP_Instance_Private_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppp_instance_private_impl_(NULL) { - if (dispatcher->IsPlugin()) { - ppp_instance_private_impl_ = static_cast<const PPP_Instance_Private*>( - dispatcher->local_get_interface()(PPP_INSTANCE_PRIVATE_INTERFACE)); - } +PPP_Instance_Private_Proxy::PPP_Instance_Private_Proxy( + Dispatcher* dispatcher, const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPP_Instance_Private_Proxy::~PPP_Instance_Private_Proxy() { @@ -74,7 +71,7 @@ void PPP_Instance_Private_Proxy::OnMsgGetInstanceObject( PP_Instance instance, SerializedVarReturnValue result) { result.Return(dispatcher(), - ppp_instance_private_impl_->GetInstanceObject(instance)); + ppp_instance_private_target()->GetInstanceObject(instance)); } } // namespace proxy diff --git a/ppapi/proxy/ppp_instance_private_proxy.h b/ppapi/proxy/ppp_instance_private_proxy.h index 1759eb9..afab722 100644 --- a/ppapi/proxy/ppp_instance_private_proxy.h +++ b/ppapi/proxy/ppp_instance_private_proxy.h @@ -20,11 +20,16 @@ class SerializedVarReturnValue; class PPP_Instance_Private_Proxy : public InterfaceProxy { public: - PPP_Instance_Private_Proxy(Dispatcher* dispatcher); + PPP_Instance_Private_Proxy(Dispatcher* dispatcher, + const void* target_interface); virtual ~PPP_Instance_Private_Proxy(); static const Info* GetInfo(); + const PPP_Instance_Private* ppp_instance_private_target() const { + return reinterpret_cast<const PPP_Instance_Private*>(target_interface()); + } + private: // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -32,13 +37,6 @@ class PPP_Instance_Private_Proxy : public InterfaceProxy { // Message handlers. void OnMsgGetInstanceObject(PP_Instance instance, SerializedVarReturnValue result); - - // When this proxy is in the plugin side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the host, this value is always NULL. - const PPP_Instance_Private* ppp_instance_private_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPP_Instance_Private_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppp_instance_proxy.cc b/ppapi/proxy/ppp_instance_proxy.cc index aa4b7e7..1da10be 100644 --- a/ppapi/proxy/ppp_instance_proxy.cc +++ b/ppapi/proxy/ppp_instance_proxy.cc @@ -50,7 +50,7 @@ void DidChangeView(PP_Instance instance, HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); const PPB_Fullscreen_Dev* fullscreen_interface = static_cast<const PPB_Fullscreen_Dev*>( - dispatcher->local_get_interface()(PPB_FULLSCREEN_DEV_INTERFACE)); + dispatcher->GetLocalInterface(PPB_FULLSCREEN_DEV_INTERFACE)); DCHECK(fullscreen_interface); PP_Bool fullscreen = fullscreen_interface->IsFullscreen(instance); dispatcher->Send( @@ -73,7 +73,7 @@ PP_Bool HandleDocumentLoad(PP_Instance instance, // Set up the URLLoader for proxying. PPB_URLLoader_Proxy* url_loader_proxy = static_cast<PPB_URLLoader_Proxy*>( - dispatcher->GetInterfaceProxy(INTERFACE_ID_PPB_URL_LOADER)); + dispatcher->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_URL_LOADER)); url_loader_proxy->PrepareURLLoaderForSendingToPlugin(url_loader); // PluginResourceTracker in the plugin process assumes that resources that it @@ -83,7 +83,7 @@ PP_Bool HandleDocumentLoad(PP_Instance instance, // Please also see comments in PPP_Instance_Proxy::OnMsgHandleDocumentLoad() // about releasing of this extra reference. const PPB_Core* core = reinterpret_cast<const PPB_Core*>( - dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); + dispatcher->GetLocalInterface(PPB_CORE_INTERFACE)); if (!core) { NOTREACHED(); return PP_FALSE; @@ -105,21 +105,16 @@ static const PPP_Instance_1_0 instance_interface_1_0 = { &HandleDocumentLoad }; -InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher) { - return new PPP_Instance_Proxy(dispatcher); +template <class PPP_Instance_Type> +InterfaceProxy* CreateInstanceProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPP_Instance_Proxy( + dispatcher, + static_cast<const PPP_Instance_Type*>(target_interface)); } } // namespace -PPP_Instance_Proxy::PPP_Instance_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { - if (dispatcher->IsPlugin()) { - combined_interface_.reset( - new PPP_Instance_Combined(*static_cast<const PPP_Instance_1_0*>( - dispatcher->local_get_interface()(PPP_INSTANCE_INTERFACE_1_0)))); - } -} - PPP_Instance_Proxy::~PPP_Instance_Proxy() { } @@ -130,7 +125,7 @@ const InterfaceProxy::Info* PPP_Instance_Proxy::GetInfo1_0() { PPP_INSTANCE_INTERFACE_1_0, INTERFACE_ID_PPP_INSTANCE, false, - &CreateInstanceProxy + &CreateInstanceProxy<PPP_Instance_1_0>, }; return &info; } diff --git a/ppapi/proxy/ppp_instance_proxy.h b/ppapi/proxy/ppp_instance_proxy.h index 7b70245..f9b471c 100644 --- a/ppapi/proxy/ppp_instance_proxy.h +++ b/ppapi/proxy/ppp_instance_proxy.h @@ -25,7 +25,12 @@ class SerializedVarReturnValue; class PPP_Instance_Proxy : public InterfaceProxy { public: - PPP_Instance_Proxy(Dispatcher* dispatcher); + template <class PPP_Instance_Type> + PPP_Instance_Proxy(Dispatcher* dispatcher, + const PPP_Instance_Type* target_interface) + : InterfaceProxy(dispatcher, static_cast<const void*>(target_interface)), + combined_interface_(new PPP_Instance_Combined(*target_interface)) { + } virtual ~PPP_Instance_Proxy(); // Return the info for the 1.0 (latest, canonical) version of the interface. diff --git a/ppapi/proxy/ppp_messaging_proxy.cc b/ppapi/proxy/ppp_messaging_proxy.cc index 390794a..59f4574 100644 --- a/ppapi/proxy/ppp_messaging_proxy.cc +++ b/ppapi/proxy/ppp_messaging_proxy.cc @@ -37,19 +37,16 @@ static const PPP_Messaging messaging_interface = { &HandleMessage }; -InterfaceProxy* CreateMessagingProxy(Dispatcher* dispatcher) { - return new PPP_Messaging_Proxy(dispatcher); +InterfaceProxy* CreateMessagingProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPP_Messaging_Proxy(dispatcher, target_interface); } } // namespace -PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppp_messaging_impl_(NULL) { - if (dispatcher->IsPlugin()) { - ppp_messaging_impl_ = static_cast<const PPP_Messaging*>( - dispatcher->local_get_interface()(PPP_MESSAGING_INTERFACE)); - } +PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPP_Messaging_Proxy::~PPP_Messaging_Proxy() { @@ -83,7 +80,7 @@ void PPP_Messaging_Proxy::OnMsgHandleMessage( // SerializedVarReceiveInput will decrement the reference count, but we want // to give the recipient a reference. PluginResourceTracker::GetInstance()->var_tracker().AddRefVar(received_var); - ppp_messaging_impl_->HandleMessage(instance, received_var); + ppp_messaging_target()->HandleMessage(instance, received_var); } } // namespace proxy diff --git a/ppapi/proxy/ppp_messaging_proxy.h b/ppapi/proxy/ppp_messaging_proxy.h index bc898f31..2deb40f 100644 --- a/ppapi/proxy/ppp_messaging_proxy.h +++ b/ppapi/proxy/ppp_messaging_proxy.h @@ -17,11 +17,15 @@ class SerializedVarReceiveInput; class PPP_Messaging_Proxy : public InterfaceProxy { public: - PPP_Messaging_Proxy(Dispatcher* dispatcher); + PPP_Messaging_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPP_Messaging_Proxy(); static const Info* GetInfo(); + const PPP_Messaging* ppp_messaging_target() const { + return static_cast<const PPP_Messaging*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; @@ -29,13 +33,6 @@ class PPP_Messaging_Proxy : public InterfaceProxy { // Message handlers. void OnMsgHandleMessage(PP_Instance instance, SerializedVarReceiveInput data); - - // When this proxy is in the plugin side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the host, this value is always NULL. - const PPP_Messaging* ppp_messaging_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPP_Messaging_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppp_mouse_lock_proxy.cc b/ppapi/proxy/ppp_mouse_lock_proxy.cc index e39a914..8980bcf 100644 --- a/ppapi/proxy/ppp_mouse_lock_proxy.cc +++ b/ppapi/proxy/ppp_mouse_lock_proxy.cc @@ -29,18 +29,16 @@ static const PPP_MouseLock_Dev mouse_lock_interface = { &MouseLockLost }; -InterfaceProxy* CreateMouseLockProxy(Dispatcher* dispatcher) { - return new PPP_MouseLock_Proxy(dispatcher); +InterfaceProxy* CreateMouseLockProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPP_MouseLock_Proxy(dispatcher, target_interface); } } // namespace -PPP_MouseLock_Proxy::PPP_MouseLock_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { - if (dispatcher->IsPlugin()) { - ppp_mouse_lock_impl_ = static_cast<const PPP_MouseLock_Dev*>( - dispatcher->local_get_interface()(PPP_MOUSELOCK_DEV_INTERFACE)); - } +PPP_MouseLock_Proxy::PPP_MouseLock_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPP_MouseLock_Proxy::~PPP_MouseLock_Proxy() { @@ -69,8 +67,8 @@ bool PPP_MouseLock_Proxy::OnMessageReceived(const IPC::Message& msg) { } void PPP_MouseLock_Proxy::OnMsgMouseLockLost(PP_Instance instance) { - if (ppp_mouse_lock_impl_) - ppp_mouse_lock_impl_->MouseLockLost(instance); + if (ppp_mouse_lock_target()) + ppp_mouse_lock_target()->MouseLockLost(instance); } } // namespace proxy diff --git a/ppapi/proxy/ppp_mouse_lock_proxy.h b/ppapi/proxy/ppp_mouse_lock_proxy.h index 752e97a..cfd451c 100644 --- a/ppapi/proxy/ppp_mouse_lock_proxy.h +++ b/ppapi/proxy/ppp_mouse_lock_proxy.h @@ -15,24 +15,21 @@ namespace proxy { class PPP_MouseLock_Proxy : public InterfaceProxy { public: - PPP_MouseLock_Proxy(Dispatcher* dispatcher); + PPP_MouseLock_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPP_MouseLock_Proxy(); static const Info* GetInfo(); + const PPP_MouseLock_Dev* ppp_mouse_lock_target() const { + return static_cast<const PPP_MouseLock_Dev*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; private: // Message handlers. void OnMsgMouseLockLost(PP_Instance instance); - - // When this proxy is in the plugin side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the host, this value is always NULL. - const PPP_MouseLock_Dev* ppp_mouse_lock_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPP_MouseLock_Proxy); }; } // namespace proxy diff --git a/ppapi/proxy/ppp_video_decoder_proxy.cc b/ppapi/proxy/ppp_video_decoder_proxy.cc index 325a695..35a29c0 100644 --- a/ppapi/proxy/ppp_video_decoder_proxy.cc +++ b/ppapi/proxy/ppp_video_decoder_proxy.cc @@ -78,19 +78,16 @@ static const PPP_VideoDecoder_Dev video_decoder_interface = { &NotifyError }; -InterfaceProxy* CreateVideoDecoderPPPProxy(Dispatcher* dispatcher) { - return new PPP_VideoDecoder_Proxy(dispatcher); +InterfaceProxy* CreateVideoDecoderPPPProxy( + Dispatcher* dispatcher, const void* target_interface) { + return new PPP_VideoDecoder_Proxy(dispatcher, target_interface); } } // namespace -PPP_VideoDecoder_Proxy::PPP_VideoDecoder_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppp_video_decoder_impl_(NULL) { - if (dispatcher->IsPlugin()) { - ppp_video_decoder_impl_ = static_cast<const PPP_VideoDecoder_Dev*>( - dispatcher->local_get_interface()(PPP_VIDEODECODER_DEV_INTERFACE)); - } +PPP_VideoDecoder_Proxy::PPP_VideoDecoder_Proxy( + Dispatcher* dispatcher, const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { } PPP_VideoDecoder_Proxy::~PPP_VideoDecoder_Proxy() { @@ -132,7 +129,7 @@ void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers( const PP_Size& dimensions) { PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); - ppp_video_decoder_impl_->ProvidePictureBuffers( + ppp_video_decoder_target()->ProvidePictureBuffers( decoder.instance(), plugin_decoder, req_num_of_bufs, dimensions); } @@ -140,7 +137,7 @@ void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer( const HostResource& decoder, int32_t picture_id) { PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); - ppp_video_decoder_impl_->DismissPictureBuffer( + ppp_video_decoder_target()->DismissPictureBuffer( decoder.instance(), plugin_decoder, picture_id); } @@ -148,7 +145,7 @@ void PPP_VideoDecoder_Proxy::OnMsgPictureReady( const HostResource& decoder, const PP_Picture_Dev& picture) { PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); - ppp_video_decoder_impl_->PictureReady( + ppp_video_decoder_target()->PictureReady( decoder.instance(), plugin_decoder, picture); } @@ -156,7 +153,7 @@ void PPP_VideoDecoder_Proxy::OnMsgNotifyEndOfStream( const HostResource& decoder) { PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); - ppp_video_decoder_impl_->EndOfStream(decoder.instance(), + ppp_video_decoder_target()->EndOfStream(decoder.instance(), plugin_decoder); } @@ -164,7 +161,7 @@ void PPP_VideoDecoder_Proxy::OnMsgNotifyError( const HostResource& decoder, PP_VideoDecodeError_Dev error) { PP_Resource plugin_decoder = PluginResourceTracker::GetInstance()-> PluginResourceForHostResource(decoder); - ppp_video_decoder_impl_->NotifyError( + ppp_video_decoder_target()->NotifyError( decoder.instance(), plugin_decoder, error); } diff --git a/ppapi/proxy/ppp_video_decoder_proxy.h b/ppapi/proxy/ppp_video_decoder_proxy.h index e12c668..84346ba 100644 --- a/ppapi/proxy/ppp_video_decoder_proxy.h +++ b/ppapi/proxy/ppp_video_decoder_proxy.h @@ -18,11 +18,15 @@ namespace proxy { class PPP_VideoDecoder_Proxy : public InterfaceProxy { public: - PPP_VideoDecoder_Proxy(Dispatcher* dispatcher); + PPP_VideoDecoder_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPP_VideoDecoder_Proxy(); static const Info* GetInfo(); + const PPP_VideoDecoder_Dev* ppp_video_decoder_target() const { + return static_cast<const PPP_VideoDecoder_Dev*>(target_interface()); + } + // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); @@ -39,11 +43,6 @@ class PPP_VideoDecoder_Proxy : public InterfaceProxy { void OnMsgNotifyError(const ppapi::HostResource& decoder, PP_VideoDecodeError_Dev error); - // When this proxy is in the plugin side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the host, this value is always NULL. - const PPP_VideoDecoder_Dev* ppp_video_decoder_impl_; - DISALLOW_COPY_AND_ASSIGN(PPP_VideoDecoder_Proxy); }; diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index f3ee425..0a0c791 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -45,17 +45,12 @@ namespace ppapi { namespace proxy { ResourceCreationProxy::ResourceCreationProxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { + : dispatcher_(dispatcher) { } ResourceCreationProxy::~ResourceCreationProxy() { } -// static -InterfaceProxy* ResourceCreationProxy::Create(Dispatcher* dispatcher) { - return new ResourceCreationProxy(dispatcher); -} - ResourceCreationAPI* ResourceCreationProxy::AsResourceCreationAPI() { return this; } @@ -342,7 +337,7 @@ PP_Resource ResourceCreationProxy::CreateWheelInputEvent( } bool ResourceCreationProxy::Send(IPC::Message* msg) { - return dispatcher()->Send(msg); + return dispatcher_->Send(msg); } bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) { @@ -400,14 +395,14 @@ void ResourceCreationProxy::OnMsgCreateImageData( // Get the shared memory handle. const PPB_ImageDataTrusted* trusted = reinterpret_cast<const PPB_ImageDataTrusted*>( - dispatcher()->local_get_interface()(PPB_IMAGEDATA_TRUSTED_INTERFACE)); + dispatcher_->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE)); uint32_t byte_count = 0; if (trusted) { int32_t handle; if (trusted->GetSharedMemory(resource, &handle, &byte_count) == PP_OK) { #if defined(OS_WIN) ImageHandle ih = ImageData::HandleFromInt(handle); - *result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false); + *result_image_handle = dispatcher_->ShareHandleWithRemote(ih, false); #else *result_image_handle = ImageData::HandleFromInt(handle); #endif diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 1db9164..0f1589b 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -11,8 +11,8 @@ #include "ipc/ipc_channel.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_instance.h" -#include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/serialized_structs.h" +#include "ppapi/shared_impl/function_group_base.h" #include "ppapi/thunk/resource_creation_api.h" struct PP_Size; @@ -25,16 +25,14 @@ namespace proxy { class Dispatcher; -class ResourceCreationProxy : public InterfaceProxy, - public thunk::ResourceCreationAPI { +class ResourceCreationProxy : public FunctionGroupBase, + public thunk::ResourceCreationAPI, + public IPC::Channel::Listener, + public IPC::Message::Sender { public: explicit ResourceCreationProxy(Dispatcher* dispatcher); virtual ~ResourceCreationProxy(); - // Factory function used for registration (normal code can just use the - // constructor). - static InterfaceProxy* Create(Dispatcher* dispatcher); - virtual thunk::ResourceCreationAPI* AsResourceCreationAPI() OVERRIDE; // ResourceCreationAPI (called in plugin). @@ -151,6 +149,8 @@ class ResourceCreationProxy : public InterfaceProxy, std::string* image_data_desc, ImageHandle* result_image_handle); + Dispatcher* dispatcher_; + DISALLOW_COPY_AND_ASSIGN(ResourceCreationProxy); }; |