summaryrefslogtreecommitdiffstats
path: root/core/java/android/webkit/PluginUtil.java
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2009-09-08 13:01:56 -0400
committerDerek Sollenberger <djsollen@google.com>2009-09-08 15:42:23 -0400
commit2c3eb14d43edcecbd85072f7068126cffd7ca493 (patch)
treed40c829f9be94823b2f6bfdf18d4a23d36de01f4 /core/java/android/webkit/PluginUtil.java
parent377c5c15f8fea14b575b6b0f14ac7fd3a4d44b3a (diff)
downloadframeworks_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
Diffstat (limited to 'core/java/android/webkit/PluginUtil.java')
-rw-r--r--core/java/android/webkit/PluginUtil.java62
1 files changed, 62 insertions, 0 deletions
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;
+ }
+}