summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2010-03-23 14:07:05 -0400
committerDerek Sollenberger <djsollen@google.com>2010-03-23 14:34:09 -0400
commit27a298a6476fbd78e67f35441e1428bc878a969d (patch)
treeca631f680e2bc3b4c0a8d54ec3b6c983d4c1c26c
parent7d7e576868fe78bf1b95968ad5d6ddc395c65ec9 (diff)
downloadexternal_webkit-27a298a6476fbd78e67f35441e1428bc878a969d.zip
external_webkit-27a298a6476fbd78e67f35441e1428bc878a969d.tar.gz
external_webkit-27a298a6476fbd78e67f35441e1428bc878a969d.tar.bz2
Allowing native code access to the application context as long as
there is at least one valid instance of the webviewcore class. This change allows plugins access to the application context when the plugin package is loaded, prior to any instances of the plugin being created. Change-Id: I74a58cf76cc3c2d0ef7bca19346f13f58f616830
-rw-r--r--WebCore/plugins/android/PluginViewAndroid.cpp19
-rw-r--r--WebKit/android/jni/WebViewCore.cpp21
-rw-r--r--WebKit/android/jni/WebViewCore.h4
-rw-r--r--WebKit/android/plugins/android_npapi.h9
4 files changed, 48 insertions, 5 deletions
diff --git a/WebCore/plugins/android/PluginViewAndroid.cpp b/WebCore/plugins/android/PluginViewAndroid.cpp
index 5b7aea9..452c9fb 100644
--- a/WebCore/plugins/android/PluginViewAndroid.cpp
+++ b/WebCore/plugins/android/PluginViewAndroid.cpp
@@ -369,11 +369,22 @@ NPError PluginView::getValueStatic(NPNVariable variable, void* value)
{
// our interface query is valid with no NPP instance
NPError error = NPERR_GENERIC_ERROR;
- if ((value != NULL) && (variable == NPNVisOfflineBool)) {
- bool* retValue = static_cast<bool*>(value);
- *retValue = !networkStateNotifier().onLine();
- return NPERR_NO_ERROR;
+
+ switch (variable) {
+ case NPNVisOfflineBool: {
+ if (value != NULL) {
+ bool* retValue = static_cast<bool*>(value);
+ *retValue = !networkStateNotifier().onLine();
+ return NPERR_NO_ERROR;
+ }
+ }
+ case kJavaContext_ANPGetValue: {
+ jobject* retObject = static_cast<jobject*>(value);
+ *retObject = android::WebViewCore::getApplicationContext();
+ return NPERR_NO_ERROR;
+ }
}
+
(void)anp_getInterface(variable, value, &error);
return error;
}
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index a0e4642..00ac725 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -168,6 +168,27 @@ bool WebViewCore::isInstance(WebViewCore* inst) {
return gInstanceList.find(inst) >= 0;
}
+jobject WebViewCore::getApplicationContext() {
+
+ // check to see if there is a valid webviewcore object
+ if (gInstanceList.isEmpty())
+ return 0;
+
+ // get the context from the webview
+ jobject context = gInstanceList[0]->getContext();
+
+ if (!context)
+ return 0;
+
+ // get the application context using JNI
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ jclass contextClass = env->GetObjectClass(context);
+ jmethodID appContextMethod = env->GetMethodID(contextClass, "getApplicationContext", "()Landroid/content/Context;");
+ jobject result = env->CallObjectMethod(context, appContextMethod);
+ checkException(env);
+ return result;
+}
+
// ----------------------------------------------------------------------------
#define GET_NATIVE_VIEW(env, obj) ((WebViewCore*)env->GetIntField(obj, gWebViewCoreFields.m_nativeClass))
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index abe0d8d..8c885e6 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -569,6 +569,10 @@ namespace android {
// call only from webkit thread (like add/remove), return true if inst
// is still alive
static bool isInstance(WebViewCore*);
+
+ // if there exists at least on WebViewCore instance then we return the
+ // application context, otherwise NULL is returned.
+ static jobject getApplicationContext();
};
} // namespace android
diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h
index b4974f4..25cee97 100644
--- a/WebKit/android/plugins/android_npapi.h
+++ b/WebKit/android/plugins/android_npapi.h
@@ -126,7 +126,14 @@ typedef uint32_t ANPMatrixFlag;
*/
#define kSupportedDrawingModel_ANPGetValue ((NPNVariable)2000)
-/** queries for the context (android.content.Context) in which the plugin resides
+/** queries for the context (android.content.Context) of the plugin. If no
+ instance is specified the application's context is returned. If the instance
+ is given then the context returned is identical to the context used to
+ create the webview in which that instance resides.
+
+ NOTE: Holding onto a non-application context after your instance has been
+ destroyed will cause a memory leak. Refer to the android documentation to
+ determine what context is best suited for your particular scenario.
NPN_GetValue(inst, kJavaContext_ANPGetValue, jobject context)
*/