consolidating to only use one surface per plugin. give plugin access to java context.
There is a companion commit in external webkit.
diff --git a/core/java/android/webkit/PluginFullScreenHolder.java b/core/java/android/webkit/PluginFullScreenHolder.java
index 6a0b145..b641803 100644
--- a/core/java/android/webkit/PluginFullScreenHolder.java
+++ b/core/java/android/webkit/PluginFullScreenHolder.java
@@ -30,6 +30,7 @@
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
+import android.view.ViewGroup;
class PluginFullScreenHolder extends Dialog {
@@ -37,6 +38,7 @@
private final WebView mWebView;
private final int mNpp;
+ private View mContentView;
private int mX;
private int mY;
private int mWidth;
@@ -64,6 +66,12 @@
}
@Override
+ public void setContentView(View contentView) {
+ super.setContentView(contentView);
+ mContentView = contentView;
+ }
+
+ @Override
public void onBackPressed() {
mWebView.mPrivateHandler.obtainMessage(WebView.HIDE_FULLSCREEN)
.sendToTarget();
@@ -113,6 +121,11 @@
@Override
protected void 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(
WebViewCore.EventHub.HIDE_FULLSCREEN, mNpp, 0);
}
diff --git a/core/java/android/webkit/PluginManager.java b/core/java/android/webkit/PluginManager.java
index 141984a..cdcb662 100644
--- a/core/java/android/webkit/PluginManager.java
+++ b/core/java/android/webkit/PluginManager.java
@@ -21,6 +21,7 @@
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
@@ -31,8 +32,6 @@
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.SystemProperties;
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
@@ -43,12 +42,6 @@
*/
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
* {@link android.content.IntentFilter IntentFilter} that accepts this
@@ -75,7 +68,7 @@
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
// inside the WebView process
@@ -87,7 +80,7 @@
private PluginManager(Context context) {
mContext = context;
- mPluginInfoCache = new ArrayList<PluginInfo>();
+ mPackageInfoCache = new ArrayList<PackageInfo>();
}
public static synchronized PluginManager getInstance(Context context) {
@@ -122,10 +115,10 @@
PLUGIN_ACTION), PackageManager.GET_SERVICES
| PackageManager.GET_META_DATA);
- synchronized(mPluginInfoCache) {
+ synchronized(mPackageInfoCache) {
// clear the list of existing packageInfo objects
- mPluginInfoCache.clear();
+ mPackageInfoCache.clear();
for (ResolveInfo info : plugins) {
@@ -192,9 +185,6 @@
}
}
- PluginInfo pluginInfo = new PluginInfo();
- pluginInfo.packageInfo = pkgInfo;
-
// determine the type of plugin from the manifest
if (serviceInfo.metaData == null) {
Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined");
@@ -202,9 +192,7 @@
}
String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE);
- if (TYPE_NATIVE.equals(pluginType)) {
- pluginInfo.isNative = true;
- } else {
+ if (!TYPE_NATIVE.equals(pluginType)) {
Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType);
continue;
}
@@ -212,17 +200,11 @@
try {
Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name);
- boolean classFound = false;
- for(Class<?> implemented : cls.getInterfaces()) {
- if (pluginInfo.isNative && implemented.equals(NativePlugin.class)) {
- pluginInfo.pluginClass = cls.asSubclass(WebkitPlugin.class);
- classFound = true;
- break;
- }
- }
+ //TODO implement any requirements of the plugin class here!
+ boolean classFound = true;
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;
}
@@ -235,7 +217,7 @@
}
// if all checks have passed then make the plugin available
- mPluginInfoCache.add(pluginInfo);
+ mPackageInfoCache.add(pkgInfo);
directories.add(directory);
}
}
@@ -252,9 +234,8 @@
}
// must be synchronized to ensure the consistency of the cache
- synchronized(mPluginInfoCache) {
- for (PluginInfo pluginInfo : mPluginInfoCache) {
- PackageInfo pkgInfo = pluginInfo.packageInfo;
+ synchronized(mPackageInfoCache) {
+ for (PackageInfo pkgInfo : mPackageInfoCache) {
if (pluginLib.startsWith(pkgInfo.applicationInfo.dataDir)) {
return pkgInfo.packageName;
}
@@ -270,39 +251,6 @@
}
/* 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 */
Class<?> getPluginClass(String packageName, String className)
throws NameNotFoundException, ClassNotFoundException {
Context pluginContext = mContext.createPackageContext(packageName,
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 38cb883..4602fa8 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -2255,6 +2255,11 @@
}
// called by JNI
+ private Context getContext() {
+ return mContext;
+ }
+
+ // called by JNI
private Class<?> getPluginClass(String libName, String clsName) {
if (mWebView == null) {
@@ -2281,40 +2286,17 @@
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
// View object provided by the plugin class.
- private void showFullScreenPlugin(WebkitPlugin webkitPlugin, final int npp,
- int x, int y, int width, int height) {
- if (mWebView == null) {
- return;
- }
+ private void showFullScreenPlugin(ViewManager.ChildView childView,
+ final int npp, int x, int y, int width, int height) {
- final SurfaceDrawingModel surface = webkitPlugin.getFullScreenSurface();
- if(surface == null) {
- Log.e(LOGTAG, "Attempted to create an full-screen surface with a " +
- "null drawing model");
+ if (mWebView == null) {
return;
}
PluginFullScreenData data = new PluginFullScreenData();
- data.mView = surface.getSurface();
+ data.mView = childView.mView;
data.mNpp = npp;
data.mDocX = x;
data.mDocY = y;
@@ -2351,20 +2333,18 @@
// called by JNI. PluginWidget functions for creating an embedded View for
// the surface drawing model.
- private ViewManager.ChildView createSurface(WebkitPlugin webkitPlugin,
- int x, int y, int width, int height) {
-
+ private ViewManager.ChildView addSurface(View pluginView, int x, int y,
+ int width, int height) {
if (mWebView == null) {
return null;
}
- SurfaceDrawingModel embeddedSurface = webkitPlugin.getEmbeddedSurface();
- if(embeddedSurface == null) {
- Log.e(LOGTAG, "Attempted to create an embedded surface with a null drawing model");
+ if (pluginView == null) {
+ Log.e(LOGTAG, "Attempted to add an empty plugin view to the view hierarchy");
return null;
}
- View pluginView = embeddedSurface.getSurface();
+ // ensures the view system knows the view can redraw itself
pluginView.setWillNotDraw(false);
ViewManager.ChildView view = mWebView.mViewManager.createView();
diff --git a/core/java/android/webkit/plugin/NativePlugin.java b/core/java/android/webkit/plugin/NativePlugin.java
deleted file mode 100644
index 5019c35..0000000
--- a/core/java/android/webkit/plugin/NativePlugin.java
+++ /dev/null
@@ -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);
-
-}
diff --git a/core/java/android/webkit/plugin/SurfaceDrawingModel.java b/core/java/android/webkit/plugin/SurfaceDrawingModel.java
deleted file mode 100644
index 93ba466..0000000
--- a/core/java/android/webkit/plugin/SurfaceDrawingModel.java
+++ /dev/null
@@ -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();
-
-}
diff --git a/core/java/android/webkit/plugin/WebkitPlugin.java b/core/java/android/webkit/plugin/WebkitPlugin.java
deleted file mode 100644
index 3d13c1c..0000000
--- a/core/java/android/webkit/plugin/WebkitPlugin.java
+++ /dev/null
@@ -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();
-
-}