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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
8 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 9 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
9 #include "components/autofill/core/browser/autofill_driver.h" | 10 #include "components/autofill/core/browser/autofill_driver.h" |
10 #include "components/autofill/core/browser/autofill_manager.h" | 11 #include "components/autofill/core/browser/autofill_manager.h" |
11 #include "components/autofill/core/browser/popup_item_ids.h" | 12 #include "components/autofill/core/browser/popup_item_ids.h" |
12 #include "grit/component_strings.h" | 13 #include "grit/component_strings.h" |
13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
14 | 15 |
15 namespace autofill { | 16 namespace autofill { |
16 | 17 |
17 AutofillExternalDelegate::AutofillExternalDelegate( | 18 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, |
18 AutofillManager* manager, | 19 AutofillDriver* driver) |
19 AutofillDriver* driver) | |
20 : manager_(manager), | 20 : manager_(manager), |
21 driver_(driver), | 21 driver_(driver), |
22 query_id_(0), | 22 query_id_(0), |
23 display_warning_if_disabled_(false), | 23 display_warning_if_disabled_(false), |
24 has_suggestion_(false), | 24 has_suggestion_(false), |
25 has_shown_popup_for_current_edit_(false), | 25 has_shown_popup_for_current_edit_(false), |
26 weak_ptr_factory_(this) { | 26 weak_ptr_factory_(this) { |
27 DCHECK(manager); | 27 DCHECK(manager); |
28 } | 28 } |
29 | 29 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 labels.pop_back(); | 84 labels.pop_back(); |
85 icons.pop_back(); | 85 icons.pop_back(); |
86 ids.pop_back(); | 86 ids.pop_back(); |
87 } | 87 } |
88 | 88 |
89 // If anything else is added to modify the values after inserting the data | 89 // If anything else is added to modify the values after inserting the data |
90 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be | 90 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be |
91 // updated to match. | 91 // updated to match. |
92 InsertDataListValues(&values, &labels, &icons, &ids); | 92 InsertDataListValues(&values, &labels, &icons, &ids); |
93 | 93 |
94 #if defined(OS_MACOSX) | |
95 if (values.empty() && | |
96 manager_->ShouldShowAccessAddressBookSuggestion(query_form_, | |
97 query_field_)) { | |
98 values.push_back( | |
99 l10n_util::GetStringUTF16(IDS_AUTOFILL_ACCESS_MAC_CONTACTS)); | |
100 labels.push_back(base::string16()); | |
101 icons.push_back(base::string16()); | |
102 ids.push_back(POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); | |
103 } | |
104 #endif | |
105 | |
94 if (values.empty()) { | 106 if (values.empty()) { |
95 // No suggestions, any popup currently showing is obsolete. | 107 // No suggestions, any popup currently showing is obsolete. |
96 manager_->delegate()->HideAutofillPopup(); | 108 manager_->delegate()->HideAutofillPopup(); |
97 return; | 109 return; |
98 } | 110 } |
99 | 111 |
100 // Send to display. | 112 // Send to display. |
101 if (query_field_.is_focusable) { | 113 if (query_field_.is_focusable) { |
102 manager_->delegate()->ShowAutofillPopup( | 114 manager_->delegate()->ShowAutofillPopup( |
103 element_bounds_, | 115 element_bounds_, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 } else if (identifier == POPUP_ITEM_ID_CLEAR_FORM) { | 162 } else if (identifier == POPUP_ITEM_ID_CLEAR_FORM) { |
151 // User selected 'Clear form'. | 163 // User selected 'Clear form'. |
152 driver_->RendererShouldClearFilledForm(); | 164 driver_->RendererShouldClearFilledForm(); |
153 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { | 165 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { |
154 NOTREACHED(); // Should be handled elsewhere. | 166 NOTREACHED(); // Should be handled elsewhere. |
155 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { | 167 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { |
156 driver_->RendererShouldAcceptDataListSuggestion(value); | 168 driver_->RendererShouldAcceptDataListSuggestion(value); |
157 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { | 169 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { |
158 // User selected an Autocomplete, so we fill directly. | 170 // User selected an Autocomplete, so we fill directly. |
159 driver_->RendererShouldFillFieldWithValue(value); | 171 driver_->RendererShouldFillFieldWithValue(value); |
172 } else if (identifier == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) { | |
173 #if defined(OS_MACOSX) | |
174 // User wants to give Chrome access to user's address book. | |
175 manager_->AccessAddressBook(); | |
176 | |
177 // A blocking modal was presented, and the user has already responded to the | |
Ilya Sherman
2014/05/29 01:28:24
nit: The blocking modal might not have been presen
erikchen
2014/05/29 20:31:31
Done.
| |
178 // modal. The user's response added an NSEvent to the NSRunLoop. When the | |
179 // NSEvent is processed, it will be sent to the renderer, which will send | |
180 // back an IPC to cause the text field to lose focus, which will dismiss the | |
Ilya Sherman
2014/05/29 01:28:24
nit: Technically, the text field loses focus on th
erikchen
2014/05/29 20:31:31
Done. I've rewritten the comment block to add clar
| |
181 // autofill popup. We queue a task which will ping the renderer. When the | |
182 // renderer returns an IPC acknowledging the ping, FIFO processing of IPCs | |
183 // ensures that all side effects the blocking modal will have been | |
Ilya Sherman
2014/05/29 01:28:24
nit: "all side effects the blocking modal" -> "all
erikchen
2014/05/29 20:31:31
Done.
| |
184 // processed. At that time, redisplay the popup. | |
185 base::MessageLoop::current()->PostTask( | |
186 FROM_HERE, | |
187 base::Bind(&AutofillExternalDelegate::PingRenderer, GetWeakPtr())); | |
188 #else | |
189 NOTREACHED(); | |
190 #endif | |
160 } else { | 191 } else { |
161 FillAutofillFormData(identifier, false); | 192 FillAutofillFormData(identifier, false); |
162 } | 193 } |
163 | 194 |
164 manager_->delegate()->HideAutofillPopup(); | 195 manager_->delegate()->HideAutofillPopup(); |
165 } | 196 } |
166 | 197 |
167 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, | 198 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, |
168 int identifier) { | 199 int identifier) { |
169 if (identifier > 0) | 200 if (identifier > 0) |
170 manager_->RemoveAutofillProfileOrCreditCard(identifier); | 201 manager_->RemoveAutofillProfileOrCreditCard(identifier); |
171 else | 202 else |
172 manager_->RemoveAutocompleteEntry(query_field_.name, value); | 203 manager_->RemoveAutocompleteEntry(query_field_.name, value); |
173 } | 204 } |
174 | 205 |
175 void AutofillExternalDelegate::DidEndTextFieldEditing() { | 206 void AutofillExternalDelegate::DidEndTextFieldEditing() { |
176 manager_->delegate()->HideAutofillPopup(); | 207 manager_->delegate()->HideAutofillPopup(); |
177 | 208 |
178 has_shown_popup_for_current_edit_ = false; | 209 has_shown_popup_for_current_edit_ = false; |
179 } | 210 } |
180 | 211 |
181 void AutofillExternalDelegate::ClearPreviewedForm() { | 212 void AutofillExternalDelegate::ClearPreviewedForm() { |
182 driver_->RendererShouldClearPreviewedForm(); | 213 driver_->RendererShouldClearPreviewedForm(); |
183 } | 214 } |
184 | 215 |
185 void AutofillExternalDelegate::Reset() { | 216 void AutofillExternalDelegate::Reset() { |
186 manager_->delegate()->HideAutofillPopup(); | 217 manager_->delegate()->HideAutofillPopup(); |
187 } | 218 } |
188 | 219 |
220 void AutofillExternalDelegate::OnPingAck() { | |
221 ReissueQuery(); | |
Ilya Sherman
2014/05/29 01:28:24
nit: Possibly worth just inlining the code at this
erikchen
2014/05/29 20:31:31
Done.
| |
222 } | |
223 | |
189 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { | 224 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { |
190 return weak_ptr_factory_.GetWeakPtr(); | 225 return weak_ptr_factory_.GetWeakPtr(); |
191 } | 226 } |
192 | 227 |
193 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, | 228 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, |
194 bool is_preview) { | 229 bool is_preview) { |
195 // If the selected element is a warning we don't want to do anything. | 230 // If the selected element is a warning we don't want to do anything. |
196 if (unique_id == POPUP_ITEM_ID_WARNING_MESSAGE) | 231 if (unique_id == POPUP_ITEM_ID_WARNING_MESSAGE) |
197 return; | 232 return; |
198 | 233 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 | 336 |
302 // Set the values that all datalist elements share. | 337 // Set the values that all datalist elements share. |
303 icons->insert(icons->begin(), | 338 icons->insert(icons->begin(), |
304 data_list_values_.size(), | 339 data_list_values_.size(), |
305 base::string16()); | 340 base::string16()); |
306 unique_ids->insert(unique_ids->begin(), | 341 unique_ids->insert(unique_ids->begin(), |
307 data_list_values_.size(), | 342 data_list_values_.size(), |
308 POPUP_ITEM_ID_DATALIST_ENTRY); | 343 POPUP_ITEM_ID_DATALIST_ENTRY); |
309 } | 344 } |
310 | 345 |
346 #if defined(OS_MACOSX) | |
347 void AutofillExternalDelegate::ReissueQuery() { | |
348 manager_->OnQueryFormFieldAutofill(query_id_, | |
349 query_form_, | |
350 query_field_, | |
351 element_bounds_, | |
352 display_warning_if_disabled_); | |
353 } | |
354 | |
355 void AutofillExternalDelegate::PingRenderer() { | |
356 driver_->PingRenderer(); | |
357 } | |
358 #endif | |
359 | |
311 } // namespace autofill | 360 } // namespace autofill |
OLD | NEW |