From c0b8a96d28c55cb51e4f9e1f85c8d3ecf1ff13bf Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Tue, 22 Sep 2009 14:08:09 -0400 Subject: [PATCH] launching plugin activity when a plugin requests to go full screen. Change-Id: Ib42bb08d01a75ca3a9c02085ee185396bb7b7378 --- core/java/android/webkit/PluginManager.java | 126 ++++++++++++-------- core/java/android/webkit/WebViewCore.java | 46 +++++-- 2 files changed, 116 insertions(+), 56 deletions(-) diff --git a/core/java/android/webkit/PluginManager.java b/core/java/android/webkit/PluginManager.java index 32eea5fcc95ac..766bd75852ce8 100644 --- a/core/java/android/webkit/PluginManager.java +++ b/core/java/android/webkit/PluginManager.java @@ -63,8 +63,11 @@ public class PluginManager { private final Context mContext; + private ArrayList mPackageInfoCache; + private PluginManager(Context context) { mContext = context; + mPackageInfoCache = new ArrayList(); } public static synchronized PluginManager getInstance(Context context) { @@ -92,65 +95,94 @@ public class PluginManager { } String[] getPluginDirectories() { + ArrayList directories = new ArrayList(); PackageManager pm = mContext.getPackageManager(); List plugins = pm.queryIntentServices(new Intent( PLUGIN_ACTION), PackageManager.GET_SERVICES); - for (ResolveInfo info : plugins) { - ServiceInfo serviceInfo = info.serviceInfo; - if (serviceInfo == null) { - Log.w(LOGTAG, "Ignore bad plugin"); - continue; - } - PackageInfo pkgInfo; - try { - pkgInfo = pm.getPackageInfo(serviceInfo.packageName, - PackageManager.GET_PERMISSIONS - | PackageManager.GET_SIGNATURES); - } catch (NameNotFoundException e) { - Log.w(LOGTAG, "Cant find plugin: " + serviceInfo.packageName); - continue; - } - if (pkgInfo == null) { - continue; - } - String directory = pkgInfo.applicationInfo.dataDir + "/lib"; - if (directories.contains(directory)) { - continue; - } - String permissions[] = pkgInfo.requestedPermissions; - if (permissions == null) { - continue; - } - boolean permissionOk = false; - for (String permit : permissions) { - if (PLUGIN_PERMISSION.equals(permit)) { - permissionOk = true; + + synchronized(mPackageInfoCache) { + + // clear the list of existing packageInfo objects + mPackageInfoCache.clear(); + + for (ResolveInfo info : plugins) { + ServiceInfo serviceInfo = info.serviceInfo; + if (serviceInfo == null) { + Log.w(LOGTAG, "Ignore bad plugin"); + continue; + } + PackageInfo pkgInfo; + try { + pkgInfo = pm.getPackageInfo(serviceInfo.packageName, + PackageManager.GET_PERMISSIONS + | PackageManager.GET_SIGNATURES); + } catch (NameNotFoundException e) { + Log.w(LOGTAG, "Cant find plugin: " + serviceInfo.packageName); + continue; + } + if (pkgInfo == null) { + continue; + } + String directory = pkgInfo.applicationInfo.dataDir + "/lib"; + if (directories.contains(directory)) { + continue; + } + String permissions[] = pkgInfo.requestedPermissions; + if (permissions == null) { + continue; + } + boolean permissionOk = false; + for (String permit : permissions) { + if (PLUGIN_PERMISSION.equals(permit)) { + permissionOk = true; + break; + } + } + if (!permissionOk) { + continue; + } + Signature signatures[] = pkgInfo.signatures; + if (signatures == null) { + continue; + } + boolean signatureMatch = false; + for (Signature signature : signatures) { + // TODO: check signature against Google provided one + signatureMatch = true; break; } + if (!signatureMatch) { + continue; + } + mPackageInfoCache.add(pkgInfo); + directories.add(directory); } - if (!permissionOk) { - continue; - } - Signature signatures[] = pkgInfo.signatures; - if (signatures == null) { - continue; - } - boolean signatureMatch = false; - for (Signature signature : signatures) { - // TODO: check signature against Google provided one - signatureMatch = true; - break; - } - if (!signatureMatch) { - continue; - } - 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(); } diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index 52bf5083becbc..ce45373e98fb3 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -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,22 +2092,49 @@ 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); - if (stub == null) { - Log.e(LOGTAG, "Unable to find plugin class (" + className + - ") in the apk (" + packageName + ")"); + + 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 (" + clsName + + ") in the apk (" + pkgName + ")"); + return null; + } + View pluginView = stub.getEmbeddedView(npp, mWebView.getContext()); - + ViewManager.ChildView view = mWebView.mViewManager.createView(); view.mView = pluginView; view.attachView(x, y, width, height);