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

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

Issue 11636040: AutofillPopupController clarifications + simplifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new workstation Created 8 years 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 | Annotate | Revision Log
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/autofill/autocomplete_history_manager.h" 6 #include "chrome/browser/autofill/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/browser/ui/autofill/autofill_popup_controller_impl.h" 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
10 #include "chrome/common/autofill_messages.h" 10 #include "chrome/common/autofill_messages.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 content::Source<content::NavigationController>( 61 content::Source<content::NavigationController>(
62 &(web_contents->GetController()))); 62 &(web_contents->GetController())));
63 } 63 }
64 } 64 }
65 65
66 AutofillExternalDelegate::~AutofillExternalDelegate() { 66 AutofillExternalDelegate::~AutofillExternalDelegate() {
67 if (controller_) 67 if (controller_)
68 controller_->Hide(); 68 controller_->Hide();
69 } 69 }
70 70
71 void AutofillExternalDelegate::SelectAutofillSuggestion(int unique_id) {
72 ClearPreviewedForm();
73
74 // Only preview the data if it is a profile.
75 if (unique_id > 0)
76 FillAutofillFormData(unique_id, true);
77 }
78
79 void AutofillExternalDelegate::OnQuery(int query_id, 71 void AutofillExternalDelegate::OnQuery(int query_id,
80 const FormData& form, 72 const FormData& form,
81 const FormFieldData& field, 73 const FormFieldData& field,
82 const gfx::Rect& element_bounds, 74 const gfx::Rect& element_bounds,
83 bool display_warning_if_disabled) { 75 bool display_warning_if_disabled) {
84 autofill_query_form_ = form; 76 autofill_query_form_ = form;
85 autofill_query_field_ = field; 77 autofill_query_field_ = field;
86 display_warning_if_disabled_ = display_warning_if_disabled; 78 display_warning_if_disabled_ = display_warning_if_disabled;
87 autofill_query_id_ = query_id; 79 autofill_query_id_ = query_id;
88 80
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 const std::vector<string16>& data_list_values, 190 const std::vector<string16>& data_list_values,
199 const std::vector<string16>& data_list_labels, 191 const std::vector<string16>& data_list_labels,
200 const std::vector<string16>& data_list_icons, 192 const std::vector<string16>& data_list_icons,
201 const std::vector<int>& data_list_unique_ids) { 193 const std::vector<int>& data_list_unique_ids) {
202 data_list_values_ = data_list_values; 194 data_list_values_ = data_list_values;
203 data_list_labels_ = data_list_labels; 195 data_list_labels_ = data_list_labels;
204 data_list_icons_ = data_list_icons; 196 data_list_icons_ = data_list_icons;
205 data_list_unique_ids_ = data_list_unique_ids; 197 data_list_unique_ids_ = data_list_unique_ids;
206 } 198 }
207 199
208 void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) { 200 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) {
209 if (web_contents_) { 201 ClearPreviewedForm();
210 autofill_manager_->RemoveAutocompleteEntry( 202
211 autofill_query_field_.name, value); 203 // Only preview the data if it is a profile.
212 } 204 if (identifier > 0)
205 FillAutofillFormData(identifier, true);
213 } 206 }
214 207
215 void AutofillExternalDelegate::RemoveAutofillProfileOrCreditCard( 208 void AutofillExternalDelegate::DidAcceptSuggestion(const string16& value,
216 int unique_id) { 209 int identifier) {
217 autofill_manager_->RemoveAutofillProfileOrCreditCard(unique_id); 210 RenderViewHost* host = web_contents_->GetRenderViewHost();
211
212 if (identifier == WebAutofillClient::MenuItemIDAutofillOptions) {
213 // User selected 'Autofill Options'.
214 autofill_manager_->OnShowAutofillDialog();
215 } else if (identifier == WebAutofillClient::MenuItemIDClearForm) {
216 // User selected 'Clear form'.
217 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
218 } else if (identifier == WebAutofillClient::MenuItemIDPasswordEntry &&
219 password_autofill_manager_.DidAcceptAutofillSuggestion(
220 autofill_query_field_, value)) {
221 // DidAcceptAutofillSuggestion has already handled the work to fill in
222 // the page as required.
223 } else if (identifier == WebAutofillClient::MenuItemIDDataListEntry) {
224 host->Send(new AutofillMsg_AcceptDataListSuggestion(host->GetRoutingID(),
225 value));
226 } else if (identifier == WebAutofillClient::MenuItemIDAutocompleteEntry) {
227 // User selected an Autocomplete, so we fill directly.
228 host->Send(new AutofillMsg_SetNodeText(host->GetRoutingID(), value));
229 } else {
230 FillAutofillFormData(identifier, false);
231 }
232
233 HideAutofillPopup();
234 }
235
236 void AutofillExternalDelegate::RemoveSuggestion(const string16& value,
237 int identifier) {
238 if (identifier > 0) {
239 autofill_manager_->RemoveAutofillProfileOrCreditCard(identifier);
240 } else if (web_contents_) {
241 autofill_manager_->RemoveAutocompleteEntry(autofill_query_field_.name,
242 value);
243 }
218 } 244 }
219 245
220 void AutofillExternalDelegate::DidEndTextFieldEditing() { 246 void AutofillExternalDelegate::DidEndTextFieldEditing() {
221 HideAutofillPopup(); 247 HideAutofillPopup();
222 248
223 has_shown_autofill_popup_for_current_edit_ = false; 249 has_shown_autofill_popup_for_current_edit_ = false;
224 } 250 }
225 251
226 bool AutofillExternalDelegate::DidAcceptAutofillSuggestion(
227 const string16& value,
228 int unique_id,
229 unsigned index) {
230 // If the selected element is a warning we don't want to do anything.
231 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
232 return false;
233
234 RenderViewHost* host = web_contents_->GetRenderViewHost();
235
236 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) {
237 // User selected 'Autofill Options'.
238 autofill_manager_->OnShowAutofillDialog();
239 } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) {
240 // User selected 'Clear form'.
241 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
242 } else if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry &&
243 password_autofill_manager_.DidAcceptAutofillSuggestion(
244 autofill_query_field_, value)) {
245 // DidAcceptAutofillSuggestion has already handled the work to fill in
246 // the page as required.
247 } else if (unique_id == WebAutofillClient::MenuItemIDDataListEntry) {
248 host->Send(new AutofillMsg_AcceptDataListSuggestion(host->GetRoutingID(),
249 value));
250 } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) {
251 // User selected an Autocomplete, so we fill directly.
252 host->Send(new AutofillMsg_SetNodeText(
253 host->GetRoutingID(),
254 value));
255 } else {
256 FillAutofillFormData(unique_id, false);
257 }
258
259 HideAutofillPopup();
260
261 return true;
262 }
263
264 void AutofillExternalDelegate::ClearPreviewedForm() { 252 void AutofillExternalDelegate::ClearPreviewedForm() {
265 if (web_contents_) { 253 if (web_contents_) {
266 RenderViewHost* host = web_contents_->GetRenderViewHost(); 254 RenderViewHost* host = web_contents_->GetRenderViewHost();
267 255
268 if (host) 256 if (host)
269 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); 257 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID()));
270 } 258 }
271 } 259 }
272 260
273 void AutofillExternalDelegate::ControllerDestroyed() { 261 void AutofillExternalDelegate::ControllerDestroyed() {
(...skipping 18 matching lines...) Expand all
292 } 280 }
293 281
294 void AutofillExternalDelegate::AddPasswordFormMapping( 282 void AutofillExternalDelegate::AddPasswordFormMapping(
295 const FormFieldData& form, 283 const FormFieldData& form,
296 const PasswordFormFillData& fill_data) { 284 const PasswordFormFillData& fill_data) {
297 password_autofill_manager_.AddPasswordFormMapping(form, fill_data); 285 password_autofill_manager_.AddPasswordFormMapping(form, fill_data);
298 } 286 }
299 287
300 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, 288 void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
301 bool is_preview) { 289 bool is_preview) {
290 // If the selected element is a warning we don't want to do anything.
291 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
292 return;
293
302 RenderViewHost* host = web_contents_->GetRenderViewHost(); 294 RenderViewHost* host = web_contents_->GetRenderViewHost();
303 295
304 if (is_preview) { 296 if (is_preview) {
305 host->Send(new AutofillMsg_SetAutofillActionPreview( 297 host->Send(new AutofillMsg_SetAutofillActionPreview(
306 host->GetRoutingID())); 298 host->GetRoutingID()));
307 } else { 299 } else {
308 host->Send(new AutofillMsg_SetAutofillActionFill( 300 host->Send(new AutofillMsg_SetAutofillActionFill(
309 host->GetRoutingID())); 301 host->GetRoutingID()));
310 } 302 }
311 303
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (!*content::Details<bool>(details).ptr()) 407 if (!*content::Details<bool>(details).ptr())
416 HideAutofillPopup(); 408 HideAutofillPopup();
417 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { 409 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
418 HideAutofillPopup(); 410 HideAutofillPopup();
419 } else { 411 } else {
420 NOTREACHED(); 412 NOTREACHED();
421 } 413 }
422 } 414 }
423 415
424 416
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698