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/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_autofill_(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 if (modal_presented) | |
| 179 redisplay_autofill_ = true; | |
|
Ilya Sherman
2014/05/22 15:13:59
Why does it matter whether the modal dialog was pr
erikchen
2014/05/22 20:40:59
It's important to not set the redisplay_popop_on_f
| |
| 180 #else | |
| 181 NOTREACHED(); | |
| 182 #endif | |
| 160 } else { | 183 } else { |
| 161 FillAutofillFormData(identifier, false); | 184 FillAutofillFormData(identifier, false); |
| 162 } | 185 } |
| 163 | 186 |
| 164 manager_->delegate()->HideAutofillPopup(); | 187 manager_->delegate()->HideAutofillPopup(); |
| 165 } | 188 } |
| 166 | 189 |
| 167 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, | 190 void AutofillExternalDelegate::RemoveSuggestion(const base::string16& value, |
| 168 int identifier) { | 191 int identifier) { |
| 169 if (identifier > 0) | 192 if (identifier > 0) |
| 170 manager_->RemoveAutofillProfileOrCreditCard(identifier); | 193 manager_->RemoveAutofillProfileOrCreditCard(identifier); |
| 171 else | 194 else |
| 172 manager_->RemoveAutocompleteEntry(query_field_.name, value); | 195 manager_->RemoveAutocompleteEntry(query_field_.name, value); |
| 173 } | 196 } |
| 174 | 197 |
| 175 void AutofillExternalDelegate::DidEndTextFieldEditing() { | 198 void AutofillExternalDelegate::DidEndTextFieldEditing() { |
| 176 manager_->delegate()->HideAutofillPopup(); | 199 manager_->delegate()->HideAutofillPopup(); |
| 177 | 200 |
| 178 has_shown_popup_for_current_edit_ = false; | 201 has_shown_popup_for_current_edit_ = false; |
| 202 | |
| 203 #if defined(OS_MACOSX) | |
| 204 // The user was presented a modal dialog, which they had to interact with | |
| 205 // before the Chrome process could resume. Their interaction is guaranteed to | |
| 206 // cause the text field to lose focus. They were either granting or denying | |
| 207 // Chrome access to their address book, so immediately try to redisplay the | |
| 208 // autofill popup. | |
| 209 if (redisplay_autofill_) { | |
| 210 manager_->OnQueryFormFieldAutofill(query_id_, | |
| 211 query_form_, | |
| 212 query_field_, | |
| 213 element_bounds_, | |
| 214 display_warning_if_disabled_); | |
| 215 redisplay_autofill_ = false; | |
| 216 } | |
| 217 #endif | |
| 179 } | 218 } |
| 180 | 219 |
| 181 void AutofillExternalDelegate::ClearPreviewedForm() { | 220 void AutofillExternalDelegate::ClearPreviewedForm() { |
| 182 driver_->RendererShouldClearPreviewedForm(); | 221 driver_->RendererShouldClearPreviewedForm(); |
| 183 } | 222 } |
| 184 | 223 |
| 185 void AutofillExternalDelegate::Reset() { | 224 void AutofillExternalDelegate::Reset() { |
| 186 manager_->delegate()->HideAutofillPopup(); | 225 manager_->delegate()->HideAutofillPopup(); |
| 187 } | 226 } |
| 188 | 227 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 // Set the values that all datalist elements share. | 341 // Set the values that all datalist elements share. |
| 303 icons->insert(icons->begin(), | 342 icons->insert(icons->begin(), |
| 304 data_list_values_.size(), | 343 data_list_values_.size(), |
| 305 base::string16()); | 344 base::string16()); |
| 306 unique_ids->insert(unique_ids->begin(), | 345 unique_ids->insert(unique_ids->begin(), |
| 307 data_list_values_.size(), | 346 data_list_values_.size(), |
| 308 POPUP_ITEM_ID_DATALIST_ENTRY); | 347 POPUP_ITEM_ID_DATALIST_ENTRY); |
| 309 } | 348 } |
| 310 | 349 |
| 311 } // namespace autofill | 350 } // namespace autofill |
| OLD | NEW |