diff options
Diffstat (limited to 'WebKit/android/jni')
| -rw-r--r-- | WebKit/android/jni/MIMETypeRegistry.cpp | 65 | ||||
| -rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 95 | ||||
| -rw-r--r-- | WebKit/android/jni/WebViewCore.h | 12 |
3 files changed, 101 insertions, 71 deletions
diff --git a/WebKit/android/jni/MIMETypeRegistry.cpp b/WebKit/android/jni/MIMETypeRegistry.cpp new file mode 100644 index 0000000..4e9ae68 --- /dev/null +++ b/WebKit/android/jni/MIMETypeRegistry.cpp @@ -0,0 +1,65 @@ +/* + * Copyright 2010, 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. + */ + +#define LOG_TAG "WebCore" + +#include "config.h" + +#include "MIMETypeRegistry.h" +#include "PlatformString.h" +#include "jni_utility.h" +#include "WebCoreJni.h" + +#include <jni.h> +#include <utils/Log.h> + +namespace WebCore { + +static jmethodID gMimeTypeFromExtension; +static jclass gMimeClass; + +String MIMETypeRegistry::getMIMETypeForExtension(const String& ext) +{ + JNIEnv* env = JSC::Bindings::getJNIEnv(); + if (!gMimeTypeFromExtension) { + gMimeClass = env->FindClass("android/webkit/MimeTypeMap"); + LOG_ASSERT(gMimeClass, "Could not find class MimeTypeMap"); + gMimeTypeFromExtension = env->GetStaticMethodID(gMimeClass, + "mimeTypeFromExtension", + "(Ljava/lang/String;)Ljava/lang/String;"); + LOG_ASSERT(gMimeTypeFromExtension, + "Could not find method mimeTypeFromExtension"); + } + jstring extString = + env->NewString((const jchar*) ext.characters(), ext.length()); + jobject mimeType = env->CallStaticObjectMethod(gMimeClass, + gMimeTypeFromExtension, extString); + String result = android::to_string(env, (jstring) mimeType); + env->DeleteLocalRef(extString); + env->DeleteLocalRef(mimeType); + return result; +} + +} diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index ee1f880..5d2b8bb 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -218,13 +218,13 @@ struct WebViewCore::JavaGlue { jmethodID m_geolocationPermissionsHidePrompt; jmethodID m_addMessageToConsole; jmethodID m_getPluginClass; - jmethodID m_createPluginJavaInstance; jmethodID m_showFullScreenPlugin; jmethodID m_hideFullScreenPlugin; jmethodID m_updateFullScreenPlugin; - jmethodID m_createSurface; + jmethodID m_addSurface; jmethodID m_updateSurface; jmethodID m_destroySurface; + jmethodID m_getContext; jmethodID m_sendFindAgain; AutoJObject object(JNIEnv* env) { return getRealObject(env, m_obj); @@ -294,7 +294,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_javaGlue->m_restoreScale = GetJMethod(env, clazz, "restoreScale", "(I)V"); m_javaGlue->m_restoreScreenWidthScale = GetJMethod(env, clazz, "restoreScreenWidthScale", "(I)V"); m_javaGlue->m_needTouchEvents = GetJMethod(env, clazz, "needTouchEvents", "(Z)V"); - m_javaGlue->m_requestKeyboard = GetJMethod(env, clazz, "requestKeyboard", "(Z)V"); + m_javaGlue->m_requestKeyboard = GetJMethod(env, clazz, "requestKeyboard", "(ZZ)V"); m_javaGlue->m_exceededDatabaseQuota = GetJMethod(env, clazz, "exceededDatabaseQuota", "(Ljava/lang/String;Ljava/lang/String;JJ)V"); m_javaGlue->m_reachedMaxAppCacheSize = GetJMethod(env, clazz, "reachedMaxAppCacheSize", "(J)V"); m_javaGlue->m_populateVisitedLinks = GetJMethod(env, clazz, "populateVisitedLinks", "()V"); @@ -302,13 +302,13 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_javaGlue->m_geolocationPermissionsHidePrompt = GetJMethod(env, clazz, "geolocationPermissionsHidePrompt", "()V"); m_javaGlue->m_addMessageToConsole = GetJMethod(env, clazz, "addMessageToConsole", "(Ljava/lang/String;ILjava/lang/String;)V"); m_javaGlue->m_getPluginClass = GetJMethod(env, clazz, "getPluginClass", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Class;"); - m_javaGlue->m_createPluginJavaInstance = GetJMethod(env, clazz, "createPluginJavaInstance", "(Ljava/lang/String;I)Landroid/webkit/plugin/WebkitPlugin;"); - m_javaGlue->m_showFullScreenPlugin = GetJMethod(env, clazz, "showFullScreenPlugin", "(Landroid/webkit/plugin/WebkitPlugin;IIIII)V"); + m_javaGlue->m_showFullScreenPlugin = GetJMethod(env, clazz, "showFullScreenPlugin", "(Landroid/webkit/ViewManager$ChildView;IIIII)V"); m_javaGlue->m_hideFullScreenPlugin = GetJMethod(env, clazz, "hideFullScreenPlugin", "()V"); m_javaGlue->m_updateFullScreenPlugin = GetJMethod(env, clazz, "updateFullScreenPlugin", "(IIII)V"); - m_javaGlue->m_createSurface = GetJMethod(env, clazz, "createSurface", "(Landroid/webkit/plugin/WebkitPlugin;IIII)Landroid/webkit/ViewManager$ChildView;"); + m_javaGlue->m_addSurface = GetJMethod(env, clazz, "addSurface", "(Landroid/view/View;IIII)Landroid/webkit/ViewManager$ChildView;"); m_javaGlue->m_updateSurface = GetJMethod(env, clazz, "updateSurface", "(Landroid/webkit/ViewManager$ChildView;IIII)V"); m_javaGlue->m_destroySurface = GetJMethod(env, clazz, "destroySurface", "(Landroid/webkit/ViewManager$ChildView;)V"); + m_javaGlue->m_getContext = GetJMethod(env, clazz, "getContext", "()Landroid/content/Context;"); m_javaGlue->m_sendFindAgain = GetJMethod(env, clazz, "sendFindAgain", "()V"); env->SetIntField(javaWebViewCore, gWebViewCoreFields.m_nativeClass, (jint)this); @@ -1049,7 +1049,7 @@ void WebViewCore::needTouchEvents(bool need) #endif } -void WebViewCore::requestKeyboard(bool showKeyboard) +void WebViewCore::requestKeyboard(bool showKeyboard, bool isTextView) { DBG_NAV_LOGD("showKeyboard=%d", showKeyboard); LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!"); @@ -1060,7 +1060,8 @@ void WebViewCore::requestKeyboard(bool showKeyboard) // can be gone. Check before using it. if (!obj.get()) return; - env->CallVoidMethod(obj.get(), m_javaGlue->m_requestKeyboard, showKeyboard); + env->CallVoidMethod(obj.get(), m_javaGlue->m_requestKeyboard, showKeyboard, + isTextView); checkException(env); } @@ -2294,8 +2295,12 @@ bool WebViewCore::handleMouseClick(WebCore::Frame* framePtr, WebCore::Node* node m_mousePos.y(), focusNode, handled ? "true" : "false"); if (focusNode) { WebCore::RenderObject* renderer = focusNode->renderer(); - if (renderer && (renderer->isTextField() || renderer->isTextArea())) - setFocusControllerActive(true); + if (renderer && (renderer->isTextField() || renderer->isTextArea())) { + bool ime = !(static_cast<WebCore::HTMLInputElement*>(focusNode)) + ->readOnly(); + setFocusControllerActive(ime); + requestKeyboard(ime, true); + } } return handled; } @@ -2587,10 +2592,6 @@ jclass WebViewCore::getPluginClass(const WebCore::String& libName, const char* c { JNIEnv* env = JSC::Bindings::getJNIEnv(); AutoJObject obj = m_javaGlue->object(env); - // if it is called during DESTROY is handled, the real object of WebViewCore - // can be gone. Check before using it. - if (!obj.get()) - return NULL; jstring libString = env->NewString(libName.characters(), libName.length()); jstring classString = env->NewStringUTF(className); @@ -2610,40 +2611,15 @@ jclass WebViewCore::getPluginClass(const WebCore::String& libName, const char* c } } -jobject WebViewCore::createPluginJavaInstance(const WebCore::String& libName, NPP npp) -{ - JNIEnv* env = JSC::Bindings::getJNIEnv(); - AutoJObject obj = m_javaGlue->object(env); - // if it is called during DESTROY is handled, the real object of WebViewCore - // can be gone. Check before using it. - if (!obj.get()) - return 0; - - jstring libString = env->NewString(libName.characters(), libName.length()); - jobject result = env->CallObjectMethod(obj.get(), - m_javaGlue->m_createPluginJavaInstance, - libString, (int) npp); - - //cleanup unneeded local JNI references - env->DeleteLocalRef(libString); - - checkException(env); - return result; -} - -void WebViewCore::showFullScreenPlugin(jobject webkitPlugin, NPP npp, int x, +void WebViewCore::showFullScreenPlugin(jobject childView, NPP npp, int x, int y, int width, int height) { JNIEnv* env = JSC::Bindings::getJNIEnv(); AutoJObject obj = m_javaGlue->object(env); - // if it is called during DESTROY is handled, the real object of WebViewCore - // can be gone. Check before using it. - if (!obj.get()) - return; env->CallVoidMethod(obj.get(), m_javaGlue->m_showFullScreenPlugin, - webkitPlugin, (int)npp, x, y, width, height); + childView, (int)npp, x, y, width, height); checkException(env); } @@ -2651,10 +2627,6 @@ void WebViewCore::hideFullScreenPlugin() { JNIEnv* env = JSC::Bindings::getJNIEnv(); AutoJObject obj = m_javaGlue->object(env); - // if it is called during DESTROY is handled, the real object of WebViewCore - // can be gone. Check before using it. - if (!obj.get()) - return; env->CallVoidMethod(obj.get(), m_javaGlue->m_hideFullScreenPlugin); checkException(env); @@ -2664,41 +2636,28 @@ void WebViewCore::updateFullScreenPlugin(int x, int y, int width, int height) { JNIEnv* env = JSC::Bindings::getJNIEnv(); AutoJObject obj = m_javaGlue->object(env); - // if it is called during DESTROY is handled, the real object of WebViewCore - // can be gone. Check before using it. - if (!obj.get()) - return; env->CallVoidMethod(obj.get(), m_javaGlue->m_updateFullScreenPlugin, x, y, width, height); checkException(env); } -jobject WebViewCore::createSurface(jobject webkitPlugin, int x, int y, int width, int height) +jobject WebViewCore::addSurface(jobject view, int x, int y, int width, int height) { JNIEnv* env = JSC::Bindings::getJNIEnv(); AutoJObject obj = m_javaGlue->object(env); - // if it is called during DESTROY is handled, the real object of WebViewCore - // can be gone. Check before using it. - if (!obj.get()) - return 0; jobject result = env->CallObjectMethod(obj.get(), - m_javaGlue->m_createSurface, - webkitPlugin, x, y, width, height); + m_javaGlue->m_addSurface, + view, x, y, width, height); checkException(env); return result; - } void WebViewCore::updateSurface(jobject childView, int x, int y, int width, int height) { JNIEnv* env = JSC::Bindings::getJNIEnv(); AutoJObject obj = m_javaGlue->object(env); - // if it is called during DESTROY is handled, the real object of WebViewCore - // can be gone. Check before using it. - if (!obj.get()) - return; env->CallVoidMethod(obj.get(), m_javaGlue->m_updateSurface, childView, x, y, width, height); @@ -2709,15 +2668,21 @@ void WebViewCore::destroySurface(jobject childView) { JNIEnv* env = JSC::Bindings::getJNIEnv(); AutoJObject obj = m_javaGlue->object(env); - // if it is called during DESTROY is handled, the real object of WebViewCore - // can be gone. Check before using it. - if (!obj.get()) - return; env->CallVoidMethod(obj.get(), m_javaGlue->m_destroySurface, childView); checkException(env); } +jobject WebViewCore::getContext() +{ + JNIEnv* env = JSC::Bindings::getJNIEnv(); + AutoJObject obj = m_javaGlue->object(env); + + jobject result = env->CallObjectMethod(obj.get(), m_javaGlue->m_getContext); + checkException(env); + return result; +} + bool WebViewCore::validNodeAndBounds(Frame* frame, Node* node, const IntRect& originalAbsoluteBounds) { diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index 912b8e6..f1893ff 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -379,14 +379,11 @@ namespace android { void needTouchEvents(bool); // Notify the Java side that webkit is requesting a keyboard - void requestKeyboard(bool); + void requestKeyboard(bool showKeyboard, bool isTextView); // Generates a class loader that contains classes from the plugin's apk jclass getPluginClass(const WebCore::String& libName, const char* className); - // Creates a new instance of the plugin's java component - jobject createPluginJavaInstance(const WebCore::String& libName, NPP npp); - // Creates a full screen surface for a plugin void showFullScreenPlugin(jobject webkitPlugin, NPP npp, int x, int y, int width, int height); @@ -396,8 +393,8 @@ namespace android { // Update coordinates and dimensions for a full screen plugin void updateFullScreenPlugin(int x, int y, int width, int height); - // Creates a Surface (i.e. View) for a plugin - jobject createSurface(jobject webkitPlugin, int x, int y, int width, int height); + // Adds the plugin's view (aka surface) to the view hierarchy + jobject addSurface(jobject view, int x, int y, int width, int height); // Updates a Surface coordinates and dimensions for a plugin void updateSurface(jobject childView, int x, int y, int width, int height); @@ -405,6 +402,9 @@ namespace android { // Destroys a SurfaceView for a plugin void destroySurface(jobject childView); + // Returns the context (android.content.Context) of the WebView + jobject getContext(); + bool validNodeAndBounds(Frame* , Node* , const IntRect& ); // other public functions public: |
