Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate.cc

Issue 10443084: Add Datalist Support to New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autocomplete_history_manager.h" 6 #include "chrome/browser/autocomplete_history_manager.h"
7 #include "chrome/browser/autofill/autofill_external_delegate.h" 7 #include "chrome/browser/autofill/autofill_external_delegate.h"
8 #include "chrome/browser/autofill/autofill_manager.h" 8 #include "chrome/browser/autofill/autofill_manager.h"
9 #include "chrome/common/autofill_messages.h" 9 #include "chrome/common/autofill_messages.h"
10 #include "chrome/common/chrome_constants.h" 10 #include "chrome/common/chrome_constants.h"
(...skipping 19 matching lines...) Expand all
30 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL), 30 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL),
31 autofill_query_id_(0), 31 autofill_query_id_(0),
32 display_warning_if_disabled_(false), 32 display_warning_if_disabled_(false),
33 has_shown_autofill_popup_for_current_edit_(false) { 33 has_shown_autofill_popup_for_current_edit_(false) {
34 } 34 }
35 35
36 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) { 36 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) {
37 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions || 37 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions ||
38 unique_id == WebAutofillClient::MenuItemIDClearForm || 38 unique_id == WebAutofillClient::MenuItemIDClearForm ||
39 unique_id == WebAutofillClient::MenuItemIDSeparator || 39 unique_id == WebAutofillClient::MenuItemIDSeparator ||
40 unique_id == WebAutofillClient::MenuItemIDWarningMessage) 40 unique_id == WebAutofillClient::MenuItemIDWarningMessage)
Ilya Sherman 2012/05/30 21:55:43 Hmm, I would have expected this if-stmt to be upda
csharp 2012/05/31 14:20:26 If the datalist element was added to this list the
Ilya Sherman 2012/06/01 06:28:16 Ah, I see. Yeah, I think the preview should vanis
csharp 2012/06/04 15:02:03 Done.
41 return; 41 return;
42 42
43 ClearPreviewedForm(); 43 ClearPreviewedForm();
44 44
45 if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry) 45 if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry)
46 return; 46 return;
47 47
48 FillAutofillFormData(unique_id, true); 48 // Only preview the data if it is a profile.
49 if (unique_id > 0)
50 FillAutofillFormData(unique_id, true);
49 } 51 }
50 52
51 void AutofillExternalDelegate::OnQuery(int query_id, 53 void AutofillExternalDelegate::OnQuery(int query_id,
52 const webkit::forms::FormData& form, 54 const webkit::forms::FormData& form,
53 const webkit::forms::FormField& field, 55 const webkit::forms::FormField& field,
54 const gfx::Rect& bounds, 56 const gfx::Rect& bounds,
55 bool display_warning_if_disabled) { 57 bool display_warning_if_disabled) {
56 autofill_query_form_ = form; 58 autofill_query_form_ = form;
57 autofill_query_field_ = field; 59 autofill_query_field_ = field;
58 display_warning_if_disabled_ = display_warning_if_disabled; 60 display_warning_if_disabled_ = display_warning_if_disabled;
59 autofill_query_id_ = query_id; 61 autofill_query_id_ = query_id;
60 62
61 OnQueryPlatformSpecific(query_id, form, field, bounds); 63 OnQueryPlatformSpecific(query_id, form, field, bounds);
62 } 64 }
63 65
64 void AutofillExternalDelegate::OnSuggestionsReturned( 66 void AutofillExternalDelegate::OnSuggestionsReturned(
65 int query_id, 67 int query_id,
66 const std::vector<string16>& values, 68 const std::vector<string16>& values,
67 const std::vector<string16>& labels, 69 const std::vector<string16>& labels,
68 const std::vector<string16>& icons, 70 const std::vector<string16>& icons,
69 const std::vector<int>& unique_ids) { 71 const std::vector<int>& unique_ids) {
70 if (query_id != autofill_query_id_) 72 if (query_id != autofill_query_id_)
71 return; 73 return;
72 74
73 if (values.empty()) { 75 // List any data list values at the start.
76 std::vector<string16> v(data_list_values_);
77 std::vector<string16> l(data_list_labels_);
78 std::vector<string16> i(data_list_icons_);
79 std::vector<int> ids(data_list_unique_ids_);
80
81 // If there are both <datalist> items and Autofill suggestions, add a
82 // separator between them.
83 if (!values.empty() && !v.empty()) {
84 v.push_back(string16());
85 l.push_back(string16());
86 i.push_back(string16());
87 ids.push_back(WebAutofillClient::MenuItemIDSeparator);
88 }
89
90 // Append the Autofill suggestions.
91 v.insert(v.end(), values.begin(), values.end());
92 l.insert(l.end(), labels.begin(), labels.end());
93 i.insert(i.end(), icons.begin(), icons.end());
94 ids.insert(ids.end(), unique_ids.begin(), unique_ids.end());
95
96 if (v.empty()) {
74 // No suggestions, any popup currently showing is obsolete. 97 // No suggestions, any popup currently showing is obsolete.
75 HideAutofillPopup(); 98 HideAutofillPopup();
76 return; 99 return;
77 } 100 }
78 101
79 std::vector<string16> v(values);
80 std::vector<string16> l(labels);
81 std::vector<string16> i(icons);
82 std::vector<int> ids(unique_ids);
83
84 // Add a separator to go between the values and menu items. 102 // Add a separator to go between the values and menu items.
85 v.push_back(string16()); 103 v.push_back(string16());
86 l.push_back(string16()); 104 l.push_back(string16());
87 i.push_back(string16()); 105 i.push_back(string16());
88 ids.push_back(WebAutofillClient::MenuItemIDSeparator); 106 ids.push_back(WebAutofillClient::MenuItemIDSeparator);
89 107
90 DCHECK_GT(ids.size(), 0U); 108 DCHECK_GT(ids.size(), 0U);
91 if (!autofill_query_field_.should_autocomplete) { 109 if (!autofill_query_field_.should_autocomplete) {
92 // If autofill is disabled and we had suggestions, show a warning instead. 110 // If autofill is disabled and we had suggestions, show a warning instead.
93 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); 111 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
94 l.assign(1, string16()); 112 l.assign(1, string16());
95 i.assign(1, string16()); 113 i.assign(1, string16());
96 ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage); 114 ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage);
97 } else if (ids[0] < 0 && ids.size() > 1) { 115 } else if (ids[0] == WebAutofillClient::MenuItemIDWarningMessage &&
Ilya Sherman 2012/05/30 21:55:43 ids[0] is no longer guaranteed to be the first Aut
csharp 2012/05/31 14:20:26 Done.
116 ids.size() > 1) {
98 // If we received a warning instead of suggestions from autofill but regular 117 // If we received a warning instead of suggestions from autofill but regular
99 // suggestions from autocomplete, don't show the autofill warning. 118 // suggestions from autocomplete, don't show the autofill warning.
100 v.erase(v.begin()); 119 v.erase(v.begin());
101 l.erase(l.begin()); 120 l.erase(l.begin());
102 i.erase(i.begin()); 121 i.erase(i.begin());
103 ids.erase(ids.begin()); 122 ids.erase(ids.begin());
104 } 123 }
105 124
106 // If we were about to show a warning and we shouldn't, don't. 125 // If we were about to show a warning and we shouldn't, don't.
107 if (ids[0] < 0 && !display_warning_if_disabled_) 126 if (ids[0] == WebAutofillClient::MenuItemIDWarningMessage &&
127 !display_warning_if_disabled_)
108 return; 128 return;
109 129
110 // Only include "Autofill Options" special menu item if we have Autofill 130 // Only include "Autofill Options" special menu item if we have Autofill
111 // items, identified by |unique_ids| having at least one valid value. 131 // items, identified by |unique_ids| having at least one valid value.
112 bool has_autofill_item = false; 132 bool has_autofill_item = false;
113 for (size_t i = 0; i < ids.size(); ++i) { 133 for (size_t i = 0; i < ids.size(); ++i) {
114 if (ids[i] > 0) { 134 if (ids[i] > 0) {
115 has_autofill_item = true; 135 has_autofill_item = true;
116 break; 136 break;
117 } 137 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 183 }
164 184
165 SetBounds(bounds); 185 SetBounds(bounds);
166 186
167 std::vector<string16> empty(suggestions.size()); 187 std::vector<string16> empty(suggestions.size());
168 std::vector<int> password_ids(suggestions.size(), 188 std::vector<int> password_ids(suggestions.size(),
169 WebAutofillClient::MenuItemIDPasswordEntry); 189 WebAutofillClient::MenuItemIDPasswordEntry);
170 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids); 190 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids);
171 } 191 }
172 192
193 void AutofillExternalDelegate::SetCurrentDataListValues(
194 const std::vector<string16>& data_list_values,
195 const std::vector<string16>& data_list_labels,
196 const std::vector<string16>& data_list_icons,
197 const std::vector<int>& data_list_unique_ids) {
198 data_list_values_ = data_list_values;
199 data_list_labels_ = data_list_labels;
200 data_list_icons_ = data_list_icons;
201 data_list_unique_ids_ = data_list_unique_ids;
202 }
Ilya Sherman 2012/05/30 21:55:43 Shouldn't this method also update the popup conten
csharp 2012/05/31 14:20:26 This method shouldn't ever get called when the pop
Ilya Sherman 2012/06/01 06:28:16 Ok. The DCHECK is probably good enough for now; b
csharp 2012/06/04 15:02:03 Had to replace the DCHECK with an if, since if you
203
173 void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) { 204 void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) {
174 if (tab_contents_wrapper_) { 205 if (tab_contents_wrapper_) {
175 tab_contents_wrapper_->autocomplete_history_manager()-> 206 tab_contents_wrapper_->autocomplete_history_manager()->
176 OnRemoveAutocompleteEntry(autofill_query_field_.name, value); 207 OnRemoveAutocompleteEntry(autofill_query_field_.name, value);
177 } 208 }
178 } 209 }
179 210
180 void AutofillExternalDelegate::RemoveAutofillProfileOrCreditCard( 211 void AutofillExternalDelegate::RemoveAutofillProfileOrCreditCard(
181 int unique_id) { 212 int unique_id) {
182 autofill_manager_->RemoveAutofillProfileOrCreditCard(unique_id); 213 autofill_manager_->RemoveAutofillProfileOrCreditCard(unique_id);
183 } 214 }
184 215
185 216
186 void AutofillExternalDelegate::DidEndTextFieldEditing() { 217 void AutofillExternalDelegate::DidEndTextFieldEditing() {
187 HideAutofillPopup(); 218 HideAutofillPopup();
188 219
189 has_shown_autofill_popup_for_current_edit_ = false; 220 has_shown_autofill_popup_for_current_edit_ = false;
190 } 221 }
191 222
192 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( 223 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
193 const string16& value, 224 const string16& value,
194 int unique_id, 225 int unique_id,
195 unsigned index) { 226 unsigned index) {
196 // If the selected element is a warning we don't want to do anything. 227 // If the selected element is a warning we don't want to do anything.
197 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage) 228 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
198 return false; 229 return false;
199 230
231 RenderViewHost* host =
232 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
233
200 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) { 234 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) {
201 // User selected 'Autofill Options'. 235 // User selected 'Autofill Options'.
202 autofill_manager_->OnShowAutofillDialog(); 236 autofill_manager_->OnShowAutofillDialog();
203 } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) { 237 } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) {
204 // User selected 'Clear form'. 238 // User selected 'Clear form'.
205 RenderViewHost* host =
206 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
207 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); 239 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
208 } else if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry && 240 } else if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry &&
209 password_autofill_manager_.DidAcceptAutofillSuggestion( 241 password_autofill_manager_.DidAcceptAutofillSuggestion(
210 autofill_query_field_, value)) { 242 autofill_query_field_, value)) {
211 // DidAcceptAutofillSuggestion has already handled the work to fill in 243 // DidAcceptAutofillSuggestion has already handled the work to fill in
212 // the page as required. 244 // the page as required.
245 } else if (unique_id == WebAutofillClient::MenuItemIDDataListEntry) {
246 host->Send(new AutofillMsg_AcceptDataListSuggestion(host->GetRoutingID(),
247 value));
213 } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) { 248 } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) {
214 // User selected an Autocomplete, so we fill directly. 249 // User selected an Autocomplete, so we fill directly.
215 RenderViewHost* host =
216 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
217 host->Send(new AutofillMsg_SetNodeText( 250 host->Send(new AutofillMsg_SetNodeText(
218 host->GetRoutingID(), 251 host->GetRoutingID(),
219 value)); 252 value));
220 } else { 253 } else {
221 FillAutofillFormData(unique_id, false); 254 FillAutofillFormData(unique_id, false);
222 } 255 }
223 256
224 HideAutofillPopup(); 257 HideAutofillPopup();
225 258
226 return true; 259 return true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // none, so all platforms use the default. 306 // none, so all platforms use the default.
274 307
275 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 308 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
276 309
277 AutofillExternalDelegate* AutofillExternalDelegate::Create( 310 AutofillExternalDelegate* AutofillExternalDelegate::Create(
278 TabContentsWrapper*, AutofillManager*) { 311 TabContentsWrapper*, AutofillManager*) {
279 return NULL; 312 return NULL;
280 } 313 }
281 314
282 #endif 315 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698