summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2010-03-23 12:25:14 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-03-23 12:25:14 -0700
commitec3394757ae8070435b0a1579bf954661d6ee3f7 (patch)
tree295520a088716e016dc1b9e4922b1167a79e0bfb
parentbd150a788daef4180dc4d1afea9d7517b6721eff (diff)
parent27a298a6476fbd78e67f35441e1428bc878a969d (diff)
downloadexternal_webkit-ec3394757ae8070435b0a1579bf954661d6ee3f7.zip
external_webkit-ec3394757ae8070435b0a1579bf954661d6ee3f7.tar.gz
external_webkit-ec3394757ae8070435b0a1579bf954661d6ee3f7.tar.bz2
Merge "Allowing native code access to the application context as long as there is at least one valid instance of the webviewcore class."
-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)
*/