diff options
author | Ben Murdoch <benm@google.com> | 2010-09-10 21:21:28 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-09-23 17:07:42 +0100 |
commit | c95d7f499ee3250e2d4a51f7e8f04bb6ebfc6add (patch) | |
tree | c0a08b300482f0cef7e37a0305bcef1898f8ace3 /WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp | |
parent | 45ca37e14f3f68f52a77e0d06514716809ed89ab (diff) | |
download | external_webkit-c95d7f499ee3250e2d4a51f7e8f04bb6ebfc6add.zip external_webkit-c95d7f499ee3250e2d4a51f7e8f04bb6ebfc6add.tar.gz external_webkit-c95d7f499ee3250e2d4a51f7e8f04bb6ebfc6add.tar.bz2 |
Integrate AutoFill with WebTextView in Java.
Adds the necessary JNI hooks so that when the user focuses a form
field that AutoFill has identified as "autofillable", the Java side
WebTextView will show an option in the auto complete drop down box
that when selected will call back to AutoFill in native code and
actually fill out the form.
AutoFill is still disabled at compile time by default. To test the
feature set ENABLE_AUTOFILL=true and rebuild WebKit.
Needs a corresponding frameworks/base change.
Change-Id: Ie76ff9cbf0b44f3f3644079ed64ce71bfbc9859a
Diffstat (limited to 'WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp')
-rw-r--r-- | WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
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) |