Chromium Code Reviews| 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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 10 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 namespace autofill { | 42 namespace autofill { |
| 43 | 43 |
| 44 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, | 44 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, |
| 45 AutofillDriver* driver) | 45 AutofillDriver* driver) |
| 46 : manager_(manager), | 46 : manager_(manager), |
| 47 driver_(driver), | 47 driver_(driver), |
| 48 query_id_(0), | 48 query_id_(0), |
| 49 display_warning_if_disabled_(false), | 49 display_warning_if_disabled_(false), |
| 50 has_suggestion_(false), | 50 has_suggestion_(false), |
| 51 has_shown_popup_for_current_edit_(false), | 51 has_shown_popup_for_current_edit_(false), |
| 52 weak_ptr_factory_(this) { | 52 weak_ptr_factory_(this) |
| 53 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
| 54 , has_shown_address_book_prompt(false) | |
| 55 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | |
| 56 { | |
| 53 DCHECK(manager); | 57 DCHECK(manager); |
| 54 } | 58 } |
| 55 | 59 |
| 56 AutofillExternalDelegate::~AutofillExternalDelegate() {} | 60 AutofillExternalDelegate::~AutofillExternalDelegate() {} |
| 57 | 61 |
| 58 void AutofillExternalDelegate::OnQuery(int query_id, | 62 void AutofillExternalDelegate::OnQuery(int query_id, |
| 59 const FormData& form, | 63 const FormData& form, |
| 60 const FormFieldData& field, | 64 const FormFieldData& field, |
| 61 const gfx::RectF& element_bounds, | 65 const gfx::RectF& element_bounds, |
| 62 bool display_warning_if_disabled) { | 66 bool display_warning_if_disabled) { |
| 67 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
| 68 if (query_form_ != form) | |
| 69 has_shown_address_book_prompt = false; | |
| 70 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | |
| 71 | |
| 63 query_form_ = form; | 72 query_form_ = form; |
| 64 query_field_ = field; | 73 query_field_ = field; |
| 65 display_warning_if_disabled_ = display_warning_if_disabled; | 74 display_warning_if_disabled_ = display_warning_if_disabled; |
| 66 query_id_ = query_id; | 75 query_id_ = query_id; |
| 67 element_bounds_ = element_bounds; | 76 element_bounds_ = element_bounds; |
| 68 } | 77 } |
| 69 | 78 |
| 70 void AutofillExternalDelegate::OnSuggestionsReturned( | 79 void AutofillExternalDelegate::OnSuggestionsReturned( |
| 71 int query_id, | 80 int query_id, |
| 72 const std::vector<base::string16>& suggested_values, | 81 const std::vector<base::string16>& suggested_values, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 labels.pop_back(); | 119 labels.pop_back(); |
| 111 icons.pop_back(); | 120 icons.pop_back(); |
| 112 ids.pop_back(); | 121 ids.pop_back(); |
| 113 } | 122 } |
| 114 | 123 |
| 115 // If anything else is added to modify the values after inserting the data | 124 // If anything else is added to modify the values after inserting the data |
| 116 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be | 125 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be |
| 117 // updated to match. | 126 // updated to match. |
| 118 InsertDataListValues(&values, &labels, &icons, &ids); | 127 InsertDataListValues(&values, &labels, &icons, &ids); |
| 119 | 128 |
| 120 // Temporarily disabled. See http://crbug.com/408695 | |
| 121 #if 0 | |
| 122 #if defined(OS_MACOSX) && !defined(OS_IOS) | 129 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 123 if (values.empty() && | 130 if (values.empty() && |
| 124 manager_->ShouldShowAccessAddressBookSuggestion(query_form_, | 131 manager_->ShouldShowAccessAddressBookSuggestion(query_form_, |
| 125 query_field_)) { | 132 query_field_)) { |
| 126 values.push_back( | 133 values.push_back( |
| 127 l10n_util::GetStringUTF16(IDS_AUTOFILL_ACCESS_MAC_CONTACTS)); | 134 l10n_util::GetStringUTF16(IDS_AUTOFILL_ACCESS_MAC_CONTACTS)); |
| 128 labels.push_back(base::string16()); | 135 labels.push_back(base::string16()); |
| 129 icons.push_back(base::ASCIIToUTF16("macContactsIcon")); | 136 icons.push_back(base::ASCIIToUTF16("macContactsIcon")); |
| 130 ids.push_back(POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); | 137 ids.push_back(POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); |
| 131 | 138 |
| 132 EmitHistogram(SHOWED_ACCESS_ADDRESS_BOOK_ENTRY); | 139 if (!has_shown_address_book_prompt) { |
| 140 has_shown_address_book_prompt = true; | |
| 141 EmitHistogram(SHOWED_ACCESS_ADDRESS_BOOK_ENTRY); | |
| 142 manager_->ShowedAccessAddressBookPrompt(); | |
| 143 } | |
| 133 } | 144 } |
| 134 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 145 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 135 #endif | |
| 136 | 146 |
| 137 if (values.empty()) { | 147 if (values.empty()) { |
| 138 // No suggestions, any popup currently showing is obsolete. | 148 // No suggestions, any popup currently showing is obsolete. |
| 139 manager_->client()->HideAutofillPopup(); | 149 manager_->client()->HideAutofillPopup(); |
| 140 return; | 150 return; |
| 141 } | 151 } |
| 142 | 152 |
| 143 // Send to display. | 153 // Send to display. |
| 144 if (query_field_.is_focusable) { | 154 if (query_field_.is_focusable) { |
| 145 manager_->client()->ShowAutofillPopup(element_bounds_, | 155 manager_->client()->ShowAutofillPopup(element_bounds_, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 driver_->RendererShouldClearFilledForm(); | 203 driver_->RendererShouldClearFilledForm(); |
| 194 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { | 204 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { |
| 195 NOTREACHED(); // Should be handled elsewhere. | 205 NOTREACHED(); // Should be handled elsewhere. |
| 196 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { | 206 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { |
| 197 driver_->RendererShouldAcceptDataListSuggestion(value); | 207 driver_->RendererShouldAcceptDataListSuggestion(value); |
| 198 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { | 208 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { |
| 199 // User selected an Autocomplete, so we fill directly. | 209 // User selected an Autocomplete, so we fill directly. |
| 200 driver_->RendererShouldFillFieldWithValue(value); | 210 driver_->RendererShouldFillFieldWithValue(value); |
| 201 } else if (identifier == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) { | 211 } else if (identifier == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) { |
| 202 #if defined(OS_MACOSX) && !defined(OS_IOS) | 212 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 203 EmitHistogram(SELECTED_ACCESS_ADDRESS_BOOK_ENTRY); | 213 EmitHistogram(SELECTED_ACCESS_ADDRESS_BOOK_ENTRY); |
|
Evan Stade
2014/09/18 21:26:37
histogram to count how many times the prompt was s
erikchen
2014/09/18 21:55:57
Done.
| |
| 204 | 214 |
| 205 // User wants to give Chrome access to user's address book. | 215 // User wants to give Chrome access to user's address book. |
| 206 manager_->AccessAddressBook(); | 216 manager_->AccessAddressBook(); |
| 207 | 217 |
| 208 // There is no deterministic method for deciding whether a blocking dialog | 218 // There is no deterministic method for deciding whether a blocking dialog |
| 209 // was presented. The following comments and code assume that a blocking | 219 // was presented. The following comments and code assume that a blocking |
| 210 // dialog was presented, but still behave correctly if no dialog was | 220 // dialog was presented, but still behave correctly if no dialog was |
| 211 // presented. | 221 // presented. |
| 212 | 222 |
| 213 // A blocking dialog was presented, and the user has already responded to | 223 // A blocking dialog was presented, and the user has already responded to |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 POPUP_ITEM_ID_DATALIST_ENTRY); | 402 POPUP_ITEM_ID_DATALIST_ENTRY); |
| 393 } | 403 } |
| 394 | 404 |
| 395 #if defined(OS_MACOSX) && !defined(OS_IOS) | 405 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 396 void AutofillExternalDelegate::PingRenderer() { | 406 void AutofillExternalDelegate::PingRenderer() { |
| 397 driver_->PingRenderer(); | 407 driver_->PingRenderer(); |
| 398 } | 408 } |
| 399 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 409 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 400 | 410 |
| 401 } // namespace autofill | 411 } // namespace autofill |
| OLD | NEW |