OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_external_delegate.h" | 5 #include "components/autofill/core/browser/autofill_external_delegate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 void EmitHistogram(AccessAddressBookEventType type) { | 40 void EmitHistogram(AccessAddressBookEventType type) { |
41 UMA_HISTOGRAM_ENUMERATION( | 41 UMA_HISTOGRAM_ENUMERATION( |
42 "Autofill.MacAddressBook", type, ACCESS_ADDRESS_BOOK_ENTRY_MAX); | 42 "Autofill.MacAddressBook", type, ACCESS_ADDRESS_BOOK_ENTRY_MAX); |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 46 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
47 | 47 |
48 namespace autofill { | 48 namespace autofill { |
49 | 49 |
50 namespace { | |
51 | |
52 bool ShouldAutofill(const FormFieldData& form_field) { | |
53 return form_field.should_autocomplete || | |
54 !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
55 switches::kRespectAutocompleteOffForAutofill); | |
56 } | |
57 | |
58 } // namespace | |
59 | |
60 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, | 50 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, |
61 AutofillDriver* driver) | 51 AutofillDriver* driver) |
62 : manager_(manager), | 52 : manager_(manager), |
63 driver_(driver), | 53 driver_(driver), |
64 query_id_(0), | 54 query_id_(0), |
65 display_warning_if_disabled_(false), | |
66 has_suggestion_(false), | 55 has_suggestion_(false), |
67 has_shown_popup_for_current_edit_(false), | 56 has_shown_popup_for_current_edit_(false), |
68 should_show_scan_credit_card_(false), | 57 should_show_scan_credit_card_(false), |
69 has_shown_address_book_prompt(false), | 58 has_shown_address_book_prompt(false), |
70 weak_ptr_factory_(this) { | 59 weak_ptr_factory_(this) { |
71 DCHECK(manager); | 60 DCHECK(manager); |
72 } | 61 } |
73 | 62 |
74 AutofillExternalDelegate::~AutofillExternalDelegate() {} | 63 AutofillExternalDelegate::~AutofillExternalDelegate() {} |
75 | 64 |
76 void AutofillExternalDelegate::OnQuery(int query_id, | 65 void AutofillExternalDelegate::OnQuery(int query_id, |
77 const FormData& form, | 66 const FormData& form, |
78 const FormFieldData& field, | 67 const FormFieldData& field, |
79 const gfx::RectF& element_bounds, | 68 const gfx::RectF& element_bounds) { |
80 bool display_warning_if_disabled) { | |
81 if (!query_form_.SameFormAs(form)) | 69 if (!query_form_.SameFormAs(form)) |
82 has_shown_address_book_prompt = false; | 70 has_shown_address_book_prompt = false; |
83 | 71 |
84 query_form_ = form; | 72 query_form_ = form; |
85 query_field_ = field; | 73 query_field_ = field; |
86 display_warning_if_disabled_ = display_warning_if_disabled; | |
87 query_id_ = query_id; | 74 query_id_ = query_id; |
88 element_bounds_ = element_bounds; | 75 element_bounds_ = element_bounds; |
89 should_show_scan_credit_card_ = | 76 should_show_scan_credit_card_ = |
90 manager_->ShouldShowScanCreditCard(query_form_, query_field_); | 77 manager_->ShouldShowScanCreditCard(query_form_, query_field_); |
91 } | 78 } |
92 | 79 |
93 void AutofillExternalDelegate::OnSuggestionsReturned( | 80 void AutofillExternalDelegate::OnSuggestionsReturned( |
94 int query_id, | 81 int query_id, |
95 const std::vector<Suggestion>& input_suggestions) { | 82 const std::vector<Suggestion>& input_suggestions) { |
96 if (query_id != query_id_) | 83 if (query_id != query_id_) |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 void AutofillExternalDelegate::ClearPreviewedForm() { | 280 void AutofillExternalDelegate::ClearPreviewedForm() { |
294 driver_->RendererShouldClearPreviewedForm(); | 281 driver_->RendererShouldClearPreviewedForm(); |
295 } | 282 } |
296 | 283 |
297 void AutofillExternalDelegate::Reset() { | 284 void AutofillExternalDelegate::Reset() { |
298 manager_->client()->HideAutofillPopup(); | 285 manager_->client()->HideAutofillPopup(); |
299 } | 286 } |
300 | 287 |
301 void AutofillExternalDelegate::OnPingAck() { | 288 void AutofillExternalDelegate::OnPingAck() { |
302 // Reissue the most recent query, which will reopen the Autofill popup. | 289 // Reissue the most recent query, which will reopen the Autofill popup. |
303 manager_->OnQueryFormFieldAutofill(query_id_, | 290 manager_->OnQueryFormFieldAutofill(query_id_, query_form_, query_field_, |
304 query_form_, | 291 element_bounds_); |
305 query_field_, | |
306 element_bounds_, | |
307 display_warning_if_disabled_); | |
308 } | 292 } |
309 | 293 |
310 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { | 294 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { |
311 return weak_ptr_factory_.GetWeakPtr(); | 295 return weak_ptr_factory_.GetWeakPtr(); |
312 } | 296 } |
313 | 297 |
314 void AutofillExternalDelegate::OnCreditCardScanned( | 298 void AutofillExternalDelegate::OnCreditCardScanned( |
315 const base::string16& card_number, | 299 const base::string16& card_number, |
316 int expiration_month, | 300 int expiration_month, |
317 int expiration_year) { | 301 int expiration_year) { |
(...skipping 16 matching lines...) Expand all Loading... |
334 // Fill the values for the whole form. | 318 // Fill the values for the whole form. |
335 manager_->FillOrPreviewForm(renderer_action, | 319 manager_->FillOrPreviewForm(renderer_action, |
336 query_id_, | 320 query_id_, |
337 query_form_, | 321 query_form_, |
338 query_field_, | 322 query_field_, |
339 unique_id); | 323 unique_id); |
340 } | 324 } |
341 | 325 |
342 void AutofillExternalDelegate::ApplyAutofillWarnings( | 326 void AutofillExternalDelegate::ApplyAutofillWarnings( |
343 std::vector<Suggestion>* suggestions) { | 327 std::vector<Suggestion>* suggestions) { |
344 if (!ShouldAutofill(query_field_)) { | 328 if (suggestions->size() > 1 && |
345 // Autofill is disabled. If there were some profile or credit card | 329 (*suggestions)[0].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE) { |
346 // suggestions to show, show a warning instead. Otherwise, clear out the | |
347 // list of suggestions. | |
348 if (!suggestions->empty() && (*suggestions)[0].frontend_id > 0) { | |
349 // If Autofill is disabled and we had suggestions, show a warning instead. | |
350 suggestions->assign(1, Suggestion( | |
351 l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED))); | |
352 (*suggestions)[0].frontend_id = POPUP_ITEM_ID_WARNING_MESSAGE; | |
353 } else { | |
354 suggestions->clear(); | |
355 } | |
356 } else if (suggestions->size() > 1 && | |
357 (*suggestions)[0].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE) { | |
358 // If we received a warning instead of suggestions from Autofill but regular | 330 // If we received a warning instead of suggestions from Autofill but regular |
359 // suggestions from autocomplete, don't show the Autofill warning. | 331 // suggestions from autocomplete, don't show the Autofill warning. |
360 suggestions->erase(suggestions->begin()); | 332 suggestions->erase(suggestions->begin()); |
361 } | 333 } |
362 | |
363 // If we were about to show a warning and we shouldn't, don't. | |
364 if (!suggestions->empty() && | |
365 (*suggestions)[0].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE && | |
366 !display_warning_if_disabled_) { | |
367 suggestions->clear(); | |
368 } | |
369 } | 334 } |
370 | 335 |
371 void AutofillExternalDelegate::ApplyAutofillOptions( | 336 void AutofillExternalDelegate::ApplyAutofillOptions( |
372 std::vector<Suggestion>* suggestions) { | 337 std::vector<Suggestion>* suggestions) { |
373 // The form has been auto-filled, so give the user the chance to clear the | 338 // The form has been auto-filled, so give the user the chance to clear the |
374 // form. Append the 'Clear form' menu item. | 339 // form. Append the 'Clear form' menu item. |
375 if (query_field_.is_autofilled) { | 340 if (query_field_.is_autofilled) { |
376 suggestions->push_back(Suggestion( | 341 suggestions->push_back(Suggestion( |
377 l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM))); | 342 l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM))); |
378 suggestions->back().frontend_id = POPUP_ITEM_ID_CLEAR_FORM; | 343 suggestions->back().frontend_id = POPUP_ITEM_ID_CLEAR_FORM; |
(...skipping 27 matching lines...) Expand all Loading... |
406 } | 371 } |
407 } | 372 } |
408 | 373 |
409 #if defined(OS_MACOSX) && !defined(OS_IOS) | 374 #if defined(OS_MACOSX) && !defined(OS_IOS) |
410 void AutofillExternalDelegate::PingRenderer() { | 375 void AutofillExternalDelegate::PingRenderer() { |
411 driver_->PingRenderer(); | 376 driver_->PingRenderer(); |
412 } | 377 } |
413 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 378 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
414 | 379 |
415 } // namespace autofill | 380 } // namespace autofill |
OLD | NEW |