summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-05 22:13:39 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-05 22:13:39 +0000
commitf6b8a8d47aeba7ee52e1b3f1ee93f84972a0348c (patch)
treeeaa8ffdb4d676906caba00f241f5c320d460ffb4 /ppapi
parent4c2e935b2b9adc5894b9de72b4a119a8cd173b63 (diff)
downloadchromium_src-f6b8a8d47aeba7ee52e1b3f1ee93f84972a0348c.zip
chromium_src-f6b8a8d47aeba7ee52e1b3f1ee93f84972a0348c.tar.gz
chromium_src-f6b8a8d47aeba7ee52e1b3f1ee93f84972a0348c.tar.bz2
Add proxies for core and class (for calling from WebKit to the plugin). These
don't build by themselves, this is part of a larger patch. You can see most of the serialization mechanics already checked in to the same directory. TEST=none BUG=none Review URL: http://codereview.chromium.org/4345003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65261 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/proxy/ppb_core_proxy.cc118
-rw-r--r--ppapi/proxy/ppb_core_proxy.h41
-rw-r--r--ppapi/proxy/ppp_class_proxy.cc303
-rw-r--r--ppapi/proxy/ppp_class_proxy.h89
4 files changed, 551 insertions, 0 deletions
diff --git a/ppapi/proxy/ppb_core_proxy.cc b/ppapi/proxy/ppb_core_proxy.cc
new file mode 100644
index 0000000..7d8c5f4
--- /dev/null
+++ b/ppapi/proxy/ppb_core_proxy.cc
@@ -0,0 +1,118 @@
+// 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/proxy/ppb_core_proxy.h"
+
+#include <stdlib.h> // For malloc
+
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "base/time.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/ppb_core.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
+namespace pp {
+namespace proxy {
+
+namespace {
+
+base::MessageLoopProxy* GetMainThreadMessageLoop() {
+ static scoped_refptr<base::MessageLoopProxy> proxy(
+ base::MessageLoopProxy::CreateForCurrentThread());
+ return proxy.get();
+}
+
+void AddRefResource(PP_Resource resource) {
+ PluginDispatcher::Get()->plugin_resource_tracker()->AddRefResource(resource);
+}
+
+void ReleaseResource(PP_Resource resource) {
+ PluginDispatcher::Get()->plugin_resource_tracker()->ReleaseResource(resource);
+}
+
+void* MemAlloc(size_t num_bytes) {
+ return malloc(num_bytes);
+}
+
+void MemFree(void* ptr) {
+ free(ptr);
+}
+
+double GetTime() {
+ return base::Time::Now().ToDoubleT();
+}
+
+double GetTimeTicks() {
+ // TODO(brettw) http://code.google.com/p/chromium/issues/detail?id=57448
+ // This should be a tick timer rather than wall clock time, but needs to
+ // match message times, which also currently use wall clock time.
+ return GetTime();
+}
+
+void CallOnMainThread(int delay_in_ms,
+ PP_CompletionCallback callback,
+ int32_t result) {
+ GetMainThreadMessageLoop()->PostDelayedTask(
+ FROM_HERE,
+ NewRunnableFunction(callback.func, callback.user_data, result),
+ delay_in_ms);
+}
+
+bool IsMainThread() {
+ return GetMainThreadMessageLoop()->BelongsToCurrentThread();
+}
+
+const PPB_Core core_interface = {
+ &AddRefResource,
+ &ReleaseResource,
+ &MemAlloc,
+ &MemFree,
+ &GetTime,
+ &GetTimeTicks,
+ &CallOnMainThread,
+ &IsMainThread
+};
+
+} // namespace
+
+PPB_Core_Proxy::PPB_Core_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_Core_Proxy::~PPB_Core_Proxy() {
+}
+
+const void* PPB_Core_Proxy::GetSourceInterface() const {
+ return &core_interface;
+}
+
+InterfaceID PPB_Core_Proxy::GetInterfaceId() const {
+ return INTERFACE_ID_PPB_CORE;
+}
+
+void PPB_Core_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(PPB_Core_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCore_AddRefResource,
+ OnMsgAddRefResource)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCore_ReleaseResource,
+ OnMsgReleaseResource)
+ IPC_END_MESSAGE_MAP()
+ // TODO(brettw) handle bad messages!
+}
+
+void PPB_Core_Proxy::OnMsgAddRefResource(PP_Resource resource) {
+ ppb_core_target()->AddRefResource(resource);
+}
+
+void PPB_Core_Proxy::OnMsgReleaseResource(PP_Resource resource) {
+ ppb_core_target()->ReleaseResource(resource);
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_core_proxy.h b/ppapi/proxy/ppb_core_proxy.h
new file mode 100644
index 0000000..66f17d8a
--- /dev/null
+++ b/ppapi/proxy/ppb_core_proxy.h
@@ -0,0 +1,41 @@
+// 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_PPB_CORE_PROXY_H_
+#define PPAPI_PPB_CORE_PROXY_H_
+
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_var.h"
+#include "ppapi/proxy/interface_proxy.h"
+
+struct PPB_Core;
+
+namespace pp {
+namespace proxy {
+
+class PPB_Core_Proxy : public InterfaceProxy {
+ public:
+ PPB_Core_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPB_Core_Proxy();
+
+ const PPB_Core* ppb_core_target() const {
+ return reinterpret_cast<const PPB_Core*>(target_interface());
+ }
+
+ // InterfaceProxy implementation.
+ virtual const void* GetSourceInterface() const;
+ virtual InterfaceID GetInterfaceId() const;
+ virtual void OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // Message handlers.
+ void OnMsgAddRefResource(PP_Resource resource);
+ void OnMsgReleaseResource(PP_Resource resource);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PPB_CORE_PROXY_H_
diff --git a/ppapi/proxy/ppp_class_proxy.cc b/ppapi/proxy/ppp_class_proxy.cc
new file mode 100644
index 0000000..b2fad17
--- /dev/null
+++ b/ppapi/proxy/ppp_class_proxy.cc
@@ -0,0 +1,303 @@
+// 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/proxy/ppp_class_proxy.h"
+
+#include "ppapi/c/dev/ppb_var_deprecated.h"
+#include "ppapi/c/dev/ppp_class_deprecated.h"
+#include "ppapi/proxy/dispatcher.h"
+#include "ppapi/proxy/interface_id.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/serialized_var.h"
+
+namespace pp {
+namespace proxy {
+
+namespace {
+
+// PPP_Class in the browser implementation -------------------------------------
+
+// Represents a plugin-implemented class in the browser process. This just
+// stores the data necessary to call back the plugin.
+struct ObjectProxy {
+ ObjectProxy(Dispatcher* d, int64 p, int64 ud)
+ : dispatcher(d),
+ ppp_class(p),
+ user_data(ud) {
+ }
+
+ Dispatcher* dispatcher;
+ int64 ppp_class;
+ int64 user_data;
+};
+
+ObjectProxy* ToObjectProxy(void* data) {
+ return reinterpret_cast<ObjectProxy*>(data);
+}
+
+bool HasProperty(void* object, PP_Var name, PP_Var* exception) {
+ ObjectProxy* obj = ToObjectProxy(object);
+ bool result = false;
+ ReceiveSerializedException se(obj->dispatcher, exception);
+ obj->dispatcher->Send(new PpapiMsg_PPPClass_HasProperty(
+ INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data,
+ SerializedVarSendInput(obj->dispatcher, name), &se, &result));
+ return result;
+}
+
+bool HasMethod(void* object, PP_Var name, PP_Var* exception) {
+ ObjectProxy* obj = ToObjectProxy(object);
+ bool result = false;
+ ReceiveSerializedException se(obj->dispatcher, exception);
+ obj->dispatcher->Send(new PpapiMsg_PPPClass_HasMethod(
+ INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data,
+ SerializedVarSendInput(obj->dispatcher, name), &se, &result));
+ return result;
+}
+
+PP_Var GetProperty(void* object,
+ PP_Var name,
+ PP_Var* exception) {
+ ObjectProxy* obj = ToObjectProxy(object);
+ ReceiveSerializedException se(obj->dispatcher, exception);
+ ReceiveSerializedVarReturnValue result;
+ obj->dispatcher->Send(new PpapiMsg_PPPClass_GetProperty(
+ INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data,
+ SerializedVarSendInput(obj->dispatcher, name), &se, &result));
+ return result.Return(obj->dispatcher);
+}
+
+void GetAllPropertyNames(void* object,
+ uint32_t* property_count,
+ PP_Var** properties,
+ PP_Var* exception) {
+ NOTIMPLEMENTED();
+ // TODO(brettw) implement this.
+}
+
+void SetProperty(void* object,
+ PP_Var name,
+ PP_Var value,
+ PP_Var* exception) {
+ ObjectProxy* obj = ToObjectProxy(object);
+ ReceiveSerializedException se(obj->dispatcher, exception);
+ obj->dispatcher->Send(new PpapiMsg_PPPClass_SetProperty(
+ INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data,
+ SerializedVarSendInput(obj->dispatcher, name),
+ SerializedVarSendInput(obj->dispatcher, value), &se));
+}
+
+void RemoveProperty(void* object,
+ PP_Var name,
+ PP_Var* exception) {
+ ObjectProxy* obj = ToObjectProxy(object);
+ ReceiveSerializedException se(obj->dispatcher, exception);
+ obj->dispatcher->Send(new PpapiMsg_PPPClass_RemoveProperty(
+ INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data,
+ SerializedVarSendInput(obj->dispatcher, name), &se));
+}
+
+PP_Var Call(void* object,
+ PP_Var method_name,
+ uint32_t argc,
+ PP_Var* argv,
+ PP_Var* exception) {
+ ObjectProxy* obj = ToObjectProxy(object);
+
+ ReceiveSerializedVarReturnValue result;
+ ReceiveSerializedException se(obj->dispatcher, exception);
+ std::vector<SerializedVar> argv_vect;
+ SerializedVarSendInput::ConvertVector(obj->dispatcher, argv, argc,
+ &argv_vect);
+
+ obj->dispatcher->Send(new PpapiMsg_PPPClass_Call(
+ INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data,
+ SerializedVarSendInput(obj->dispatcher, method_name), argv_vect,
+ &se, &result));
+ return result.Return(obj->dispatcher);
+}
+
+PP_Var Construct(void* object,
+ uint32_t argc,
+ PP_Var* argv,
+ PP_Var* exception) {
+ ObjectProxy* obj = ToObjectProxy(object);
+
+ ReceiveSerializedVarReturnValue result;
+ ReceiveSerializedException se(obj->dispatcher, exception);
+ std::vector<SerializedVar> argv_vect;
+ SerializedVarSendInput::ConvertVector(obj->dispatcher, argv, argc,
+ &argv_vect);
+
+ obj->dispatcher->Send(new PpapiMsg_PPPClass_Construct(
+ INTERFACE_ID_PPP_CLASS,
+ obj->ppp_class, obj->user_data, argv_vect, &se, &result));
+ return result.Return(obj->dispatcher);
+}
+
+void Deallocate(void* object) {
+ ObjectProxy* obj = ToObjectProxy(object);
+ obj->dispatcher->Send(new PpapiMsg_PPPClass_Deallocate(
+ INTERFACE_ID_PPP_CLASS, obj->ppp_class, obj->user_data));
+ delete obj;
+}
+
+const PPP_Class_Deprecated class_interface = {
+ &HasProperty,
+ &HasMethod,
+ &GetProperty,
+ &GetAllPropertyNames,
+ &SetProperty,
+ &RemoveProperty,
+ &Call,
+ &Construct,
+ &Deallocate
+};
+
+// Plugin helper functions -----------------------------------------------------
+
+// Converts an int64 object from IPC to a PPP_Class* for calling into the
+// plugin's implementation.
+const PPP_Class_Deprecated* ToPPPClass(int64 value) {
+ return reinterpret_cast<const PPP_Class_Deprecated*>(
+ static_cast<intptr_t>(value));
+}
+
+// Converts an int64 object from IPC to a void* for calling into the plugin's
+// implementation as the user data.
+void* ToUserData(int64 value) {
+ return reinterpret_cast<void*>(static_cast<intptr_t>(value));
+}
+
+} // namespace
+
+// PPP_Class_Proxy -------------------------------------------------------------
+
+PPP_Class_Proxy::PPP_Class_Proxy(Dispatcher* dispatcher)
+ : InterfaceProxy(dispatcher, NULL) {
+}
+
+PPP_Class_Proxy::~PPP_Class_Proxy() {
+}
+
+// static
+PP_Var PPP_Class_Proxy::CreateProxiedObject(const PPB_Var_Deprecated* var,
+ Dispatcher* dispatcher,
+ PP_Module module_id,
+ int64 ppp_class,
+ int64 class_data) {
+ ObjectProxy* object_proxy = new ObjectProxy(dispatcher,
+ ppp_class, class_data);
+ return var->CreateObject(module_id, &class_interface, object_proxy);
+}
+
+const void* PPP_Class_Proxy::GetSourceInterface() const {
+ return &class_interface;
+}
+
+InterfaceID PPP_Class_Proxy::GetInterfaceId() const {
+ return INTERFACE_ID_PPP_CLASS;
+}
+
+void PPP_Class_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(PPP_Class_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_HasProperty,
+ OnMsgHasProperty)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_HasMethod,
+ OnMsgHasMethod)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_GetProperty,
+ OnMsgGetProperty)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_EnumerateProperties,
+ OnMsgEnumerateProperties)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_SetProperty,
+ OnMsgSetProperty)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Call,
+ OnMsgCall)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Construct,
+ OnMsgConstruct)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPPClass_Deallocate,
+ OnMsgDeallocate)
+ IPC_END_MESSAGE_MAP()
+}
+
+void PPP_Class_Proxy::OnMsgHasProperty(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarOutParam exception,
+ bool* result) {
+ *result = ToPPPClass(ppp_class)->HasProperty(ToUserData(object),
+ property.Get(dispatcher()), exception.OutParam(dispatcher()));
+}
+
+void PPP_Class_Proxy::OnMsgHasMethod(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarOutParam exception,
+ bool* result) {
+ *result = ToPPPClass(ppp_class)->HasMethod(ToUserData(object),
+ property.Get(dispatcher()), exception.OutParam(dispatcher()));
+}
+
+void PPP_Class_Proxy::OnMsgGetProperty(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarOutParam exception,
+ SerializedVarReturnValue result) {
+ result.Return(dispatcher(), ToPPPClass(ppp_class)->GetProperty(
+ ToUserData(object), property.Get(dispatcher()),
+ exception.OutParam(dispatcher())));
+}
+
+void PPP_Class_Proxy::OnMsgEnumerateProperties(
+ int64 ppp_class, int64 object,
+ std::vector<pp::proxy::SerializedVar>* props,
+ SerializedVarOutParam exception) {
+ NOTIMPLEMENTED();
+ // TODO(brettw) implement this.
+}
+
+void PPP_Class_Proxy::OnMsgSetProperty(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarReceiveInput value,
+ SerializedVarOutParam exception) {
+ ToPPPClass(ppp_class)->SetProperty(
+ ToUserData(object), property.Get(dispatcher()), value.Get(dispatcher()),
+ exception.OutParam(dispatcher()));
+}
+
+void PPP_Class_Proxy::OnMsgRemoveProperty(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarOutParam exception) {
+ ToPPPClass(ppp_class)->RemoveProperty(
+ ToUserData(object), property.Get(dispatcher()),
+ exception.OutParam(dispatcher()));
+}
+
+void PPP_Class_Proxy::OnMsgCall(
+ int64 ppp_class, int64 object,
+ SerializedVarReceiveInput method_name,
+ SerializedVarVectorReceiveInput arg_vector,
+ SerializedVarOutParam exception,
+ SerializedVarReturnValue result) {
+ uint32_t arg_count = 0;
+ PP_Var* args = arg_vector.Get(dispatcher(), &arg_count);
+ result.Return(dispatcher(), ToPPPClass(ppp_class)->Call(
+ ToUserData(object), method_name.Get(dispatcher()),
+ arg_count, args, exception.OutParam(dispatcher())));
+}
+
+void PPP_Class_Proxy::OnMsgConstruct(
+ int64 ppp_class, int64 object,
+ SerializedVarVectorReceiveInput arg_vector,
+ SerializedVarOutParam exception,
+ SerializedVarReturnValue result) {
+ uint32_t arg_count = 0;
+ PP_Var* args = arg_vector.Get(dispatcher(), &arg_count);
+ result.Return(dispatcher(), ToPPPClass(ppp_class)->Construct(
+ ToUserData(object), arg_count, args, exception.OutParam(dispatcher())));
+}
+
+void PPP_Class_Proxy::OnMsgDeallocate(int64 ppp_class, int64 object) {
+ ToPPPClass(ppp_class)->Deallocate(ToUserData(object));
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppp_class_proxy.h b/ppapi/proxy/ppp_class_proxy.h
new file mode 100644
index 0000000..b22d86a
--- /dev/null
+++ b/ppapi/proxy/ppp_class_proxy.h
@@ -0,0 +1,89 @@
+// 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_PROXY_PPP_CLASS_PROXY_H_
+#define PPAPI_PROXY_PPP_CLASS_PROXY_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "ppapi/c/pp_module.h"
+#include "ppapi/c/pp_var.h"
+#include "ppapi/proxy/interface_proxy.h"
+
+struct PPB_Var_Deprecated;
+struct PPP_Class_Deprecated;
+
+namespace pp {
+namespace proxy {
+
+class SerializedVar;
+class SerializedVarReceiveInput;
+class SerializedVarVectorReceiveInput;
+class SerializedVarOutParam;
+class SerializedVarReturnValue;
+
+class PPP_Class_Proxy : public InterfaceProxy {
+ public:
+ // PPP_Class isn't a normal interface that you can query for, so this
+ // constructor doesn't take an interface pointer.
+ PPP_Class_Proxy(Dispatcher* dispatcher);
+ virtual ~PPP_Class_Proxy();
+
+ // Creates a proxied object in the browser process. This takes the browser's
+ // PPB_Var_Deprecated interface to use to create the object. The class and
+ static PP_Var CreateProxiedObject(const PPB_Var_Deprecated* var,
+ Dispatcher* dispatcher,
+ PP_Module module_id,
+ int64 ppp_class,
+ int64 class_data);
+
+ // InterfaceProxy implementation.
+ virtual const void* GetSourceInterface() const;
+ virtual InterfaceID GetInterfaceId() const;
+ virtual void OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // IPC message handlers.
+ void OnMsgHasProperty(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarOutParam exception,
+ bool* result);
+ void OnMsgHasMethod(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarOutParam exception,
+ bool* result);
+ void OnMsgGetProperty(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarOutParam exception,
+ SerializedVarReturnValue result);
+ void OnMsgEnumerateProperties(
+ int64 ppp_class, int64 object,
+ std::vector<pp::proxy::SerializedVar>* props,
+ SerializedVarOutParam exception);
+ void OnMsgSetProperty(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarReceiveInput value,
+ SerializedVarOutParam exception);
+ void OnMsgRemoveProperty(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput property,
+ SerializedVarOutParam exception);
+ void OnMsgCall(int64 ppp_class, int64 object,
+ SerializedVarReceiveInput method_name,
+ SerializedVarVectorReceiveInput arg_vector,
+ SerializedVarOutParam exception,
+ SerializedVarReturnValue result);
+ void OnMsgConstruct(int64 ppp_class, int64 object,
+ SerializedVarVectorReceiveInput arg_vector,
+ SerializedVarOutParam exception,
+ SerializedVarReturnValue result);
+ void OnMsgDeallocate(int64 ppp_class, int64 object);
+
+ DISALLOW_COPY_AND_ASSIGN(PPP_Class_Proxy);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PPP_CLASS_PROXY_H_