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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 8 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
9 #include "components/autofill/core/browser/autofill_driver.h" | 9 #include "components/autofill/core/browser/autofill_driver.h" |
10 #include "components/autofill/core/browser/autofill_manager.h" | 10 #include "components/autofill/core/browser/autofill_manager.h" |
11 #include "components/autofill/core/browser/popup_item_ids.h" | 11 #include "components/autofill/core/browser/popup_item_ids.h" |
12 #include "grit/component_strings.h" | 12 #include "grit/component_strings.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 | 14 |
15 namespace autofill { | 15 namespace autofill { |
16 | 16 |
17 AutofillExternalDelegate::AutofillExternalDelegate( | 17 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, |
18 AutofillManager* manager, | 18 AutofillDriver* driver) |
19 AutofillDriver* driver) | |
20 : manager_(manager), | 19 : manager_(manager), |
21 driver_(driver), | 20 driver_(driver), |
22 query_id_(0), | 21 query_id_(0), |
23 display_warning_if_disabled_(false), | 22 display_warning_if_disabled_(false), |
24 has_suggestion_(false), | 23 has_suggestion_(false), |
25 has_shown_popup_for_current_edit_(false), | 24 has_shown_popup_for_current_edit_(false), |
25 #if defined(OS_MACOSX) | |
26 redisplay_popop_on_focus_lost_(false), | |
27 #endif | |
26 weak_ptr_factory_(this) { | 28 weak_ptr_factory_(this) { |
27 DCHECK(manager); | 29 DCHECK(manager); |
28 } | 30 } |
29 | 31 |
30 AutofillExternalDelegate::~AutofillExternalDelegate() {} | 32 AutofillExternalDelegate::~AutofillExternalDelegate() {} |
31 | 33 |
32 void AutofillExternalDelegate::OnQuery(int query_id, | 34 void AutofillExternalDelegate::OnQuery(int query_id, |
33 const FormData& form, | 35 const FormData& form, |
34 const FormFieldData& field, | 36 const FormFieldData& field, |
35 const gfx::RectF& element_bounds, | 37 const gfx::RectF& element_bounds, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 labels.pop_back(); | 86 labels.pop_back(); |
85 icons.pop_back(); | 87 icons.pop_back(); |
86 ids.pop_back(); | 88 ids.pop_back(); |
87 } | 89 } |
88 | 90 |
89 // If anything else is added to modify the values after inserting the data | 91 // If anything else is added to modify the values after inserting the data |
90 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be | 92 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be |
91 // updated to match. | 93 // updated to match. |
92 InsertDataListValues(&values, &labels, &icons, &ids); | 94 InsertDataListValues(&values, &labels, &icons, &ids); |
93 | 95 |
96 #if defined(OS_MACOSX) | |
97 if (values.empty() && | |
98 manager_->ShouldShowAccessAddressBookSuggestion(query_form_, | |
99 query_field_)) { | |
100 values.push_back( | |
101 l10n_util::GetStringUTF16(IDS_AUTOFILL_ACCESS_MAC_CONTACTS)); | |
102 labels.push_back(base::string16()); | |
103 icons.push_back(base::string16()); | |
104 ids.push_back(POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); | |
105 } | |
106 #endif | |
107 | |
94 if (values.empty()) { | 108 if (values.empty()) { |
95 // No suggestions, any popup currently showing is obsolete. | 109 // No suggestions, any popup currently showing is obsolete. |
96 manager_->delegate()->HideAutofillPopup(); | 110 manager_->delegate()->HideAutofillPopup(); |
97 return; | 111 return; |
98 } | 112 } |
99 | 113 |
100 // Send to display. | 114 // Send to display. |
101 if (query_field_.is_focusable) { | 115 if (query_field_.is_focusable) { |
102 manager_->delegate()->ShowAutofillPopup( | 116 manager_->delegate()->ShowAutofillPopup( |
103 element_bounds_, | 117 element_bounds_, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 } else if (identifier == POPUP_ITEM_ID_CLEAR_FORM) { | 164 } else if (identifier == POPUP_ITEM_ID_CLEAR_FORM) { |
151 // User selected 'Clear form'. | 165 // User selected 'Clear form'. |
152 driver_->RendererShouldClearFilledForm(); | 166 driver_->RendererShouldClearFilledForm(); |
153 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { | 167 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { |
154 NOTREACHED(); // Should be handled elsewhere. | 168 NOTREACHED(); // Should be handled elsewhere. |
155 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { | 169 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { |
156 driver_->RendererShouldAcceptDataListSuggestion(value); | 170 driver_->RendererShouldAcceptDataListSuggestion(value); |
157 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { | 171 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { |
158 // User selected an Autocomplete, so we fill directly. | 172 // User selected an Autocomplete, so we fill directly. |
159 driver_->RendererShouldFillFieldWithValue(value); | 173 driver_->RendererShouldFillFieldWithValue(value); |
174 } else if (identifier == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) { | |
175 #if defined(OS_MACOSX) | |
176 // User wants to give Chrome access to user's address book. | |
177 bool modal_presented = manager_->AccessAddressBook(); | |
178 | |
179 // If a modal view was not presented, immediately refresh the popup. | |
180 if (!modal_presented) { | |
181 manager_->delegate()->HideAutofillPopup(); | |
182 ReissueQuery(); | |
183 return; | |
184 } | |
185 | |
186 // A blocking modal was presented. When the user responds, the text field | |
187 // loses focus. At that point, the user may have granted permission to their | |
188 // address book. Immediately redisplay the popup, which may contain new | |
189 // suggestions from the address book. | |
190 redisplay_popop_on_focus_lost_ = true; | |
Ilya Sherman
2014/05/23 15:47:10
Hmm, this still seems not really correct. Presuma
erikchen
2014/05/23 17:19:38
Focus is not lost as soon as the modal dialog is d
Ilya Sherman
2014/05/28 06:43:27
Hmm, this still seems like more complexity than we
| |
191 #else | |
192 NOTREACHED(); | |
193 #endif | |
160 } else { | 194 } else { |
161 FillAutofillFormData(identifier, false); | 195 FillAutofillFormData(identifier, false); |
162 } | 196 } |
163 | 197 |
164 manager_->delegate()->HideAutofillPopup(); | 198 manager_->delegate()->HideAutofillPopup(); |
165 } | 199 } |
166 | 200 |
167 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, | 201 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, |
168 int identifier) { | 202 int identifier) { |
169 if (identifier > 0) | 203 if (identifier > 0) |
170 manager_->RemoveAutofillProfileOrCreditCard(identifier); | 204 manager_->RemoveAutofillProfileOrCreditCard(identifier); |
171 else | 205 else |
172 manager_->RemoveAutocompleteEntry(query_field_.name, value); | 206 manager_->RemoveAutocompleteEntry(query_field_.name, value); |
173 } | 207 } |
174 | 208 |
175 void AutofillExternalDelegate::DidEndTextFieldEditing() { | 209 void AutofillExternalDelegate::DidEndTextFieldEditing() { |
176 manager_->delegate()->HideAutofillPopup(); | 210 manager_->delegate()->HideAutofillPopup(); |
177 | 211 |
178 has_shown_popup_for_current_edit_ = false; | 212 has_shown_popup_for_current_edit_ = false; |
213 | |
214 #if defined(OS_MACOSX) | |
215 // The user was presented a modal dialog, which they had to interact with | |
216 // before the Chrome process could resume. Their interaction is guaranteed to | |
217 // cause the text field to lose focus. They were either granting or denying | |
218 // Chrome access to their address book, so immediately try to redisplay the | |
219 // autofill popup. | |
220 if (redisplay_popop_on_focus_lost_) { | |
221 ReissueQuery(); | |
222 redisplay_popop_on_focus_lost_ = false; | |
223 } | |
224 #endif | |
179 } | 225 } |
180 | 226 |
181 void AutofillExternalDelegate::ClearPreviewedForm() { | 227 void AutofillExternalDelegate::ClearPreviewedForm() { |
182 driver_->RendererShouldClearPreviewedForm(); | 228 driver_->RendererShouldClearPreviewedForm(); |
183 } | 229 } |
184 | 230 |
185 void AutofillExternalDelegate::Reset() { | 231 void AutofillExternalDelegate::Reset() { |
186 manager_->delegate()->HideAutofillPopup(); | 232 manager_->delegate()->HideAutofillPopup(); |
187 } | 233 } |
188 | 234 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 | 347 |
302 // Set the values that all datalist elements share. | 348 // Set the values that all datalist elements share. |
303 icons->insert(icons->begin(), | 349 icons->insert(icons->begin(), |
304 data_list_values_.size(), | 350 data_list_values_.size(), |
305 base::string16()); | 351 base::string16()); |
306 unique_ids->insert(unique_ids->begin(), | 352 unique_ids->insert(unique_ids->begin(), |
307 data_list_values_.size(), | 353 data_list_values_.size(), |
308 POPUP_ITEM_ID_DATALIST_ENTRY); | 354 POPUP_ITEM_ID_DATALIST_ENTRY); |
309 } | 355 } |
310 | 356 |
357 #if defined(OS_MACOSX) | |
358 void AutofillExternalDelegate::ReissueQuery() { | |
359 manager_->OnQueryFormFieldAutofill(query_id_, | |
360 query_form_, | |
361 query_field_, | |
362 element_bounds_, | |
363 display_warning_if_disabled_); | |
364 } | |
365 #endif | |
366 | |
311 } // namespace autofill | 367 } // namespace autofill |
OLD | NEW |