Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b3a5d65 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

First pass at replacing native plugin views with java.

Change-Id: I6d1f45f31210c2353fa348cc37be8d91bcd5e887
parent d1d67782
Loading
Loading
Loading
Loading
+6 −13
Original line number Diff line number Diff line
@@ -167285,6 +167285,8 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="NPP" type="int">
</parameter>
<parameter name="context" type="android.content.Context">
</parameter>
</method>
@@ -167438,24 +167440,13 @@
</parameter>
</method>
</class>
<class name="PluginStub"
 extends="java.lang.Object"
<interface name="PluginStub"
 abstract="true"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<constructor name="PluginStub"
 type="android.webkit.PluginStub"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="npp" type="int">
</parameter>
</constructor>
<method name="getEmbeddedView"
 return="android.view.View"
 abstract="true"
@@ -167479,10 +167470,12 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="NPP" type="int">
</parameter>
<parameter name="context" type="android.content.Context">
</parameter>
</method>
</class>
</interface>
<class name="SslErrorHandler"
 extends="android.os.Handler"
 abstract="false"
+2 −2
Original line number Diff line number Diff line
@@ -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 {
+6 −9
Original line number Diff line number Diff line
@@ -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);
}
+4 −7
Original line number Diff line number Diff line
@@ -33,18 +33,15 @@ class PluginUtil {
     */
    /* package */
    static PluginStub getPluginStub(Context context, String packageName, 
            String className, int NPP) {
            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;
+20 −71
Original line number Diff line number Diff line
@@ -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,83 +2061,31 @@ 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);
        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;
        }
        
    private void destroySurface(SurfaceView surface) {
        SurfaceViewProxy proxy = (SurfaceViewProxy) surface;
        proxy.destroy();
    }
        View pluginView = stub.getEmbeddedView(npp, mWebView.getContext());
        
    private void attachSurface(SurfaceView surface, int x, int y,
            int width, int height) {
        SurfaceViewProxy proxy = (SurfaceViewProxy) surface;
        proxy.attach(x, y, width, height);
        ViewManager.ChildView view = mWebView.mViewManager.createView();
        view.mView = pluginView;
        view.attachView(x, y, width, height);
        return view;
    }
    
    // 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 void destroySurface(ViewManager.ChildView childView) {
        childView.removeView();
    }

    private native void nativePause();
    private native void nativeResume();
Loading