diff options
author | Derek Sollenberger <djsollen@google.com> | 2009-09-08 13:01:56 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2009-09-08 15:42:23 -0400 |
commit | 2c3eb14d43edcecbd85072f7068126cffd7ca493 (patch) | |
tree | d40c829f9be94823b2f6bfdf18d4a23d36de01f4 | |
parent | 377c5c15f8fea14b575b6b0f14ac7fd3a4d44b3a (diff) | |
download | frameworks_base-2c3eb14d43edcecbd85072f7068126cffd7ca493.zip frameworks_base-2c3eb14d43edcecbd85072f7068126cffd7ca493.tar.gz frameworks_base-2c3eb14d43edcecbd85072f7068126cffd7ca493.tar.bz2 |
adding support for webkit plugins to use the java view system
Change-Id: I4fb328e5f30476fe4aa70565bacb969dc97b495d
-rw-r--r-- | api/current.xml | 45 | ||||
-rw-r--r-- | core/java/android/webkit/PluginActivity.java | 67 | ||||
-rw-r--r-- | core/java/android/webkit/PluginStub.java | 50 | ||||
-rw-r--r-- | core/java/android/webkit/PluginUtil.java | 62 |
4 files changed, 224 insertions, 0 deletions
diff --git a/api/current.xml b/api/current.xml index ce2ac27..83b201c 100644 --- a/api/current.xml +++ b/api/current.xml @@ -165277,6 +165277,51 @@ </parameter> </method> </class> +<class name="PluginStub" + extends="java.lang.Object" + abstract="true" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<constructor name="PluginStub" + type="android.webkit.PluginStub" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="npp" type="int"> +</parameter> +</constructor> +<method name="getEmbeddedView" + return="android.view.View" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="context" type="android.content.Context"> +</parameter> +</method> +<method name="getFullScreenView" + return="android.view.View" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="context" type="android.content.Context"> +</parameter> +</method> +</class> <class name="SslErrorHandler" extends="android.os.Handler" abstract="false" diff --git a/core/java/android/webkit/PluginActivity.java b/core/java/android/webkit/PluginActivity.java new file mode 100644 index 0000000..f9e3080 --- /dev/null +++ b/core/java/android/webkit/PluginActivity.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.webkit; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; + +/** + * This activity is invoked when a plugin elects to go into full screen mode. + * @hide + */ +public class PluginActivity extends Activity { + + /* package */ static final String INTENT_EXTRA_PACKAGE_NAME = + "android.webkit.plugin.PACKAGE_NAME"; + /* package */ static final String INTENT_EXTRA_CLASS_NAME = + "android.webkit.plugin.CLASS_NAME"; + /* package */ static final String INTENT_EXTRA_NPP_INSTANCE = + "android.webkit.plugin.NPP_INSTANCE"; + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + final Intent intent = getIntent(); + if (intent == null) { + // No intent means no class to lookup. + finish(); + } + final String packageName = + intent.getStringExtra(INTENT_EXTRA_PACKAGE_NAME); + final String className = intent.getStringExtra(INTENT_EXTRA_CLASS_NAME); + final int npp = intent.getIntExtra(INTENT_EXTRA_NPP_INSTANCE, -1); + // Retrieve the PluginStub implemented in packageName.className + PluginStub stub = + PluginUtil.getPluginStub(this, packageName, className, npp); + + if (stub != null) { + View pluginView = stub.getFullScreenView(this); + if (pluginView != null) { + setContentView(pluginView); + } else { + // No custom full-sreen view returned by the plugin, odd but + // just in case, finish the activity. + finish(); + } + } else { + finish(); + } + } +} diff --git a/core/java/android/webkit/PluginStub.java b/core/java/android/webkit/PluginStub.java new file mode 100644 index 0000000..c24da8d --- /dev/null +++ b/core/java/android/webkit/PluginStub.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.webkit; + +import android.content.Context; +import android.view.View; + +/** + * This abstract class is used to implement plugins in a WebView. A plugin + * package may extend this class and implement the abstract functions to create + * embedded or fullscreeen views displayed in a WebView. The PluginStub + * implementation will be provided the same NPP instance that is created + * through the native interface. + */ +public abstract class PluginStub { + /** + * Construct a new PluginStub implementation for the given NPP instance. + * @param npp The native NPP instance. + */ + public PluginStub(int npp) { } + + /** + * Return a custom embedded view to draw the plugin. + * @param context The current application's Context. + * @return A custom View that will be managed by WebView. + */ + public abstract View getEmbeddedView(Context context); + + /** + * Return a custom full-screen view to be displayed when the user requests + * a plugin display as full-screen. Note that the application may choose not + * to display this View as completely full-screen. + * @param context The current application's Context. + * @return A custom View that will be managed by the application. + */ + public abstract View getFullScreenView(Context context); +} diff --git a/core/java/android/webkit/PluginUtil.java b/core/java/android/webkit/PluginUtil.java new file mode 100644 index 0000000..c0a7375 --- /dev/null +++ b/core/java/android/webkit/PluginUtil.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.webkit; + +import android.content.Context; +import android.content.pm.PackageManager.NameNotFoundException; +import android.util.Log; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +class PluginUtil { + + private static final String LOGTAG = "PluginUtil"; + + /** + * + * @param packageName the name of the apk where the class can be found + * @param className the fully qualified name of a subclass of PluginStub + */ + /* package */ + static PluginStub getPluginStub(Context context, String packageName, + String className, int NPP) { + try { + Context pluginContext = context.createPackageContext(packageName, + Context.CONTEXT_INCLUDE_CODE | + Context.CONTEXT_IGNORE_SECURITY); + ClassLoader pluginCL = pluginContext.getClassLoader(); + + Class<?> stubClass = + pluginCL.loadClass(className); + Constructor<?> stubConstructor = + stubClass.getConstructor(int.class); + Object stubObject = stubConstructor.newInstance(NPP); + + if (stubObject instanceof PluginStub) { + return (PluginStub) stubObject; + } else { + Log.e(LOGTAG, "The plugin class is not of type PluginStub"); + } + } 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)); + } + return null; + } +} |