diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 01:29:24 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 01:29:24 +0000 |
commit | 95056b58863ba1fc6716ef796bb847cca8919188 (patch) | |
tree | 5440761639aa7031810c7be5a817857ac596d02f /chrome/browser/autofill/autofill_manager.cc | |
parent | f5c895f2e6660df9756fec85584bf85b598186f5 (diff) | |
download | chromium_src-95056b58863ba1fc6716ef796bb847cca8919188.zip chromium_src-95056b58863ba1fc6716ef796bb847cca8919188.tar.gz chromium_src-95056b58863ba1fc6716ef796bb847cca8919188.tar.bz2 |
Send suggestions from the AutoFillManager to the AutoFillSuggestionsPopup in WebKit.
BUG=18201
TEST=none
Review URL: http://codereview.chromium.org/627005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39310 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/autofill_manager.cc')
-rw-r--r-- | chrome/browser/autofill/autofill_manager.cc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index bf0857d..33f7dcb0 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -11,10 +11,12 @@ #include "chrome/browser/autofill/autofill_infobar_delegate.h" #include "chrome/browser/autofill/form_structure.h" #include "chrome/browser/profile.h" +#include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" +#include "webkit/glue/form_field.h" #include "webkit/glue/form_field_values.h" AutoFillManager::AutoFillManager(TabContents* tab_contents) @@ -73,6 +75,78 @@ void AutoFillManager::FormsSeen( } } +bool AutoFillManager::GetAutoFillSuggestions( + int query_id, const webkit_glue::FormField& field) { + // TODO(jhawkins): Use the autofill preference. + if (!CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableNewAutoFill)) + return false; + + RenderViewHost* host = tab_contents_->render_view_host(); + if (!host) + return false; + + const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles(); + if (profiles.empty()) + return false; + + AutoFillFieldType type = UNKNOWN_TYPE; + for (std::vector<FormStructure*>::iterator form = form_structures_.begin(); + form != form_structures_.end(); ++form) { + for (std::vector<AutoFillField*>::const_iterator iter = (*form)->begin(); + iter != (*form)->end(); ++iter) { + // The field list is terminated with a NULL AutoFillField, so don't try to + // dereference it. + if (!*iter) + break; + + AutoFillField* form_field = *iter; + if (*form_field != field) + continue; + + if (form_field->possible_types().find(NAME_FIRST) != + form_field->possible_types().end() || + form_field->heuristic_type() == NAME_FIRST) { + type = NAME_FIRST; + break; + } + + if (form_field->possible_types().find(NAME_FULL) != + form_field->possible_types().end() || + form_field->heuristic_type() == NAME_FULL) { + type = NAME_FULL; + break; + } + } + } + + if (type == UNKNOWN_TYPE) + return false; + + std::vector<string16> names; + std::vector<string16> labels; + for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); + iter != profiles.end(); ++iter) { + string16 name = (*iter)->GetFieldText(AutoFillType(type)); + string16 label = (*iter)->Label(); + + // TODO(jhawkins): What if name.length() == 0? + if (StartsWith(name, field.value(), false)) { + names.push_back(name); + labels.push_back(label); + } + } + + // No suggestions. + if (names.empty()) + return false; + + // TODO(jhawkins): If the default profile is in this list, set it as the + // default suggestion index. + host->AutoFillSuggestionsReturned(query_id, names, labels, -1); + return true; +} + void AutoFillManager::OnAutoFillDialogApply( std::vector<AutoFillProfile>* profiles, std::vector<CreditCard>* credit_cards) { |