diff options
| author | Derek Sollenberger <djsollen@google.com> | 2009-11-24 15:05:24 -0500 |
|---|---|---|
| committer | Derek Sollenberger <djsollen@google.com> | 2009-11-30 10:39:22 -0500 |
| commit | 1a15528b92bc6af8faeaad983c380fcca4d1de44 (patch) | |
| tree | f8238f73ea86fde4637bd233c41d3d9550bfc37a /WebKit/android/plugins | |
| parent | ff2e3e9f1bdd1f49652c92473824e3a46c46e575 (diff) | |
| download | external_webkit-1a15528b92bc6af8faeaad983c380fcca4d1de44.zip external_webkit-1a15528b92bc6af8faeaad983c380fcca4d1de44.tar.gz external_webkit-1a15528b92bc6af8faeaad983c380fcca4d1de44.tar.bz2 | |
Refactoring plugins to use new java interfaces.
This change contains extensive cleanup as we now keep track of a pointer
to the plugin's java entry point (WebkitPlugin.class). Also given that we
track this object and changes to plugin packaging we nolonger need to pass
additional parameters in quite a few methods.
Diffstat (limited to 'WebKit/android/plugins')
| -rw-r--r-- | WebKit/android/plugins/ANPSystemInterface.cpp | 7 | ||||
| -rw-r--r-- | WebKit/android/plugins/PluginWidgetAndroid.cpp | 72 | ||||
| -rw-r--r-- | WebKit/android/plugins/PluginWidgetAndroid.h | 9 | ||||
| -rw-r--r-- | WebKit/android/plugins/android_npapi.h | 28 |
4 files changed, 43 insertions, 73 deletions
diff --git a/WebKit/android/plugins/ANPSystemInterface.cpp b/WebKit/android/plugins/ANPSystemInterface.cpp index 92085cc..42ec9e4 100644 --- a/WebKit/android/plugins/ANPSystemInterface.cpp +++ b/WebKit/android/plugins/ANPSystemInterface.cpp @@ -77,12 +77,9 @@ static jclass anp_loadJavaClass(NPP instance, const char* className) { WebCore::PluginView* pluginView = pluginViewForInstance(instance); PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget(); - const WebCore::String& libName = pluginView->plugin()->path(); - SkString skLibName; - skLibName.setUTF16(libName.characters(), libName.length()); - jclass result; - result = pluginWidget->webViewCore()->getPluginClass(skLibName.c_str(), className); + result = pluginWidget->webViewCore()->getPluginClass(pluginView->plugin()->path(), + className); return result; } diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp index dcd8943..9c8d25d 100644 --- a/WebKit/android/plugins/PluginWidgetAndroid.cpp +++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp @@ -36,6 +36,7 @@ #include "SkFlipPixelRef.h" #include "SkString.h" #include "WebViewCore.h" +#include "jni_utility.h" #define DEBUG_VISIBLE_RECTS 1 // temporary debug printfs and fixes @@ -52,8 +53,8 @@ PluginWidgetAndroid::PluginWidgetAndroid(WebCore::PluginView* view) m_pluginBounds.setEmpty(); m_hasFocus = false; m_zoomLevel = 0; - m_javaClassName = NULL; m_childView = NULL; + m_webkitPlugin = NULL; } PluginWidgetAndroid::~PluginWidgetAndroid() { @@ -63,9 +64,16 @@ PluginWidgetAndroid::~PluginWidgetAndroid() { m_core->destroySurface(m_childView); } } - if (m_javaClassName) { - free(m_javaClassName); + + // cleanup any remaining JNI References + JNIEnv* env = JSC::Bindings::getJNIEnv(); + if (m_childView) { + env->DeleteGlobalRef(m_childView); + } + if (m_webkitPlugin) { + env->DeleteGlobalRef(m_webkitPlugin); } + m_flipPixelRef->safeUnref(); } @@ -74,6 +82,19 @@ void PluginWidgetAndroid::init(android::WebViewCore* core) { m_core->addPlugin(this); } +jobject PluginWidgetAndroid::getJavaPluginInstance() { + if (m_webkitPlugin == NULL && m_core != NULL) { + + jobject tempObj = m_core->createPluginJavaInstance(m_pluginView->plugin()->path(), + m_pluginView->instance()); + if (tempObj) { + JNIEnv* env = JSC::Bindings::getJNIEnv(); + m_webkitPlugin = env->NewGlobalRef(tempObj); + } + } + return m_webkitPlugin; +} + static SkBitmap::Config computeConfig(bool isTransparent) { return isTransparent ? SkBitmap::kARGB_8888_Config : SkBitmap::kRGB_565_Config; @@ -105,15 +126,13 @@ void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) { // if the surface does not exist then create a new surface } else if(!m_childView) { - - const String& libName = m_pluginView->plugin()->path(); - SkString skLibName; - skLibName.setUTF16(libName.characters(), libName.length()); - - m_childView = m_core->createSurface(skLibName.c_str(), m_javaClassName, - m_pluginView->instance(), - docPoint.x(), docPoint.y(), - window->width, window->height); + jobject tempObj = m_core->createSurface(getJavaPluginInstance(), + docPoint.x(), docPoint.y(), + window->width, window->height); + if (tempObj) { + JNIEnv* env = JSC::Bindings::getJNIEnv(); + m_childView = env->NewGlobalRef(tempObj); + } } } else { m_flipPixelRef->safeUnref(); @@ -122,44 +141,17 @@ void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) { } } -bool PluginWidgetAndroid::setPluginStubJavaClassName(const char* className) { - - if (m_javaClassName) { - free(m_javaClassName); - } - - // don't call strdup() if the className is to be set to NULL - if (!className) { - m_javaClassName = NULL; - return true; - } - - // make a local copy of the className - m_javaClassName = strdup(className); - return (m_javaClassName != NULL); -} - void PluginWidgetAndroid::requestFullScreenMode() { - if (!m_javaClassName) { - return; - } - const String& libName = m_pluginView->plugin()->path(); SkString skLibName; skLibName.setUTF16(libName.characters(), libName.length()); - m_core->startFullScreenPluginActivity(skLibName.c_str(), m_javaClassName, + m_core->startFullScreenPluginActivity(skLibName.c_str(), m_pluginView->instance()); } bool PluginWidgetAndroid::setDrawingModel(ANPDrawingModel model) { - - // disallow the surface drawing model if no java class name has been given - if (model == kSurface_ANPDrawingModel && m_javaClassName == NULL) { - return false; - } - m_drawingModel = model; return true; } diff --git a/WebKit/android/plugins/PluginWidgetAndroid.h b/WebKit/android/plugins/PluginWidgetAndroid.h index b7df4f0..da2291f 100644 --- a/WebKit/android/plugins/PluginWidgetAndroid.h +++ b/WebKit/android/plugins/PluginWidgetAndroid.h @@ -67,12 +67,6 @@ struct PluginWidgetAndroid { */ void setWindow(NPWindow* window, bool isTransparent); - /* Called to notify us of the plugin's java class that implements the - * PluginStub interface. A local copy is made of the className so the caller - * can safely free the memory as soon as the function returns. - */ - bool setPluginStubJavaClassName(const char* className); - /* Called whenever the plugin itself requests a new drawing model. If the hardware does not support the requested model then false is returned, otherwise true is returned. @@ -141,6 +135,7 @@ private: WebCore::IntPoint frameToDocumentCoords(int frameX, int frameY) const; void computeVisibleFrameRect(); void scrollToVisibleFrameRect(); + jobject getJavaPluginInstance(); WebCore::PluginView* m_pluginView; android::WebViewCore* m_core; @@ -153,8 +148,8 @@ private: SkIRect m_requestedFrameRect; bool m_hasFocus; float m_zoomLevel; - char* m_javaClassName; jobject m_childView; + jobject m_webkitPlugin; /* We limit the number of rectangles to minimize storage and ensure adequate speed. diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h index 71913fa..88c45f4 100644 --- a/WebKit/android/plugins/android_npapi.h +++ b/WebKit/android/plugins/android_npapi.h @@ -149,10 +149,10 @@ enum ANPDrawingModels { kBitmap_ANPDrawingModel = 0, /** Draw into a surface (e.g. raster, openGL, etc.) using the Java surface interface. When this model is used the browser will invoke the Java - class specified by kSetPluginStubJavaClassName_ANPSetValue which will - return an instance of a android Java View. The instance is then embedded - in the html. The plugin can then manipulate the view as it would any - normal Java View in android. + class specified in the plugin's apk manifest. From that class the browser + will invoke the appropriate method to return an an instance of a android + Java View. The instance is then embedded in the html. The plugin can then + manipulate the view as it would any normal Java View in android. Unlike the bitmap model, a surface model is opaque so no html content behind the plugin will be visible. Unless the plugin needs to be @@ -171,27 +171,13 @@ enum ANPDrawingModels { }; typedef int32_t ANPDrawingModel; -/** Set the name of the Java class found in the plugin's apk that implements the - PluginStub interface. The value provided must be a null terminated char* - that contains the fully qualified class name (e.g., your.package.className). - A local copy is made of the char* so the caller can safely free the memory - as soon as the function returns. - - This value must be set prior to selecting the Surface_ANPDrawingModel or - requesting to enter full-screen mode. - - NPN_SetValue(inst, kSetPluginStubJavaClassName_ANPSetValue, - (void*)nullTerminatedChar*) - */ -#define kSetPluginStubJavaClassName_ANPSetValue ((NPPVariable)1001) - /** Request to receive/disable events. If the pointer is NULL then all flags will be disabled. Otherwise, the event type will be enabled iff its corresponding bit in the EventFlags bit field is set. NPN_SetValue(inst, ANPAcceptEvents, (void*)EventFlags) */ -#define kAcceptEvents_ANPSetValue ((NPPVariable)1002) +#define kAcceptEvents_ANPSetValue ((NPPVariable)1001) /** The EventFlags are a set of bits used to determine which types of events the plugin wishes to receive. For example, if the value is 0x03 then both key @@ -674,8 +660,8 @@ struct ANPWindowInterfaceV0 : ANPInterface { */ void (*showKeyboard)(NPP instance, bool value); /** Called when a plugin wishes to enter into full screen mode. The plugin's - Java class (set using kSetPluginStubJavaClassName_ANPSetValue) will be - called asynchronously to provide a View object to be displayed full screen. + Java class (defined in the plugin's apk manifest) will be called + asynchronously to provide a View object to be displayed full screen. */ void (*requestFullScreen)(NPP instance); }; |
