| 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( |
| 18 AutofillManager* autofill_manager, | 18 AutofillManager* autofill_manager, |
| 19 AutofillDriver* autofill_driver) | 19 AutofillDriver* autofill_driver, |
| 20 PasswordAutofillManager* password_autofill_manager) |
| 20 : autofill_manager_(autofill_manager), | 21 : autofill_manager_(autofill_manager), |
| 21 autofill_driver_(autofill_driver), | 22 autofill_driver_(autofill_driver), |
| 22 password_autofill_manager_(autofill_driver), | 23 password_autofill_manager_(password_autofill_manager), |
| 23 autofill_query_id_(0), | 24 autofill_query_id_(0), |
| 24 display_warning_if_disabled_(false), | 25 display_warning_if_disabled_(false), |
| 25 has_autofill_suggestion_(false), | 26 has_autofill_suggestion_(false), |
| 26 has_shown_autofill_popup_for_current_edit_(false), | 27 has_shown_autofill_popup_for_current_edit_(false), |
| 27 weak_ptr_factory_(this) { | 28 weak_ptr_factory_(this) { |
| 28 DCHECK(autofill_manager); | 29 DCHECK(autofill_manager); |
| 29 } | 30 } |
| 30 | 31 |
| 31 AutofillExternalDelegate::~AutofillExternalDelegate() {} | 32 AutofillExternalDelegate::~AutofillExternalDelegate() {} |
| 32 | 33 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 173 |
| 173 void AutofillExternalDelegate::DidAcceptSuggestion(const base::string16& value, | 174 void AutofillExternalDelegate::DidAcceptSuggestion(const base::string16& value, |
| 174 int identifier) { | 175 int identifier) { |
| 175 if (identifier == POPUP_ITEM_ID_AUTOFILL_OPTIONS) { | 176 if (identifier == POPUP_ITEM_ID_AUTOFILL_OPTIONS) { |
| 176 // User selected 'Autofill Options'. | 177 // User selected 'Autofill Options'. |
| 177 autofill_manager_->ShowAutofillSettings(); | 178 autofill_manager_->ShowAutofillSettings(); |
| 178 } else if (identifier == POPUP_ITEM_ID_CLEAR_FORM) { | 179 } else if (identifier == POPUP_ITEM_ID_CLEAR_FORM) { |
| 179 // User selected 'Clear form'. | 180 // User selected 'Clear form'. |
| 180 autofill_driver_->RendererShouldClearFilledForm(); | 181 autofill_driver_->RendererShouldClearFilledForm(); |
| 181 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { | 182 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { |
| 182 bool success = password_autofill_manager_.DidAcceptAutofillSuggestion( | 183 bool success = password_autofill_manager_->DidAcceptAutofillSuggestion( |
| 183 autofill_query_field_, value); | 184 autofill_query_field_, value); |
| 184 DCHECK(success); | 185 DCHECK(success); |
| 185 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { | 186 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { |
| 186 autofill_driver_->RendererShouldAcceptDataListSuggestion(value); | 187 autofill_driver_->RendererShouldAcceptDataListSuggestion(value); |
| 187 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { | 188 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { |
| 188 // User selected an Autocomplete, so we fill directly. | 189 // User selected an Autocomplete, so we fill directly. |
| 189 autofill_driver_->RendererShouldSetNodeText(value); | 190 autofill_driver_->RendererShouldSetNodeText(value); |
| 190 } else { | 191 } else { |
| 191 FillAutofillFormData(identifier, false); | 192 FillAutofillFormData(identifier, false); |
| 192 } | 193 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 209 | 210 |
| 210 has_shown_autofill_popup_for_current_edit_ = false; | 211 has_shown_autofill_popup_for_current_edit_ = false; |
| 211 } | 212 } |
| 212 | 213 |
| 213 void AutofillExternalDelegate::ClearPreviewedForm() { | 214 void AutofillExternalDelegate::ClearPreviewedForm() { |
| 214 autofill_driver_->RendererShouldClearPreviewedForm(); | 215 autofill_driver_->RendererShouldClearPreviewedForm(); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void AutofillExternalDelegate::Reset() { | 218 void AutofillExternalDelegate::Reset() { |
| 218 autofill_manager_->delegate()->HideAutofillPopup(); | 219 autofill_manager_->delegate()->HideAutofillPopup(); |
| 219 | 220 password_autofill_manager_->Reset(); |
| 220 password_autofill_manager_.Reset(); | |
| 221 } | 221 } |
| 222 | 222 |
| 223 void AutofillExternalDelegate::AddPasswordFormMapping( | 223 void AutofillExternalDelegate::AddPasswordFormMapping( |
| 224 const FormFieldData& username_field, | 224 const FormFieldData& username_field, |
| 225 const PasswordFormFillData& fill_data) { | 225 const PasswordFormFillData& fill_data) { |
| 226 password_autofill_manager_.AddPasswordFormMapping(username_field, fill_data); | 226 password_autofill_manager_->AddPasswordFormMapping(username_field, fill_data); |
| 227 } | 227 } |
| 228 | 228 |
| 229 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { | 229 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { |
| 230 return weak_ptr_factory_.GetWeakPtr(); | 230 return weak_ptr_factory_.GetWeakPtr(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, | 233 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, |
| 234 bool is_preview) { | 234 bool is_preview) { |
| 235 // If the selected element is a warning we don't want to do anything. | 235 // If the selected element is a warning we don't want to do anything. |
| 236 if (unique_id == POPUP_ITEM_ID_WARNING_MESSAGE) | 236 if (unique_id == POPUP_ITEM_ID_WARNING_MESSAGE) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // Set the values that all datalist elements share. | 344 // Set the values that all datalist elements share. |
| 345 autofill_icons->insert(autofill_icons->begin(), | 345 autofill_icons->insert(autofill_icons->begin(), |
| 346 data_list_values_.size(), | 346 data_list_values_.size(), |
| 347 base::string16()); | 347 base::string16()); |
| 348 autofill_unique_ids->insert(autofill_unique_ids->begin(), | 348 autofill_unique_ids->insert(autofill_unique_ids->begin(), |
| 349 data_list_values_.size(), | 349 data_list_values_.size(), |
| 350 POPUP_ITEM_ID_DATALIST_ENTRY); | 350 POPUP_ITEM_ID_DATALIST_ENTRY); |
| 351 } | 351 } |
| 352 | 352 |
| 353 } // namespace autofill | 353 } // namespace autofill |
| OLD | NEW |