diff options
| -rw-r--r-- | WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.cpp | 2 | ||||
| -rw-r--r-- | WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp | 35 | ||||
| -rw-r--r-- | WebKit/android/WebCoreSupport/autofill/WebAutoFill.h | 18 | ||||
| -rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 4 | ||||
| -rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 28 | ||||
| -rw-r--r-- | WebKit/android/jni/WebViewCore.h | 1 |
6 files changed, 81 insertions, 7 deletions
diff --git a/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.cpp b/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.cpp index 51f7a93..abe4b35 100644 --- a/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.cpp +++ b/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.cpp @@ -38,7 +38,7 @@ AutoFillHostAndroid::AutoFillHostAndroid(WebAutoFill* autoFill) void AutoFillHostAndroid::AutoFillSuggestionsReturned(int queryId, const std::vector<string16>& names, const std::vector<string16>& labels, const std::vector<int>& uniqueIds) { if (mAutoFill) - mAutoFill->fillFormFields(queryId, names[0], labels[0], uniqueIds[0]); + mAutoFill->querySuccessful(queryId, names[0], labels[0], uniqueIds[0]); } void AutoFillHostAndroid::AutoFillFormDataFilled(int queryId, const webkit_glue::FormData& form) diff --git a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp index 2046f46..278889c 100644 --- a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp +++ b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp @@ -42,10 +42,13 @@ #include "WebUrlLoaderClient.h" #include "WebViewCore.h" +#define FORM_NOT_AUTOFILLABLE -1 + namespace android { WebAutoFill::WebAutoFill() + : mWebViewCore(0) { mFormManager = new FormManager(); mQueryId = 1; @@ -77,6 +80,7 @@ WebAutoFill::WebAutoFill() WebAutoFill::~WebAutoFill() { mQueryMap.clear(); + mSuggestionMap.clear(); } void WebAutoFill::searchDocument(WebCore::Document* document) @@ -90,6 +94,7 @@ void WebAutoFill::searchDocument(WebCore::Document* document) return; mQueryMap.clear(); + mSuggestionMap.clear(); mQueryId = 1; mAutoFillManager->Reset(); mFormManager->Reset(); @@ -110,14 +115,38 @@ void WebAutoFill::formFieldFocused(WebCore::HTMLFormControlElement* formFieldEle mFormManager->FindFormWithFormControlElement(*formFieldElement, FormManager::REQUIRE_AUTOCOMPLETE, form); mQueryMap[mQueryId] = form; - mAutoFillManager->GetAutoFillSuggestions(mQueryId, false, formField); + bool suggestions = mAutoFillManager->GetAutoFillSuggestions(mQueryId, false, formField); mQueryId++; + if (!suggestions) { + ASSERT(mWebViewCore); + // Tell Java no autofill suggestions for this form. + mWebViewCore->setWebTextViewAutoFillable(FORM_NOT_AUTOFILLABLE); + return; + } +} + +void WebAutoFill::querySuccessful(int queryId, const string16& value, const string16& label, int uniqueId) +{ + // Store the results for the query and inform java that autofill suggestions for this form are available. + // Pass java the queryId so that it can pass it back if the user decides to use autofill. + AutoFillSuggestion suggestion; + suggestion.value = value; + suggestion.label = label; + suggestion.uniqueId = uniqueId; + mSuggestionMap[queryId] = AutoFillSuggestion(); + + ASSERT(mWebViewCore); + mWebViewCore->setWebTextViewAutoFillable(queryId); } -void WebAutoFill::fillFormFields(int queryId, const string16& value, const string16& label, int uniqueId) +void WebAutoFill::fillFormFields(int queryId) { webkit_glue::FormData* form = mQueryMap[queryId]; - mAutoFillManager->FillAutoFillFormData(queryId, *form, value, label, uniqueId); + AutoFillQuerySuggestionMap::iterator iter = mSuggestionMap.find(queryId); + ASSERT(iter != mSuggestionMap.end()); + AutoFillSuggestion* suggestion = &iter->second; + mAutoFillManager->FillAutoFillFormData(queryId, *form, suggestion->value, suggestion->label, suggestion->uniqueId); + mSuggestionMap.erase(iter); } void WebAutoFill::fillFormInPage(int queryId, const webkit_glue::FormData& form) diff --git a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h index 335f9b2..986e1a2 100644 --- a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h +++ b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h @@ -57,8 +57,10 @@ public: void searchDocument(WebCore::Document*); void formFieldFocused(WebCore::HTMLFormControlElement*); - void fillFormFields(int queryId, const string16& value, const string16& label, int uniqueId); + void fillFormFields(int queryId); + void querySuccessful(int queryId, const string16& value, const string16& label, int uniqueId); void fillFormInPage(int queryId, const webkit_glue::FormData& form); + void setWebViewCore(WebViewCore* webViewCore) { mWebViewCore = webViewCore; } private: OwnPtr<FormManager> mFormManager; @@ -69,9 +71,19 @@ private: typedef std::vector<webkit_glue::FormData, std::allocator<webkit_glue::FormData> > FormList; FormList mForms; - typedef std::map<int, webkit_glue::FormData*> AutoFillQueryMap; - AutoFillQueryMap mQueryMap; + typedef std::map<int, webkit_glue::FormData*> AutoFillQueryFormDataMap; + AutoFillQueryFormDataMap mQueryMap; + + typedef struct { + string16 value; + string16 label; + int uniqueId; + } AutoFillSuggestion; + typedef std::map<int, AutoFillSuggestion> AutoFillQuerySuggestionMap; + AutoFillQuerySuggestionMap mSuggestionMap; int mQueryId; + + WebViewCore* mWebViewCore; }; } diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 1d5eacb..d6dd4bc 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -977,6 +977,10 @@ static void CreateFrame(JNIEnv* env, jobject obj, jobject javaview, jobject jAss // Create a WebViewCore to access the Java WebViewCore associated with this page WebViewCore* webViewCore = new WebViewCore(env, javaview, frame); +#if ENABLE(WEB_AUTOFILL) + editorC->getAutoFill()->setWebViewCore(webViewCore); +#endif + // Create a FrameView RefPtr<WebCore::FrameView> frameView = WebCore::FrameView::create(frame); // Create a WebFrameView diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 1ae92d1..b9af546 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -58,6 +58,7 @@ #include "HTMLAnchorElement.h" #include "HTMLAreaElement.h" #include "HTMLElement.h" +#include "HTMLFormControlElement.h" #include "HTMLImageElement.h" #include "HTMLInputElement.h" #include "HTMLLabelElement.h" @@ -108,6 +109,7 @@ #include "WebFrameView.h" #include "WindowsKeyboardCodes.h" #include "android_graphics.h" +#include "autofill/WebAutoFill.h" #include "markup.h" #include <JNIHelp.h> @@ -262,6 +264,7 @@ struct WebViewCore::JavaGlue { jmethodID m_centerFitRect; jmethodID m_setScrollbarModes; jmethodID m_setInstallableWebApp; + jmethodID m_setWebTextViewAutoFillable; AutoJObject object(JNIEnv* env) { return getRealObject(env, m_obj); } @@ -352,6 +355,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_javaGlue->m_centerFitRect = GetJMethod(env, clazz, "centerFitRect", "(IIII)V"); m_javaGlue->m_setScrollbarModes = GetJMethod(env, clazz, "setScrollbarModes", "(II)V"); m_javaGlue->m_setInstallableWebApp = GetJMethod(env, clazz, "setInstallableWebApp", "()V"); + m_javaGlue->m_setWebTextViewAutoFillable = GetJMethod(env, clazz, "setWebTextViewAutoFillable", "(I)V"); env->SetIntField(javaWebViewCore, gWebViewCoreFields.m_nativeClass, (jint)this); @@ -3214,6 +3218,12 @@ void WebViewCore::notifyWebAppCanBeInstalled() checkException(env); } +void WebViewCore::setWebTextViewAutoFillable(int queryId) +{ + JNIEnv* env = JSC::Bindings::getJNIEnv(); + env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_setWebTextViewAutoFillable, queryId); +} + bool WebViewCore::drawIsPaused() const { JNIEnv* env = JSC::Bindings::getJNIEnv(); @@ -3864,6 +3874,22 @@ static jobject GetTouchHighlightRects(JNIEnv* env, jobject obj, jint x, jint y, return array; } +static void AutoFillForm(JNIEnv* env, jobject obj, jint queryId) +{ +#if ENABLE(WEB_AUTOFILL) + WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj); + if (!viewImpl) + return; + + WebCore::Frame* frame = viewImpl->mainFrame(); + if (frame) { + EditorClientAndroid* editorC = static_cast<EditorClientAndroid*>(frame->page()->editorClient()); + WebAutoFill* autoFill = editorC->getAutoFill(); + autoFill->fillFormFields(queryId); + } +#endif +} + // ---------------------------------------------------------------------------- /* @@ -3965,6 +3991,8 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { (void*) ValidNodeAndBounds }, { "nativeGetTouchHighlightRects", "(III)Ljava/util/ArrayList;", (void*) GetTouchHighlightRects }, + { "nativeAutoFillForm", "(I)V", + (void*) AutoFillForm }, }; int register_webviewcore(JNIEnv* env) diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index 00054f3..61ddd7d 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -489,6 +489,7 @@ namespace android { void splitContent(PictureSet*); void notifyWebAppCanBeInstalled(); + void setWebTextViewAutoFillable(int queryId); DeviceOrientationManager* deviceOrientationManager() { return &m_deviceOrientationManager; } |
