diff options
author | sehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-08 04:35:22 +0000 |
---|---|---|
committer | sehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-08 04:35:22 +0000 |
commit | afa09a4f216d897dc2f651f9a7053ffd81a29753 (patch) | |
tree | 21287b3a4de2dd3d7951a0cc0fdad60ea4ae5e25 /webkit/tools/pepper_test_plugin | |
parent | bf7e9637d7935075e56bd3d15df864f78312df53 (diff) | |
download | chromium_src-afa09a4f216d897dc2f651f9a7053ffd81a29753.zip chromium_src-afa09a4f216d897dc2f651f9a7053ffd81a29753.tar.gz chromium_src-afa09a4f216d897dc2f651f9a7053ffd81a29753.tar.bz2 |
Enable pepper events to flow to the plugin. Also enable printing of the event
types observed at NPP_HandleEvent.
Review URL: http://codereview.chromium.org/465110
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/pepper_test_plugin')
-rw-r--r-- | webkit/tools/pepper_test_plugin/event_handler.cc | 182 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/event_handler.h | 54 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/main.cc | 4 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp | 2 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.cc | 10 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/test_page.html | 37 |
6 files changed, 284 insertions, 5 deletions
diff --git a/webkit/tools/pepper_test_plugin/event_handler.cc b/webkit/tools/pepper_test_plugin/event_handler.cc new file mode 100644 index 0000000..75ede4e --- /dev/null +++ b/webkit/tools/pepper_test_plugin/event_handler.cc @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "webkit/tools/pepper_test_plugin/event_handler.h" + +#include <stdio.h> +#include <string> + +#include "base/logging.h" +#include "base/string_util.h" +#include "webkit/tools/pepper_test_plugin/plugin_object.h" + +EventHandler* event_handler = NULL; + +// EventHandler ---------------------------------------------------------------- + +EventHandler::EventHandler(NPP npp) + : npp_(npp), + text_box_(NULL) { +} + +EventHandler::~EventHandler() { +} + +void EventHandler::addText(const char* cstr) { + NPVariant variant; + // Create a a string variant to be set for the innerText. + MakeNPVariant(cstr, &variant); + // Report the string to the div. + NPVariant result; + browser->invokeDefault(npp_, text_box_, &variant, 1, &result); + // Release the variant. + browser->releasevariantvalue(&variant); + browser->releasevariantvalue(&result); +} + +std::string EventHandler::EventName(double timestamp, int32 type) { + std::string str = DoubleToString(timestamp) + ": "; + switch (type) { + case NPEventType_MouseDown: + return str + "MouseDown"; + case NPEventType_MouseUp: + return str + "MouseUp"; + case NPEventType_MouseMove: + return str + "MouseMove"; + case NPEventType_MouseEnter: + return str + "MouseEnter"; + case NPEventType_MouseLeave: + return str + "MouseLeave"; + case NPEventType_MouseWheel: + return str + "MouseWheel"; + case NPEventType_RawKeyDown: + return str + "RawKeyDown"; + case NPEventType_KeyDown: + return str + "KeyDown"; + case NPEventType_KeyUp: + return str + "KeyUp"; + case NPEventType_Char: + return str + "Char"; + case NPEventType_Minimize: + return str + "Minimize"; + case NPEventType_Focus: + return str + "Focus"; + case NPEventType_Device: + return str + "Device"; + case NPEventType_Undefined: + default: + return str + "Undefined"; + } +} + +int EventHandler::handle(void* event) { + NPPepperEvent* npevent = reinterpret_cast<NPPepperEvent*>(event); + std::string str = EventName(npevent->timeStampSeconds, npevent->type); + switch (npevent->type) { + case NPEventType_MouseDown: + case NPEventType_MouseUp: + case NPEventType_MouseMove: + case NPEventType_MouseEnter: + case NPEventType_MouseLeave: + str += StringPrintf(": mod %x, but: %x, x: %d, y: %d, click: %d", + npevent->u.mouse.modifier, + npevent->u.mouse.button, + npevent->u.mouse.x, + npevent->u.mouse.y, + npevent->u.mouse.clickCount); + break; + case NPEventType_MouseWheel: + str += StringPrintf(": mod %x, dx: %f, dy: %f, wtx: %f, wty: %d: sbp %d", + npevent->u.wheel.modifier, + npevent->u.wheel.deltaX, + npevent->u.wheel.deltaY, + npevent->u.wheel.wheelTicksX, + npevent->u.wheel.wheelTicksY, + npevent->u.wheel.scrollByPage); + break; + case NPEventType_RawKeyDown: + case NPEventType_KeyDown: + case NPEventType_KeyUp: + str += StringPrintf(": mod %x, key: %x", + npevent->u.key.modifier, + npevent->u.key.normalizedKeyCode); + break; + case NPEventType_Char: + str += StringPrintf(": mod %x, text: ", + npevent->u.character.modifier); + size_t i; + for (i = 0; i < ARRAYSIZE(npevent->u.character.text); ++i) { + str += StringPrintf("%x ", npevent->u.character.text[i]); + } + str += ", unmod: "; + for (i = 0; i < ARRAYSIZE(npevent->u.character.unmodifiedText); ++i) { + str += StringPrintf("%x ", npevent->u.character.unmodifiedText[i]); + } + break; + case NPEventType_Minimize: + case NPEventType_Focus: + case NPEventType_Device: + break; + case NPEventType_Undefined: + default: + break; + } + addText(str.c_str()); + return 0; +} + +bool EventHandler::set_text_box(NPObject* text_box_object) { + text_box_ = text_box_object; + // Keep a reference to the text box update object. + browser->retainobject(text_box_object); + // Announce that we are alive. + addText("Set the callback for text\n"); + return true; +} + +char* EventHandler::string_duplicate(const char* cstr, size_t* len) { + *len = strlen(cstr); + char* str = reinterpret_cast<char*>(browser->memalloc(*len + 1)); + if (NULL == str) { + *len = 0; + return NULL; + } + strcpy(str, cstr); + return str; +} + +void EventHandler::MakeNPVariant(const char* cstr, NPVariant* var) { + if (NULL == cstr) { + STRINGN_TO_NPVARIANT(NULL, 0, *var); + return; + } + size_t len; + char* name = string_duplicate(cstr, &len); + if (NULL == name) { + STRINGN_TO_NPVARIANT(NULL, 0, *var); + return; + } + STRINGN_TO_NPVARIANT(name, len, *var); +} diff --git a/webkit/tools/pepper_test_plugin/event_handler.h b/webkit/tools/pepper_test_plugin/event_handler.h new file mode 100644 index 0000000..5764e28 --- /dev/null +++ b/webkit/tools/pepper_test_plugin/event_handler.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_EVENT_HANDLER_H_ +#define WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_EVENT_HANDLER_H_ + +#include <string> +#include "base/basictypes.h" +#include "webkit/glue/plugins/nphostapi.h" + +class EventHandler { + public: + explicit EventHandler(NPP npp); + ~EventHandler(); + int handle(void* event); + bool set_text_box(NPObject* text_box_object); + + private: + void addText(const char* cstr); + static char* string_duplicate(const char* cstr, size_t* len); + static void MakeNPVariant(const char* cstr, NPVariant* var); + std::string EventName(double timestamp, int32 type); + + NPP npp_; + NPObject* text_box_; + + DISALLOW_COPY_AND_ASSIGN(EventHandler); +}; + +extern EventHandler* event_handler; + +#endif // WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_EVENT_HANDLER_H_ diff --git a/webkit/tools/pepper_test_plugin/main.cc b/webkit/tools/pepper_test_plugin/main.cc index 091eddf..1b7da69 100644 --- a/webkit/tools/pepper_test_plugin/main.cc +++ b/webkit/tools/pepper_test_plugin/main.cc @@ -37,6 +37,7 @@ #include "base/logging.h" #include "base/string_util.h" #include "webkit/tools/pepper_test_plugin/plugin_object.h" +#include "webkit/tools/pepper_test_plugin/event_handler.h" #ifdef WIN32 #define NPAPI WINAPI @@ -169,6 +170,7 @@ NPError NPP_New(NPMIMEType pluginType, PluginObject* obj = reinterpret_cast<PluginObject*>( browser->createobject(instance, PluginObject::GetPluginClass())); instance->pdata = obj; + event_handler = new EventHandler(instance); } return NPERR_NO_ERROR; @@ -222,7 +224,7 @@ void NPP_Print(NPP instance, NPPrint* platformPrint) { } int16 NPP_HandleEvent(NPP instance, void* event) { - return 0; + return event_handler->handle(event); } void NPP_URLNotify(NPP instance, const char* url, NPReason reason, diff --git a/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp index 9c35fa6..a19574e 100644 --- a/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp +++ b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp @@ -31,6 +31,8 @@ 'plugin_object.h', 'test_object.cc', 'test_object.h', + 'event_handler.cc', + 'event_handler.h' ], 'run_as': { 'working_directory': '.', diff --git a/webkit/tools/pepper_test_plugin/plugin_object.cc b/webkit/tools/pepper_test_plugin/plugin_object.cc index 432bfc4..5b001da 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.cc +++ b/webkit/tools/pepper_test_plugin/plugin_object.cc @@ -32,6 +32,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/effects/SkGradientShader.h" +#include "webkit/tools/pepper_test_plugin/event_handler.h" #include "webkit/tools/pepper_test_plugin/test_object.h" NPNetscapeFuncs* browser; @@ -56,12 +57,14 @@ static const NPUTF8* plugin_property_identifier_names[NUM_PROPERTY_IDENTIFIERS] enum { ID_TEST_GET_PROPERTY = 0, + ID_SET_TEXT_BOX, NUM_METHOD_IDENTIFIERS }; static NPIdentifier plugin_method_identifiers[NUM_METHOD_IDENTIFIERS]; static const NPUTF8* plugin_method_identifier_names[NUM_METHOD_IDENTIFIERS] = { "testGetProperty", + "setTextBox", }; void EnsureIdentifiersInitialized() { @@ -150,8 +153,13 @@ bool PluginInvoke(NPObject* header, const NPVariant* args, uint32 arg_count, NPVariant* result) { PluginObject* plugin = reinterpret_cast<PluginObject*>(header); - if (name == plugin_method_identifiers[ID_TEST_GET_PROPERTY]) + if (name == plugin_method_identifiers[ID_TEST_GET_PROPERTY]) { return TestGetProperty(plugin, args, arg_count, result); + } else if (name == plugin_method_identifiers[ID_SET_TEXT_BOX]) { + if (1 == arg_count && NPVARIANT_IS_OBJECT(args[0])) { + return event_handler->set_text_box(NPVARIANT_TO_OBJECT(args[0])); + } + } return false; } diff --git a/webkit/tools/pepper_test_plugin/test_page.html b/webkit/tools/pepper_test_plugin/test_page.html index f76b09d..c25dbd2 100644 --- a/webkit/tools/pepper_test_plugin/test_page.html +++ b/webkit/tools/pepper_test_plugin/test_page.html @@ -1,7 +1,38 @@ -<body style="background-image:url(http://www.google.com/intl/en_ALL/images/logo.gif); background-repeat:repeat;"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title> Pepper Plugin Demo </title> +<script type="text/javascript"> +var event_box; + +var addLine = function(line) { + event_box.innerHTML = line + '<br>' + event_box.innerHTML; +} + +var runScripts = function() { + event_box = document.getElementById("event_text_box");; + var plugin_obj = document.getElementById("plugin"); + addLine('<b>Event log</b>'); + plugin_obj.setTextBox(addLine); +} +</script> +</head> + +<body style="background-image:url(http://www.google.com/intl/en_ALL/images/logo.gif); background-repeat:repeat;" onload="runScripts()"> -This page embeds a file declared as the pepper test plugins MIME type so that it will get loaded for testing. <p> -<embed type="pepper-application/x-pepper-test-plugin" width="400" height="400"/> +This page embeds a file declared as the pepper test plugins MIME type so that it will get loaded for testing. +</p> +<table> +<tr> +<td valign="top" width="50%"> +<object id="plugin" type="pepper-application/x-pepper-test-plugin" width="400" height="400" /> +</td> +<td valign="top" style="background-color:Silver" width="50%"> +<div id="event_text_box" style="width:400px; height:400px; overflow:auto"> +</div> +</td> +</tr> +</table> </body> +</html>
\ No newline at end of file |