summaryrefslogtreecommitdiffstats
path: root/remoting/client/plugin
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-22 19:28:18 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-22 19:28:18 +0000
commitedd588048c797259869da320342fe1c79786f3e6 (patch)
tree85779cc5722693c737b9e37c9d613643fc6971d9 /remoting/client/plugin
parent25158152300deccafb3ca928576e2568107979f1 (diff)
downloadchromium_src-edd588048c797259869da320342fe1c79786f3e6.zip
chromium_src-edd588048c797259869da320342fe1c79786f3e6.tar.gz
chromium_src-edd588048c797259869da320342fe1c79786f3e6.tar.bz2
Convert chromoting to pepperv2 API.
Currently disables use of PepperView, and HostConnection->Connect(). This is mainly an attempt to get the build working. Will re-enable functionality later. BUG=none TEST=none Review URL: http://codereview.chromium.org/2857011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50502 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client/plugin')
-rw-r--r--remoting/client/plugin/chromoting_main.cc24
-rw-r--r--remoting/client/plugin/chromoting_plugin.cc158
-rw-r--r--remoting/client/plugin/chromoting_plugin.h38
-rw-r--r--remoting/client/plugin/chromoting_plugin_unittest.cc72
-rw-r--r--remoting/client/plugin/pepper_view.h3
5 files changed, 93 insertions, 202 deletions
diff --git a/remoting/client/plugin/chromoting_main.cc b/remoting/client/plugin/chromoting_main.cc
deleted file mode 100644
index 9d02936..0000000
--- a/remoting/client/plugin/chromoting_main.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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/chromoting_plugin.h"
-
-// Initialize general plugin info like name and description.
-// This information needs to live outside of the PepperPlugin since it can
-// be requested by the browser before the PepperPlugin has been instantiated.
-void InitializePluginInfo(pepper::PepperPlugin::Info* plugin_info) {
- plugin_info->mime_description = remoting::ChromotingPlugin::kMimeType;
- plugin_info->plugin_name = "Chromoting";
- plugin_info->plugin_description = "Remote access for Chrome";
-}
-
-// Create the Pepper plugin instance.
-//
-// This is called in response to the NPP_New call.
-// This instantiates a PepperPlugin subclass that implements the plugin
-// specific functionality.
-pepper::PepperPlugin* CreatePlugin(NPNetscapeFuncs* browser_funcs,
- NPP instance) {
- return new remoting::ChromotingPlugin(browser_funcs, instance);
-}
diff --git a/remoting/client/plugin/chromoting_plugin.cc b/remoting/client/plugin/chromoting_plugin.cc
index 714ee2b..1657e20 100644
--- a/remoting/client/plugin/chromoting_plugin.cc
+++ b/remoting/client/plugin/chromoting_plugin.cc
@@ -14,6 +14,9 @@
#include "remoting/client/jingle_host_connection.h"
#include "remoting/client/plugin/pepper_view.h"
#include "remoting/jingle_glue/jingle_thread.h"
+#include "third_party/ppapi/c/pp_event.h"
+#include "third_party/ppapi/c/pp_rect.h"
+#include "third_party/ppapi/cpp/image_data.h"
using std::string;
using std::vector;
@@ -23,30 +26,33 @@ namespace remoting {
const char* ChromotingPlugin::kMimeType =
"pepper-application/x-chromoting-plugin::Chromoting";
-ChromotingPlugin::ChromotingPlugin(NPNetscapeFuncs* browser_funcs,
- NPP instance)
- : PepperPlugin(browser_funcs, instance), width_(0), height_(0),
- device_(NULL) {
+ChromotingPlugin::ChromotingPlugin(PP_Instance instance)
+ : pp::Instance(instance),
+ width_(0),
+ height_(0) {
}
ChromotingPlugin::~ChromotingPlugin() {
-}
+ if (host_connection_.get())
+ host_connection_->Disconnect();
+
+ // TODO(ajwong): We need to ensure all objects have actually stopped posting
+ // to the message loop before this point. Right now, we don't have a well
+ // defined stop for the plugin process, and the thread shutdown is likely a
+ // race condition.
+ if (network_thread_.get())
+ network_thread_->Stop();
-NPError ChromotingPlugin::New(NPMIMEType pluginType,
- int16 argc, char* argn[], char* argv[]) {
- LOG(INFO) << "Started ChromotingPlugin::New";
+ if (main_thread_.get())
+ main_thread_->Stop();
+}
- // Verify the mime type and subtype
- std::string mime(kMimeType);
- std::string::size_type type_end = mime.find("/");
- std::string::size_type subtype_end = mime.find(":", type_end);
- if (strncmp(pluginType, kMimeType, subtype_end)) {
- return NPERR_GENERIC_ERROR;
- }
+bool ChromotingPlugin::Init(uint32_t argc, const char* argn[], const char* argv[]) {
+ LOG(INFO) << "Started ChromotingPlugin::Init";
// Extract the URL from the arguments.
- char* url = NULL;
- for (int i = 0; i < argc; ++i) {
+ const char* url = NULL;
+ for (uint32_t i = 0; i < argc; ++i) {
if (strcmp(argn[i], "src") == 0) {
url = argv[i];
break;
@@ -54,7 +60,7 @@ NPError ChromotingPlugin::New(NPMIMEType pluginType,
}
if (!url) {
- return NPERR_GENERIC_ERROR;
+ return false;
}
string user_id;
@@ -62,100 +68,94 @@ NPError ChromotingPlugin::New(NPMIMEType pluginType,
string host_jid;
if (!ParseUrl(url, &user_id, &auth_token, &host_jid)) {
LOG(WARNING) << "Could not parse URL: " << url;
- return NPERR_GENERIC_ERROR;
+ return false;
}
- // Setup pepper context.
- device_ = extensions()->acquireDevice(instance(), NPPepper2DDevice);
-
// Start the threads.
main_thread_.reset(new base::Thread("ChromoClientMain"));
if (!main_thread_->Start()) {
LOG(ERROR) << "Main thread failed to start.";
- return NPERR_GENERIC_ERROR;
+ return false;
}
network_thread_.reset(new JingleThread());
network_thread_->Start();
// Create the chromting objects.
host_connection_.reset(new JingleHostConnection(network_thread_.get()));
+ /*
view_.reset(new PepperView(main_thread_->message_loop(), device_,
instance()));
- client_.reset(new ChromotingClient(main_thread_->message_loop(),
- host_connection_.get(), view_.get()));
+ */
+ //client_.reset(new ChromotingClient(main_thread_->message_loop(),
+ // host_connection_.get(), view_.get()));
// Kick off the connection.
- host_connection_->Connect(user_id, auth_token, host_jid, client_.get());
-
- return NPERR_NO_ERROR;
-}
-
-NPError ChromotingPlugin::Destroy(NPSavedData** save) {
- host_connection_->Disconnect();
-
- // TODO(ajwong): We need to ensure all objects have actually stopped posting
- // to the message loop before this point. Right now, we don't have a well
- // defined stop for the plugin process, and the thread shutdown is likely a
- // race condition.
- network_thread_->Stop();
- main_thread_->Stop();
+ //host_connection_->Connect(user_id, auth_token, host_jid, client_.get());
- main_thread_.reset();
- network_thread_.reset();
- return NPERR_NO_ERROR;
+ return true;
}
-NPError ChromotingPlugin::SetWindow(NPWindow* window) {
- width_ = window->width;
- height_ = window->height;
+void ChromotingPlugin::ViewChanged(const PP_Rect& position,
+ const PP_Rect& clip) {
+ // TODO(ajwong): This is going to be a race condition when the view changes
+ // and we're in the middle of a Paint().
+ LOG(INFO) << "ViewChanged "
+ << position.point.x << ","
+ << position.point.y << ","
+ << position.size.width << ","
+ << position.size.height;
+
+ // TODO(ajwong): Do we care about the position? Probably not...
+ if (position.size.width == width_ || position.size.height == height_)
+ return;
+
+ width_ = position.size.width;
+ height_ = position.size.height;
+
+ device_context_ = pp::DeviceContext2D(width_, height_, false);
+ if (!BindGraphicsDeviceContext(device_context_)) {
+ LOG(ERROR) << "Couldn't bind the device context.";
+ return;
+ }
- client_->SetViewport(0, 0, window->width, window->height);
- client_->Repaint();
+ pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, width_, height_, false);
+ if (!image.is_null()) {
+ for (int y = 0; y < image.height(); y++) {
+ for (int x = 0; x < image.width(); x++) {
+ *image.GetAddr32(x, y) = 0xccff00cc;
+ }
+ }
+ device_context_.ReplaceContents(&image);
+ device_context_.Flush(NULL, this);
+ } else {
+ LOG(ERROR) << "Unable to allocate image.";
+ }
- return NPERR_NO_ERROR;
+ //client_->SetViewport(0, 0, width_, height_);
+ //client_->Repaint();
}
-int16 ChromotingPlugin::HandleEvent(void* event) {
- NPPepperEvent* npevent = static_cast<NPPepperEvent*>(event);
-
- switch (npevent->type) {
- case NPEventType_MouseDown:
- // Fall through
- case NPEventType_MouseUp:
- // Fall through
- case NPEventType_MouseMove:
- // Fall through
- case NPEventType_MouseEnter:
- // Fall through
- case NPEventType_MouseLeave:
+bool ChromotingPlugin::HandleEvent(const PP_Event& event) {
+ switch (event.type) {
+ case PP_Event_Type_MouseDown:
+ case PP_Event_Type_MouseUp:
+ case PP_Event_Type_MouseMove:
+ case PP_Event_Type_MouseEnter:
+ case PP_Event_Type_MouseLeave:
//client_->handle_mouse_event(npevent);
break;
- case NPEventType_MouseWheel:
- case NPEventType_RawKeyDown:
- break;
- case NPEventType_KeyDown:
- case NPEventType_KeyUp:
- break;
- case NPEventType_Char:
+
+ case PP_Event_Type_Char:
//client_->handle_char_event(npevent);
break;
- case NPEventType_Minimize:
- case NPEventType_Focus:
- case NPEventType_Device:
+
+ default:
break;
}
return false;
}
-NPError ChromotingPlugin::GetValue(NPPVariable variable, void* value) {
- return NPERR_NO_ERROR;
-}
-
-NPError ChromotingPlugin::SetValue(NPNVariable variable, void* value) {
- return NPERR_NO_ERROR;
-}
-
bool ChromotingPlugin::ParseUrl(const std::string& url,
string* user_id,
string* auth_token,
diff --git a/remoting/client/plugin/chromoting_plugin.h b/remoting/client/plugin/chromoting_plugin.h
index 16e6f1d..d19b612 100644
--- a/remoting/client/plugin/chromoting_plugin.h
+++ b/remoting/client/plugin/chromoting_plugin.h
@@ -10,8 +10,9 @@
#include "base/at_exit.h"
#include "base/scoped_ptr.h"
#include "remoting/client/host_connection.h"
-#include "remoting/client/pepper/pepper_plugin.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"
namespace base {
class Thread;
@@ -26,7 +27,7 @@ class PepperView;
class ChromotingClient;
-class ChromotingPlugin : public pepper::PepperPlugin {
+class ChromotingPlugin : public pp::Instance {
public:
// The mimetype for which this plugin is registered.
//
@@ -34,46 +35,27 @@ class ChromotingPlugin : public pepper::PepperPlugin {
// point. I think we should handle a special protocol (eg., chromotocol://)
static const char *kMimeType;
- ChromotingPlugin(NPNetscapeFuncs* browser_funcs, NPP instance);
+ ChromotingPlugin(PP_Instance instance);
virtual ~ChromotingPlugin();
- // PepperPlugin implementation.
- virtual NPError New(NPMIMEType pluginType, int16 argc, char* argn[],
- char* argv[]);
- virtual NPError Destroy(NPSavedData** save);
- virtual NPError SetWindow(NPWindow* window);
- virtual int16 HandleEvent(void* event);
- virtual NPError GetValue(NPPVariable variable, void* value);
- virtual NPError SetValue(NPNVariable variable, void* value);
+ virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
+ virtual bool HandleEvent(const PP_Event& event);
+ virtual void ViewChanged(const PP_Rect& position, const PP_Rect& clip);
private:
FRIEND_TEST(ChromotingPluginTest, ParseUrl);
FRIEND_TEST(ChromotingPluginTest, TestCaseSetup);
- NPDevice* device() { return device_; }
-
static bool ParseUrl(const std::string& url,
std::string* user_id,
std::string* auth_token,
std::string* host_jid);
// Size of the plugin window.
- int width_, height_;
-
- // Rendering device provided by browser.
- NPDevice* device_;
+ int width_;
+ int height_;
- // Since the ChromotingPlugin's lifetime is conceptually the lifetime of the
- // object, use it to control running of atexit() calls.
- //
- // TODO(ajwong): Should this be moved into PepperPlugin? Or maybe even
- // higher?
- //
- // TODO(ajwong): This causes unittests to fail so commenting out for now. We
- // need to understand process instantiation better. This may also be a
- // non-issue when we are no longer being loaded as a DSO.
- //
- // base::AtExitManager at_exit_manager_;
+ pp::DeviceContext2D device_context_;
scoped_ptr<base::Thread> main_thread_;
scoped_ptr<JingleThread> network_thread_;
diff --git a/remoting/client/plugin/chromoting_plugin_unittest.cc b/remoting/client/plugin/chromoting_plugin_unittest.cc
index fedf252..edda0e3 100644
--- a/remoting/client/plugin/chromoting_plugin_unittest.cc
+++ b/remoting/client/plugin/chromoting_plugin_unittest.cc
@@ -5,86 +5,18 @@
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "remoting/client/plugin/chromoting_plugin.h"
-#include "remoting/client/pepper/fake_browser.h"
#include "testing/gtest/include/gtest/gtest.h"
-// Routine to create the PepperPlugin subclass that implements all of the
-// plugin-specific functionality.
-pepper::PepperPlugin* CreatePlugin(NPNetscapeFuncs* browser_funcs,
- NPP instance);
-
namespace remoting {
+// TODO(ajwong): Once ChromotingPlugin stablizes a little more, come up with
+// sane unittests.
class ChromotingPluginTest : public testing::Test {
protected:
-
virtual void SetUp() {
- // Set up the fake browser callback routines.
- fake_browser_ = Singleton<FakeBrowser>::get();
- NPNetscapeFuncs* browser_funcs_ = fake_browser_->GetBrowserFuncs();
- instance_.reset(new NPP_t());
-
- // Create the ChromotingPlugin for testing.
- pepper::PepperPlugin* pepper_plugin =
- CreatePlugin(browser_funcs_, instance_.get());
- plugin_.reset(
- static_cast<ChromotingPlugin*>(pepper_plugin));
- }
-
- virtual void TearDown() {
}
-
- FakeBrowser* fake_browser_;
- scoped_ptr<NPP_t> instance_;
- scoped_ptr<ChromotingPlugin> plugin_;
};
-TEST_F(ChromotingPluginTest, TestCaseSetup) {
- ASSERT_TRUE(plugin_->browser() != NULL);
- ASSERT_TRUE(plugin_->extensions() != NULL);
- ASSERT_TRUE(plugin_->instance() != NULL);
-
- // Device is not set until New() is called.
- ASSERT_TRUE(plugin_->device() == NULL);
-}
-
-#if 0
-TODO(ajwong): reenable once we have the threading sorted out.
-TEST_F(ChromotingPluginTest, TestNew) {
- NPMIMEType mimetype =
- const_cast<NPMIMEType>("pepper-application/x-chromoting-plugin");
- int16 argc;
- char* argn[4];
- char* argv[4];
-
- // Test 0 arguments.
- argc = 0;
- ASSERT_EQ(NPERR_GENERIC_ERROR, plugin_->New(mimetype, argc, argn, argv));
-
- // Test 1 argument (missing "src").
- argc = 1;
- argn[0] = const_cast<char*>("noturl");
- argv[0] = const_cast<char*>("random.value");
- ASSERT_EQ(NPERR_GENERIC_ERROR, plugin_->New(mimetype, argc, argn, argv));
-
- // Test "src" argument.
- argc = 1;
- argn[0] = const_cast<char*>("src");
- argv[0] = const_cast<char*>("chromotocol://name?user=u&auth=a&jid=j");
- ASSERT_EQ(NPERR_NO_ERROR, plugin_->New(mimetype, argc, argn, argv));
-
- ASSERT_EQ(NPERR_NO_ERROR, plugin_->Destroy(NULL));
-}
-
-TEST_F(ChromotingPluginTest, TestSetWindow) {
- NPWindow* window = fake_browser_->GetWindow();
- NPError result;
-
- result = plugin_->SetWindow(window);
- ASSERT_EQ(NPERR_NO_ERROR, result);
-}
-#endif
-
TEST_F(ChromotingPluginTest, ParseUrl) {
const char url[] = "chromotocol://hostid?user=auser&auth=someauth&jid=ajid";
std::string user_id;
diff --git a/remoting/client/plugin/pepper_view.h b/remoting/client/plugin/pepper_view.h
index 286a15a..9dc8a56 100644
--- a/remoting/client/plugin/pepper_view.h
+++ b/remoting/client/plugin/pepper_view.h
@@ -8,7 +8,8 @@
#include "base/scoped_ptr.h"
#include "base/task.h"
#include "remoting/client/chromoting_view.h"
-#include "remoting/client/pepper/pepper_plugin.h"
+#include "third_party/npapi/bindings/npapi.h"
+#include "third_party/npapi/bindings/npapi_extensions.h"
class MessageLoop;