am 7c5bf466: consolidating to only use one surface per plugin. give plugin access to java context.

Merge commit '7c5bf4666cb8f2f79a61f46f14dd2272b0ba41db' into eclair-mr2-plus-aosp

* commit '7c5bf4666cb8f2f79a61f46f14dd2272b0ba41db':
  consolidating to only use one surface per plugin. give plugin access to java context.
This commit is contained in:
Derek Sollenberger
2010-01-11 13:11:13 -08:00
committed by Android Git Automerger
6 changed files with 39 additions and 208 deletions

View File

@@ -30,6 +30,7 @@ import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
class PluginFullScreenHolder extends Dialog { class PluginFullScreenHolder extends Dialog {
@@ -37,6 +38,7 @@ class PluginFullScreenHolder extends Dialog {
private final WebView mWebView; private final WebView mWebView;
private final int mNpp; private final int mNpp;
private View mContentView;
private int mX; private int mX;
private int mY; private int mY;
private int mWidth; private int mWidth;
@@ -63,6 +65,12 @@ class PluginFullScreenHolder extends Dialog {
mHeight = height; mHeight = height;
} }
@Override
public void setContentView(View contentView) {
super.setContentView(contentView);
mContentView = contentView;
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
mWebView.mPrivateHandler.obtainMessage(WebView.HIDE_FULLSCREEN) mWebView.mPrivateHandler.obtainMessage(WebView.HIDE_FULLSCREEN)
@@ -113,6 +121,11 @@ class PluginFullScreenHolder extends Dialog {
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
// manually remove the contentView's parent since the dialog does not
if (mContentView != null && mContentView.getParent() != null) {
ViewGroup vg = (ViewGroup) mContentView.getParent();
vg.removeView(mContentView);
}
mWebView.getWebViewCore().sendMessage( mWebView.getWebViewCore().sendMessage(
WebViewCore.EventHub.HIDE_FULLSCREEN, mNpp, 0); WebViewCore.EventHub.HIDE_FULLSCREEN, mNpp, 0);
} }

View File

@@ -21,6 +21,7 @@ import java.util.List;
import android.annotation.SdkConstant; import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SdkConstant.SdkConstantType;
import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
@@ -31,8 +32,6 @@ import android.content.pm.Signature;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.util.Log; import android.util.Log;
import android.webkit.plugin.NativePlugin;
import android.webkit.plugin.WebkitPlugin;
/** /**
* Class for managing the relationship between the {@link WebView} and installed * Class for managing the relationship between the {@link WebView} and installed
@@ -43,12 +42,6 @@ import android.webkit.plugin.WebkitPlugin;
*/ */
public class PluginManager { public class PluginManager {
private class PluginInfo {
public PackageInfo packageInfo;
public boolean isNative;
public Class<? extends WebkitPlugin> pluginClass;
}
/** /**
* Service Action: A plugin wishes to be loaded in the WebView must provide * Service Action: A plugin wishes to be loaded in the WebView must provide
* {@link android.content.IntentFilter IntentFilter} that accepts this * {@link android.content.IntentFilter IntentFilter} that accepts this
@@ -75,7 +68,7 @@ public class PluginManager {
private final Context mContext; private final Context mContext;
private ArrayList<PluginInfo> mPluginInfoCache; private ArrayList<PackageInfo> mPackageInfoCache;
// Only plugin matches one of the signatures in the list can be loaded // Only plugin matches one of the signatures in the list can be loaded
// inside the WebView process // inside the WebView process
@@ -87,7 +80,7 @@ public class PluginManager {
private PluginManager(Context context) { private PluginManager(Context context) {
mContext = context; mContext = context;
mPluginInfoCache = new ArrayList<PluginInfo>(); mPackageInfoCache = new ArrayList<PackageInfo>();
} }
public static synchronized PluginManager getInstance(Context context) { public static synchronized PluginManager getInstance(Context context) {
@@ -122,10 +115,10 @@ public class PluginManager {
PLUGIN_ACTION), PackageManager.GET_SERVICES PLUGIN_ACTION), PackageManager.GET_SERVICES
| PackageManager.GET_META_DATA); | PackageManager.GET_META_DATA);
synchronized(mPluginInfoCache) { synchronized(mPackageInfoCache) {
// clear the list of existing packageInfo objects // clear the list of existing packageInfo objects
mPluginInfoCache.clear(); mPackageInfoCache.clear();
for (ResolveInfo info : plugins) { for (ResolveInfo info : plugins) {
@@ -192,9 +185,6 @@ public class PluginManager {
} }
} }
PluginInfo pluginInfo = new PluginInfo();
pluginInfo.packageInfo = pkgInfo;
// determine the type of plugin from the manifest // determine the type of plugin from the manifest
if (serviceInfo.metaData == null) { if (serviceInfo.metaData == null) {
Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined"); Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined");
@@ -202,9 +192,7 @@ public class PluginManager {
} }
String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE); String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE);
if (TYPE_NATIVE.equals(pluginType)) { if (!TYPE_NATIVE.equals(pluginType)) {
pluginInfo.isNative = true;
} else {
Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType); Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType);
continue; continue;
} }
@@ -212,17 +200,11 @@ public class PluginManager {
try { try {
Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name); Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name);
boolean classFound = false; //TODO implement any requirements of the plugin class here!
for(Class<?> implemented : cls.getInterfaces()) { boolean classFound = true;
if (pluginInfo.isNative && implemented.equals(NativePlugin.class)) {
pluginInfo.pluginClass = cls.asSubclass(WebkitPlugin.class);
classFound = true;
break;
}
}
if (!classFound) { if (!classFound) {
Log.e(LOGTAG, "The plugin's class'" + serviceInfo.name + "' does not extend the appropriate interface."); Log.e(LOGTAG, "The plugin's class' " + serviceInfo.name + "' does not extend the appropriate class.");
continue; continue;
} }
@@ -235,7 +217,7 @@ public class PluginManager {
} }
// if all checks have passed then make the plugin available // if all checks have passed then make the plugin available
mPluginInfoCache.add(pluginInfo); mPackageInfoCache.add(pkgInfo);
directories.add(directory); directories.add(directory);
} }
} }
@@ -252,9 +234,8 @@ public class PluginManager {
} }
// must be synchronized to ensure the consistency of the cache // must be synchronized to ensure the consistency of the cache
synchronized(mPluginInfoCache) { synchronized(mPackageInfoCache) {
for (PluginInfo pluginInfo : mPluginInfoCache) { for (PackageInfo pkgInfo : mPackageInfoCache) {
PackageInfo pkgInfo = pluginInfo.packageInfo;
if (pluginLib.startsWith(pkgInfo.applicationInfo.dataDir)) { if (pluginLib.startsWith(pkgInfo.applicationInfo.dataDir)) {
return pkgInfo.packageName; return pkgInfo.packageName;
} }
@@ -269,39 +250,6 @@ public class PluginManager {
return mContext.getDir("plugins", 0).getPath(); return mContext.getDir("plugins", 0).getPath();
} }
/* package */
WebkitPlugin getPluginInstance(String pkgName, int npp) {
// must be synchronized to ensure the consistency of the cache
synchronized(mPluginInfoCache) {
// lookup plugin based on pkgName and instantiate if possible.
for (PluginInfo pluginInfo : mPluginInfoCache) {
if (pluginInfo.packageInfo.packageName.equals(pkgName)) {
try {
WebkitPlugin webkitPlugin = pluginInfo.pluginClass.newInstance();
if (pluginInfo.isNative) {
NativePlugin nativePlugin = (NativePlugin) webkitPlugin;
nativePlugin.initializePlugin(npp, mContext);
}
return webkitPlugin;
} catch (Exception e) {
// Any number of things could have happened. Log the exception and
// return null. Careful not to use Log.e(LOGTAG, "String", e)
// because that reports the exception to the checkin service.
Log.e(LOGTAG, Log.getStackTraceString(e));
}
break;
}
}
}
return null;
}
/* package */ /* package */
Class<?> getPluginClass(String packageName, String className) Class<?> getPluginClass(String packageName, String className)
throws NameNotFoundException, ClassNotFoundException { throws NameNotFoundException, ClassNotFoundException {

View File

@@ -2254,6 +2254,11 @@ final class WebViewCore {
} }
} }
// called by JNI
private Context getContext() {
return mContext;
}
// called by JNI // called by JNI
private Class<?> getPluginClass(String libName, String clsName) { private Class<?> getPluginClass(String libName, String clsName) {
@@ -2281,40 +2286,17 @@ final class WebViewCore {
return null; return null;
} }
private WebkitPlugin createPluginJavaInstance(String libName, int npp) {
if (mWebView == null) {
return null;
}
PluginManager pluginManager = PluginManager.getInstance(null);
String pkgName = pluginManager.getPluginsAPKName(libName);
if (pkgName == null) {
Log.w(LOGTAG, "Unable to resolve " + libName + " to a plugin APK");
return null;
}
return pluginManager.getPluginInstance(pkgName, npp);
}
// called by JNI. PluginWidget function to launch a full-screen view using a // called by JNI. PluginWidget function to launch a full-screen view using a
// View object provided by the plugin class. // View object provided by the plugin class.
private void showFullScreenPlugin(WebkitPlugin webkitPlugin, final int npp, private void showFullScreenPlugin(ViewManager.ChildView childView,
int x, int y, int width, int height) { final int npp, int x, int y, int width, int height) {
if (mWebView == null) {
return;
}
final SurfaceDrawingModel surface = webkitPlugin.getFullScreenSurface(); if (mWebView == null) {
if(surface == null) {
Log.e(LOGTAG, "Attempted to create an full-screen surface with a " +
"null drawing model");
return; return;
} }
PluginFullScreenData data = new PluginFullScreenData(); PluginFullScreenData data = new PluginFullScreenData();
data.mView = surface.getSurface(); data.mView = childView.mView;
data.mNpp = npp; data.mNpp = npp;
data.mDocX = x; data.mDocX = x;
data.mDocY = y; data.mDocY = y;
@@ -2351,20 +2333,18 @@ final class WebViewCore {
// called by JNI. PluginWidget functions for creating an embedded View for // called by JNI. PluginWidget functions for creating an embedded View for
// the surface drawing model. // the surface drawing model.
private ViewManager.ChildView createSurface(WebkitPlugin webkitPlugin, private ViewManager.ChildView addSurface(View pluginView, int x, int y,
int x, int y, int width, int height) { int width, int height) {
if (mWebView == null) { if (mWebView == null) {
return null; return null;
} }
SurfaceDrawingModel embeddedSurface = webkitPlugin.getEmbeddedSurface(); if (pluginView == null) {
if(embeddedSurface == null) { Log.e(LOGTAG, "Attempted to add an empty plugin view to the view hierarchy");
Log.e(LOGTAG, "Attempted to create an embedded surface with a null drawing model");
return null; return null;
} }
View pluginView = embeddedSurface.getSurface(); // ensures the view system knows the view can redraw itself
pluginView.setWillNotDraw(false); pluginView.setWillNotDraw(false);
ViewManager.ChildView view = mWebView.mViewManager.createView(); ViewManager.ChildView view = mWebView.mViewManager.createView();

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2009, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package android.webkit.plugin;
import android.content.Context;
/**
*
* @hide pending API solidification
*/
public interface NativePlugin extends WebkitPlugin {
void initializePlugin(int npp, Context context);
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2009, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package android.webkit.plugin;
import android.view.View;
/**
*
* @hide pending API solidification
*/
public interface SurfaceDrawingModel {
public View getSurface();
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2009, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package android.webkit.plugin;
/**
*
* @hide pending API solidification
*/
public interface WebkitPlugin {
SurfaceDrawingModel getEmbeddedSurface();
SurfaceDrawingModel getFullScreenSurface();
}