diff options
| author | Mike Reed <reed@google.com> | 2009-12-10 11:36:37 -0500 |
|---|---|---|
| committer | Mike Reed <reed@google.com> | 2009-12-10 16:01:02 -0500 |
| commit | 56074874733a95498646a3fc575ef62fd9218f58 (patch) | |
| tree | afc0a588253b2dcdbf609598cb6274d8ea9d0ebc /WebKit/android/plugins | |
| parent | c1d0b3861ca3935f97e55a77d7b45205df988be2 (diff) | |
| download | external_webkit-56074874733a95498646a3fc575ef62fd9218f58.zip external_webkit-56074874733a95498646a3fc575ef62fd9218f58.tar.gz external_webkit-56074874733a95498646a3fc575ef62fd9218f58.tar.bz2 | |
add event interface for plugins, so they can post an event to themselves (from any thread)
Diffstat (limited to 'WebKit/android/plugins')
| -rw-r--r-- | WebKit/android/plugins/ANPEventInterface.cpp | 84 | ||||
| -rw-r--r-- | WebKit/android/plugins/android_npapi.h | 26 |
2 files changed, 110 insertions, 0 deletions
diff --git a/WebKit/android/plugins/ANPEventInterface.cpp b/WebKit/android/plugins/ANPEventInterface.cpp new file mode 100644 index 0000000..2fdf159 --- /dev/null +++ b/WebKit/android/plugins/ANPEventInterface.cpp @@ -0,0 +1,84 @@ +/* + * Copyright 2009, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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 THE COPYRIGHT HOLDERS ``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 THE COPYRIGHT OWNER 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. + */ + +// must include config.h first for webkit to fiddle with new/delete +#include "config.h" +#include "SkANP.h" +#include "WebViewCore.h" +#include "PluginView.h" +#include "PluginWidgetAndroid.h" + +#include "JavaSharedClient.h" + +using namespace android; + +struct WrappedANPEvent { + WebViewCore* fWVC; + PluginWidgetAndroid* fPWA; + ANPEvent fEvent; +}; + +/* Its possible we may be called after the plugin that initiated the event + has been torn-down. Thus we check that the assicated webviewcore and + pluginwidget are still active before dispatching the event. + */ +static void send_anpevent(void* data) { + WrappedANPEvent* wrapper = static_cast<WrappedANPEvent*>(data); + WebViewCore* core = wrapper->fWVC; + PluginWidgetAndroid* widget = wrapper->fPWA; + + // be sure we're still alive before delivering the event + if (WebViewCore::isInstance(core) && core->isPlugin(widget)) { + widget->sendEvent(wrapper->fEvent); + } + delete wrapper; +} + +static void anp_postEvent(NPP instance, const ANPEvent* event) { + if (instance && instance->ndata && event) { + PluginView* pluginView = static_cast<PluginView*>(instance->ndata); + PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget(); + WebViewCore* wvc = pluginWidget->webViewCore(); + + WrappedANPEvent* wrapper = new WrappedANPEvent; + // recored these, and recheck that they are valid before delivery + // in send_anpevent + wrapper->fWVC = pluginWidget->webViewCore(); + wrapper->fPWA = pluginWidget; + // make a copy of the event + wrapper->fEvent = *event; + JavaSharedClient::EnqueueFunctionPtr(send_anpevent, wrapper); + } +} + +/////////////////////////////////////////////////////////////////////////////// + +#define ASSIGN(obj, name) (obj)->name = anp_##name + +void ANPEventInterfaceV0_Init(ANPInterface* value) { + ANPEventInterfaceV0* i = reinterpret_cast<ANPEventInterfaceV0*>(value); + + ASSIGN(i, postEvent); +} diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h index 14553ff..1111836 100644 --- a/WebKit/android/plugins/android_npapi.h +++ b/WebKit/android/plugins/android_npapi.h @@ -118,6 +118,7 @@ typedef uint32_t ANPMatrixFlag; #define kBitmapInterfaceV0_ANPGetValue ((NPNVariable)1008) #define kSurfaceInterfaceV0_ANPGetValue ((NPNVariable)1009) #define kSystemInterfaceV0_ANPGetValue ((NPNVariable)1010) +#define kEventInterfaceV0_ANPGetValue ((NPNVariable)1011) /** queries for which drawing model is desired (for the draw event) @@ -759,6 +760,21 @@ enum ANPEventTypes { */ kDraw_ANPEventType = 4, kLifecycle_ANPEventType = 5, + + /** This event type is completely defined by the plugin. + When creating an event, the caller must always set the first + two fields, the remaining data is optional. + ANPEvent evt; + evt.inSize = sizeof(ANPEvent); + evt.eventType = kCustom_ANPEventType + // other data slots are optional + evt.other[] = ...; + To post a copy of the event, call + eventInterface->postEvent(myNPPInstance, &evt); + That call makes a copy of the event struct, and post that on the event + queue for the plugin. + */ + kCustom_ANPEventType = 6, }; typedef int32_t ANPEventType; @@ -883,4 +899,14 @@ struct ANPEvent { } data; }; +struct ANPEventInterfaceV0 : ANPInterface { + /** Post a copy of the specified event to the plugin. The event will be + delivered to the plugin in its main thread (the thread that receives + other ANPEvents). If, after posting before delivery, the NPP instance + is torn down, the event will be discarded. + */ + void (*postEvent)(NPP inst, const ANPEvent* event); +}; + + #endif |
