| 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/command_line.h" |
| 7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 9 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 12 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
| 12 #include "components/autofill/core/browser/autofill_driver.h" | 13 #include "components/autofill/core/browser/autofill_driver.h" |
| 13 #include "components/autofill/core/browser/autofill_manager.h" | 14 #include "components/autofill/core/browser/autofill_manager.h" |
| 14 #include "components/autofill/core/browser/popup_item_ids.h" | 15 #include "components/autofill/core/browser/popup_item_ids.h" |
| 16 #include "components/autofill/core/common/autofill_switches.h" |
| 15 #include "grit/components_strings.h" | 17 #include "grit/components_strings.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 17 | 19 |
| 18 #if defined(OS_MACOSX) && !defined(OS_IOS) | 20 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 enum AccessAddressBookEventType { | 23 enum AccessAddressBookEventType { |
| 22 // An Autofill entry was shown that prompts the user to give Chrome access to | 24 // An Autofill entry was shown that prompts the user to give Chrome access to |
| 23 // the user's Address Book. | 25 // the user's Address Book. |
| 24 SHOWED_ACCESS_ADDRESS_BOOK_ENTRY = 0, | 26 SHOWED_ACCESS_ADDRESS_BOOK_ENTRY = 0, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 void EmitHistogram(AccessAddressBookEventType type) { | 37 void EmitHistogram(AccessAddressBookEventType type) { |
| 36 UMA_HISTOGRAM_ENUMERATION( | 38 UMA_HISTOGRAM_ENUMERATION( |
| 37 "Autofill.MacAddressBook", type, ACCESS_ADDRESS_BOOK_ENTRY_MAX); | 39 "Autofill.MacAddressBook", type, ACCESS_ADDRESS_BOOK_ENTRY_MAX); |
| 38 } | 40 } |
| 39 | 41 |
| 40 } // namespace | 42 } // namespace |
| 41 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 43 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 42 | 44 |
| 43 namespace autofill { | 45 namespace autofill { |
| 44 | 46 |
| 47 namespace { |
| 48 |
| 49 bool ShouldAutofill(const FormFieldData& form_field) { |
| 50 return form_field.should_autocomplete || |
| 51 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 52 switches::kIgnoreAutocompleteOffForAutofill); |
| 53 } |
| 54 |
| 55 } // namespace |
| 56 |
| 45 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, | 57 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, |
| 46 AutofillDriver* driver) | 58 AutofillDriver* driver) |
| 47 : manager_(manager), | 59 : manager_(manager), |
| 48 driver_(driver), | 60 driver_(driver), |
| 49 query_id_(0), | 61 query_id_(0), |
| 50 display_warning_if_disabled_(false), | 62 display_warning_if_disabled_(false), |
| 51 has_suggestion_(false), | 63 has_suggestion_(false), |
| 52 has_shown_popup_for_current_edit_(false), | 64 has_shown_popup_for_current_edit_(false), |
| 53 has_shown_address_book_prompt(false), | 65 has_shown_address_book_prompt(false), |
| 54 weak_ptr_factory_(this) { | 66 weak_ptr_factory_(this) { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 query_form_, | 312 query_form_, |
| 301 query_field_, | 313 query_field_, |
| 302 unique_id); | 314 unique_id); |
| 303 } | 315 } |
| 304 | 316 |
| 305 void AutofillExternalDelegate::ApplyAutofillWarnings( | 317 void AutofillExternalDelegate::ApplyAutofillWarnings( |
| 306 std::vector<base::string16>* values, | 318 std::vector<base::string16>* values, |
| 307 std::vector<base::string16>* labels, | 319 std::vector<base::string16>* labels, |
| 308 std::vector<base::string16>* icons, | 320 std::vector<base::string16>* icons, |
| 309 std::vector<int>* unique_ids) { | 321 std::vector<int>* unique_ids) { |
| 310 if (!query_field_.should_autocomplete) { | 322 if (!ShouldAutofill(query_field_)) { |
| 311 // Autofill is disabled. If there were some profile or credit card | 323 // Autofill is disabled. If there were some profile or credit card |
| 312 // suggestions to show, show a warning instead. Otherwise, clear out the | 324 // suggestions to show, show a warning instead. Otherwise, clear out the |
| 313 // list of suggestions. | 325 // list of suggestions. |
| 314 if (!unique_ids->empty() && (*unique_ids)[0] > 0) { | 326 if (!unique_ids->empty() && (*unique_ids)[0] > 0) { |
| 315 // If Autofill is disabled and we had suggestions, show a warning instead. | 327 // If Autofill is disabled and we had suggestions, show a warning instead. |
| 316 values->assign( | 328 values->assign( |
| 317 1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); | 329 1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); |
| 318 labels->assign(1, base::string16()); | 330 labels->assign(1, base::string16()); |
| 319 icons->assign(1, base::string16()); | 331 icons->assign(1, base::string16()); |
| 320 unique_ids->assign(1, POPUP_ITEM_ID_WARNING_MESSAGE); | 332 unique_ids->assign(1, POPUP_ITEM_ID_WARNING_MESSAGE); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 POPUP_ITEM_ID_DATALIST_ENTRY); | 413 POPUP_ITEM_ID_DATALIST_ENTRY); |
| 402 } | 414 } |
| 403 | 415 |
| 404 #if defined(OS_MACOSX) && !defined(OS_IOS) | 416 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 405 void AutofillExternalDelegate::PingRenderer() { | 417 void AutofillExternalDelegate::PingRenderer() { |
| 406 driver_->PingRenderer(); | 418 driver_->PingRenderer(); |
| 407 } | 419 } |
| 408 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 420 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 409 | 421 |
| 410 } // namespace autofill | 422 } // namespace autofill |
| OLD | NEW |