diff options
Diffstat (limited to 'WebKit/android/WebCoreSupport/autofill')
3 files changed, 48 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; }; } |
