summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-23 23:32:55 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-23 23:32:55 +0000
commit19215f85f0e477936a13c77450d0b12e40d7839c (patch)
tree95e4791d7a1e9bb1bd9736b2f3ec4cd0d1e5608a /remoting
parent4dd33d2a1bf4bff8c1c637bf38dda3f6d7882af5 (diff)
downloadchromium_src-19215f85f0e477936a13c77450d0b12e40d7839c.zip
chromium_src-19215f85f0e477936a13c77450d0b12e40d7839c.tar.gz
chromium_src-19215f85f0e477936a13c77450d0b12e40d7839c.tar.bz2
Add in support for internal pepper plugins into the PepperPluginRegistry and pepper::PluginModule.
Used Chromoting's plugin as the first attempt at using this interface. BUG=none TEST=compiles Review URL: http://codereview.chromium.org/2843018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50667 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/client/plugin/chromoting_plugin.cc27
-rw-r--r--remoting/client/plugin/chromoting_plugin.h16
-rw-r--r--remoting/client/plugin/pepper_entrypoints.cc233
-rw-r--r--remoting/client/plugin/pepper_entrypoints.h20
-rw-r--r--remoting/remoting.gyp85
5 files changed, 325 insertions, 56 deletions
diff --git a/remoting/client/plugin/chromoting_plugin.cc b/remoting/client/plugin/chromoting_plugin.cc
index 1657e20..9bc6fc2 100644
--- a/remoting/client/plugin/chromoting_plugin.cc
+++ b/remoting/client/plugin/chromoting_plugin.cc
@@ -23,13 +23,15 @@ using std::vector;
namespace remoting {
-const char* ChromotingPlugin::kMimeType =
- "pepper-application/x-chromoting-plugin::Chromoting";
-
-ChromotingPlugin::ChromotingPlugin(PP_Instance instance)
- : pp::Instance(instance),
- width_(0),
- height_(0) {
+const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting";
+
+ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance,
+ const PPB_Instance* ppb_instance_funcs)
+ : width_(0),
+ height_(0),
+ drawing_context_(NULL),
+ pp_instance_(pp_instance),
+ ppb_instance_funcs_(ppb_instance_funcs) {
}
ChromotingPlugin::~ChromotingPlugin() {
@@ -47,7 +49,8 @@ ChromotingPlugin::~ChromotingPlugin() {
main_thread_->Stop();
}
-bool ChromotingPlugin::Init(uint32_t argc, const char* argn[], const char* argv[]) {
+bool ChromotingPlugin::Init(uint32_t argc, const char* argn[],
+ const char* argv[]) {
LOG(INFO) << "Started ChromotingPlugin::Init";
// Extract the URL from the arguments.
@@ -112,8 +115,13 @@ void ChromotingPlugin::ViewChanged(const PP_Rect& position,
width_ = position.size.width;
height_ = position.size.height;
+ /*
+ * TODO(ajwong): Reenable this code once we fingure out how we want to
+ * abstract away the C-api for DeviceContext2D.
device_context_ = pp::DeviceContext2D(width_, height_, false);
- if (!BindGraphicsDeviceContext(device_context_)) {
+ if (!ppb_instance_funcs_->BindGraphicsDeviceContext(
+ pp_instance_,
+ device_context_.pp_resource())) {
LOG(ERROR) << "Couldn't bind the device context.";
return;
}
@@ -130,6 +138,7 @@ void ChromotingPlugin::ViewChanged(const PP_Rect& position,
} else {
LOG(ERROR) << "Unable to allocate image.";
}
+ */
//client_->SetViewport(0, 0, width_, height_);
//client_->Repaint();
diff --git a/remoting/client/plugin/chromoting_plugin.h b/remoting/client/plugin/chromoting_plugin.h
index d19b612..757e038 100644
--- a/remoting/client/plugin/chromoting_plugin.h
+++ b/remoting/client/plugin/chromoting_plugin.h
@@ -11,8 +11,11 @@
#include "base/scoped_ptr.h"
#include "remoting/client/host_connection.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
-#include "third_party/ppapi/cpp/device_context_2d.h"
-#include "third_party/ppapi/cpp/instance.h"
+#include "third_party/ppapi/c/pp_event.h"
+#include "third_party/ppapi/c/pp_instance.h"
+#include "third_party/ppapi/c/pp_rect.h"
+#include "third_party/ppapi/c/pp_resource.h"
+#include "third_party/ppapi/c/ppb_instance.h"
namespace base {
class Thread;
@@ -27,7 +30,7 @@ class PepperView;
class ChromotingClient;
-class ChromotingPlugin : public pp::Instance {
+class ChromotingPlugin {
public:
// The mimetype for which this plugin is registered.
//
@@ -35,7 +38,7 @@ class ChromotingPlugin : public pp::Instance {
// point. I think we should handle a special protocol (eg., chromotocol://)
static const char *kMimeType;
- ChromotingPlugin(PP_Instance instance);
+ ChromotingPlugin(PP_Instance instance, const PPB_Instance* instance_funcs);
virtual ~ChromotingPlugin();
virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
@@ -55,7 +58,10 @@ class ChromotingPlugin : public pp::Instance {
int width_;
int height_;
- pp::DeviceContext2D device_context_;
+ PP_Resource drawing_context_;
+
+ PP_Instance pp_instance_;
+ const PPB_Instance* ppb_instance_funcs_;
scoped_ptr<base::Thread> main_thread_;
scoped_ptr<JingleThread> network_thread_;
diff --git a/remoting/client/plugin/pepper_entrypoints.cc b/remoting/client/plugin/pepper_entrypoints.cc
new file mode 100644
index 0000000..0ca7a06
--- /dev/null
+++ b/remoting/client/plugin/pepper_entrypoints.cc
@@ -0,0 +1,233 @@
+// 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 "remoting/client/plugin/pepper_entrypoints.h"
+
+#include "remoting/client/plugin/chromoting_plugin.h"
+#include "third_party/ppapi/c/pp_instance.h"
+#include "third_party/ppapi/c/pp_module.h"
+#include "third_party/ppapi/c/ppp_instance.h"
+#include "third_party/ppapi/cpp/instance.h"
+#include "third_party/ppapi/cpp/module.h"
+
+static const int kModuleInitSuccess = 0;
+static const int kModuleInitFailure = 1;
+
+namespace remoting {
+
+// Fork of ppapi::Module
+//
+// TODO(ajwong): Generalize this into something that other internal plugins can
+// use. Either that, or attempt to refactor the external ppapi C++ wrapper to
+// make it friendly for multiple Modules in one process. I think we can do this
+// by:
+// 1) Moving the singleton Module instance + C-bindings into another class
+// (eg., ModuleExporter) under a different gyp targe.
+// 2) Extracting the idea of a "Browser" out of the module that returns
+// PPB_Core, etc. This can be a singleton per process regardless of
+// module.
+// 3) Migrate all PPB related objects to get data out of Browser interface
+// instead of Module::Get().
+class ChromotingModule {
+ public:
+ ChromotingModule() {}
+
+ // This function will be automatically called after the object is created.
+ // This is where you can put functions that rely on other parts of the API,
+ // now that the module has been created.
+ virtual bool Init() { return true; }
+
+ PP_Module pp_module() const { return pp_module_; }
+ const PPB_Core& core() const { return *core_; }
+
+ // Implements GetInterface for the browser to get plugin interfaces. Override
+ // if you need to implement your own interface types that this wrapper
+ // doesn't support.
+ virtual const void* GetInstanceInterface(const char* interface_name) {
+ if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0)
+ return &instance_interface_;
+
+ return NULL;
+ }
+
+ // Returns an interface in the browser.
+ const void* GetBrowserInterface(const char* interface_name) {
+ return get_browser_interface_(interface_name);
+ }
+
+ // Returns the object associated with this PP_Instance, or NULL if one is
+ // not found.
+ ChromotingPlugin* InstanceForPPInstance(PP_Instance instance) {
+ InstanceMap::iterator found = current_instances_.find(instance);
+ if (found == current_instances_.end())
+ return NULL;
+ return found->second;
+ }
+
+ // Sets the browser interface and calls the regular init function that
+ // can be overridden by the base classes.
+ //
+ // TODO(brettw) make this private when I can figure out how to make the
+ // initialize function a friend.
+ bool InternalInit(PP_Module mod,
+ PPB_GetInterface get_browser_interface) {
+ pp_module_ = mod;
+ get_browser_interface_ = get_browser_interface;
+ core_ = reinterpret_cast<const PPB_Core*>(GetBrowserInterface(
+ PPB_CORE_INTERFACE));
+ if (!core_)
+ return false; // Can't run without the core interface.
+
+ return Init();
+ }
+
+ // Implementation of Global PPP functions ---------------------------------
+ static int PPP_InitializeModule(PP_Module module_id,
+ PPB_GetInterface get_browser_interface) {
+ ChromotingModule* module = new ChromotingModule();
+ if (!module)
+ return kModuleInitFailure;
+
+ if (!module->InternalInit(module_id, get_browser_interface)) {
+ delete module;
+ return kModuleInitFailure;
+ }
+
+ module_singleton_ = module;
+ return kModuleInitSuccess;
+ }
+
+ static void PPP_ShutdownModule() {
+ delete module_singleton_;
+ module_singleton_ = NULL;
+ }
+
+ static const void* PPP_GetInterface(const char* interface_name) {
+ if (!module_singleton_)
+ return NULL;
+ return module_singleton_->GetInstanceInterface(interface_name);
+ }
+
+ protected:
+ virtual ChromotingPlugin* CreateInstance(PP_Instance instance) {
+ const PPB_Instance* ppb_instance_funcs =
+ reinterpret_cast<const PPB_Instance *>(
+ module_singleton_->GetBrowserInterface(PPB_INSTANCE_INTERFACE));
+ return new ChromotingPlugin(instance, ppb_instance_funcs);
+ }
+
+ private:
+ static bool Instance_New(PP_Instance instance) {
+ if (!module_singleton_)
+ return false;
+ ChromotingPlugin* obj = module_singleton_->CreateInstance(instance);
+ if (obj) {
+ module_singleton_->current_instances_[instance] = obj;
+ return true;
+ }
+ return false;
+ }
+
+ static void Instance_Delete(PP_Instance instance) {
+ if (!module_singleton_)
+ return;
+ ChromotingModule::InstanceMap::iterator found =
+ module_singleton_->current_instances_.find(instance);
+ if (found == module_singleton_->current_instances_.end())
+ return;
+
+ // Remove it from the map before deleting to try to catch reentrancy.
+ ChromotingPlugin* obj = found->second;
+ module_singleton_->current_instances_.erase(found);
+ delete obj;
+ }
+
+ static bool Instance_Initialize(PP_Instance pp_instance,
+ uint32_t argc,
+ const char* argn[],
+ const char* argv[]) {
+ if (!module_singleton_)
+ return false;
+ ChromotingPlugin* instance =
+ module_singleton_->InstanceForPPInstance(pp_instance);
+ if (!instance)
+ return false;
+ return instance->Init(argc, argn, argv);
+ }
+
+ static bool Instance_HandleEvent(PP_Instance pp_instance,
+ const PP_Event* event) {
+ if (!module_singleton_)
+ return false;
+ ChromotingPlugin* instance =
+ module_singleton_->InstanceForPPInstance(pp_instance);
+ if (!instance)
+ return false;
+ return instance->HandleEvent(*event);
+ }
+
+ static PP_Var Instance_GetInstanceObject(PP_Instance pp_instance) {
+ PP_Var var;
+ var.type = PP_VarType_Void;
+ return var;
+ }
+
+ static void Instance_ViewChanged(PP_Instance pp_instance,
+ const PP_Rect* position,
+ const PP_Rect* clip) {
+ if (!module_singleton_)
+ return;
+ ChromotingPlugin* instance =
+ module_singleton_->InstanceForPPInstance(pp_instance);
+ if (!instance)
+ return;
+ instance->ViewChanged(*position, *clip);
+ }
+
+ // Bindings and identifiers to and from the browser.
+ PP_Module pp_module_;
+ PPB_GetInterface get_browser_interface_;
+ PPB_Core const* core_;
+
+ // Instance tracking.
+ typedef std::map<PP_Instance, ChromotingPlugin*> InstanceMap;
+ InstanceMap current_instances_;
+
+ // Static members for the ppapi C-bridge.
+ static PPP_Instance instance_interface_;
+ static ChromotingModule* module_singleton_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromotingModule);
+};
+
+ChromotingModule* ChromotingModule::module_singleton_ = NULL;
+
+PPP_Instance ChromotingModule::instance_interface_ = {
+ &ChromotingModule::Instance_New,
+ &ChromotingModule::Instance_Delete,
+ &ChromotingModule::Instance_Initialize,
+ &ChromotingModule::Instance_HandleEvent,
+ &ChromotingModule::Instance_GetInstanceObject,
+ &ChromotingModule::Instance_ViewChanged,
+};
+
+// Implementation of Global PPP functions ---------------------------------
+//
+// TODO(ajwong): This is to get around friending issues. Fix it after we decide
+// whether or not ChromotingModule should be generalized.
+int PPP_InitializeModule(PP_Module module_id,
+ PPB_GetInterface get_browser_interface) {
+ return ChromotingModule::PPP_InitializeModule(module_id,
+ get_browser_interface);
+}
+
+void PPP_ShutdownModule() {
+ return ChromotingModule::PPP_ShutdownModule();
+}
+
+const void* PPP_GetInterface(const char* interface_name) {
+ return ChromotingModule::PPP_GetInterface(interface_name);
+}
+
+} // namespace remoting
diff --git a/remoting/client/plugin/pepper_entrypoints.h b/remoting/client/plugin/pepper_entrypoints.h
new file mode 100644
index 0000000..ab6de20
--- /dev/null
+++ b/remoting/client/plugin/pepper_entrypoints.h
@@ -0,0 +1,20 @@
+// 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 REMOTING_CLIENT_PLUGIN_PEPPER_ENTRYPOINTS_
+#define REMOTING_CLIENT_PLUGIN_PEPPER_ENTRYPOINTS_
+
+#include "third_party/ppapi/c/pp_module.h"
+#include "third_party/ppapi/c/ppb.h"
+
+namespace remoting {
+
+int PPP_InitializeModule(PP_Module module_id,
+ PPB_GetInterface get_browser_interface);
+void PPP_ShutdownModule();
+const void* PPP_GetInterface(const char* interface_name);
+
+} // namespace remoting
+
+#endif // REMOTING_CLIENT_PLUGIN_PEPPER_ENTRYPOINTS_
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 47dc6ea..818fbd3 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -16,46 +16,8 @@
},
'conditions': [
- # Chromoting Client targets
['OS=="linux" or OS=="mac"', {
'targets': [
- {
- 'target_name': 'chromoting_client_plugin',
- 'type': 'static_library',
- 'defines': [
- 'HAVE_STDINT_H', # Required by on2_integer.h
- ],
- 'dependencies': [
- 'chromoting_base',
- 'chromoting_client',
- 'chromoting_jingle_glue',
- '../third_party/ppapi/ppapi.gyp:ppapi_cpp',
- '../third_party/zlib/zlib.gyp:zlib',
- ],
- 'sources': [
- 'client/plugin/chromoting_plugin.cc',
- 'client/plugin/chromoting_plugin.h',
- 'client/plugin/pepper_view.cc',
- 'client/plugin/pepper_view.h',
- '../media/base/yuv_convert.cc',
- '../media/base/yuv_convert.h',
- '../media/base/yuv_row.h',
- '../media/base/yuv_row_posix.cc',
- '../media/base/yuv_row_table.cc',
- ],
- 'conditions': [
- ['OS=="win"', {
- 'sources': [
- '../media/base/yuv_row_win.cc',
- ],
- }],
- ['OS=="linux" and target_arch=="x64" and linux_fpic!=1', {
- # Shared libraries need -fPIC on x86-64
- 'cflags': ['-fPIC'],
- }],
- ], # end of 'conditions'
- }, # end of target 'chromoting_client_plugin'
-
# Simple webserver for testing chromoting client plugin.
{
'target_name': 'chromoting_client_test_webserver',
@@ -63,13 +25,13 @@
'sources': [
'tools/client_webserver/main.c',
],
- }, # end of target 'chromoting_client_test_webserver'
-
- ], # end of Client targets
- }], # end of OS conditions for Client targets
+ }
+ ], # end of target 'chromoting_client_test_webserver'
+ }],
# TODO(hclam): Enable this target for mac.
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
+
'targets': [
{
'target_name': 'chromoting_x11_client',
@@ -100,6 +62,45 @@
'targets': [
{
+ 'target_name': 'chromoting_plugin',
+ 'type': 'static_library',
+ 'defines': [
+ 'HAVE_STDINT_H', # Required by on2_integer.h
+ ],
+ 'dependencies': [
+ 'chromoting_base',
+ 'chromoting_client',
+ 'chromoting_jingle_glue',
+ '../third_party/ppapi/ppapi.gyp:ppapi_c',
+ '../third_party/zlib/zlib.gyp:zlib',
+ ],
+ 'sources': [
+ 'client/plugin/chromoting_plugin.cc',
+ 'client/plugin/chromoting_plugin.h',
+ 'client/plugin/pepper_entrypoints.cc',
+ 'client/plugin/pepper_entrypoints.h',
+ 'client/plugin/pepper_view.cc',
+ 'client/plugin/pepper_view.h',
+ '../media/base/yuv_convert.cc',
+ '../media/base/yuv_convert.h',
+ '../media/base/yuv_row.h',
+ '../media/base/yuv_row_table.cc',
+ ],
+ 'conditions': [
+ ['OS=="win"', {
+ 'sources': [
+ '../media/base/yuv_row_win.cc',
+ ],
+ }],
+ ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="mac"', {
+ 'sources': [
+ '../media/base/yuv_row_posix.cc',
+ ],
+ }],
+ ], # end of 'conditions'
+ }, # end of target 'chromoting_plugin'
+
+ {
'target_name': 'chromoting_base',
'type': '<(library)',
'dependencies': [