summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeon Scroggins <scroggo@google.com>2009-10-02 15:55:01 -0400
committerLeon Scroggins <scroggo@google.com>2009-10-09 13:46:58 -0400
commitbf280393189a33efa29a33c0d96c84710484f2f7 (patch)
tree084219fe1caff06c871fdf567426d42d7f79dafb
parentb7460af0ad232b4bea4893febafe08895a3ef35b (diff)
downloadexternal_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
-rw-r--r--WebCore/Android.mk1
-rw-r--r--WebCore/WebCorePrefixAndroid.h4
-rw-r--r--WebCore/platform/android/FileChooserAndroid.cpp4
-rw-r--r--WebCore/platform/android/TemporaryLinkStubs.cpp12
-rw-r--r--WebCore/rendering/RenderFileUploadControl.cpp4
-rw-r--r--WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp9
-rw-r--r--WebKit/android/jni/WebCoreFrameBridge.cpp36
-rw-r--r--WebKit/android/jni/WebViewCore.cpp17
-rw-r--r--WebKit/android/jni/WebViewCore.h4
-rw-r--r--WebKit/android/nav/CacheBuilder.cpp3
10 files changed, 68 insertions, 26 deletions
diff --git a/WebCore/Android.mk b/WebCore/Android.mk
index 595f5a5..bd97d03 100644
--- a/WebCore/Android.mk
+++ b/WebCore/Android.mk
@@ -37,7 +37,6 @@
# editing/BackForwardListChromium.cpp \
# editing/SmartReplace*.cpp \
# history/BackForwardListChromium.cpp \
-# html/FileList.cpp \
# html/HTMLElementsAllInOne.cpp \
# loader/CachedXBLDocument.cpp \
# loader/CachedXSLStyleSheet.cpp \
diff --git a/WebCore/WebCorePrefixAndroid.h b/WebCore/WebCorePrefixAndroid.h
index 01e9b28..068ae98 100644
--- a/WebCore/WebCorePrefixAndroid.h
+++ b/WebCore/WebCorePrefixAndroid.h
@@ -98,10 +98,6 @@ typedef unsigned char flex_uint8_t;
#define ANDROID_MULTIPLE_WINDOWS
#define ANDROID_CSS_TAP_HIGHLIGHT_COLOR
-// Hack to make File Upload buttons draw disabled.
-// Will be removed if/when we get file uploads working.
-#define ANDROID_DISABLE_UPLOAD
-
#define ANDROID_BLOCK_NETWORK_IMAGE
// Changes needed to support native plugins (npapi.h). If the change is generic,
diff --git a/WebCore/platform/android/FileChooserAndroid.cpp b/WebCore/platform/android/FileChooserAndroid.cpp
index ec1b758..d54c809 100644
--- a/WebCore/platform/android/FileChooserAndroid.cpp
+++ b/WebCore/platform/android/FileChooserAndroid.cpp
@@ -38,7 +38,7 @@ String FileChooser::basenameForWidth(const Font& font, int width) const
// often be much longer than the provided width, this may be fast enough.
String output = m_filenames[0].copy();
while (font.width(TextRun(output.impl())) > width && output.length() > 4) {
- output = output.replace(output.length() - 4, 4, String("..."));
+ output = output.replace(0, 4, String("..."));
}
return output;
}
@@ -49,7 +49,7 @@ String FileChooser::basenameForWidth(const Font& font, int width) const
// second string is rendered on the screen when no file has been selected.
String fileButtonChooseFileLabel()
{
- return String("Uploads Disabled");
+ return String("Upload a file");
}
String fileButtonNoFileSelectedLabel()
diff --git a/WebCore/platform/android/TemporaryLinkStubs.cpp b/WebCore/platform/android/TemporaryLinkStubs.cpp
index 33344ed..39c0bb7 100644
--- a/WebCore/platform/android/TemporaryLinkStubs.cpp
+++ b/WebCore/platform/android/TemporaryLinkStubs.cpp
@@ -46,7 +46,6 @@
#include "EditCommand.h"
#include "Editor.h"
#include "File.h"
-#include "FileList.h"
#include "Font.h"
#include "Frame.h"
#include "FrameLoader.h"
@@ -506,17 +505,6 @@ ScrollbarTheme* ScrollbarTheme::nativeTheme()
} // namespace WebCore
-FileList::FileList()
-{
- notImplemented();
-}
-
-File* FileList::item(unsigned index) const
-{
- notImplemented();
- return 0;
-}
-
AXObjectCache::~AXObjectCache()
{
notImplemented();
diff --git a/WebCore/rendering/RenderFileUploadControl.cpp b/WebCore/rendering/RenderFileUploadControl.cpp
index 9b5579c..72623f7 100644
--- a/WebCore/rendering/RenderFileUploadControl.cpp
+++ b/WebCore/rendering/RenderFileUploadControl.cpp
@@ -134,11 +134,7 @@ void RenderFileUploadControl::updateFromElement()
addChild(renderer);
}
-#ifndef ANDROID_DISABLE_UPLOAD
m_button->setDisabled(!theme()->isEnabled(this));
-#else
- m_button->setDisabled(true);
-#endif
// This only supports clearing out the files, but that's OK because for
// security reasons that's the only change the DOM is allowed to make.
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;