diff options
author | Leon Scroggins <scroggo@google.com> | 2009-10-02 15:55:01 -0400 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2009-10-09 13:46:58 -0400 |
commit | bf280393189a33efa29a33c0d96c84710484f2f7 (patch) | |
tree | 084219fe1caff06c871fdf567426d42d7f79dafb /WebKit | |
parent | b7460af0ad232b4bea4893febafe08895a3ef35b (diff) | |
download | external_webkit-bf280393189a33efa29a33c0d96c84710484f2f7.zip external_webkit-bf280393189a33efa29a33c0d96c84710484f2f7.tar.gz external_webkit-bf280393189a33efa29a33c0d96c84710484f2f7.tar.bz2 |
File upload.
Webkit implementation for passing in the data for file uploads.
Requires a change to frameworks/base to not break things; also
requires a change to packages/apps/Browser to work.
Fixes http://b/issue?id=675743
Diffstat (limited to 'WebKit')
-rw-r--r-- | WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp | 9 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 36 | ||||
-rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 17 | ||||
-rw-r--r-- | WebKit/android/jni/WebViewCore.h | 4 | ||||
-rw-r--r-- | WebKit/android/nav/CacheBuilder.cpp | 3 |
5 files changed, 66 insertions, 3 deletions
diff --git a/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp b/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp index 1c17ffe..dd608b6 100644 --- a/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp +++ b/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp @@ -368,7 +368,14 @@ void ChromeClientAndroid::onMainFrameLoadStarted() m_geolocationPermissions->resetTemporaryPermissionStates(); } -void ChromeClientAndroid::runOpenPanel(Frame*, PassRefPtr<FileChooser>) { notImplemented(); } +void ChromeClientAndroid::runOpenPanel(Frame* frame, + PassRefPtr<FileChooser> chooser) +{ + android::WebViewCore* core = android::WebViewCore::getWebViewCore( + frame->view()); + core->openFileChooser(chooser); +} + bool ChromeClientAndroid::setCursor(PlatformCursorHandle) { notImplemented(); diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 745cc57..863c91f 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -146,6 +146,8 @@ struct WebFrame::JavaBrowserFrame jmethodID mRequestFocus; jmethodID mGetRawResFilename; jmethodID mDensity; + jmethodID mGetFileSize; + jmethodID mGetFile; AutoJObject frame(JNIEnv* env) { return getRealObject(env, mObj); } @@ -202,6 +204,8 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* mJavaFrame->mGetRawResFilename = env->GetMethodID(clazz, "getRawResFilename", "(I)Ljava/lang/String;"); mJavaFrame->mDensity = env->GetMethodID(clazz, "density","()F"); + mJavaFrame->mGetFileSize = env->GetMethodID(clazz, "getFileSize", "(Ljava/lang/String;)I"); + mJavaFrame->mGetFile = env->GetMethodID(clazz, "getFile", "(Ljava/lang/String;[BI)I"); LOG_ASSERT(mJavaFrame->mStartLoadingResource, "Could not find method startLoadingResource"); LOG_ASSERT(mJavaFrame->mLoadStarted, "Could not find method loadStarted"); @@ -221,6 +225,8 @@ WebFrame::WebFrame(JNIEnv* env, jobject obj, jobject historyList, WebCore::Page* LOG_ASSERT(mJavaFrame->mRequestFocus, "Could not find method requestFocus"); LOG_ASSERT(mJavaFrame->mGetRawResFilename, "Could not find method getRawResFilename"); LOG_ASSERT(mJavaFrame->mDensity, "Could not find method density"); + LOG_ASSERT(mJavaFrame->mGetFileSize, "Could not find method getFileSize"); + LOG_ASSERT(mJavaFrame->mGetFile, "Could not find method getFile"); mUserAgent = WebCore::String(); mUserInitiatedClick = false; @@ -274,6 +280,19 @@ static jobject createJavaMapFromHTTPHeaders(JNIEnv* env, const WebCore::HTTPHead return hashMap; } +// In WebViewCore.java, we artificially append the filename to the URI so that +// webkit treats the actual display name of the file as the filename, rather +// than the last segment of the URI (which will simply be a number). When we +// pass the URI up to BrowserFrame, we no longer need the appended name (in fact +// it causes problems), so remove it here. +// FIXME: If we rewrite pathGetFileName (the current version is in +// FileSystemPOSIX), we can get the filename that way rather than appending it. +static jstring uriFromUriFileName(JNIEnv* env, const WebCore::String& name) +{ + const WebCore::String fileName = name.left(name.reverseFind('/')); + return env->NewString(fileName.characters(), fileName.length()); +} + WebCoreResourceLoader* WebFrame::startLoadingResource(WebCore::ResourceHandle* loader, const WebCore::ResourceRequest& request, @@ -329,6 +348,14 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader, const WebCore::FormDataElement& e = elements[i]; if (e.m_type == WebCore::FormDataElement::data) { size += e.m_data.size(); + } else if (e.m_type == WebCore::FormDataElement::encodedFile) { + // Remove the filename, as we only need the URI + jstring name = uriFromUriFileName(env, e.m_filename); + int delta = env->CallIntMethod(obj.get(), + mJavaFrame->mGetFileSize, name); + env->DeleteLocalRef(name); + checkException(env); + size += delta; } } @@ -347,6 +374,15 @@ WebFrame::startLoadingResource(WebCore::ResourceHandle* loader, int delta = e.m_data.size(); memcpy(bytes + offset, e.m_data.data(), delta); offset += delta; + } else if (e.m_type + == WebCore::FormDataElement::encodedFile) { + // Remove the filename, as we only need the URI + jstring name = uriFromUriFileName(env, e.m_filename); + int delta = env->CallIntMethod(obj.get(), + mJavaFrame->mGetFile, name, jPostDataStr, offset); + env->DeleteLocalRef(name); + checkException(env); + offset += delta; } } env->ReleaseByteArrayElements(jPostDataStr, bytes, 0); diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 0d201b1..ac3bcc4 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -162,6 +162,7 @@ struct WebViewCore::JavaGlue { jmethodID m_scrollBy; jmethodID m_contentDraw; jmethodID m_requestListBox; + jmethodID m_openFileChooser; jmethodID m_requestSingleListBox; jmethodID m_jsAlert; jmethodID m_jsConfirm; @@ -238,6 +239,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_javaGlue->m_scrollBy = GetJMethod(env, clazz, "contentScrollBy", "(IIZ)V"); m_javaGlue->m_contentDraw = GetJMethod(env, clazz, "contentDraw", "()V"); m_javaGlue->m_requestListBox = GetJMethod(env, clazz, "requestListBox", "([Ljava/lang/String;[Z[I)V"); + m_javaGlue->m_openFileChooser = GetJMethod(env, clazz, "openFileChooser", "()Ljava/lang/String;"); m_javaGlue->m_requestSingleListBox = GetJMethod(env, clazz, "requestListBox", "([Ljava/lang/String;[ZI)V"); m_javaGlue->m_jsAlert = GetJMethod(env, clazz, "jsAlert", "(Ljava/lang/String;Ljava/lang/String;)V"); m_javaGlue->m_jsConfirm = GetJMethod(env, clazz, "jsConfirm", "(Ljava/lang/String;Ljava/lang/String;)Z"); @@ -1870,6 +1872,21 @@ static jobjectArray makeLabelArray(JNIEnv* env, const uint16_t** labels, size_t return array; } +void WebViewCore::openFileChooser(PassRefPtr<WebCore::FileChooser> chooser) { + if (!chooser) + return; + JNIEnv* env = JSC::Bindings::getJNIEnv(); + jstring jName = (jstring) env->CallObjectMethod( + m_javaGlue->object(env).get(), m_javaGlue->m_openFileChooser); + checkException(env); + const UChar* string = (const UChar*) env->GetStringChars(jName, NULL); + if (!string) + return; + WebCore::String webcoreString = to_string(env, jName); + env->ReleaseStringChars(jName, string); + chooser->chooseFile(webcoreString); +} + void WebViewCore::listBoxRequest(WebCoreReply* reply, const uint16_t** labels, size_t count, const int enabled[], size_t enabledCount, bool multiple, const int selected[], size_t selectedCountOrSelection) { diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index d5810f4..f7d04d2 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -27,6 +27,7 @@ #define WEBVIEWCORE_H #include "android_npapi.h" +#include "FileChooser.h" #include "CacheBuilder.h" #include "CachedHistory.h" #include "PictureSet.h" @@ -388,6 +389,9 @@ namespace android { // other public functions public: + // Open a file chooser for selecting a file to upload + void openFileChooser(PassRefPtr<WebCore::FileChooser> ); + // reset the picture set to empty void clearContent(); diff --git a/WebKit/android/nav/CacheBuilder.cpp b/WebKit/android/nav/CacheBuilder.cpp index 31483f2..1f25a59 100644 --- a/WebKit/android/nav/CacheBuilder.cpp +++ b/WebKit/android/nav/CacheBuilder.cpp @@ -1096,8 +1096,7 @@ void CacheBuilder::BuildFrame(Frame* root, Frame* frame, } if (node->hasTagName(WebCore::HTMLNames::inputTag)) { HTMLInputElement* input = (HTMLInputElement*) node; - if (input->inputType() == HTMLInputElement::FILE) - continue; + isTextField = input->isTextField(); if (isTextField) wantsKeyEvents = true; |