summaryrefslogtreecommitdiffstats
path: root/WebKit/android
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android')
-rw-r--r--WebKit/android/jni/WebViewCore.cpp58
-rw-r--r--WebKit/android/jni/WebViewCore.h10
-rw-r--r--WebKit/android/plugins/ANPSurfaceInterface.cpp110
-rw-r--r--WebKit/android/plugins/ANPSurface_npapi.h23
-rw-r--r--WebKit/android/plugins/PluginSurface.cpp199
-rw-r--r--WebKit/android/plugins/PluginSurface.h80
-rw-r--r--WebKit/android/plugins/PluginWidgetAndroid.cpp71
-rw-r--r--WebKit/android/plugins/PluginWidgetAndroid.h20
-rw-r--r--WebKit/android/plugins/android_npapi.h53
9 files changed, 200 insertions, 424 deletions
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index 3889b8e..dc51a8f 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -88,7 +88,6 @@
#include "SkCanvas.h"
#include "SkPicture.h"
#include "SkUtils.h"
-#include "SurfaceCallback.h"
#include "StringImpl.h"
#include "Text.h"
#include "TypingCommand.h"
@@ -185,7 +184,6 @@ struct WebViewCore::JavaGlue {
jmethodID m_addMessageToConsole;
jmethodID m_createSurface;
jmethodID m_destroySurface;
- jmethodID m_attachSurface;
AutoJObject object(JNIEnv* env) {
return getRealObject(env, m_obj);
}
@@ -258,9 +256,8 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m
m_javaGlue->m_geolocationPermissionsShowPrompt = GetJMethod(env, clazz, "geolocationPermissionsShowPrompt", "(Ljava/lang/String;)V");
m_javaGlue->m_geolocationPermissionsHidePrompt = GetJMethod(env, clazz, "geolocationPermissionsHidePrompt", "()V");
m_javaGlue->m_addMessageToConsole = GetJMethod(env, clazz, "addMessageToConsole", "(Ljava/lang/String;ILjava/lang/String;)V");
- m_javaGlue->m_createSurface = GetJMethod(env, clazz, "createSurface", "(IIZ)Landroid/view/SurfaceView;");
- m_javaGlue->m_destroySurface = GetJMethod(env, clazz, "destroySurface", "(Landroid/view/SurfaceView;)V");
- m_javaGlue->m_attachSurface = GetJMethod(env, clazz, "attachSurface", "(Landroid/view/SurfaceView;IIII)V");
+ m_javaGlue->m_createSurface = GetJMethod(env, clazz, "createSurface", "(Ljava/lang/String;Ljava/lang/String;IIIII)Landroid/webkit/ViewManager$ChildView;");
+ m_javaGlue->m_destroySurface = GetJMethod(env, clazz, "destroySurface", "(Landroid/webkit/ViewManager$ChildView;)V");
env->SetIntField(javaWebViewCore, gWebViewCoreFields.m_nativeClass, (jint)this);
@@ -2191,30 +2188,25 @@ void WebViewCore::setBackgroundColor(SkColor c)
view->setBaseBackgroundColor(bcolor);
}
-jobject WebViewCore::createSurface(SurfaceCallback* cb, PixelFormat format,
- bool isFixedSize)
+jobject WebViewCore::createSurface(const char* packageName, const char* className,
+ NPP npp, int x, int y, int width, int height)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- jobject surface = env->CallObjectMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_createSurface, (int) cb, (int) format, isFixedSize);
- checkException(env);
- return surface;
-}
-void WebViewCore::destroySurface(jobject surface)
-{
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_destroySurface, surface);
+ jstring packageString = env->NewStringUTF(packageName);
+ jstring classString = env->NewStringUTF(className);
+ jobject result = env->CallObjectMethod(m_javaGlue->object(env).get(),
+ m_javaGlue->m_createSurface, packageString,
+ classString,(int) npp, x, y, width, height);
checkException(env);
+ return result;
+
}
-void WebViewCore::attachSurface(jobject surface, int x, int y, int width,
- int height)
+void WebViewCore::destroySurface(jobject childView)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->CallVoidMethod(m_javaGlue->object(env).get(),
- m_javaGlue->m_attachSurface, surface, x, y, width, height);
+ env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_destroySurface, childView);
checkException(env);
}
@@ -2703,28 +2695,6 @@ static void UpdatePluginState(JNIEnv* env, jobject obj, jint framePtr, jint node
(PluginState) state);
}
-static void SurfaceChanged(JNIEnv* env, jobject obj, jint pointer, jint state,
- jint format, jint width, jint height)
-{
- // Be safe and check for a valid callback
- if (!pointer)
- return;
- SurfaceCallback* cb = reinterpret_cast<SurfaceCallback*>(pointer);
- switch (state) {
- case 0:
- cb->surfaceCreated();
- break;
- case 1:
- cb->surfaceChanged(format, width, height);
- break;
- case 2:
- cb->surfaceDestroyed();
- break;
- default:
- break;
- }
-}
-
static void Pause(JNIEnv* env, jobject obj)
{
ANPEvent event;
@@ -2827,8 +2797,6 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = {
(void*) DumpNavTree },
{ "nativeSetNewStorageLimit", "(J)V",
(void*) SetNewStorageLimit },
- { "nativeSurfaceChanged", "(IIIII)V",
- (void*) SurfaceChanged },
{ "nativeGeolocationPermissionsProvide", "(Ljava/lang/String;ZZ)V",
(void*) GeolocationPermissionsProvide },
{ "nativePause", "()V", (void*) Pause },
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index 47410f9..cf1d21f 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -366,13 +366,11 @@ namespace android {
void requestKeyboard(bool);
// Creates a SurfaceView for a plugin
- jobject createSurface(SurfaceCallback* cb, PixelFormat format, bool isFixedSize);
+ jobject createSurface(const char* packageName, const char* className,
+ NPP npp, int x, int y, int width, int height);
- // Destroys the SurfaceView after removing from the view system.
- void destroySurface(jobject surface);
-
- // Positions the SurfaceView at x,y with dimensions width x height
- void attachSurface(jobject surface, int x, int y, int width, int height);
+ // Destroys a SurfaceView for a plugin
+ void destroySurface(jobject childView);
// other public functions
public:
diff --git a/WebKit/android/plugins/ANPSurfaceInterface.cpp b/WebKit/android/plugins/ANPSurfaceInterface.cpp
index a96220f..dd5dbe0 100644
--- a/WebKit/android/plugins/ANPSurfaceInterface.cpp
+++ b/WebKit/android/plugins/ANPSurfaceInterface.cpp
@@ -26,50 +26,102 @@
// must include config.h first for webkit to fiddle with new/delete
#include "config.h"
-#include "PluginSurface.h"
#include "PluginView.h"
#include "PluginWidgetAndroid.h"
#include "SkANP.h"
+#include <ui/Surface.h>
+#include <ui/Rect.h>
+#include <ui/Region.h>
+#include "jni_utility.h"
+#include <utils/RefBase.h>
+#include "android_graphics.h"
+#include "ANPSurface_npapi.h"
-using namespace WebCore;
+using namespace android;
-static ANPSurface* anp_newRasterSurface(NPP instance, ANPBitmapFormat format,
- bool fixedSize) {
- if (instance && instance->ndata) {
- PluginView* view = static_cast<PluginView*>(instance->ndata);
- PluginWidgetAndroid* widget = view->platformPluginWidget();
- return widget->createRasterSurface(format, fixedSize);
+static inline sp<Surface> getSurface(JNIEnv* env, jobject view) {
+ if (!env || !view) {
+ return NULL;
}
- return NULL;
+
+ jclass clazz = env->FindClass("android/view/Surface");
+ jfieldID surfaceField = env->GetFieldID(clazz, "mSurface", "I");
+
+ clazz = env->FindClass("android/view/SurfaceView");
+ jmethodID getHolder = env->GetMethodID(clazz, "getHolder", "()Landroid/view/SurfaceHolder;");
+
+ clazz = env->FindClass("android/view/SurfaceHolder");
+ jmethodID getSurface = env->GetMethodID(clazz, "getSurface", "()Landroid/view/Surface;");
+
+ jobject holder = env->CallObjectMethod(view, getHolder);
+ jobject surface = env->CallObjectMethod(holder, getSurface);
+ return sp<Surface>((Surface*) env->GetIntField(surface, surfaceField));
}
-static void anp_deleteSurface(ANPSurface* surface) {
- if (surface) {
- if (surface->data) {
- android::PluginSurface* s =
- static_cast<android::PluginSurface*>(surface->data);
- s->destroy();
- }
- delete surface;
+static inline ANPBitmapFormat convertPixelFormat(PixelFormat format) {
+ switch (format) {
+ case PIXEL_FORMAT_RGBA_8888: return kRGBA_8888_ANPBitmapFormat;
+ case PIXEL_FORMAT_RGB_565: return kRGB_565_ANPBitmapFormat;
+ default: return kUnknown_ANPBitmapFormat;
}
}
-static bool anp_lock(ANPSurface* surface, ANPBitmap* bitmap, ANPRectI* dirtyRect) {
- if (bitmap && surface && surface->data) {
- android::PluginSurface* s =
- static_cast<android::PluginSurface*>(surface->data);
+static bool anp_lock(JNIEnv* env, jobject surfaceView, ANPBitmap* bitmap, ANPRectI* dirtyRect) {
+ if (!bitmap || !surfaceView) {
+ return false;
+ }
- return s->lock(dirtyRect, bitmap);
+ sp<Surface> surface = getSurface(env, surfaceView);
+
+ if (!bitmap || !Surface::isValid(surface)) {
+ return false;
}
- return false;
+
+ Region dirtyRegion;
+ if (dirtyRect) {
+ Rect rect(dirtyRect->left, dirtyRect->top, dirtyRect->right, dirtyRect->bottom);
+ if (!rect.isEmpty()) {
+ dirtyRegion.set(rect);
+ }
+ } else {
+ dirtyRegion.set(Rect(0x3FFF, 0x3FFF));
+ }
+
+ Surface::SurfaceInfo info;
+ status_t err = surface->lock(&info, &dirtyRegion);
+ if (err < 0) {
+ return false;
+ }
+
+ ssize_t bpr = info.s * bytesPerPixel(info.format);
+
+ bitmap->format = convertPixelFormat(info.format);
+ bitmap->width = info.w;
+ bitmap->height = info.h;
+ bitmap->rowBytes = bpr;
+
+ if (info.w > 0 && info.h > 0) {
+ bitmap->baseAddr = info.bits;
+ } else {
+ bitmap->baseAddr = NULL;
+ return false;
+ }
+
+ return true;
}
-static void anp_unlock(ANPSurface* surface) {
- if (surface && surface->data) {
- android::PluginSurface* s =
- static_cast<android::PluginSurface*>(surface->data);
- s->unlock();
+static void anp_unlock(JNIEnv* env, jobject surfaceView) {
+ if (!surfaceView) {
+ return;
}
+
+ sp<Surface> surface = getSurface(env, surfaceView);
+
+ if (!Surface::isValid(surface)) {
+ return;
+ }
+
+ surface->unlockAndPost();
}
///////////////////////////////////////////////////////////////////////////////
@@ -79,8 +131,6 @@ static void anp_unlock(ANPSurface* surface) {
void ANPSurfaceInterfaceV0_Init(ANPInterface* value) {
ANPSurfaceInterfaceV0* i = reinterpret_cast<ANPSurfaceInterfaceV0*>(value);
- ASSIGN(i, newRasterSurface);
- ASSIGN(i, deleteSurface);
ASSIGN(i, lock);
ASSIGN(i, unlock);
}
diff --git a/WebKit/android/plugins/ANPSurface_npapi.h b/WebKit/android/plugins/ANPSurface_npapi.h
new file mode 100644
index 0000000..7dcec92
--- /dev/null
+++ b/WebKit/android/plugins/ANPSurface_npapi.h
@@ -0,0 +1,23 @@
+#ifndef ANPSurface_npapi_H
+#define ANPSurface_npapi_H
+
+#include "android_npapi.h"
+#include <jni.h>
+
+struct ANPSurfaceInterfaceV0 : ANPInterface {
+ /** Locks the surface from manipulation by other threads and provides a bitmap
+ to be written to. The dirtyRect param specifies which portion of the
+ bitmap will be written to. If the dirtyRect is NULL then the entire
+ surface will be considered dirty. If the lock was successful the function
+ will return true and the bitmap will be set to point to a valid bitmap.
+ If not the function will return false and the bitmap will be set to NULL.
+ */
+ bool (*lock)(JNIEnv* env, jobject surface, ANPBitmap* bitmap, ANPRectI* dirtyRect);
+ /** Given a locked surface handle (i.e. result of a successful call to lock)
+ the surface is unlocked and the contents of the bitmap, specifically
+ those inside the dirtyRect are written to the screen.
+ */
+ void (*unlock)(JNIEnv* env, jobject surface);
+};
+
+#endif //ANPSurface_npapi_H
diff --git a/WebKit/android/plugins/PluginSurface.cpp b/WebKit/android/plugins/PluginSurface.cpp
deleted file mode 100644
index 451ceee..0000000
--- a/WebKit/android/plugins/PluginSurface.cpp
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * 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 APPLE COMPUTER, 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 "config.h"
-
-#include "PluginSurface.h"
-
-#include "android_graphics.h"
-#include "PluginWidgetAndroid.h"
-#include "WebViewCore.h"
-#include "jni_utility.h"
-
-#include <ui/Rect.h>
-#include <ui/Region.h>
-#include <ui/Surface.h>
-
-namespace android {
-
-// jni field offset for the native surface pointer.
-static jfieldID gSurfaceField;
-static jmethodID gGetHolder;
-static jmethodID gGetSurface;
-
-static void initFields(JNIEnv* env) {
- if (gSurfaceField)
- return;
-
- jclass clazz = env->FindClass("android/view/Surface");
- gSurfaceField = env->GetFieldID(clazz, "mSurface", "I");
-
- clazz = env->FindClass("android/view/SurfaceView");
- gGetHolder = env->GetMethodID(clazz, "getHolder", "()Landroid/view/SurfaceHolder;");
-
- clazz = env->FindClass("android/view/SurfaceHolder");
- gGetSurface = env->GetMethodID(clazz, "getSurface", "()Landroid/view/Surface;");
-}
-
-static inline sp<Surface> getSurface(jobject view) {
- if (!view) {
- return NULL;
- }
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- initFields(env);
- jobject holder = env->CallObjectMethod(view, gGetHolder);
- jobject surface = env->CallObjectMethod(holder, gGetSurface);
- return sp<Surface>((Surface*) env->GetIntField(surface, gSurfaceField));
-}
-
-static inline ANPBitmapFormat convertPixelFormat(PixelFormat format) {
- switch (format) {
- case PIXEL_FORMAT_RGBA_8888: return kRGBA_8888_ANPBitmapFormat;
- case PIXEL_FORMAT_RGB_565: return kRGB_565_ANPBitmapFormat;
- default: return kUnknown_ANPBitmapFormat;
- }
-}
-
-static inline PixelFormat convertANPBitmapFormat(ANPBitmapFormat format) {
- switch (format) {
- case kRGBA_8888_ANPBitmapFormat: return PIXEL_FORMAT_RGBA_8888;
- case kRGB_565_ANPBitmapFormat: return PIXEL_FORMAT_RGB_565;
- default: return PIXEL_FORMAT_UNKNOWN;
- }
-}
-
-PluginSurface::PluginSurface(PluginWidgetAndroid* widget, ANPBitmapFormat format,
- bool isFixedSize)
- : m_jSurfaceView(0)
- , m_widget(widget) {
- // Create our java SurfaceView.
- jobject obj = widget->webViewCore()->createSurface(this, convertANPBitmapFormat(format), isFixedSize);
- if (obj) {
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- m_jSurfaceView = env->NewGlobalRef(obj);
- env->DeleteLocalRef(obj);
- }
-}
-
-void PluginSurface::attach(int x, int y, int width, int height) {
- if (m_jSurfaceView) {
- m_widget->webViewCore()->attachSurface(m_jSurfaceView, x, y, width,
- height);
- }
-}
-
-void PluginSurface::destroy() {
- m_surface.clear();
- if (m_jSurfaceView) {
- m_widget->webViewCore()->destroySurface(m_jSurfaceView);
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- env->DeleteGlobalRef(m_jSurfaceView);
- m_jSurfaceView = 0;
- }
-}
-
-bool PluginSurface::lock(ANPRectI* dirty, ANPBitmap* bitmap) {
- if (!bitmap || !Surface::isValid(m_surface)) {
- return false;
- }
-
- Region dirtyRegion;
- if (dirty) {
- Rect rect(dirty->left, dirty->top, dirty->right, dirty->bottom);
- if (!rect.isEmpty()) {
- dirtyRegion.set(rect);
- }
- } else {
- dirtyRegion.set(Rect(0x3FFF, 0x3FFF));
- }
-
- Surface::SurfaceInfo info;
- status_t err = m_surface->lock(&info, &dirtyRegion);
- if (err < 0) {
- return false;
- }
-
- ssize_t bpr = info.s * bytesPerPixel(info.format);
-
- bitmap->format = convertPixelFormat(info.format);
- bitmap->width = info.w;
- bitmap->height = info.h;
- bitmap->rowBytes = bpr;
-
- if (info.w > 0 && info.h > 0) {
- bitmap->baseAddr = info.bits;
- } else {
- bitmap->baseAddr = NULL;
- return false;
- }
-
- return true;
-}
-
-void PluginSurface::unlock() {
- if (!Surface::isValid(m_surface)) {
- return;
- }
-
- m_surface->unlockAndPost();
-}
-
-static void sendSurfaceEvent(PluginWidgetAndroid* widget,
- ANPSurfaceAction action, int format = 0, int width = 0,
- int height = 0) {
- // format is currently not reported to the plugin. The plumbing from Java
- // to C is still provided in case we add the format back to the event.
- ANPEvent event;
- SkANP::InitEvent(&event, kSurface_ANPEventType);
-
- event.data.surface.action = action;
- if (action == kChanged_ANPSurfaceAction) {
- event.data.surface.data.changed.width = width;
- event.data.surface.data.changed.height = height;
- }
-
- widget->sendEvent(event);
-}
-
-// SurfaceCallback methods
-void PluginSurface::surfaceCreated() {
- m_surface = getSurface(m_jSurfaceView);
- // Not sure what values for format, width, and height should be here.
- sendSurfaceEvent(m_widget, kCreated_ANPSurfaceAction);
-}
-
-void PluginSurface::surfaceChanged(int format, int width, int height) {
- m_surface = getSurface(m_jSurfaceView);
- sendSurfaceEvent(m_widget, kChanged_ANPSurfaceAction, format, width,
- height);
-}
-
-void PluginSurface::surfaceDestroyed() {
- m_surface = getSurface(m_jSurfaceView);
- // Not sure what values for format, width, and height should be here.
- sendSurfaceEvent(m_widget, kDestroyed_ANPSurfaceAction);
-}
-
-} // namespace android
diff --git a/WebKit/android/plugins/PluginSurface.h b/WebKit/android/plugins/PluginSurface.h
deleted file mode 100644
index 893f698..0000000
--- a/WebKit/android/plugins/PluginSurface.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2009, The Android Open Source Project
- * Copyright (C) 2008 Google 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 COMPUTER, 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 COMPUTER, 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 PluginSurface_H
-#define PluginSurface_H
-
-#include "android_npapi.h"
-#include "SkANP.h"
-#include "SurfaceCallback.h"
-
-#include <jni.h>
-#include <ui/Surface.h>
-#include <utils/RefBase.h>
-
-struct PluginWidgetAndroid;
-class SkBitmap;
-struct SkIRect;
-
-enum ANPSurfaceTypes {
- kRaster_ANPSurfaceType = 0
-};
-typedef int32_t ANPSurfaceType;
-
-struct ANPSurface {
- void* data;
- ANPSurfaceType type;
-};
-
-namespace android {
-
-class Surface;
-
-class PluginSurface : public SurfaceCallback {
-public:
- PluginSurface(PluginWidgetAndroid* widget, ANPBitmapFormat format, bool isFixedSize);
- virtual ~PluginSurface() {
- destroy();
- }
-
- void attach(int x, int y, int width, int height);
- void destroy();
- bool lock(ANPRectI* dirty, ANPBitmap* bitmap);
- void unlock();
-
- virtual void surfaceCreated();
- virtual void surfaceChanged(int format, int width, int height);
- virtual void surfaceDestroyed();
-
-private:
- jobject m_jSurfaceView;
- sp<Surface> m_surface;
- PluginWidgetAndroid* m_widget;
-};
-
-} // namespace android
-
-#endif
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp
index 60d7058..6318276 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.cpp
+++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp
@@ -29,7 +29,6 @@
#include "Element.h"
#include "Frame.h"
#include "PluginPackage.h"
-#include "PluginSurface.h"
#include "PluginView.h"
#include "PluginWidgetAndroid.h"
#include "ScrollView.h"
@@ -49,11 +48,19 @@ PluginWidgetAndroid::PluginWidgetAndroid(WebCore::PluginView* view)
m_visibleDocRect.setEmpty();
m_hasFocus = false;
m_zoomLevel = 0;
+ m_javaClassName = NULL;
+ m_childView = NULL;
}
PluginWidgetAndroid::~PluginWidgetAndroid() {
if (m_core) {
m_core->removePlugin(this);
+ if (m_childView) {
+ m_core->destroySurface(m_childView);
+ }
+ }
+ if (m_javaClassName) {
+ free(m_javaClassName);
}
m_flipPixelRef->safeUnref();
}
@@ -68,13 +75,48 @@ static SkBitmap::Config computeConfig(bool isTransparent) {
: SkBitmap::kRGB_565_Config;
}
+/*
+ * Returns the name of the apk that contains this plugin. The caller is
+ * responsible for calling free(...) on the char* that is returned.
+ */
+static char* getPackageName(PluginPackage* pluginPackage) {
+
+ // get the directory where the plugin library is stored. The structure of
+ // the path looks like /data/app/plugin.package.name/lib.
+ const char* pluginDir = pluginPackage->parentDirectory().latin1().data();
+
+ // trim "/lib" off the directory name and store in tempString
+ int length = strlen(pluginDir) - 4; // -4 for "/lib"
+ char* tempString = (char*) malloc(length + 1); // +1 for null termination
+ strncpy(tempString, pluginDir, length);
+ tempString[length] = '\0';
+
+ // find the final '/' in tempString
+ char* result = strrchr(tempString, '/');
+
+ char* packageName = NULL;
+ if (result) {
+ // duplicate the tempString without the leading '/'
+ packageName = strdup(result+1);
+ }
+
+ // free extra memory and return the package name
+ free(tempString);
+ return packageName;
+}
+
void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) {
m_pluginWindow = window;
if (m_drawingModel == kSurface_ANPDrawingModel) {
- if (m_surface) {
+ if (!m_childView) {
IntPoint docPoint = frameToDocumentCoords(window->x, window->y);
- m_surface->attach(docPoint.x(), docPoint.y(), window->width, window->height);
+ char* packageName = getPackageName(m_pluginView->plugin());
+ m_childView = m_core->createSurface(packageName, m_javaClassName,
+ m_pluginView->instance(),
+ docPoint.x(), docPoint.y(),
+ window->width, window->height);
+ free(packageName);
}
} else {
m_flipPixelRef->safeUnref();
@@ -83,7 +125,18 @@ void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) {
}
}
+bool PluginWidgetAndroid::setJavaClassName(const char* className) {
+ m_javaClassName = strdup(className);
+ return (m_javaClassName != NULL);
+}
+
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;
}
@@ -210,18 +263,6 @@ bool PluginWidgetAndroid::isAcceptingEvent(ANPEventFlag flag) {
return m_eventFlags & flag;
}
-ANPSurface* PluginWidgetAndroid::createRasterSurface(ANPBitmapFormat format,
- bool fixedSize) {
- if (m_drawingModel != kSurface_ANPDrawingModel) {
- return NULL;
- }
- m_surface.set(new android::PluginSurface(this, format, fixedSize));
- ANPSurface* surface = new ANPSurface;
- surface->data = m_surface.get();
- surface->type = kRaster_ANPSurfaceType;
- return surface;
-}
-
void PluginWidgetAndroid::setVisibleScreen(const ANPRectI& visibleDocRect, float zoom) {
// TODO update the bitmap size based on the zoom? (for kBitmap_ANPDrawingModel)
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.h b/WebKit/android/plugins/PluginWidgetAndroid.h
index d1575d7..af77aa9 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.h
+++ b/WebKit/android/plugins/PluginWidgetAndroid.h
@@ -29,8 +29,7 @@
#include "android_npapi.h"
#include "IntPoint.h"
#include "SkRect.h"
-
-#include <wtf/OwnPtr.h>
+#include <jni.h>
namespace WebCore {
class PluginView;
@@ -68,6 +67,11 @@ struct PluginWidgetAndroid {
*/
void setWindow(NPWindow* window, bool isTransparent);
+ /* Called to notify us of the plugin's java class that implements the
+ * PluginStub interface.
+ */
+ bool setJavaClassName(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.
@@ -110,15 +114,6 @@ struct PluginWidgetAndroid {
*/
bool isAcceptingEvent(ANPEventFlag);
- /* Create an ANPSurface that the plugin may draw in to. The drawing model
- must be kSurface_ANPDrawingModel for this call to succeed. The format
- specifies what kind of pixel access will be available. If true the
- fixedSize param signals that the browser will auto-scale the surface for
- the plugin (e.g. in the case of zooming). If false the surface will be
- resized when zoomed and the plugin must manually scale to the new size.
- */
- ANPSurface* createRasterSurface(ANPBitmapFormat format, bool fixedSize);
-
/* Notify the plugin of the currently visible screen coordinates (document
space) and the current zoom level.
*/
@@ -148,9 +143,10 @@ private:
NPWindow* m_pluginWindow;
SkIRect m_visibleDocRect;
SkIRect m_requestedFrameRect;
- OwnPtr<android::PluginSurface> m_surface;
bool m_hasFocus;
float m_zoomLevel;
+ char* m_javaClassName;
+ jobject m_childView;
/* 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 37c8ed3..e397e65 100644
--- a/WebKit/android/plugins/android_npapi.h
+++ b/WebKit/android/plugins/android_npapi.h
@@ -87,10 +87,6 @@ struct ANPMatrix;
struct ANPPaint;
struct ANPPath;
struct ANPRegion;
-/** The ANPSurface acts as a handle between the plugin and the native libraries
- that render the surface to the screen.
- */
-struct ANPSurface;
struct ANPTypeface;
enum ANPMatrixFlags {
@@ -134,12 +130,21 @@ typedef uint32_t ANPMatrixFlag;
///////////////////////////////////////////////////////////////////////////////
// NPN_SetValue
-/** Request to set the drawing model.
+/** Request to set the drawing model. SetValue will return false if the drawing
+ model is not supported or has insufficient information for configuration.
- NPN_SetValue(inst, ANPRequestDrawingModel_EnumValue, (void*)foo_ANPDrawingModel)
+ NPN_SetValue(inst, kRequestDrawingModel_ANPSetValue, (void*)foo_ANPDrawingModel)
*/
#define kRequestDrawingModel_ANPSetValue ((NPPVariable)1000)
+/** 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)
+
+ NPN_SetValue(inst, kSetJavaClassName_ANPSetValue, (void*)nullTerminatedChar*)
+ */
+#define kSetJavaClassName_ANPSetValue ((NPPVariable)1001)
+
/** These are used as bitfields in ANPSupportedDrawingModels_EnumValue,
and as-is in ANPRequestDrawingModel_EnumValue. The drawing model determines
how to interpret the ANPDrawingContext provided in the Draw event and how
@@ -156,7 +161,9 @@ enum ANPDrawingModels {
surface model should be chosen over the bitmap model as it will have faster
performance. An example surface is the raster surface where the service
interface is used to lock/unlock and draw into bitmap without waiting for
- draw events.
+ draw events. Prior to requesting this drawing model the plugin must provide
+ the name of the Java class that implements the PluginStub interface via
+ kSetJavaClassName_ANPSetValue.
*/
kSurface_ANPDrawingModel = 1,
};
@@ -168,7 +175,7 @@ typedef int32_t ANPDrawingModel;
NPN_SetValue(inst, ANPAcceptEvents, (void*)EventFlags)
*/
-#define kAcceptEvents_ANPSetValue ((NPPVariable)1001)
+#define kAcceptEvents_ANPSetValue ((NPPVariable)1002)
/** 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
@@ -213,34 +220,6 @@ struct ANPBitmapInterfaceV0 : ANPInterface {
bool (*getPixelPacking)(ANPBitmapFormat, ANPPixelPacking* packing);
};
-struct ANPSurfaceInterfaceV0 : ANPInterface {
- /** Creates a new raster surface handle based on the given bitmap format. If
- raster surfaces or the bitmap format is not supported then NULL is
- returned. Setting the fixedSize parameter to true notifies the browser
- that it is responsible for scaling the bitmap when zoomed. Setting the
- fixedSize to false will cause a kChanged_ANPSurfaceAction to be fired
- each time the user changes the zoom level.
- */
- ANPSurface* (*newRasterSurface)(NPP instance, ANPBitmapFormat, bool fixedSize);
- /** Given a valid surface handle (i.e. one created by calling newSurface)
- the underlying surface is removed and the pointer is set to NULL.
- */
- void (*deleteSurface)(ANPSurface* surface);
- /** Locks the surface from manipulation by other threads and provides a bitmap
- to be written to. The dirtyRect param specifies which portion of the
- bitmap will be written to. If the dirtyRect is NULL then the entire
- surface will be considered dirty. If the lock was successful the function
- will return true and the bitmap will be set to point to a valid bitmap.
- If not the function will return false and the bitmap will be set to NULL.
- */
- bool (*lock)(ANPSurface* surface, ANPBitmap* bitmap, ANPRectI* dirtyRect);
- /** Given a locked surface handle (i.e. result of a successful call to lock)
- the surface is unlocked and the contents of the bitmap, specifically
- those inside the dirtyRect are written to the screen.
- */
- void (*unlock)(ANPSurface* surface);
-};
-
struct ANPMatrixInterfaceV0 : ANPInterface {
/** Return a new identity matrix
*/
@@ -503,7 +482,7 @@ struct ANPTypefaceInterfaceV0 : ANPInterface {
/** Return a UTF8 encoded path name for the font directory, or NULL if not
supported. If returned, this string address will be valid for the life
- of the plugin instance. It will always end with a '/' character.
+ of the plugin instance. It will always end with a '/' character.
*/
const char* (*getFontDirectoryPath)();
};