diff options
author | Derek Sollenberger <djsollen@google.com> | 2009-09-08 18:31:40 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2009-09-15 19:33:54 -0400 |
commit | 0b3a5d65247be1fb79d66af534fa78a94743864f (patch) | |
tree | 4528b972912c47ee3c8f3161a9b9ba32134b3a74 /core/java | |
parent | d1d6778247d4b3798f9b9fafca4312a348826a0b (diff) | |
download | frameworks_base-0b3a5d65247be1fb79d66af534fa78a94743864f.zip frameworks_base-0b3a5d65247be1fb79d66af534fa78a94743864f.tar.gz frameworks_base-0b3a5d65247be1fb79d66af534fa78a94743864f.tar.bz2 |
First pass at replacing native plugin views with java.
Change-Id: I6d1f45f31210c2353fa348cc37be8d91bcd5e887
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/webkit/PluginActivity.java | 4 | ||||
-rw-r--r-- | core/java/android/webkit/PluginStub.java | 15 | ||||
-rw-r--r-- | core/java/android/webkit/PluginUtil.java | 11 | ||||
-rw-r--r-- | core/java/android/webkit/WebViewCore.java | 91 |
4 files changed, 32 insertions, 89 deletions
diff --git a/core/java/android/webkit/PluginActivity.java b/core/java/android/webkit/PluginActivity.java index f9e3080..cda7b59 100644 --- a/core/java/android/webkit/PluginActivity.java +++ b/core/java/android/webkit/PluginActivity.java @@ -49,10 +49,10 @@ public class PluginActivity extends Activity { final int npp = intent.getIntExtra(INTENT_EXTRA_NPP_INSTANCE, -1); // Retrieve the PluginStub implemented in packageName.className PluginStub stub = - PluginUtil.getPluginStub(this, packageName, className, npp); + PluginUtil.getPluginStub(this, packageName, className); if (stub != null) { - View pluginView = stub.getFullScreenView(this); + View pluginView = stub.getFullScreenView(npp, this); if (pluginView != null) { setContentView(pluginView); } else { diff --git a/core/java/android/webkit/PluginStub.java b/core/java/android/webkit/PluginStub.java index c24da8d..cbb36aa 100644 --- a/core/java/android/webkit/PluginStub.java +++ b/core/java/android/webkit/PluginStub.java @@ -19,32 +19,29 @@ import android.content.Context; import android.view.View; /** - * This abstract class is used to implement plugins in a WebView. A plugin + * This interface is used to implement plugins in a WebView. A plugin * package may extend this class and implement the abstract functions to create * embedded or fullscreeen views displayed in a WebView. The PluginStub * implementation will be provided the same NPP instance that is created * through the native interface. */ -public abstract class PluginStub { - /** - * Construct a new PluginStub implementation for the given NPP instance. - * @param npp The native NPP instance. - */ - public PluginStub(int npp) { } +public interface PluginStub { /** * Return a custom embedded view to draw the plugin. + * @param npp The native NPP instance. * @param context The current application's Context. * @return A custom View that will be managed by WebView. */ - public abstract View getEmbeddedView(Context context); + public abstract View getEmbeddedView(int NPP, Context context); /** * Return a custom full-screen view to be displayed when the user requests * a plugin display as full-screen. Note that the application may choose not * to display this View as completely full-screen. + * @param npp The native NPP instance. * @param context The current application's Context. * @return A custom View that will be managed by the application. */ - public abstract View getFullScreenView(Context context); + public abstract View getFullScreenView(int NPP, Context context); } diff --git a/core/java/android/webkit/PluginUtil.java b/core/java/android/webkit/PluginUtil.java index c0a7375..8fdbd67 100644 --- a/core/java/android/webkit/PluginUtil.java +++ b/core/java/android/webkit/PluginUtil.java @@ -32,19 +32,16 @@ class PluginUtil { * @param className the fully qualified name of a subclass of PluginStub */ /* package */ - static PluginStub getPluginStub(Context context, String packageName, - String className, int NPP) { + static PluginStub getPluginStub(Context context, String packageName, + String className) { try { Context pluginContext = context.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); ClassLoader pluginCL = pluginContext.getClassLoader(); - Class<?> stubClass = - pluginCL.loadClass(className); - Constructor<?> stubConstructor = - stubClass.getConstructor(int.class); - Object stubObject = stubConstructor.newInstance(NPP); + Class<?> stubClass = pluginCL.loadClass(className); + Object stubObject = stubClass.newInstance(); if (stubObject instanceof PluginStub) { return (PluginStub) stubObject; diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index 5f2d65e..ac3334c 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -34,6 +34,7 @@ import android.util.SparseBooleanArray; import android.view.KeyEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; +import android.view.View; import java.util.ArrayList; import java.util.Map; @@ -2060,84 +2061,32 @@ final class WebViewCore { } } - // This class looks like a SurfaceView to native code. In java, we can - // assume the passed in SurfaceView is this class so we can talk to the - // ViewManager through the ChildView. - private class SurfaceViewProxy extends SurfaceView - implements SurfaceHolder.Callback { - private final ViewManager.ChildView mChildView; - private int mPointer; - private final boolean mIsFixedSize; - SurfaceViewProxy(Context context, ViewManager.ChildView childView, - int pointer, int pixelFormat, boolean isFixedSize) { - super(context); - setWillNotDraw(false); // this prevents the black box artifact - getHolder().addCallback(this); - getHolder().setFormat(pixelFormat); - mChildView = childView; - mChildView.mView = this; - mPointer = pointer; - mIsFixedSize = isFixedSize; - } - void destroy() { - mPointer = 0; - mChildView.removeView(); - } - void attach(int x, int y, int width, int height) { - mChildView.attachView(x, y, width, height); - - if (mIsFixedSize) { - getHolder().setFixedSize(width, height); - } - } - - // SurfaceHolder.Callback methods - public void surfaceCreated(SurfaceHolder holder) { - if (mPointer != 0) { - nativeSurfaceChanged(mPointer, 0, 0, 0, 0); - } - } - public void surfaceChanged(SurfaceHolder holder, int format, int width, - int height) { - if (mPointer != 0) { - nativeSurfaceChanged(mPointer, 1, format, width, height); - } - } - public void surfaceDestroyed(SurfaceHolder holder) { - if (mPointer != 0) { - nativeSurfaceChanged(mPointer, 2, 0, 0, 0); - } - } - } - - // PluginWidget functions for mainting SurfaceViews for the Surface drawing + // PluginWidget functions for creating SurfaceViews for the Surface drawing // model. - private SurfaceView createSurface(int nativePointer, int pixelFormat, - boolean isFixedSize) { + private ViewManager.ChildView createSurface(String packageName, String className, + int npp, int x, int y, int width, int height) { if (mWebView == null) { return null; } - return new SurfaceViewProxy(mContext, mWebView.mViewManager.createView(), - nativePointer, pixelFormat, isFixedSize); - } - - private void destroySurface(SurfaceView surface) { - SurfaceViewProxy proxy = (SurfaceViewProxy) surface; - proxy.destroy(); + PluginStub stub = PluginUtil.getPluginStub(mWebView.getContext(), packageName, className); + if (stub == null) { + Log.e(LOGTAG, "Unable to find plugin class (" + className + + ") in the apk (" + packageName + ")"); + return null; + } + + View pluginView = stub.getEmbeddedView(npp, mWebView.getContext()); + + ViewManager.ChildView view = mWebView.mViewManager.createView(); + view.mView = pluginView; + view.attachView(x, y, width, height); + return view; } - - private void attachSurface(SurfaceView surface, int x, int y, - int width, int height) { - SurfaceViewProxy proxy = (SurfaceViewProxy) surface; - proxy.attach(x, y, width, height); + + private void destroySurface(ViewManager.ChildView childView) { + childView.removeView(); } - // Callback for the SurfaceHolder.Callback. Called for all the surface - // callbacks. The state parameter is one of Created(0), Changed(1), - // Destroyed(2). - private native void nativeSurfaceChanged(int pointer, int state, int format, - int width, int height); - private native void nativePause(); private native void nativeResume(); private native void nativeFreeMemory(); |