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

Commit c0b8a96d authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

launching plugin activity when a plugin requests to go full screen.

Change-Id: Ib42bb08d01a75ca3a9c02085ee185396bb7b7378
parent 34ca22d2
Loading
Loading
Loading
Loading
+79 −47
Original line number Diff line number Diff line
@@ -63,8 +63,11 @@ public class PluginManager {

    private final Context mContext;

    private ArrayList<PackageInfo> mPackageInfoCache;

    private PluginManager(Context context) {
        mContext = context;
        mPackageInfoCache = new ArrayList<PackageInfo>();
    }

    public static synchronized PluginManager getInstance(Context context) {
@@ -92,10 +95,17 @@ public class PluginManager {
    }

    String[] getPluginDirectories() {

        ArrayList<String> directories = new ArrayList<String>();
        PackageManager pm = mContext.getPackageManager();
        List<ResolveInfo> plugins = pm.queryIntentServices(new Intent(
                PLUGIN_ACTION), PackageManager.GET_SERVICES);

        synchronized(mPackageInfoCache) {

            // clear the list of existing packageInfo objects
            mPackageInfoCache.clear();

            for (ResolveInfo info : plugins) {
                ServiceInfo serviceInfo = info.serviceInfo;
                if (serviceInfo == null) {
@@ -145,12 +155,34 @@ public class PluginManager {
                if (!signatureMatch) {
                    continue;
                }
                mPackageInfoCache.add(pkgInfo);
                directories.add(directory);
            }
        }

        return directories.toArray(new String[directories.size()]);
    }

    String getPluginsAPKName(String pluginLib) {

        // basic error checking on input params
        if (pluginLib == null || pluginLib.length() == 0) {
            return null;
        }

        // must be synchronized to ensure the consistency of the cache
        synchronized(mPackageInfoCache) {
            for (PackageInfo pkgInfo : mPackageInfoCache) {
                if (pluginLib.startsWith(pkgInfo.applicationInfo.dataDir)) {
                    return pkgInfo.packageName;
                }
            }
        }

        // if no apk was found then return null
        return null;
    }

    String getPluginSharedDataDirectory() {
        return mContext.getDir("plugins", 0).getPath();
    }
+36 −8
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.webkit;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.DrawFilter;
import android.graphics.Paint;
@@ -2091,17 +2092,44 @@ final class WebViewCore {
        }
    }

    // PluginWidget functions for creating SurfaceViews for the Surface drawing
    // model.
    private ViewManager.ChildView createSurface(String packageName, String className,
    // called by JNI. PluginWidget function to launch an activity and overlays
    // the activity with the View provided by the plugin class.
    private void startFullScreenPluginActivity(String libName, String clsName, int npp) {
        if (mWebView == null) {
            return;
        }

        String pkgName = PluginManager.getInstance(null).getPluginsAPKName(libName);
        if (pkgName == null) {
            Log.w(LOGTAG, "Unable to resolve " + libName + " to a plugin APK");
            return;
        }

        Intent intent = new Intent("android.intent.webkit.PLUGIN");
        intent.putExtra(PluginActivity.INTENT_EXTRA_PACKAGE_NAME, pkgName);
        intent.putExtra(PluginActivity.INTENT_EXTRA_CLASS_NAME, clsName);
        intent.putExtra(PluginActivity.INTENT_EXTRA_NPP_INSTANCE, npp);
        mWebView.getContext().startActivity(intent);
    }

    // called by JNI.  PluginWidget functions for creating an embedded View for
    // the surface drawing model.
    private ViewManager.ChildView createSurface(String libName, String clsName,
            int npp, int x, int y, int width, int height) {
        if (mWebView == null) {
            return null;
        }
        PluginStub stub = PluginUtil.getPluginStub(mWebView.getContext(), packageName, className);

        String pkgName = PluginManager.getInstance(null).getPluginsAPKName(libName);
        if (pkgName == null) {
            Log.w(LOGTAG, "Unable to resolve " + libName + " to a plugin APK");
            return null;
        }

        PluginStub stub =PluginUtil.getPluginStub(mWebView.getContext(),pkgName, clsName);
        if (stub == null) {
            Log.e(LOGTAG, "Unable to find plugin class (" + className + 
                    ") in the apk (" + packageName + ")");
            Log.e(LOGTAG, "Unable to find plugin class (" + clsName +
                    ") in the apk (" + pkgName + ")");
            return null;
        }