diff options
52 files changed, 1280 insertions, 589 deletions
diff --git a/chrome/test/ui/ppapi_uitest.cc b/chrome/test/ui/ppapi_uitest.cc index 7e0e6a0..b5d8654 100644 --- a/chrome/test/ui/ppapi_uitest.cc +++ b/chrome/test/ui/ppapi_uitest.cc @@ -116,6 +116,14 @@ class PPAPITest : public UITest { } }; +TEST_F(PPAPITest, Broker) { + RunTest("Broker"); +} + +TEST_F(PPAPITest, CursorControl) { + RunTest("CursorControl"); +} + TEST_F(PPAPITest, FAILS_Instance) { RunTest("Instance"); } diff --git a/ppapi/c/trusted/ppb_broker_trusted.h b/ppapi/c/trusted/ppb_broker_trusted.h index a3c498e..84fb924 100644 --- a/ppapi/c/trusted/ppb_broker_trusted.h +++ b/ppapi/c/trusted/ppb_broker_trusted.h @@ -63,10 +63,12 @@ struct PPB_BrokerTrusted { struct PP_CompletionCallback connect_callback); /** - * Returns the handle to the pipe. Use once Connect has completed. - * Returns PP_OK on success. - * Each instance of this interface has its own pipe. - * handle is only set when returning PP_OK. + * Gets the handle to the pipe. Use once Connect has completed. Each instance + * of this interface has its own pipe. + * + * Returns PP_OK on success, and places the result into the given output + * parameter. The handle is only set when returning PP_OK. Calling this + * before connect has completed will return PP_ERROR_FAILED. */ int32_t (*GetHandle)(PP_Resource broker, int32_t* handle); }; diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 4568b56..43e6c28 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -51,6 +51,14 @@ 'thunk/ppb_audio_thunk.cc', 'thunk/ppb_audio_trusted_api.h', 'thunk/ppb_audio_trusted_thunk.cc', + 'thunk/ppb_broker_api.h', + 'thunk/ppb_broker_thunk.cc', + 'thunk/ppb_buffer_api.h', + 'thunk/ppb_buffer_thunk.cc', + 'thunk/ppb_char_set_api.h', + 'thunk/ppb_char_set_thunk.cc', + 'thunk/ppb_cursor_control_api.h', + 'thunk/ppb_cursor_control_thunk.cc', 'thunk/ppb_font_api.h', 'thunk/ppb_font_thunk.cc', 'thunk/ppb_graphics_2d_api.h', diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi index ec83d41..0fa6e7b 100644 --- a/ppapi/ppapi_tests.gypi +++ b/ppapi/ppapi_tests.gypi @@ -199,12 +199,16 @@ 'tests/all_cpp_includes.h', 'tests/arch_dependent_sizes_32.h', 'tests/arch_dependent_sizes_64.h', + 'tests/test_broker.cc', + 'tests/test_broker.h', 'tests/test_buffer.cc', 'tests/test_buffer.h', 'tests/test_c_includes.c', 'tests/test_char_set.cc', 'tests/test_char_set.h', 'tests/test_cpp_includes.cc', + 'tests/test_cursor_control.cc', + 'tests/test_cursor_control.h', 'tests/test_directory_reader.cc', 'tests/test_directory_reader.h', 'tests/test_file_io.cc', diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index 4ce47c6..e9a2c4e 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -17,6 +17,8 @@ #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/plugin_var_serialization_rules.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/ppb_char_set_proxy.h" +#include "ppapi/proxy/ppb_cursor_control_proxy.h" #include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppp_class_proxy.h" #include "ppapi/proxy/resource_creation_proxy.h" @@ -222,15 +224,21 @@ ppapi::WebKitForwarding* PluginDispatcher::GetWebKitForwarding() { ::ppapi::FunctionGroupBase* PluginDispatcher::GetFunctionAPI( pp::proxy::InterfaceID id) { - if (function_proxies_[id].get()) - return function_proxies_[id].get(); + scoped_ptr< ::ppapi::FunctionGroupBase >& proxy = function_proxies_[id]; - if (id == INTERFACE_ID_RESOURCE_CREATION) - function_proxies_[id].reset(new ResourceCreationProxy(this)); - if (id == INTERFACE_ID_PPB_FONT) - function_proxies_[id].reset(new PPB_Font_Proxy(this, NULL)); + if (proxy.get()) + return proxy.get(); - return function_proxies_[id].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_RESOURCE_CREATION) + proxy.reset(new ResourceCreationProxy(this)); + + return proxy.get(); } void PluginDispatcher::ForceFreeAllInstances() { diff --git a/ppapi/proxy/ppb_broker_proxy.cc b/ppapi/proxy/ppb_broker_proxy.cc index 0a6d781..74aa4a2 100644 --- a/ppapi/proxy/ppb_broker_proxy.cc +++ b/ppapi/proxy/ppb_broker_proxy.cc @@ -9,18 +9,60 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/thunk/ppb_broker_api.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/thunk.h" namespace pp { namespace proxy { -class Broker : public PluginResource { +namespace { + +base::PlatformFile IntToPlatformFile(int32_t handle) { +#if defined(OS_WIN) + return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle)); +#elif defined(OS_POSIX) + return handle; +#else + #error Not implemented. +#endif +} + +int32_t PlatformFileToInt(base::PlatformFile handle) { +#if defined(OS_WIN) + return static_cast<int32_t>(reinterpret_cast<intptr_t>(handle)); +#elif defined(OS_POSIX) + return handle; +#else + #error Not implemented. +#endif +} + +InterfaceProxy* CreateBrokerProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Broker_Proxy(dispatcher, target_interface); +} + +} // namespace + +class Broker : public ppapi::thunk::PPB_Broker_API, + public PluginResource { public: explicit Broker(const HostResource& resource); virtual ~Broker(); - // Resource overrides. - virtual Broker* AsBroker() { return this; } + // ResourceObjectBase overries. + virtual ppapi::thunk::PPB_Broker_API* AsBroker_API() OVERRIDE; + + // PPB_Broker_API implementation. + virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE; + virtual int32_t GetHandle(int32_t* handle) OVERRIDE; + // Called by the proxy when the host side has completed the request. + void ConnectComplete(IPC::PlatformFileForTransit socket_handle, + int32_t result); + + private: bool called_connect_; PP_CompletionCallback current_connect_callback_; @@ -30,7 +72,6 @@ class Broker : public PluginResource { // to read, but the plugin side of the proxy never takes ownership. base::SyncSocket::Handle socket_handle_; - private: DISALLOW_COPY_AND_ASSIGN(Broker); }; @@ -54,98 +95,56 @@ Broker::~Broker() { socket_handle_ = base::kInvalidPlatformFileValue; } -namespace { - -base::PlatformFile IntToPlatformFile(int32_t handle) { -#if defined(OS_WIN) - return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle)); -#elif defined(OS_POSIX) - return handle; -#else - #error Not implemented. -#endif -} - -int32_t PlatformFileToInt(base::PlatformFile handle) { -#if defined(OS_WIN) - return static_cast<int32_t>(reinterpret_cast<intptr_t>(handle)); -#elif defined(OS_POSIX) - return handle; -#else - #error Not implemented. -#endif -} - -PP_Resource CreateTrusted(PP_Instance instance) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return 0; - - HostResource result; - dispatcher->Send(new PpapiHostMsg_PPBBroker_Create( - INTERFACE_ID_PPB_BROKER, instance, &result)); - if (result.is_null()) - return 0; - - linked_ptr<Broker> object(new Broker(result)); - return PluginResourceTracker::GetInstance()->AddResource(object); -} - -PP_Bool IsBrokerTrusted(PP_Resource resource) { - Broker* object = PluginResource::GetAs<Broker>(resource); - return BoolToPPBool(!!object); +ppapi::thunk::PPB_Broker_API* Broker::AsBroker_API() { + return this; } -int32_t Connect(PP_Resource resource, - PP_CompletionCallback connect_callback) { - Broker* object = PluginResource::GetAs<Broker>(resource); - if (!object) - return PP_ERROR_BADRESOURCE; - - Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance()); - if (!dispatcher) - return PP_ERROR_BADRESOURCE; - +int32_t Broker::Connect(PP_CompletionCallback connect_callback) { if (!connect_callback.func) { // Synchronous calls are not supported. return PP_ERROR_BADARGUMENT; } - if (object->current_connect_callback_.func) + if (current_connect_callback_.func) return PP_ERROR_INPROGRESS; - else if (object->called_connect_) + else if (called_connect_) return PP_ERROR_FAILED; - object->current_connect_callback_ = connect_callback; - object->called_connect_ = true; + current_connect_callback_ = connect_callback; + called_connect_ = true; - bool success = dispatcher->Send(new PpapiHostMsg_PPBBroker_Connect( - INTERFACE_ID_PPB_BROKER, - object->host_resource())); + bool success = GetDispatcher()->Send(new PpapiHostMsg_PPBBroker_Connect( + INTERFACE_ID_PPB_BROKER, host_resource())); return success ? PP_OK_COMPLETIONPENDING : PP_ERROR_FAILED; } -int32_t GetHandle(PP_Resource resource, int32_t* handle) { - Broker* object = PluginResource::GetAs<Broker>(resource); - if (!object) - return PP_ERROR_BADRESOURCE; - *handle = PlatformFileToInt(object->socket_handle_); +int32_t Broker::GetHandle(int32_t* handle) { + if (socket_handle_ == base::kInvalidPlatformFileValue) + return PP_ERROR_FAILED; + *handle = PlatformFileToInt(socket_handle_); return PP_OK; } -const PPB_BrokerTrusted broker_interface = { - &CreateTrusted, - &IsBrokerTrusted, - &Connect, - &GetHandle, -}; +void Broker::ConnectComplete(IPC::PlatformFileForTransit socket_handle, + int32_t result) { + if (result == PP_OK) { + DCHECK(socket_handle_ == base::kInvalidPlatformFileValue); + socket_handle_ = IPC::PlatformFileForTransitToPlatformFile(socket_handle); + } else { + // The caller may still have given us a handle in the failure case. + // The easiest way to clean it up is to just put it in an object + // and then close them. This failure case is not performance critical. + base::SyncSocket temp_socket( + IPC::PlatformFileForTransitToPlatformFile(socket_handle)); + } -InterfaceProxy* CreateBrokerProxy(Dispatcher* dispatcher, - const void* target_interface) { - return new PPB_Broker_Proxy(dispatcher, target_interface); -} + if (!current_connect_callback_.func) { + // The handle might leak if the plugin never calls GetHandle(). + return; + } -} // namespace + PP_RunAndClearCompletionCallback(¤t_connect_callback_, result); +} PPB_Broker_Proxy::PPB_Broker_Proxy(Dispatcher* dispatcher, const void* target_interface) @@ -159,7 +158,7 @@ PPB_Broker_Proxy::~PPB_Broker_Proxy() { // static const InterfaceProxy::Info* PPB_Broker_Proxy::GetInfo() { static const Info info = { - &broker_interface, + ppapi::thunk::GetPPB_Broker_Thunk(), PPB_BROKER_TRUSTED_INTERFACE, INTERFACE_ID_PPB_BROKER, true, @@ -168,6 +167,22 @@ const InterfaceProxy::Info* PPB_Broker_Proxy::GetInfo() { return &info; } +// static +PP_Resource PPB_Broker_Proxy::CreateProxyResource(PP_Instance instance) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return 0; + + HostResource result; + dispatcher->Send(new PpapiHostMsg_PPBBroker_Create( + INTERFACE_ID_PPB_BROKER, instance, &result)); + if (result.is_null()) + return 0; + + linked_ptr<Broker> object(new Broker(result)); + return PluginResourceTracker::GetInstance()->AddResource(object); +} + bool PPB_Broker_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_Broker_Proxy, msg) @@ -203,38 +218,22 @@ void PPB_Broker_Proxy::OnMsgConnect(const HostResource& broker) { // the plugin owns the handle and is responsible for closing it. // The caller guarantees that socket_handle is not valid if result is not PP_OK. void PPB_Broker_Proxy::OnMsgConnectComplete( - const HostResource& broker, + const HostResource& resource, IPC::PlatformFileForTransit socket_handle, int32_t result) { DCHECK(result == PP_OK || socket_handle == IPC::InvalidPlatformFileForTransit()); - Broker* object = NULL; - if (result == PP_OK) { - object = PluginResource::GetAs<Broker>( - PluginResourceTracker::GetInstance()->PluginResourceForHostResource( - broker)); - if (!object) - result = PP_ERROR_BADRESOURCE; - } - - if (result == PP_OK) { - object->socket_handle_ = - IPC::PlatformFileForTransitToPlatformFile(socket_handle); - } else { - // The caller may still have given us a handle in the failure case. - // The easiest way to clean it up is to just put it in an object - // and then close them. This failure case is not performance critical. + ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_Broker_API> enter( + resource.host_resource(), true); + if (enter.failed()) { + // As in Broker::ConnectComplete, we need to close the resource on error. base::SyncSocket temp_socket( IPC::PlatformFileForTransitToPlatformFile(socket_handle)); + } else { + static_cast<Broker*>(enter.object())->ConnectComplete(socket_handle, + result); } - - if (!object->current_connect_callback_.func) { - // The handle might leak if the plugin never calls GetHandle(). - return; - } - - PP_RunAndClearCompletionCallback(&object->current_connect_callback_, result); } // Callback on the host side. diff --git a/ppapi/proxy/ppb_broker_proxy.h b/ppapi/proxy/ppb_broker_proxy.h index 3cae023..efa9a98 100644 --- a/ppapi/proxy/ppb_broker_proxy.h +++ b/ppapi/proxy/ppb_broker_proxy.h @@ -27,6 +27,8 @@ class PPB_Broker_Proxy : public InterfaceProxy { 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()); } diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc index a74bf18..d6f910f 100644 --- a/ppapi/proxy/ppb_buffer_proxy.cc +++ b/ppapi/proxy/ppb_buffer_proxy.cc @@ -14,11 +14,23 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/thunk/ppb_buffer_api.h" +#include "ppapi/thunk/thunk.h" namespace pp { namespace proxy { -class Buffer : public PluginResource { +namespace { + +InterfaceProxy* CreateBufferProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Buffer_Proxy(dispatcher, target_interface); +} + +} // namespace + +class Buffer : public ppapi::thunk::PPB_Buffer_API, + public PluginResource { public: Buffer(const HostResource& resource, int memory_handle, @@ -26,12 +38,16 @@ class Buffer : public PluginResource { virtual ~Buffer(); // Resource overrides. - virtual Buffer* AsBuffer() { return this; } + virtual Buffer* AsBuffer() OVERRIDE; - uint32_t size() const { return size_; } + // ResourceObjectBase overries. + virtual ppapi::thunk::PPB_Buffer_API* AsBuffer_API() OVERRIDE; - void* Map(); - void Unmap(); + // PPB_Buffer_API implementation. + virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE; + virtual PP_Bool IsMapped() OVERRIDE; + virtual void* Map() OVERRIDE; + virtual void Unmap() OVERRIDE; private: int memory_handle_; @@ -55,75 +71,32 @@ Buffer::~Buffer() { Unmap(); } -void* Buffer::Map() { - // TODO(brettw) implement this. - return mapped_data_; +Buffer* Buffer::AsBuffer() { + return this; } -void Buffer::Unmap() { - // TODO(brettw) implement this. +ppapi::thunk::PPB_Buffer_API* Buffer::AsBuffer_API() { + return this; } -namespace { - -PP_Resource Create(PP_Instance instance, uint32_t size) { - HostResource result; - int32_t shm_handle = -1; - PluginDispatcher::GetForInstance(instance)->Send( - new PpapiHostMsg_PPBBuffer_Create( - INTERFACE_ID_PPB_BUFFER, instance, size, - &result, &shm_handle)); - if (result.is_null()) - return 0; - - linked_ptr<Buffer> object(new Buffer(result, - static_cast<int>(shm_handle), size)); - return PluginResourceTracker::GetInstance()->AddResource(object); -} - -PP_Bool IsBuffer(PP_Resource resource) { - Buffer* object = PluginResource::GetAs<Buffer>(resource); - return BoolToPPBool(!!object); -} - -PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { - Buffer* object = PluginResource::GetAs<Buffer>(resource); - if (!object) { - *size_in_bytes = 0; - return PP_FALSE; - } - *size_in_bytes = object->size(); +PP_Bool Buffer::Describe(uint32_t* size_in_bytes) { + *size_in_bytes = size_; return PP_TRUE; } -void* Map(PP_Resource resource) { - Buffer* object = PluginResource::GetAs<Buffer>(resource); - if (!object) - return NULL; - return object->Map(); +PP_Bool Buffer::IsMapped() { + return PP_FromBool(!!mapped_data_); } -void Unmap(PP_Resource resource) { - Buffer* object = PluginResource::GetAs<Buffer>(resource); - if (object) - object->Unmap(); +void* Buffer::Map() { + // TODO(brettw) implement this. + return mapped_data_; } -const PPB_Buffer_Dev buffer_interface = { - &Create, - &IsBuffer, - &Describe, - &Map, - &Unmap, -}; - -InterfaceProxy* CreateBufferProxy(Dispatcher* dispatcher, - const void* target_interface) { - return new PPB_Buffer_Proxy(dispatcher, target_interface); +void Buffer::Unmap() { + // TODO(brettw) implement this. } -} // namespace - PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher, const void* target_interface) : InterfaceProxy(dispatcher, target_interface) { @@ -135,7 +108,7 @@ PPB_Buffer_Proxy::~PPB_Buffer_Proxy() { // static const InterfaceProxy::Info* PPB_Buffer_Proxy::GetInfo() { static const Info info = { - &buffer_interface, + ppapi::thunk::GetPPB_Buffer_Thunk(), PPB_BUFFER_DEV_INTERFACE, INTERFACE_ID_PPB_BUFFER, false, @@ -144,6 +117,26 @@ const InterfaceProxy::Info* PPB_Buffer_Proxy::GetInfo() { return &info; } +// static +PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, + uint32_t size) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return 0; + + HostResource result; + int32_t shm_handle = -1; + dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create( + INTERFACE_ID_PPB_BUFFER, instance, size, + &result, &shm_handle)); + if (result.is_null()) + return 0; + + linked_ptr<Buffer> object(new Buffer(result, + static_cast<int>(shm_handle), size)); + return PluginResourceTracker::GetInstance()->AddResource(object); +} + bool PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg) diff --git a/ppapi/proxy/ppb_buffer_proxy.h b/ppapi/proxy/ppb_buffer_proxy.h index 1294be5..752ab8a 100644 --- a/ppapi/proxy/ppb_buffer_proxy.h +++ b/ppapi/proxy/ppb_buffer_proxy.h @@ -22,6 +22,9 @@ class PPB_Buffer_Proxy : public InterfaceProxy { static const Info* GetInfo(); + static PP_Resource CreateProxyResource(PP_Instance instance, + uint32_t size); + const PPB_Buffer_Dev* ppb_buffer_target() const { return static_cast<const PPB_Buffer_Dev*>(target_interface()); } diff --git a/ppapi/proxy/ppb_char_set_proxy.cc b/ppapi/proxy/ppb_char_set_proxy.cc index 5a0be2e..a896693 100644 --- a/ppapi/proxy/ppb_char_set_proxy.cc +++ b/ppapi/proxy/ppb_char_set_proxy.cc @@ -11,6 +11,8 @@ #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" #include "ppapi/shared_impl/char_set_impl.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/thunk.h" namespace pp { namespace proxy { @@ -22,43 +24,6 @@ const PPB_Core* GetCoreInterface() { PluginDispatcher::GetInterfaceFromDispatcher(PPB_CORE_INTERFACE)); } -char* UTF16ToCharSet(PP_Instance /* instance */, - const uint16_t* utf16, uint32_t utf16_len, - const char* output_char_set, - PP_CharSet_ConversionError on_error, - uint32_t* output_length) { - return ppapi::CharSetImpl::UTF16ToCharSet( - GetCoreInterface(), utf16, utf16_len, output_char_set, on_error, - output_length); -} - -uint16_t* CharSetToUTF16(PP_Instance /* instance */, - const char* input, uint32_t input_len, - const char* input_char_set, - PP_CharSet_ConversionError on_error, - uint32_t* output_length) { - return ppapi::CharSetImpl::CharSetToUTF16( - GetCoreInterface(), input, input_len, input_char_set, on_error, - output_length); -} - -PP_Var GetDefaultCharSet(PP_Instance instance) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return PP_MakeUndefined(); - - ReceiveSerializedVarReturnValue result; - dispatcher->Send(new PpapiHostMsg_PPBCharSet_GetDefaultCharSet( - INTERFACE_ID_PPB_CHAR_SET, instance, &result)); - return result.Return(dispatcher); -} - -const PPB_CharSet_Dev charset_interface = { - &UTF16ToCharSet, - &CharSetToUTF16, - &GetDefaultCharSet -}; - InterfaceProxy* CreateCharSetProxy(Dispatcher* dispatcher, const void* target_interface) { return new PPB_CharSet_Proxy(dispatcher, target_interface); @@ -77,7 +42,7 @@ PPB_CharSet_Proxy::~PPB_CharSet_Proxy() { // static const InterfaceProxy::Info* PPB_CharSet_Proxy::GetInfo() { static const Info info = { - &charset_interface, + ppapi::thunk::GetPPB_CharSet_Thunk(), PPB_CHAR_SET_DEV_INTERFACE, INTERFACE_ID_PPB_CHAR_SET, false, @@ -86,6 +51,44 @@ const InterfaceProxy::Info* PPB_CharSet_Proxy::GetInfo() { return &info; } +ppapi::thunk::PPB_CharSet_FunctionAPI* +PPB_CharSet_Proxy::AsCharSet_FunctionAPI() { + return this; +} + +char* PPB_CharSet_Proxy::UTF16ToCharSet( + PP_Instance instance, + const uint16_t* utf16, uint32_t utf16_len, + const char* output_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) { + return ppapi::CharSetImpl::UTF16ToCharSet( + GetCoreInterface(), utf16, utf16_len, output_char_set, on_error, + output_length); +} + +uint16_t* PPB_CharSet_Proxy::CharSetToUTF16( + PP_Instance instance, + const char* input, uint32_t input_len, + const char* input_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) { + return ppapi::CharSetImpl::CharSetToUTF16( + GetCoreInterface(), input, input_len, input_char_set, on_error, + output_length); +} + +PP_Var PPB_CharSet_Proxy::GetDefaultCharSet(PP_Instance instance) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return PP_MakeUndefined(); + + ReceiveSerializedVarReturnValue result; + dispatcher->Send(new PpapiHostMsg_PPBCharSet_GetDefaultCharSet( + INTERFACE_ID_PPB_CHAR_SET, instance, &result)); + return result.Return(dispatcher); +} + bool PPB_CharSet_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_CharSet_Proxy, msg) @@ -99,8 +102,10 @@ bool PPB_CharSet_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_CharSet_Proxy::OnMsgGetDefaultCharSet( PP_Instance instance, SerializedVarReturnValue result) { - result.Return(dispatcher(), - ppb_char_set_target()->GetDefaultCharSet(instance)); + ppapi::thunk::EnterFunctionNoLock<ppapi::thunk::PPB_CharSet_FunctionAPI> + enter(instance, true); + if (enter.succeeded()) + result.Return(dispatcher(), enter.functions()->GetDefaultCharSet(instance)); } } // namespace proxy diff --git a/ppapi/proxy/ppb_char_set_proxy.h b/ppapi/proxy/ppb_char_set_proxy.h index f6af048..b64884c 100644 --- a/ppapi/proxy/ppb_char_set_proxy.h +++ b/ppapi/proxy/ppb_char_set_proxy.h @@ -8,6 +8,8 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_resource.h" #include "ppapi/proxy/interface_proxy.h" +#include "ppapi/shared_impl/function_group_base.h" +#include "ppapi/thunk/ppb_char_set_api.h" struct PPB_CharSet_Dev; struct PPB_Core; @@ -17,19 +19,34 @@ namespace proxy { class SerializedVarReturnValue; -class PPB_CharSet_Proxy : public InterfaceProxy { +class PPB_CharSet_Proxy : public ppapi::FunctionGroupBase, + public ppapi::thunk::PPB_CharSet_FunctionAPI, + public InterfaceProxy { public: PPB_CharSet_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_CharSet_Proxy(); static const Info* GetInfo(); - const PPB_CharSet_Dev* ppb_char_set_target() const { - return static_cast<const PPB_CharSet_Dev*>(target_interface()); - } + // FunctionGroupBase overrides. + virtual ppapi::thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI() + OVERRIDE; + + // PPB_CharSet_FunctionAPI implementation. + virtual char* UTF16ToCharSet(PP_Instance instance, + const uint16_t* utf16, uint32_t utf16_len, + const char* output_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) OVERRIDE; + virtual uint16_t* CharSetToUTF16(PP_Instance instance, + const char* input, uint32_t input_len, + const char* input_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) OVERRIDE; + virtual PP_Var GetDefaultCharSet(PP_Instance instance) OVERRIDE; // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; private: void OnMsgGetDefaultCharSet(PP_Instance instance, diff --git a/ppapi/proxy/ppb_cursor_control_proxy.cc b/ppapi/proxy/ppb_cursor_control_proxy.cc index 74d0ecd..37619b7 100644 --- a/ppapi/proxy/ppb_cursor_control_proxy.cc +++ b/ppapi/proxy/ppb_cursor_control_proxy.cc @@ -10,26 +10,59 @@ #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/thunk.h" + +using ppapi::thunk::EnterFunctionNoLock; +using ppapi::thunk::PPB_CursorControl_FunctionAPI; namespace pp { namespace proxy { namespace { -PP_Bool SetCursor(PP_Instance instance_id, - PP_CursorType_Dev type, - PP_Resource custom_image_id, - const PP_Point* hot_spot) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return PP_FALSE; +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 = { + ppapi::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::AsCursorControl_FunctionAPI() { + return this; +} + +PP_Bool PPB_CursorControl_Proxy::SetCursor(PP_Instance instance, + PP_CursorType_Dev type, + PP_Resource custom_image_id, + const PP_Point* hot_spot) { // It's legal for the image ID to be null if the type is not custom. HostResource cursor_image_resource; if (type == PP_CURSORTYPE_CUSTOM) { PluginResource* cursor_image = PluginResourceTracker::GetInstance()-> GetResourceObject(custom_image_id); - if (!cursor_image || cursor_image->instance() != instance_id) + if (!cursor_image || cursor_image->instance() != instance) return PP_FALSE; cursor_image_resource = cursor_image->host_resource(); } else { @@ -39,92 +72,41 @@ PP_Bool SetCursor(PP_Instance instance_id, PP_Bool result = PP_FALSE; PP_Point empty_point = { 0, 0 }; - dispatcher->Send(new PpapiHostMsg_PPBCursorControl_SetCursor( + dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_SetCursor( INTERFACE_ID_PPB_CURSORCONTROL, - instance_id, static_cast<int32_t>(type), cursor_image_resource, + instance, static_cast<int32_t>(type), cursor_image_resource, hot_spot ? *hot_spot : empty_point, &result)); return result; } -PP_Bool LockCursor(PP_Instance instance_id) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return PP_FALSE; - +PP_Bool PPB_CursorControl_Proxy::LockCursor(PP_Instance instance) { PP_Bool result = PP_FALSE; - dispatcher->Send(new PpapiHostMsg_PPBCursorControl_LockCursor( - INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result)); + dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_LockCursor( + INTERFACE_ID_PPB_CURSORCONTROL, instance, &result)); return result; } -PP_Bool UnlockCursor(PP_Instance instance_id) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return PP_FALSE; - +PP_Bool PPB_CursorControl_Proxy::UnlockCursor(PP_Instance instance) { PP_Bool result = PP_FALSE; - dispatcher->Send(new PpapiHostMsg_PPBCursorControl_UnlockCursor( - INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result)); + dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_UnlockCursor( + INTERFACE_ID_PPB_CURSORCONTROL, instance, &result)); return result; } -PP_Bool HasCursorLock(PP_Instance instance_id) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return PP_FALSE; - +PP_Bool PPB_CursorControl_Proxy::HasCursorLock(PP_Instance instance) { PP_Bool result = PP_FALSE; - dispatcher->Send(new PpapiHostMsg_PPBCursorControl_HasCursorLock( - INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result)); + dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_HasCursorLock( + INTERFACE_ID_PPB_CURSORCONTROL, instance, &result)); return result; } -PP_Bool CanLockCursor(PP_Instance instance_id) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return PP_FALSE; - +PP_Bool PPB_CursorControl_Proxy::CanLockCursor(PP_Instance instance) { PP_Bool result = PP_FALSE; - dispatcher->Send(new PpapiHostMsg_PPBCursorControl_CanLockCursor( - INTERFACE_ID_PPB_CURSORCONTROL, instance_id, &result)); + dispatcher()->Send(new PpapiHostMsg_PPBCursorControl_CanLockCursor( + INTERFACE_ID_PPB_CURSORCONTROL, instance, &result)); return result; } -const PPB_CursorControl_Dev cursor_control_interface = { - &SetCursor, - &LockCursor, - &UnlockCursor, - &HasCursorLock, - &CanLockCursor -}; - -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 = { - &cursor_control_interface, - PPB_CURSOR_CONTROL_DEV_INTERFACE, - INTERFACE_ID_PPB_CURSORCONTROL, - false, - &CreateCursorControlProxy, - }; - return &info; -} - bool PPB_CursorControl_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_CursorControl_Proxy, msg) @@ -149,29 +131,40 @@ void PPB_CursorControl_Proxy::OnMsgSetCursor(PP_Instance instance, HostResource custom_image, const PP_Point& hot_spot, PP_Bool* result) { - *result = ppb_cursor_control_target()->SetCursor( - instance, static_cast<PP_CursorType_Dev>(type), - custom_image.host_resource(), &hot_spot); + EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.succeeded()) { + *result = enter.functions()->SetCursor( + instance, static_cast<PP_CursorType_Dev>(type), + custom_image.host_resource(), &hot_spot); + } } void PPB_CursorControl_Proxy::OnMsgLockCursor(PP_Instance instance, PP_Bool* result) { - *result = ppb_cursor_control_target()->LockCursor(instance); + EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.succeeded()) + *result = enter.functions()->LockCursor(instance); } void PPB_CursorControl_Proxy::OnMsgUnlockCursor(PP_Instance instance, PP_Bool* result) { - *result = ppb_cursor_control_target()->UnlockCursor(instance); + EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.succeeded()) + *result = enter.functions()->UnlockCursor(instance); } void PPB_CursorControl_Proxy::OnMsgHasCursorLock(PP_Instance instance, PP_Bool* result) { - *result = ppb_cursor_control_target()->HasCursorLock(instance); + EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.succeeded()) + *result = enter.functions()->HasCursorLock(instance); } void PPB_CursorControl_Proxy::OnMsgCanLockCursor(PP_Instance instance, PP_Bool* result) { - *result = ppb_cursor_control_target()->CanLockCursor(instance); + EnterFunctionNoLock<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.succeeded()) + *result = enter.functions()->CanLockCursor(instance); } } // namespace proxy diff --git a/ppapi/proxy/ppb_cursor_control_proxy.h b/ppapi/proxy/ppb_cursor_control_proxy.h index e04b435..234f6cd 100644 --- a/ppapi/proxy/ppb_cursor_control_proxy.h +++ b/ppapi/proxy/ppb_cursor_control_proxy.h @@ -12,25 +12,40 @@ #include "ppapi/c/pp_resource.h" #include "ppapi/proxy/host_resource.h" #include "ppapi/proxy/interface_proxy.h" +#include "ppapi/shared_impl/function_group_base.h" +#include "ppapi/thunk/ppb_cursor_control_api.h" struct PPB_CursorControl_Dev; namespace pp { namespace proxy { -class PPB_CursorControl_Proxy : public InterfaceProxy { +class PPB_CursorControl_Proxy + : public ppapi::FunctionGroupBase, + public ppapi::thunk::PPB_CursorControl_FunctionAPI, + public InterfaceProxy { public: PPB_CursorControl_Proxy(Dispatcher* dispatcher, const void* target_interface); virtual ~PPB_CursorControl_Proxy(); static const Info* GetInfo(); - const PPB_CursorControl_Dev* ppb_cursor_control_target() const { - return reinterpret_cast<const PPB_CursorControl_Dev*>(target_interface()); - } + // FunctionGroupBase overrides. + ppapi::thunk::PPB_CursorControl_FunctionAPI* AsCursorControl_FunctionAPI() + OVERRIDE; + + // PPB_CursorControl_FunctionAPI implementation. + virtual PP_Bool SetCursor(PP_Instance instance, + PP_CursorType_Dev type, + PP_Resource custom_image_id, + const PP_Point* hot_spot) OVERRIDE; + virtual PP_Bool LockCursor(PP_Instance instance) OVERRIDE; + virtual PP_Bool UnlockCursor(PP_Instance instance) OVERRIDE; + virtual PP_Bool HasCursorLock(PP_Instance instance) OVERRIDE; + virtual PP_Bool CanLockCursor(PP_Instance instance) OVERRIDE; // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; private: // Message handlers. diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h index 1dd9245..bb351ea 100644 --- a/ppapi/proxy/ppb_font_proxy.h +++ b/ppapi/proxy/ppb_font_proxy.h @@ -20,8 +20,8 @@ namespace proxy { class SerializedVarReturnValue; -class PPB_Font_Proxy : public ::ppapi::FunctionGroupBase, - 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, const void* target_interface); @@ -30,7 +30,7 @@ class PPB_Font_Proxy : public ::ppapi::FunctionGroupBase, static const Info* GetInfo(); // FunctionGroupBase overrides. - virtual ::ppapi::thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() OVERRIDE; + virtual ppapi::thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() OVERRIDE; // PPB_Font_FunctionAPI implementation. virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 44d903d..0045bbb 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -14,6 +14,8 @@ #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_buffer_proxy.h" +#include "ppapi/proxy/ppb_broker_proxy.h" #include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppb_graphics_2d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" @@ -61,6 +63,15 @@ PP_Resource ResourceCreationProxy::CreateAudioTrusted(PP_Instance instance) { return 0; } +PP_Resource ResourceCreationProxy::CreateBroker(PP_Instance instance) { + return PPB_Broker_Proxy::CreateProxyResource(instance); +} + +PP_Resource ResourceCreationProxy::CreateBuffer(PP_Instance instance, + uint32_t size) { + return PPB_Buffer_Proxy::CreateProxyResource(instance, size); +} + PP_Resource ResourceCreationProxy::CreateFontObject( PP_Instance instance, const PP_FontDescription_Dev* description) { diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index c0cae7f..bd24bda 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -40,6 +40,9 @@ class ResourceCreationProxy : public ::ppapi::FunctionGroupBase, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) OVERRIDE; virtual PP_Resource CreateAudioTrusted(PP_Instance instance) OVERRIDE; + virtual PP_Resource CreateBroker(PP_Instance instance) OVERRIDE; + virtual PP_Resource CreateBuffer(PP_Instance instance, + uint32_t size) OVERRIDE; virtual PP_Resource CreateFontObject( PP_Instance instance, const PP_FontDescription_Dev* description) OVERRIDE; diff --git a/ppapi/shared_impl/function_group_base.h b/ppapi/shared_impl/function_group_base.h index e6c61ea..9cdfcc6 100644 --- a/ppapi/shared_impl/function_group_base.h +++ b/ppapi/shared_impl/function_group_base.h @@ -8,6 +8,8 @@ namespace ppapi { namespace thunk { +class PPB_CharSet_FunctionAPI; +class PPB_CursorControl_FunctionAPI; class PPB_Font_FunctionAPI; class ResourceCreationAPI; } @@ -16,13 +18,31 @@ class FunctionGroupBase { public: // Dynamic casting for this object. Returns the pointer to the given type if // it's supported. - virtual thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() { return NULL; } - virtual thunk::ResourceCreationAPI* AsResourceCreation() { return NULL; } + virtual thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI() { + return NULL; + } + virtual thunk::PPB_CursorControl_FunctionAPI* AsCursorControl_FunctionAPI() { + return NULL; + } + virtual thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() { + return NULL; + } + virtual thunk::ResourceCreationAPI* AsResourceCreation() { + return NULL; + } template <typename T> T* GetAs() { return NULL; } }; template<> +inline thunk::PPB_CharSet_FunctionAPI* FunctionGroupBase::GetAs() { + return AsCharSet_FunctionAPI(); +} +template<> +inline thunk::PPB_CursorControl_FunctionAPI* FunctionGroupBase::GetAs() { + return AsCursorControl_FunctionAPI(); +} +template<> inline thunk::PPB_Font_FunctionAPI* FunctionGroupBase::GetAs() { return AsFont_FunctionAPI(); } diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h index 05ed923..c8d88c1 100644 --- a/ppapi/shared_impl/resource_object_base.h +++ b/ppapi/shared_impl/resource_object_base.h @@ -11,6 +11,8 @@ namespace thunk { class PPB_Audio_API; class PPB_AudioConfig_API; class PPB_AudioTrusted_API; +class PPB_Broker_API; +class PPB_Buffer_API; class PPB_Font_API; class PPB_Graphics2D_API; class PPB_ImageData_API; @@ -22,6 +24,8 @@ class ResourceObjectBase { virtual thunk::PPB_Audio_API* AsAudio_API() { return NULL; } virtual thunk::PPB_AudioConfig_API* AsAudioConfig_API() { return NULL; } virtual thunk::PPB_AudioTrusted_API* AsAudioTrusted_API() { return NULL; } + virtual thunk::PPB_Buffer_API* AsBuffer_API() { return NULL; } + virtual thunk::PPB_Broker_API* AsBroker_API() { return NULL; } virtual thunk::PPB_Font_API* AsFont_API() { return NULL; } virtual thunk::PPB_Graphics2D_API* AsGraphics2D_API() { return NULL; } virtual thunk::PPB_ImageData_API* AsImageData_API() { return NULL; } @@ -42,6 +46,14 @@ inline thunk::PPB_AudioTrusted_API* ResourceObjectBase::GetAs() { return AsAudioTrusted_API(); } template<> +inline thunk::PPB_Broker_API* ResourceObjectBase::GetAs() { + return AsBroker_API(); +} +template<> +inline thunk::PPB_Buffer_API* ResourceObjectBase::GetAs() { + return AsBuffer_API(); +} +template<> inline thunk::PPB_Font_API* ResourceObjectBase::GetAs() { return AsFont_API(); } diff --git a/ppapi/tests/test_broker.cc b/ppapi/tests/test_broker.cc new file mode 100644 index 0000000..b1d5b02 --- /dev/null +++ b/ppapi/tests/test_broker.cc @@ -0,0 +1,46 @@ +// Copyright (c) 2010 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/tests/test_broker.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/trusted/ppb_broker_trusted.h" +#include "ppapi/cpp/module.h" +#include "ppapi/tests/testing_instance.h" + +REGISTER_TEST_CASE(Broker); + +TestBroker::TestBroker(TestingInstance* instance) + : TestCase(instance), + broker_interface_(NULL) { +} + +bool TestBroker::Init() { + broker_interface_ = static_cast<PPB_BrokerTrusted const*>( + pp::Module::Get()->GetBrowserInterface(PPB_BROKER_TRUSTED_INTERFACE)); + return !!broker_interface_; +} + +void TestBroker::RunTest() { + RUN_TEST(Create); +} + +std::string TestBroker::TestCreate() { + // Very simplistic test to make sure we can create a broker interface. + PP_Resource broker = broker_interface_->CreateTrusted( + instance_->pp_instance()); + ASSERT_TRUE(broker); + + ASSERT_FALSE(broker_interface_->IsBrokerTrusted(0)); + ASSERT_TRUE(broker_interface_->IsBrokerTrusted(broker)); + + // Test getting the handle for an invalid resource. + int32_t handle; + ASSERT_TRUE(broker_interface_->GetHandle(0, &handle) == PP_ERROR_BADRESOURCE); + + // Connect hasn't been called so this should fail. + ASSERT_TRUE(broker_interface_->GetHandle(broker, &handle) == PP_ERROR_FAILED); + + PASS(); +} diff --git a/ppapi/tests/test_broker.h b/ppapi/tests/test_broker.h new file mode 100644 index 0000000..4cef9e5 --- /dev/null +++ b/ppapi/tests/test_broker.h @@ -0,0 +1,29 @@ +// Copyright (c) 2010 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_TESTS_TEST_BROKER_H_ +#define PPAPI_TESTS_TEST_BROKER_H_ + +#include <string> +#include <vector> + +#include "ppapi/tests/test_case.h" + +struct PPB_BrokerTrusted; + +class TestBroker : public TestCase { + public: + TestBroker(TestingInstance* instance); + + // TestCase implementation. + virtual bool Init(); + virtual void RunTest(); + + private: + std::string TestCreate(); + + const struct PPB_BrokerTrusted* broker_interface_; +}; + +#endif // PPAPI_TESTS_TEST_BROKER_H_ diff --git a/ppapi/tests/test_char_set.cc b/ppapi/tests/test_char_set.cc index acc381f..dc417a0 100644 --- a/ppapi/tests/test_char_set.cc +++ b/ppapi/tests/test_char_set.cc @@ -16,7 +16,7 @@ TestCharSet::TestCharSet(TestingInstance* instance) } bool TestCharSet::Init() { - char_set_interface_ = reinterpret_cast<struct PPB_CharSet_Dev const*>( + char_set_interface_ = static_cast<PPB_CharSet_Dev const*>( pp::Module::Get()->GetBrowserInterface(PPB_CHAR_SET_DEV_INTERFACE)); return !!char_set_interface_; } @@ -24,6 +24,7 @@ bool TestCharSet::Init() { void TestCharSet::RunTest() { RUN_TEST(UTF16ToCharSet); RUN_TEST(CharSetToUTF16); + RUN_TEST(GetDefaultCharSet); } std::string TestCharSet::TestUTF16ToCharSet() { @@ -155,6 +156,20 @@ std::string TestCharSet::TestCharSetToUTF16() { PASS(); } +std::string TestCharSet::TestGetDefaultCharSet() { + // Test invalid instance. + pp::Var result(pp::Var::PassRef(), char_set_interface_->GetDefaultCharSet(0)); + ASSERT_TRUE(result.is_undefined()); + + // Just make sure the default char set is a nonempty string. + result = pp::Var(pp::Var::PassRef(), + char_set_interface_->GetDefaultCharSet(instance_->pp_instance())); + ASSERT_TRUE(result.is_string()); + ASSERT_FALSE(result.AsString().empty()); + + PASS(); +} + std::vector<uint16_t> TestCharSet::UTF8ToUTF16(const std::string& utf8) { uint32_t result_len = 0; uint16_t* result = char_set_interface_->CharSetToUTF16( diff --git a/ppapi/tests/test_char_set.h b/ppapi/tests/test_char_set.h index 980b29c..c6a14fe 100644 --- a/ppapi/tests/test_char_set.h +++ b/ppapi/tests/test_char_set.h @@ -24,6 +24,7 @@ class TestCharSet : public TestCase { private: std::string TestUTF16ToCharSet(); std::string TestCharSetToUTF16(); + std::string TestGetDefaultCharSet(); // Converts the given UTF-8 string to a NON-NULL TERMINATED UTF-16 string // stored in the given vector. diff --git a/ppapi/tests/test_cursor_control.cc b/ppapi/tests/test_cursor_control.cc new file mode 100644 index 0000000..80aca34 --- /dev/null +++ b/ppapi/tests/test_cursor_control.cc @@ -0,0 +1,37 @@ +// Copyright (c) 2010 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/tests/test_cursor_control.h" + +#include "ppapi/c/dev/ppb_cursor_control_dev.h" +#include "ppapi/cpp/module.h" +#include "ppapi/tests/testing_instance.h" + +REGISTER_TEST_CASE(CursorControl); + +TestCursorControl::TestCursorControl(TestingInstance* instance) + : TestCase(instance), + cursor_control_interface_(NULL) { +} + +bool TestCursorControl::Init() { + cursor_control_interface_ = static_cast<PPB_CursorControl_Dev const*>( + pp::Module::Get()->GetBrowserInterface(PPB_CURSOR_CONTROL_DEV_INTERFACE)); + return !!cursor_control_interface_; +} + +void TestCursorControl::RunTest() { + RUN_TEST(SetCursor); +} + +std::string TestCursorControl::TestSetCursor() { + // Very simplistic test to make sure we can actually call the function and + // it reports success. This is a nice integration test to make sure the + // interface is hooked up. Obviously it's not easy in a plugin to test whether + // the mouse cursor actually changed. + ASSERT_TRUE(cursor_control_interface_->SetCursor(instance_->pp_instance(), + PP_CURSORTYPE_WAIT, 0, NULL)); + + PASS(); +} diff --git a/ppapi/tests/test_cursor_control.h b/ppapi/tests/test_cursor_control.h new file mode 100644 index 0000000..65bc7a9 --- /dev/null +++ b/ppapi/tests/test_cursor_control.h @@ -0,0 +1,29 @@ +// Copyright (c) 2010 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_TESTS_TEST_CURSOR_CONTROL_H_ +#define PPAPI_TESTS_TEST_CURSOR_CONTROL_H_ + +#include <string> +#include <vector> + +#include "ppapi/tests/test_case.h" + +struct PPB_CursorControl_Dev; + +class TestCursorControl : public TestCase { + public: + TestCursorControl(TestingInstance* instance); + + // TestCase implementation. + virtual bool Init(); + virtual void RunTest(); + + private: + std::string TestSetCursor(); + + const struct PPB_CursorControl_Dev* cursor_control_interface_; +}; + +#endif // PPAPI_TESTS_TEST_CURSOR_CONTROL_H_ diff --git a/ppapi/thunk/ppb_audio_config_thunk.cc b/ppapi/thunk/ppb_audio_config_thunk.cc index 8ee8ffd..ca3d589 100644 --- a/ppapi/thunk/ppb_audio_config_thunk.cc +++ b/ppapi/thunk/ppb_audio_config_thunk.cc @@ -35,7 +35,7 @@ uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate, PP_Bool IsAudioConfig(PP_Resource resource) { EnterResource<PPB_AudioConfig_API> enter(resource, false); - return enter.succeeded() ? PP_TRUE : PP_FALSE; + return PP_FromBool(enter.succeeded()); } PP_AudioSampleRate GetSampleRate(PP_Resource config_id) { diff --git a/ppapi/thunk/ppb_broker_api.h b/ppapi/thunk/ppb_broker_api.h new file mode 100644 index 0000000..feb53f5 --- /dev/null +++ b/ppapi/thunk/ppb_broker_api.h @@ -0,0 +1,23 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_PPB_BROKER_API_H_ +#define PPAPI_THUNK_PPB_BROKER_API_H_ + +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_stdint.h" + +namespace ppapi { +namespace thunk { + +class PPB_Broker_API { + public: + virtual int32_t Connect(PP_CompletionCallback connect_callback) = 0; + virtual int32_t GetHandle(int32_t* handle) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_BROKER_API_H_ diff --git a/ppapi/thunk/ppb_broker_thunk.cc b/ppapi/thunk/ppb_broker_thunk.cc new file mode 100644 index 0000000..1394ee9 --- /dev/null +++ b/ppapi/thunk/ppb_broker_thunk.cc @@ -0,0 +1,58 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/trusted/ppb_broker_trusted.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_broker_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource CreateTrusted(PP_Instance instance) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateBroker(instance); +} + +PP_Bool IsBrokerTrusted(PP_Resource resource) { + EnterResource<PPB_Broker_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t Connect(PP_Resource resource, + PP_CompletionCallback connect_callback) { + EnterResource<PPB_Broker_API> enter(resource, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Connect(connect_callback); +} + +int32_t GetHandle(PP_Resource resource, int32_t* handle) { + EnterResource<PPB_Broker_API> enter(resource, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->GetHandle(handle); +} + +const PPB_BrokerTrusted g_ppb_broker_thunk = { + &CreateTrusted, + &IsBrokerTrusted, + &Connect, + &GetHandle, +}; + +} // namespace + +const PPB_BrokerTrusted* GetPPB_Broker_Thunk() { + return &g_ppb_broker_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_buffer_api.h b/ppapi/thunk/ppb_buffer_api.h new file mode 100644 index 0000000..6d3d5d0 --- /dev/null +++ b/ppapi/thunk/ppb_buffer_api.h @@ -0,0 +1,25 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_PPB_BUFFER_API_H_ +#define PPAPI_THUNK_PPB_BUFFER_API_H_ + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_stdint.h" + +namespace ppapi { +namespace thunk { + +class PPB_Buffer_API { + public: + virtual PP_Bool Describe(uint32_t* size_in_bytes) = 0; + virtual PP_Bool IsMapped() = 0; + virtual void* Map() = 0; + virtual void Unmap() = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_BUFFER_API_H_ diff --git a/ppapi/thunk/ppb_buffer_thunk.cc b/ppapi/thunk/ppb_buffer_thunk.cc new file mode 100644 index 0000000..cf4952c --- /dev/null +++ b/ppapi/thunk/ppb_buffer_thunk.cc @@ -0,0 +1,65 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/ppb_buffer_dev.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_buffer_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance, uint32_t size) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateBuffer(instance, size); +} + +PP_Bool IsBuffer(PP_Resource resource) { + EnterResource<PPB_Buffer_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { + EnterResource<PPB_Buffer_API> enter(resource, true); + if (enter.failed()) { + *size_in_bytes = 0; + return PP_FALSE; + } + return enter.object()->Describe(size_in_bytes); +} + +void* Map(PP_Resource resource) { + EnterResource<PPB_Buffer_API> enter(resource, true); + if (enter.failed()) + return NULL; + return enter.object()->Map(); +} + +void Unmap(PP_Resource resource) { + EnterResource<PPB_Buffer_API> enter(resource, true); + if (enter.succeeded()) + enter.object()->Unmap(); +} + +const PPB_Buffer_Dev g_ppb_buffer_thunk = { + &Create, + &IsBuffer, + &Describe, + &Map, + &Unmap, +}; + +} // namespace + +const PPB_Buffer_Dev* GetPPB_Buffer_Thunk() { + return &g_ppb_buffer_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_char_set_api.h b/ppapi/thunk/ppb_char_set_api.h new file mode 100644 index 0000000..66b5ff4 --- /dev/null +++ b/ppapi/thunk/ppb_char_set_api.h @@ -0,0 +1,35 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_PPB_CHAR_SET_API_H_ +#define PPAPI_THUNK_PPB_CHAR_SET_API_H_ + +#include "ppapi/c/dev/ppb_char_set_dev.h" +#include "ppapi/proxy/interface_id.h" + +namespace ppapi { +namespace thunk { + +class PPB_CharSet_FunctionAPI { + public: + static const ::pp::proxy::InterfaceID interface_id = + ::pp::proxy::INTERFACE_ID_PPB_CHAR_SET; + + virtual char* UTF16ToCharSet(PP_Instance instance, + const uint16_t* utf16, uint32_t utf16_len, + const char* output_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) = 0; + virtual uint16_t* CharSetToUTF16(PP_Instance instance, + const char* input, uint32_t input_len, + const char* input_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) = 0; + virtual PP_Var GetDefaultCharSet(PP_Instance instance) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_CHAR_SET_API_H_ diff --git a/ppapi/thunk/ppb_char_set_thunk.cc b/ppapi/thunk/ppb_char_set_thunk.cc new file mode 100644 index 0000000..bc36bad --- /dev/null +++ b/ppapi/thunk/ppb_char_set_thunk.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/pp_var.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_char_set_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +char* UTF16ToCharSet(PP_Instance instance, + const uint16_t* utf16, uint32_t utf16_len, + const char* output_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) { + EnterFunction<PPB_CharSet_FunctionAPI> enter(instance, true); + if (enter.failed()) + return NULL; + return enter.functions()->UTF16ToCharSet(instance, utf16, utf16_len, + output_char_set, on_error, + output_length); +} + +uint16_t* CharSetToUTF16(PP_Instance instance, + const char* input, uint32_t input_len, + const char* input_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) { + EnterFunction<PPB_CharSet_FunctionAPI> enter(instance, true); + if (enter.failed()) + return NULL; + return enter.functions()->CharSetToUTF16(instance, input, input_len, + input_char_set, on_error, + output_length); +} + +PP_Var GetDefaultCharSet(PP_Instance instance) { + EnterFunction<PPB_CharSet_FunctionAPI> enter(instance, true); + if (enter.failed()) + return PP_MakeUndefined(); + return enter.functions()->GetDefaultCharSet(instance); +} + +const PPB_CharSet_Dev g_ppb_char_set_thunk = { + &UTF16ToCharSet, + &CharSetToUTF16, + &GetDefaultCharSet +}; + + +} // namespace + +const PPB_CharSet_Dev* GetPPB_CharSet_Thunk() { + return &g_ppb_char_set_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_cursor_control_api.h b/ppapi/thunk/ppb_cursor_control_api.h new file mode 100644 index 0000000..26b1e70 --- /dev/null +++ b/ppapi/thunk/ppb_cursor_control_api.h @@ -0,0 +1,32 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_CURSOR_CONTROL_API_H_ +#define PPAPI_THUNK_CURSOR_CONTROL_API_H_ + +#include "ppapi/c/dev/ppb_cursor_control_dev.h" +#include "ppapi/proxy/interface_id.h" + +namespace ppapi { +namespace thunk { + +class PPB_CursorControl_FunctionAPI { + public: + static const ::pp::proxy::InterfaceID interface_id = + ::pp::proxy::INTERFACE_ID_PPB_CURSORCONTROL; + + virtual PP_Bool SetCursor(PP_Instance instance, + PP_CursorType_Dev type, + PP_Resource custom_image_id, + const PP_Point* hot_spot) = 0; + virtual PP_Bool LockCursor(PP_Instance instance) = 0; + virtual PP_Bool UnlockCursor(PP_Instance instance) = 0; + virtual PP_Bool HasCursorLock(PP_Instance instance) = 0; + virtual PP_Bool CanLockCursor(PP_Instance instance) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_CURSOR_CONTROL_API_H_ diff --git a/ppapi/thunk/ppb_cursor_control_thunk.cc b/ppapi/thunk/ppb_cursor_control_thunk.cc new file mode 100644 index 0000000..56ba078 --- /dev/null +++ b/ppapi/thunk/ppb_cursor_control_thunk.cc @@ -0,0 +1,67 @@ +// 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/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_cursor_control_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Bool SetCursor(PP_Instance instance, + PP_CursorType_Dev type, + PP_Resource custom_image, + const PP_Point* hot_spot) { + EnterFunction<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.failed()) + return PP_FALSE; + return enter.functions()->SetCursor(instance, type, custom_image, hot_spot); +} + +PP_Bool LockCursor(PP_Instance instance) { + EnterFunction<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.failed()) + return PP_FALSE; + return enter.functions()->LockCursor(instance); +} + +PP_Bool UnlockCursor(PP_Instance instance) { + EnterFunction<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.failed()) + return PP_FALSE; + return enter.functions()->UnlockCursor(instance); +} + +PP_Bool HasCursorLock(PP_Instance instance) { + EnterFunction<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.failed()) + return PP_FALSE; + return enter.functions()->HasCursorLock(instance); +} + +PP_Bool CanLockCursor(PP_Instance instance) { + EnterFunction<PPB_CursorControl_FunctionAPI> enter(instance, true); + if (enter.failed()) + return PP_FALSE; + return enter.functions()->CanLockCursor(instance); +} + +const PPB_CursorControl_Dev g_ppb_cursor_control_thunk = { + &SetCursor, + &LockCursor, + &UnlockCursor, + &HasCursorLock, + &CanLockCursor +}; + +} // namespace + +const PPB_CursorControl_Dev* GetPPB_CursorControl_Thunk() { + return &g_ppb_cursor_control_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index 4dd9204..d25285f 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -37,6 +37,8 @@ class ResourceCreationAPI { virtual PP_Resource CreateAudioConfig(PP_Instance instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) = 0; + virtual PP_Resource CreateBroker(PP_Instance instance) = 0; + virtual PP_Resource CreateBuffer(PP_Instance instance, uint32_t size) = 0; // Note: can't be called CreateFont due to Windows #defines. virtual PP_Resource CreateFontObject( PP_Instance instance, diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index efe320e..647f6eb 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -8,6 +8,10 @@ struct PPB_Audio; struct PPB_AudioConfig; struct PPB_AudioTrusted; +struct PPB_BrokerTrusted; +struct PPB_Buffer_Dev; +struct PPB_CharSet_Dev; +struct PPB_CursorControl_Dev; struct PPB_Font_Dev; struct PPB_Graphics2D; struct PPB_ImageData; @@ -18,6 +22,10 @@ namespace thunk { const PPB_Audio* GetPPB_Audio_Thunk(); const PPB_AudioConfig* GetPPB_AudioConfig_Thunk(); const PPB_AudioTrusted* GetPPB_AudioTrusted_Thunk(); +const PPB_BrokerTrusted* GetPPB_Broker_Thunk(); +const PPB_Buffer_Dev* GetPPB_Buffer_Thunk(); +const PPB_CharSet_Dev* GetPPB_CharSet_Thunk(); +const PPB_CursorControl_Dev* GetPPB_CursorControl_Thunk(); const PPB_Font_Dev* GetPPB_Font_Thunk(); const PPB_Graphics2D* GetPPB_Graphics2D_Thunk(); const PPB_ImageData* GetPPB_ImageData_Thunk(); diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index e9555cf..a0f0339 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -73,12 +73,8 @@ #include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/ppb_broker_impl.h" -#include "webkit/plugins/ppapi/ppb_buffer_impl.h" -#include "webkit/plugins/ppapi/ppb_char_set_impl.h" #include "webkit/plugins/ppapi/ppb_console_impl.h" #include "webkit/plugins/ppapi/ppb_crypto_impl.h" -#include "webkit/plugins/ppapi/ppb_cursor_control_impl.h" #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" #include "webkit/plugins/ppapi/ppb_file_chooser_impl.h" #include "webkit/plugins/ppapi/ppb_file_io_impl.h" @@ -252,11 +248,11 @@ const void* GetInterface(const char* name) { if (strcmp(name, PPB_AUDIO_TRUSTED_INTERFACE) == 0) return ::ppapi::thunk::GetPPB_AudioTrusted_Thunk(); if (strcmp(name, PPB_BROKER_TRUSTED_INTERFACE) == 0) - return PPB_Broker_Impl::GetTrustedInterface(); + return ::ppapi::thunk::GetPPB_Broker_Thunk(); if (strcmp(name, PPB_BUFFER_DEV_INTERFACE) == 0) - return PPB_Buffer_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_Buffer_Thunk(); if (strcmp(name, PPB_CHAR_SET_DEV_INTERFACE) == 0) - return PPB_CharSet_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_CharSet_Thunk(); if (strcmp(name, PPB_CONSOLE_DEV_INTERFACE) == 0) return PPB_Console_Impl::GetInterface(); if (strcmp(name, PPB_CORE_INTERFACE) == 0) @@ -264,7 +260,7 @@ const void* GetInterface(const char* name) { if (strcmp(name, PPB_CRYPTO_DEV_INTERFACE) == 0) return PPB_Crypto_Impl::GetInterface(); if (strcmp(name, PPB_CURSOR_CONTROL_DEV_INTERFACE) == 0) - return GetCursorControlInterface(); + return ::ppapi::thunk::GetPPB_CursorControl_Thunk(); if (strcmp(name, PPB_DIRECTORYREADER_DEV_INTERFACE) == 0) return PPB_DirectoryReader_Impl::GetInterface(); if (strcmp(name, PPB_FILECHOOSER_DEV_INTERFACE) == 0) diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index b704869..9668544 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -27,6 +27,8 @@ #include "ppapi/c/ppp_messaging.h" #include "ppapi/c/private/ppb_instance_private.h" #include "ppapi/c/private/ppp_instance_private.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_buffer_api.h" #include "printing/units.h" #include "skia/ext/platform_canvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" @@ -82,6 +84,7 @@ #include "skia/ext/skia_utils_mac.h" #endif +using ::ppapi::thunk::PPB_Buffer_API; using WebKit::WebBindings; using WebKit::WebCanvas; using WebKit::WebCursorInfo; @@ -1304,9 +1307,12 @@ PluginDelegate::PlatformContext3D* PluginInstance::CreateContext3D() { bool PluginInstance::PrintPDFOutput(PP_Resource print_output, WebKit::WebCanvas* canvas) { - scoped_refptr<PPB_Buffer_Impl> buffer( - Resource::GetAs<PPB_Buffer_Impl>(print_output)); - if (!buffer.get() || !buffer->is_mapped() || !buffer->size()) { + ::ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true); + if (enter.failed()) + return false; + + BufferAutoMapper mapper(enter.object()); + if (!mapper.data() || !mapper.size()) { NOTREACHED(); return false; } @@ -1328,14 +1334,14 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output, // (NativeMetafile and PreviewMetafile must have compatible formats, // i.e. both PDF for this to work). printing::Metafile* metafile = - printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); + printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); DCHECK(metafile != NULL); if (metafile) - ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size()); + ret = metafile->InitFromData(mapper.data(), mapper.size()); #elif defined(OS_MACOSX) printing::NativeMetafile metafile; // Create a PDF metafile and render from there into the passed in context. - if (metafile.InitFromData(buffer->mapped_buffer(), buffer->size())) { + if (metafile.InitFromData(mapper.data(), mapper.size())) { // Flip the transform. #if defined(USE_SKIA) gfx::SkiaBitLocker bit_locker(canvas); @@ -1362,7 +1368,7 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output, if (metafile) { // We only have a metafile when doing print preview, so we just want to // pass the PDF off to preview. - ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size()); + ret = metafile->InitFromData(mapper.data(), mapper.size()); } else { // On Windows, we now need to render the PDF to the DC that backs the // supplied canvas. @@ -1384,9 +1390,9 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output, static_cast<float>(current_print_settings_.dpi); ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); - ret = render_proc(buffer->mapped_buffer(), buffer->size(), 0, dc, - current_print_settings_.dpi, current_print_settings_.dpi, - 0, 0, size_in_pixels.width(), + ret = render_proc(static_cast<unsigned char*>(mapper.data()), mapper.size(), + 0, dc, current_print_settings_.dpi, + current_print_settings_.dpi, 0, 0, size_in_pixels.width(), size_in_pixels.height(), true, false, true, true); skia::EndPlatformPaint(canvas); } diff --git a/webkit/plugins/ppapi/ppb_broker_impl.cc b/webkit/plugins/ppapi/ppb_broker_impl.cc index d188ac7..2da35d6 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.cc +++ b/webkit/plugins/ppapi/ppb_broker_impl.cc @@ -8,57 +8,13 @@ #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/plugin_module.h" +using ::ppapi::thunk::PPB_Broker_API; + namespace webkit { namespace ppapi { namespace { -// PPB_BrokerTrusted ---------------------------------------------------- - -PP_Resource CreateTrusted(PP_Instance instance_id) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return 0; - scoped_refptr<PPB_Broker_Impl> broker(new PPB_Broker_Impl(instance)); - return broker->GetReference(); -} - -PP_Bool IsBrokerTrusted(PP_Resource resource) { - scoped_refptr<PPB_Broker_Impl> broker = - Resource::GetAs<PPB_Broker_Impl>(resource); - return BoolToPPBool(!!broker); -} - -int32_t Connect(PP_Resource broker_id, - PP_CompletionCallback connect_callback) { - scoped_refptr<PPB_Broker_Impl> broker = - Resource::GetAs<PPB_Broker_Impl>(broker_id); - if (!broker) - return PP_ERROR_BADRESOURCE; - if (!connect_callback.func) { - // Synchronous calls are not supported. - return PP_ERROR_BADARGUMENT; - } - return broker->Connect(broker->instance()->delegate(), connect_callback); -} - -int32_t GetHandle(PP_Resource broker_id, int32_t* handle) { - scoped_refptr<PPB_Broker_Impl> broker = - Resource::GetAs<PPB_Broker_Impl>(broker_id); - if (!broker) - return PP_ERROR_BADRESOURCE; - if (!handle) - return PP_ERROR_BADARGUMENT; - return broker->GetHandle(handle); -} - -const PPB_BrokerTrusted ppb_brokertrusted = { - &CreateTrusted, - &IsBrokerTrusted, - &Connect, - &GetHandle, -}; - // TODO(ddorwin): Put conversion functions in a common place and/or add an // invalid value to sync_socket.h. int32_t PlatformFileToInt(base::PlatformFile handle) { @@ -92,13 +48,29 @@ PPB_Broker_Impl::~PPB_Broker_Impl() { pipe_handle_ = PlatformFileToInt(base::kInvalidPlatformFileValue); } -const PPB_BrokerTrusted* PPB_Broker_Impl::GetTrustedInterface() { - return &ppb_brokertrusted; +// static +PP_Resource PPB_Broker_Impl::Create(PP_Instance instance_id) { + PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); + if (!instance) + return 0; + scoped_refptr<PPB_Broker_Impl> broker(new PPB_Broker_Impl(instance)); + return broker->GetReference(); } -int32_t PPB_Broker_Impl::Connect( - PluginDelegate* plugin_delegate, - PP_CompletionCallback connect_callback) { +PPB_Broker_Impl* PPB_Broker_Impl::AsPPB_Broker_Impl() { + return this; +} + +PPB_Broker_API* PPB_Broker_Impl::AsBroker_API() { + return this; +} + +int32_t PPB_Broker_Impl::Connect(PP_CompletionCallback connect_callback) { + if (!connect_callback.func) { + // Synchronous calls are not supported. + return PP_ERROR_BADARGUMENT; + } + // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. if (broker_) { @@ -116,7 +88,7 @@ int32_t PPB_Broker_Impl::Connect( instance()->module()->GetCallbackTracker(), resource_id, connect_callback); - broker_ = plugin_delegate->ConnectToPpapiBroker(this); + broker_ = instance()->delegate()->ConnectToPpapiBroker(this); if (!broker_) { scoped_refptr<TrackedCompletionCallback> callback; callback.swap(connect_callback_); @@ -128,16 +100,16 @@ int32_t PPB_Broker_Impl::Connect( } int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) { + if (pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue)) + return PP_ERROR_FAILED; // Handle not set yet. *handle = pipe_handle_; return PP_OK; } -PPB_Broker_Impl* PPB_Broker_Impl::AsPPB_Broker_Impl() { - return this; -} - // Transfers ownership of the handle to the plugin. void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { + DCHECK(pipe_handle_ == + PlatformFileToInt(base::kInvalidPlatformFileValue)); DCHECK(result == PP_OK || handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); diff --git a/webkit/plugins/ppapi/ppb_broker_impl.h b/webkit/plugins/ppapi/ppb_broker_impl.h index 111fba9..c569c1c 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.h +++ b/webkit/plugins/ppapi/ppb_broker_impl.h @@ -9,6 +9,7 @@ #include "base/memory/weak_ptr.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/trusted/ppb_broker_trusted.h" +#include "ppapi/thunk/ppb_broker_api.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/callbacks.h" @@ -20,24 +21,28 @@ namespace ppapi { class PluginInstance; class PPB_Broker_Impl : public Resource, + public ::ppapi::thunk::PPB_Broker_API, public base::SupportsWeakPtr<PPB_Broker_Impl> { public: - explicit PPB_Broker_Impl(PluginInstance* instance); virtual ~PPB_Broker_Impl(); - static const PPB_BrokerTrusted* GetTrustedInterface(); - - // PPB_BrokerTrusted implementation. - int32_t Connect(PluginDelegate* plugin_delegate, - PP_CompletionCallback connect_callback); - int32_t GetHandle(int32_t* handle); + static PP_Resource Create(PP_Instance instance_id); // Resource override. - virtual PPB_Broker_Impl* AsPPB_Broker_Impl(); + virtual PPB_Broker_Impl* AsPPB_Broker_Impl() OVERRIDE; + + // ResourceObjectBase override. + virtual ::ppapi::thunk::PPB_Broker_API* AsBroker_API() OVERRIDE; + + // PPB_BrokerTrusted implementation. + virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE; + virtual int32_t GetHandle(int32_t* handle) OVERRIDE; void BrokerConnected(int32_t handle, int32_t result); private: + explicit PPB_Broker_Impl(PluginInstance* instance); + // PluginDelegate ppapi broker object. // We don't own this pointer but are responsible for calling Disconnect on it. PluginDelegate::PpapiBroker* broker_; diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.cc b/webkit/plugins/ppapi/ppb_buffer_impl.cc index b834e41..182738f 100644 --- a/webkit/plugins/ppapi/ppb_buffer_impl.cc +++ b/webkit/plugins/ppapi/ppb_buffer_impl.cc @@ -14,62 +14,11 @@ #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +using ::ppapi::thunk::PPB_Buffer_API; + namespace webkit { namespace ppapi { -namespace { - -PP_Resource Create(PP_Instance instance_id, uint32_t size) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return 0; - - scoped_refptr<PPB_Buffer_Impl> buffer(new PPB_Buffer_Impl(instance)); - if (!buffer->Init(size)) - return 0; - - return buffer->GetReference(); -} - -PP_Bool IsPPB_Buffer_Impl(PP_Resource resource) { - return BoolToPPBool(!!Resource::GetAs<PPB_Buffer_Impl>(resource)); -} - -PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { - scoped_refptr<PPB_Buffer_Impl> buffer( - Resource::GetAs<PPB_Buffer_Impl>(resource)); - if (!buffer) - return PP_FALSE; - buffer->Describe(size_in_bytes); - return PP_TRUE; -} - -void* Map(PP_Resource resource) { - scoped_refptr<PPB_Buffer_Impl> buffer( - Resource::GetAs<PPB_Buffer_Impl>(resource)); - if (!buffer) - return NULL; - return buffer->Map(); -} - -void Unmap(PP_Resource resource) { - scoped_refptr<PPB_Buffer_Impl> buffer( - Resource::GetAs<PPB_Buffer_Impl>(resource)); - if (!buffer) - return; - return buffer->Unmap(); -} - -const PPB_Buffer_Dev ppb_buffer = { - &Create, - &IsPPB_Buffer_Impl, - &Describe, - &Map, - &Unmap, -}; - -} // namespace - PPB_Buffer_Impl::PPB_Buffer_Impl(PluginInstance* instance) : Resource(instance), size_(0) { } @@ -78,14 +27,24 @@ PPB_Buffer_Impl::~PPB_Buffer_Impl() { } // static -const PPB_Buffer_Dev* PPB_Buffer_Impl::GetInterface() { - return &ppb_buffer; +PP_Resource PPB_Buffer_Impl::Create(PP_Instance pp_instance, uint32_t size) { + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); + if (!instance) + return 0; + scoped_refptr<PPB_Buffer_Impl> buffer(new PPB_Buffer_Impl(instance)); + if (!buffer->Init(size)) + return 0; + return buffer->GetReference(); } PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { return this; } +PPB_Buffer_API* PPB_Buffer_Impl::AsBuffer_API() { + return this; +} + bool PPB_Buffer_Impl::Init(uint32_t size) { if (size == 0 || !instance()) return false; @@ -95,8 +54,13 @@ bool PPB_Buffer_Impl::Init(uint32_t size) { return shared_memory_.get() != NULL; } -void PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) const { +PP_Bool PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) { *size_in_bytes = size_; + return PP_TRUE; +} + +PP_Bool PPB_Buffer_Impl::IsMapped() { + return PP_FromBool(!!shared_memory_->memory()); } void* PPB_Buffer_Impl::Map() { @@ -111,5 +75,16 @@ void PPB_Buffer_Impl::Unmap() { shared_memory_->Unmap(); } +BufferAutoMapper::BufferAutoMapper(PPB_Buffer_API* api) : api_(api) { + needs_unmap_ = !PP_ToBool(api->IsMapped()); + data_ = api->Map(); + api->Describe(&size_); +} + +BufferAutoMapper::~BufferAutoMapper() { + if (needs_unmap_) + api_->Unmap(); +} + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.h b/webkit/plugins/ppapi/ppb_buffer_impl.h index e7d83f9..f68c825 100644 --- a/webkit/plugins/ppapi/ppb_buffer_impl.h +++ b/webkit/plugins/ppapi/ppb_buffer_impl.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/shared_memory.h" +#include "ppapi/thunk/ppb_buffer_api.h" #include "webkit/plugins/ppapi/resource.h" struct PPB_Buffer_Dev; @@ -17,41 +18,59 @@ namespace ppapi { class PluginInstance; -class PPB_Buffer_Impl : public Resource { +class PPB_Buffer_Impl : public Resource, + public ::ppapi::thunk::PPB_Buffer_API { public: - explicit PPB_Buffer_Impl(PluginInstance* instance); virtual ~PPB_Buffer_Impl(); - uint32_t size() const { return size_; } - unsigned char* mapped_buffer() const { - return static_cast<unsigned char*>(shared_memory_->memory()); - } - base::SharedMemoryHandle handle() const { return shared_memory_->handle(); } + static PP_Resource Create(PP_Instance instance, uint32_t size); - // Returns true if this buffer is mapped. False means that the buffer is - // either invalid or not mapped. - bool is_mapped() const { return mapped_buffer() != NULL; } + virtual PPB_Buffer_Impl* AsPPB_Buffer_Impl(); - // Returns a pointer to the interface implementing PPB_Buffer_Impl that is - // exposed to the plugin. - static const PPB_Buffer_Dev* GetInterface(); + base::SharedMemory* shared_memory() const { return shared_memory_.get(); } + uint32_t size() const { return size_; } - // Resource overrides. - virtual PPB_Buffer_Impl* AsPPB_Buffer_Impl(); + // ResourceObjectBase overries. + virtual ::ppapi::thunk::PPB_Buffer_API* AsBuffer_API() OVERRIDE; - // PPB_Buffer_Impl implementation. - bool Init(uint32_t size); - void Describe(uint32_t* size_in_bytes) const; - void* Map(); - void Unmap(); + // PPB_Buffer_API implementation. + virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE; + virtual PP_Bool IsMapped() OVERRIDE; + virtual void* Map() OVERRIDE; + virtual void Unmap() OVERRIDE; private: + explicit PPB_Buffer_Impl(PluginInstance* instance); + bool Init(uint32_t size); + scoped_ptr<base::SharedMemory> shared_memory_; uint32_t size_; DISALLOW_COPY_AND_ASSIGN(PPB_Buffer_Impl); }; +// Ensures that the given buffer is mapped, and retursn it to its previous +// mapped state in the destructor. +class BufferAutoMapper { + public: + BufferAutoMapper(::ppapi::thunk::PPB_Buffer_API* api); + ~BufferAutoMapper(); + + // Will be NULL on failure to map. + void* data() { return data_; } + uint32_t size() { return size_; } + + private: + ::ppapi::thunk::PPB_Buffer_API* api_; + + bool needs_unmap_; + + void* data_; + uint32_t size_; + + DISALLOW_COPY_AND_ASSIGN(BufferAutoMapper); +}; + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_char_set_impl.cc b/webkit/plugins/ppapi/ppb_char_set_impl.cc index 5f9b54e..fcabf2f 100644 --- a/webkit/plugins/ppapi/ppb_char_set_impl.cc +++ b/webkit/plugins/ppapi/ppb_char_set_impl.cc @@ -12,51 +12,47 @@ #include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/plugins/ppapi/var.h" +using ::ppapi::thunk::PPB_CharSet_FunctionAPI; + namespace webkit { namespace ppapi { -namespace { +PPB_CharSet_Impl::PPB_CharSet_Impl(PluginInstance* instance) + : instance_(instance) { +} + +PPB_CharSet_Impl::~PPB_CharSet_Impl() { +} + +PPB_CharSet_FunctionAPI* PPB_CharSet_Impl::AsCharSet_FunctionAPI() { + return this; +} -char* UTF16ToCharSet(PP_Instance /* instance */, - const uint16_t* utf16, uint32_t utf16_len, - const char* output_char_set, - PP_CharSet_ConversionError on_error, - uint32_t* output_length) { +char* PPB_CharSet_Impl::UTF16ToCharSet(PP_Instance instance, + const uint16_t* utf16, + uint32_t utf16_len, + const char* output_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) { return ::ppapi::CharSetImpl::UTF16ToCharSet( PluginModule::GetCore(), utf16, utf16_len, output_char_set, on_error, output_length); } -uint16_t* CharSetToUTF16(PP_Instance /* instance */, - const char* input, uint32_t input_len, - const char* input_char_set, - PP_CharSet_ConversionError on_error, - uint32_t* output_length) { +uint16_t* PPB_CharSet_Impl::CharSetToUTF16(PP_Instance instance, + const char* input, + uint32_t input_len, + const char* input_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) { return ::ppapi::CharSetImpl::CharSetToUTF16( PluginModule::GetCore(), input, input_len, input_char_set, on_error, output_length); } -PP_Var GetDefaultCharSet(PP_Instance instance_id) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return PP_MakeUndefined(); - - std::string encoding = instance->delegate()->GetDefaultEncoding(); - return StringVar::StringToPPVar(instance->module(), encoding); -} - -const PPB_CharSet_Dev ppb_charset = { - &UTF16ToCharSet, - &CharSetToUTF16, - &GetDefaultCharSet -}; - -} // namespace - -// static -const struct PPB_CharSet_Dev* PPB_CharSet_Impl::GetInterface() { - return &ppb_charset; +PP_Var PPB_CharSet_Impl::GetDefaultCharSet(PP_Instance instance) { + std::string encoding = instance_->delegate()->GetDefaultEncoding(); + return StringVar::StringToPPVar(instance_->module(), encoding); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_char_set_impl.h b/webkit/plugins/ppapi/ppb_char_set_impl.h index 9c16e05..5787317 100644 --- a/webkit/plugins/ppapi/ppb_char_set_impl.h +++ b/webkit/plugins/ppapi/ppb_char_set_impl.h @@ -5,16 +5,42 @@ #ifndef WEBKIT_PLUGINS_PPAPI_PPB_CHAR_SET_IMPL_H_ #define WEBKIT_PLUGINS_PPAPI_PPB_CHAR_SET_IMPL_H_ -struct PPB_CharSet_Dev; +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/function_group_base.h" +#include "ppapi/thunk/ppb_char_set_api.h" namespace webkit { namespace ppapi { -class PPB_CharSet_Impl { +class PluginInstance; + +class PPB_CharSet_Impl : public ::ppapi::FunctionGroupBase, + public ::ppapi::thunk::PPB_CharSet_FunctionAPI { public: - // Returns a pointer to the interface implementing PPB_CharSet that is - // exposed to the plugin. - static const PPB_CharSet_Dev* GetInterface(); + PPB_CharSet_Impl(PluginInstance* instance); + ~PPB_CharSet_Impl(); + + // FunctionGroupBase overrides. + virtual ::ppapi::thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI(); + + // PPB_CharSet_FunctionAPI implementation. + virtual char* UTF16ToCharSet(PP_Instance instance, + const uint16_t* utf16, uint32_t utf16_len, + const char* output_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) OVERRIDE; + virtual uint16_t* CharSetToUTF16(PP_Instance instance, + const char* input, uint32_t input_len, + const char* input_char_set, + PP_CharSet_ConversionError on_error, + uint32_t* output_length) OVERRIDE; + virtual PP_Var GetDefaultCharSet(PP_Instance instance) OVERRIDE; + + private: + PluginInstance* instance_; + + DISALLOW_COPY_AND_ASSIGN(PPB_CharSet_Impl); }; } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_cursor_control_impl.cc b/webkit/plugins/ppapi/ppb_cursor_control_impl.cc index 05ff7925..4bfb081 100644 --- a/webkit/plugins/ppapi/ppb_cursor_control_impl.cc +++ b/webkit/plugins/ppapi/ppb_cursor_control_impl.cc @@ -15,70 +15,48 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/resource.h" +using ::ppapi::thunk::PPB_CursorControl_FunctionAPI; + namespace webkit { namespace ppapi { -namespace { - -PP_Bool SetCursor(PP_Instance instance_id, - PP_CursorType_Dev type, - PP_Resource custom_image_id, - const PP_Point* hot_spot) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return PP_FALSE; - - return BoolToPPBool(instance->SetCursor(type, custom_image_id, hot_spot)); +PPB_CursorControl_Impl::PPB_CursorControl_Impl(PluginInstance* instance) + : instance_(instance) { } -PP_Bool LockCursor(PP_Instance instance_id) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return PP_FALSE; +PPB_CursorControl_Impl::~PPB_CursorControl_Impl() { +} - // TODO(neb): implement cursor locking. - return PP_FALSE; +PPB_CursorControl_FunctionAPI* +PPB_CursorControl_Impl::AsCursorControl_FunctionAPI() { + return this; } -PP_Bool UnlockCursor(PP_Instance instance_id) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return PP_FALSE; +PP_Bool PPB_CursorControl_Impl::SetCursor(PP_Instance instance, + PP_CursorType_Dev type, + PP_Resource custom_image_id, + const PP_Point* hot_spot) { + return PP_FromBool(instance_->SetCursor(type, custom_image_id, hot_spot)); +} - // TODO(neb): implement cursor locking. +PP_Bool PPB_CursorControl_Impl::LockCursor(PP_Instance instance) { + // TODO: implement cursor locking. return PP_FALSE; } -PP_Bool HasCursorLock(PP_Instance instance_id) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return PP_FALSE; - - // TODO(neb): implement cursor locking. +PP_Bool PPB_CursorControl_Impl::UnlockCursor(PP_Instance instance) { + // TODO: implement cursor locking. return PP_FALSE; } -PP_Bool CanLockCursor(PP_Instance instance_id) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return PP_FALSE; - - // TODO(neb): implement cursor locking. +PP_Bool PPB_CursorControl_Impl::HasCursorLock(PP_Instance instance) { + // TODO: implement cursor locking. return PP_FALSE; } -const PPB_CursorControl_Dev cursor_control_interface = { - &SetCursor, - &LockCursor, - &UnlockCursor, - &HasCursorLock, - &CanLockCursor -}; - -} // namespace - -const PPB_CursorControl_Dev* GetCursorControlInterface() { - return &cursor_control_interface; +PP_Bool PPB_CursorControl_Impl::CanLockCursor(PP_Instance instance) { + // TODO: implement cursor locking. + return PP_FALSE; } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_cursor_control_impl.h b/webkit/plugins/ppapi/ppb_cursor_control_impl.h index dcce132a..7891fe1 100644 --- a/webkit/plugins/ppapi/ppb_cursor_control_impl.h +++ b/webkit/plugins/ppapi/ppb_cursor_control_impl.h @@ -5,14 +5,42 @@ #ifndef WEBKIT_PLUGINS_PPAPI_PPB_CURSOR_CONTROL_IMPL_H_ #define WEBKIT_PLUGINS_PPAPI_PPB_CURSOR_CONTROL_IMPL_H_ -struct PPB_CursorControl_Dev; +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/function_group_base.h" +#include "ppapi/thunk/ppb_cursor_control_api.h" namespace webkit { namespace ppapi { -// There's no class implementing CursorControl so we just expose a getter for -// the interface implemented in the .cc file here. -const PPB_CursorControl_Dev* GetCursorControlInterface(); +class PluginInstance; + +class PPB_CursorControl_Impl + : public ::ppapi::FunctionGroupBase, + public ::ppapi::thunk::PPB_CursorControl_FunctionAPI { + public: + PPB_CursorControl_Impl(PluginInstance* instance); + ~PPB_CursorControl_Impl(); + + // FunctionGroupBase overrides. + virtual ::ppapi::thunk::PPB_CursorControl_FunctionAPI* + AsCursorControl_FunctionAPI() OVERRIDE; + + // PPB_CursorControl_FunctionAPI implementation. + virtual PP_Bool SetCursor(PP_Instance instance, + PP_CursorType_Dev type, + PP_Resource custom_image_id, + const PP_Point* hot_spot) OVERRIDE; + virtual PP_Bool LockCursor(PP_Instance instance) OVERRIDE; + virtual PP_Bool UnlockCursor(PP_Instance instance) OVERRIDE; + virtual PP_Bool HasCursorLock(PP_Instance instance) OVERRIDE; + virtual PP_Bool CanLockCursor(PP_Instance instance) OVERRIDE; + + private: + PluginInstance* instance_; + + DISALLOW_COPY_AND_ASSIGN(PPB_CursorControl_Impl); +}; } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc index 6d596fe..6ff6928b 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.cc +++ b/webkit/plugins/ppapi/ppb_font_impl.cc @@ -127,7 +127,8 @@ int32_t PPB_Font_Impl::PixelOffsetForCharacter(const PP_TextRun_Dev* text, return result; } -PPB_Font_FunctionImpl::PPB_Font_FunctionImpl() { +PPB_Font_FunctionImpl::PPB_Font_FunctionImpl(PluginInstance* instance) + : instance_(instance) { } PPB_Font_FunctionImpl::~PPB_Font_FunctionImpl() { diff --git a/webkit/plugins/ppapi/ppb_font_impl.h b/webkit/plugins/ppapi/ppb_font_impl.h index 86a6c8a..a07816b 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.h +++ b/webkit/plugins/ppapi/ppb_font_impl.h @@ -57,7 +57,7 @@ class PPB_Font_Impl : public Resource, class PPB_Font_FunctionImpl : public ::ppapi::FunctionGroupBase, public ::ppapi::thunk::PPB_Font_FunctionAPI { public: - PPB_Font_FunctionImpl(); + PPB_Font_FunctionImpl(PluginInstance* instance); ~PPB_Font_FunctionImpl(); // FunctionGroupBase overrides. @@ -67,6 +67,8 @@ class PPB_Font_FunctionImpl : public ::ppapi::FunctionGroupBase, virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; private: + PluginInstance* instance_; + DISALLOW_COPY_AND_ASSIGN(PPB_Font_FunctionImpl); }; diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc index cf59502..cb9acb4 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc @@ -13,6 +13,7 @@ #include "ppapi/c/dev/ppp_video_decoder_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/enter.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -239,10 +240,15 @@ bool PPB_VideoDecoder_Impl::Decode( if (!platform_video_decoder_.get()) return false; - media::BitstreamBuffer decode_buffer( - bitstream_buffer->id, - Resource::GetAs<PPB_Buffer_Impl>(bitstream_buffer->data)->handle(), - bitstream_buffer->size); + ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API> + enter(bitstream_buffer->data, true); + if (enter.failed()) + return false; + + PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); + media::BitstreamBuffer decode_buffer(bitstream_buffer->id, + buffer->shared_memory()->handle(), + static_cast<size_t>(buffer->size())); // Store the callback to inform when bitstream buffer has been processed. // TODO(vmr): handle simultaneous decodes + callbacks. @@ -423,8 +429,8 @@ SysmemBuffer::SysmemBuffer(const PP_SysmemBuffer_Dev& buffer) scoped_refptr<webkit::ppapi::PPB_Buffer_Impl> pepper_buffer = webkit::ppapi::Resource::GetAs<webkit::ppapi::PPB_Buffer_Impl>( buffer.data); - assert(pepper_buffer->is_mapped()); - data_ = pepper_buffer->mapped_buffer(); + CHECK(pepper_buffer->IsMapped()); + data_ = pepper_buffer->Map(); } Picture::Picture(const PP_Picture_Dev& picture) diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index e00c546..6e4ef7d 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -8,6 +8,8 @@ #include "ppapi/shared_impl/font_impl.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppb_audio_impl.h" +#include "webkit/plugins/ppapi/ppb_broker_impl.h" +#include "webkit/plugins/ppapi/ppb_buffer_impl.h" #include "webkit/plugins/ppapi/ppb_font_impl.h" #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" @@ -15,7 +17,8 @@ namespace webkit { namespace ppapi { -ResourceCreationImpl::ResourceCreationImpl() { +ResourceCreationImpl::ResourceCreationImpl(PluginInstance* instance) + : instance_(instance) { } ResourceCreationImpl::~ResourceCreationImpl() { @@ -63,6 +66,15 @@ PP_Resource ResourceCreationImpl::CreateAudioTrusted( return audio->GetReference(); } +PP_Resource ResourceCreationImpl::CreateBroker(PP_Instance instance) { + return PPB_Broker_Impl::Create(instance); +} + +PP_Resource ResourceCreationImpl::CreateBuffer(PP_Instance instance, + uint32_t size) { + return PPB_Buffer_Impl::Create(instance, size); +} + PP_Resource ResourceCreationImpl::CreateFontObject( PP_Instance pp_instance, const PP_FontDescription_Dev* description) { diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index 8b8e551..9569620 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -13,10 +13,12 @@ namespace webkit { namespace ppapi { +class PluginInstance; + class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, public ::ppapi::thunk::ResourceCreationAPI { public: - ResourceCreationImpl(); + ResourceCreationImpl(PluginInstance* instance); virtual ~ResourceCreationImpl(); // FunctionGroupBase implementation. @@ -31,6 +33,9 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, virtual PP_Resource CreateAudioConfig(PP_Instance instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) OVERRIDE; + virtual PP_Resource CreateBroker(PP_Instance instance) OVERRIDE; + virtual PP_Resource CreateBuffer(PP_Instance instance, + uint32_t size) OVERRIDE; virtual PP_Resource CreateFontObject( PP_Instance instance, const PP_FontDescription_Dev* description) OVERRIDE; @@ -43,6 +48,8 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, PP_Bool init_to_zero) OVERRIDE; private: + PluginInstance* instance_; + DISALLOW_COPY_AND_ASSIGN(ResourceCreationImpl); }; diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc index 452b845..7e04f61 100644 --- a/webkit/plugins/ppapi/resource_tracker.cc +++ b/webkit/plugins/ppapi/resource_tracker.cc @@ -11,9 +11,12 @@ #include "base/rand_util.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_var.h" +#include "ppapi/shared_impl/function_group_base.h" #include "ppapi/shared_impl/tracker_base.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/ppb_char_set_impl.h" +#include "webkit/plugins/ppapi/ppb_cursor_control_impl.h" #include "webkit/plugins/ppapi/ppb_font_impl.h" #include "webkit/plugins/ppapi/resource.h" #include "webkit/plugins/ppapi/resource_creation_impl.h" @@ -64,6 +67,10 @@ struct ResourceTracker::InstanceData { // Resources and object vars associated with the instance. ResourceSet resources; VarSet object_vars; + + // Lazily allocated function proxies for the different interfaces. + scoped_ptr< ::ppapi::FunctionGroupBase > + function_proxies[::pp::proxy::INTERFACE_ID_COUNT]; }; scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const { @@ -112,7 +119,7 @@ PP_Resource ResourceTracker::AddResource(Resource* resource) { // Track associated with the instance. PP_Instance pp_instance = resource->instance()->pp_instance(); DCHECK(instance_map_.find(pp_instance) != instance_map_.end()); - instance_map_[pp_instance].resources.insert(new_id); + instance_map_[pp_instance]->resources.insert(new_id); return new_id; } @@ -130,7 +137,7 @@ int32 ResourceTracker::AddVar(Var* var) { if (object_var) { PP_Instance instance = object_var->instance()->pp_instance(); DCHECK(instance_map_.find(instance) != instance_map_.end()); - instance_map_[instance].object_vars.insert(new_id); + instance_map_[instance]->object_vars.insert(new_id); } return new_id; @@ -163,7 +170,7 @@ bool ResourceTracker::UnrefResource(PP_Resource res) { PP_Instance instance = to_release->instance()->pp_instance(); to_release->LastPluginRefWasDeleted(false); - instance_map_[instance].resources.erase(res); + instance_map_[instance]->resources.erase(res); live_resources_.erase(i); } return true; @@ -181,7 +188,7 @@ void ResourceTracker::CleanupInstanceData(PP_Instance instance, NOTREACHED(); return; } - InstanceData& data = found->second; + InstanceData& data = *found->second; // Force release all plugin references to resources associated with the // deleted instance. @@ -235,8 +242,8 @@ uint32 ResourceTracker::GetLiveObjectsForInstance( InstanceMap::const_iterator found = instance_map_.find(instance); if (found == instance_map_.end()) return 0; - return static_cast<uint32>(found->second.resources.size() + - found->second.object_vars.size()); + return static_cast<uint32>(found->second->resources.size() + + found->second->object_vars.size()); } ::ppapi::ResourceObjectBase* ResourceTracker::GetResourceAPI( @@ -250,18 +257,37 @@ uint32 ResourceTracker::GetLiveObjectsForInstance( } ::ppapi::FunctionGroupBase* ResourceTracker::GetFunctionAPI( - PP_Instance inst, + PP_Instance pp_instance, pp::proxy::InterfaceID id) { - if (function_proxies_[id].get()) - return function_proxies_[id].get(); + // Get the instance object. This also ensures that the instance data is in + // the map, since we need it below. + PluginInstance* instance = GetInstance(pp_instance); + if (!instance) + return NULL; - // TODO(brettw) we need a better system for doing this. - if (id == ::pp::proxy::INTERFACE_ID_RESOURCE_CREATION) - function_proxies_[id].reset(new ResourceCreationImpl()); - else if (id == ::pp::proxy::INTERFACE_ID_PPB_FONT) - function_proxies_[id].reset(new PPB_Font_FunctionImpl); + scoped_ptr< ::ppapi::FunctionGroupBase >& proxy = + instance_map_[pp_instance]->function_proxies[id]; + if (proxy.get()) + return proxy.get(); + + switch (id) { + case pp::proxy::INTERFACE_ID_PPB_CHAR_SET: + proxy.reset(new PPB_CharSet_Impl(instance)); + break; + case pp::proxy::INTERFACE_ID_PPB_CURSORCONTROL: + proxy.reset(new PPB_CursorControl_Impl(instance)); + break; + case pp::proxy::INTERFACE_ID_PPB_FONT: + proxy.reset(new PPB_Font_FunctionImpl(instance)); + break; + case pp::proxy::INTERFACE_ID_RESOURCE_CREATION: + proxy.reset(new ResourceCreationImpl(instance)); + break; + default: + NOTREACHED(); + } - return function_proxies_[id].get(); + return proxy.get(); } scoped_refptr<Var> ResourceTracker::GetVar(int32 var_id) const { @@ -295,7 +321,7 @@ bool ResourceTracker::UnrefVar(int32 var_id) { if (!--i->second.second) { ObjectVar* object_var = i->second.first->AsObjectVar(); if (object_var) { - instance_map_[object_var->instance()->pp_instance()].object_vars.erase( + instance_map_[object_var->instance()->pp_instance()]->object_vars.erase( var_id); } live_vars_.erase(i); @@ -320,7 +346,8 @@ PP_Instance ResourceTracker::AddInstance(PluginInstance* instance) { instance_map_.find(new_instance) != instance_map_.end() || !instance->module()->ReserveInstanceID(new_instance)); - instance_map_[new_instance].instance = instance; + instance_map_[new_instance] = linked_ptr<InstanceData>(new InstanceData); + instance_map_[new_instance]->instance = instance; return new_instance; } @@ -338,7 +365,7 @@ PluginInstance* ResourceTracker::GetInstance(PP_Instance instance) { InstanceMap::iterator found = instance_map_.find(instance); if (found == instance_map_.end()) return NULL; - return found->second.instance; + return found->second->instance; } PP_Module ResourceTracker::AddModule(PluginModule* module) { diff --git a/webkit/plugins/ppapi/resource_tracker.h b/webkit/plugins/ppapi/resource_tracker.h index dca40eb..2d008f9 100644 --- a/webkit/plugins/ppapi/resource_tracker.h +++ b/webkit/plugins/ppapi/resource_tracker.h @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" #include "base/hash_tables.h" +#include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "ppapi/c/pp_instance.h" @@ -60,7 +61,7 @@ class ResourceTracker : public ::ppapi::TrackerBase { virtual ::ppapi::ResourceObjectBase* GetResourceAPI( PP_Resource res); virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( - PP_Instance inst, + PP_Instance pp_instance, pp::proxy::InterfaceID id); // PP_Vars ------------------------------------------------------------------- @@ -180,7 +181,7 @@ class ResourceTracker : public ::ppapi::TrackerBase { VarMap live_vars_; // Tracks all live instances and their associated data. - typedef std::map<PP_Instance, InstanceData> InstanceMap; + typedef std::map<PP_Instance, linked_ptr<InstanceData> > InstanceMap; InstanceMap instance_map_; // Tracks all live modules. The pointers are non-owning, the PluginModule @@ -188,9 +189,6 @@ class ResourceTracker : public ::ppapi::TrackerBase { typedef std::map<PP_Module, PluginModule*> ModuleMap; ModuleMap module_map_; - scoped_ptr< ::ppapi::FunctionGroupBase > - function_proxies_[::pp::proxy::INTERFACE_ID_COUNT]; - DISALLOW_COPY_AND_ASSIGN(ResourceTracker); }; |