am c0b8a96d: launching plugin activity when a plugin requests to go full screen.
Merge commit 'c0b8a96d28c55cb51e4f9e1f85c8d3ecf1ff13bf' into eclair-plus-aosp * commit 'c0b8a96d28c55cb51e4f9e1f85c8d3ecf1ff13bf': launching plugin activity when a plugin requests to go full screen.
This commit is contained in:
@@ -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,65 +95,94 @@ 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);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user