Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: components/autofill/core/browser/autofill_external_delegate.cc

Issue 184103016: Autofill: Refactoring to support fetching password after a username is selected (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor PasswordAutofillManager in password_manager component. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 : autofill_manager_(autofill_manager), 20 : autofill_manager_(autofill_manager),
21 autofill_driver_(autofill_driver), 21 autofill_driver_(autofill_driver),
22 password_autofill_manager_(autofill_driver),
23 autofill_query_id_(0), 22 autofill_query_id_(0),
24 display_warning_if_disabled_(false), 23 display_warning_if_disabled_(false),
25 has_autofill_suggestion_(false), 24 has_autofill_suggestion_(false),
26 has_shown_autofill_popup_for_current_edit_(false), 25 has_shown_autofill_popup_for_current_edit_(false),
27 weak_ptr_factory_(this) { 26 weak_ptr_factory_(this) {
28 DCHECK(autofill_manager); 27 DCHECK(autofill_manager);
29 } 28 }
30 29
31 AutofillExternalDelegate::~AutofillExternalDelegate() {} 30 AutofillExternalDelegate::~AutofillExternalDelegate() {}
32 31
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 element_bounds_, 103 element_bounds_,
105 autofill_query_field_.text_direction, 104 autofill_query_field_.text_direction,
106 values, 105 values,
107 labels, 106 labels,
108 icons, 107 icons,
109 ids, 108 ids,
110 GetWeakPtr()); 109 GetWeakPtr());
111 } 110 }
112 } 111 }
113 112
114 void AutofillExternalDelegate::OnShowPasswordSuggestions(
115 const std::vector<base::string16>& suggestions,
116 const std::vector<base::string16>& realms,
117 const FormFieldData& field,
118 const gfx::RectF& element_bounds) {
119 autofill_query_field_ = field;
120 element_bounds_ = element_bounds;
121
122 if (suggestions.empty()) {
123 autofill_manager_->delegate()->HideAutofillPopup();
124 return;
125 }
126
127 std::vector<base::string16> empty(suggestions.size());
128 std::vector<int> password_ids(suggestions.size(),
129 POPUP_ITEM_ID_PASSWORD_ENTRY);
130 autofill_manager_->delegate()->ShowAutofillPopup(
131 element_bounds_,
132 autofill_query_field_.text_direction,
133 suggestions,
134 realms,
135 empty,
136 password_ids,
137 GetWeakPtr());
138 }
139
140 void AutofillExternalDelegate::SetCurrentDataListValues( 113 void AutofillExternalDelegate::SetCurrentDataListValues(
141 const std::vector<base::string16>& data_list_values, 114 const std::vector<base::string16>& data_list_values,
142 const std::vector<base::string16>& data_list_labels) { 115 const std::vector<base::string16>& data_list_labels) {
143 data_list_values_ = data_list_values; 116 data_list_values_ = data_list_values;
144 data_list_labels_ = data_list_labels; 117 data_list_labels_ = data_list_labels;
145 118
146 autofill_manager_->delegate()->UpdateAutofillPopupDataListValues( 119 autofill_manager_->delegate()->UpdateAutofillPopupDataListValues(
147 data_list_values, 120 data_list_values,
148 data_list_labels); 121 data_list_labels);
149 } 122 }
(...skipping 22 matching lines...) Expand all
172 145
173 void AutofillExternalDelegate::DidAcceptSuggestion(const base::string16& value, 146 void AutofillExternalDelegate::DidAcceptSuggestion(const base::string16& value,
174 int identifier) { 147 int identifier) {
175 if (identifier == POPUP_ITEM_ID_AUTOFILL_OPTIONS) { 148 if (identifier == POPUP_ITEM_ID_AUTOFILL_OPTIONS) {
176 // User selected 'Autofill Options'. 149 // User selected 'Autofill Options'.
177 autofill_manager_->ShowAutofillSettings(); 150 autofill_manager_->ShowAutofillSettings();
178 } else if (identifier == POPUP_ITEM_ID_CLEAR_FORM) { 151 } else if (identifier == POPUP_ITEM_ID_CLEAR_FORM) {
179 // User selected 'Clear form'. 152 // User selected 'Clear form'.
180 autofill_driver_->RendererShouldClearFilledForm(); 153 autofill_driver_->RendererShouldClearFilledForm();
181 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { 154 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) {
182 bool success = password_autofill_manager_.DidAcceptAutofillSuggestion( 155 NOTREACHED(); // Should be handled elsewhere.
183 autofill_query_field_, value);
184 DCHECK(success);
185 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { 156 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) {
186 autofill_driver_->RendererShouldAcceptDataListSuggestion(value); 157 autofill_driver_->RendererShouldAcceptDataListSuggestion(value);
187 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { 158 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) {
188 // User selected an Autocomplete, so we fill directly. 159 // User selected an Autocomplete, so we fill directly.
189 autofill_driver_->RendererShouldSetNodeText(value); 160 autofill_driver_->RendererShouldSetNodeText(value);
190 } else { 161 } else {
191 FillAutofillFormData(identifier, false); 162 FillAutofillFormData(identifier, false);
192 } 163 }
193 164
194 autofill_manager_->delegate()->HideAutofillPopup(); 165 autofill_manager_->delegate()->HideAutofillPopup();
(...skipping 14 matching lines...) Expand all
209 180
210 has_shown_autofill_popup_for_current_edit_ = false; 181 has_shown_autofill_popup_for_current_edit_ = false;
211 } 182 }
212 183
213 void AutofillExternalDelegate::ClearPreviewedForm() { 184 void AutofillExternalDelegate::ClearPreviewedForm() {
214 autofill_driver_->RendererShouldClearPreviewedForm(); 185 autofill_driver_->RendererShouldClearPreviewedForm();
215 } 186 }
216 187
217 void AutofillExternalDelegate::Reset() { 188 void AutofillExternalDelegate::Reset() {
218 autofill_manager_->delegate()->HideAutofillPopup(); 189 autofill_manager_->delegate()->HideAutofillPopup();
219
220 password_autofill_manager_.Reset();
221 }
222
223 void AutofillExternalDelegate::AddPasswordFormMapping(
224 const FormFieldData& username_field,
225 const PasswordFormFillData& fill_data) {
226 password_autofill_manager_.AddPasswordFormMapping(username_field, fill_data);
227 } 190 }
228 191
229 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { 192 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() {
230 return weak_ptr_factory_.GetWeakPtr(); 193 return weak_ptr_factory_.GetWeakPtr();
231 } 194 }
232 195
233 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, 196 void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
234 bool is_preview) { 197 bool is_preview) {
235 // If the selected element is a warning we don't want to do anything. 198 // If the selected element is a warning we don't want to do anything.
236 if (unique_id == POPUP_ITEM_ID_WARNING_MESSAGE) 199 if (unique_id == POPUP_ITEM_ID_WARNING_MESSAGE)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // Set the values that all datalist elements share. 307 // Set the values that all datalist elements share.
345 autofill_icons->insert(autofill_icons->begin(), 308 autofill_icons->insert(autofill_icons->begin(),
346 data_list_values_.size(), 309 data_list_values_.size(),
347 base::string16()); 310 base::string16());
348 autofill_unique_ids->insert(autofill_unique_ids->begin(), 311 autofill_unique_ids->insert(autofill_unique_ids->begin(),
349 data_list_values_.size(), 312 data_list_values_.size(),
350 POPUP_ITEM_ID_DATALIST_ENTRY); 313 POPUP_ITEM_ID_DATALIST_ENTRY);
351 } 314 }
352 315
353 } // namespace autofill 316 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698