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

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate.cc

Issue 9600038: Add Password Autofill Manager to New Autofill (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixing final nits Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autofill/autofill_external_delegate.h" 6 #include "chrome/browser/autofill/autofill_external_delegate.h"
7 #include "chrome/browser/autofill/autofill_manager.h" 7 #include "chrome/browser/autofill/autofill_manager.h"
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
9 #include "chrome/common/autofill_messages.h" 9 #include "chrome/common/autofill_messages.h"
10 #include "chrome/common/chrome_constants.h" 10 #include "chrome/common/chrome_constants.h"
11 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "grit/chromium_strings.h" 13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 16
17 using content::RenderViewHost; 17 using content::RenderViewHost;
18 18
19 namespace {
20
21 // The value to give as the unique id for all warnings.
22 const int kWarningId = -1;
23
24 // The value to give as the unique id for all password entries.
25 const int kPasswordEntryId = -2;
26
27 } // namespace
28
19 AutofillExternalDelegate::~AutofillExternalDelegate() { 29 AutofillExternalDelegate::~AutofillExternalDelegate() {
20 } 30 }
21 31
22 AutofillExternalDelegate::AutofillExternalDelegate( 32 AutofillExternalDelegate::AutofillExternalDelegate(
23 TabContentsWrapper* tab_contents_wrapper, 33 TabContentsWrapper* tab_contents_wrapper,
24 AutofillManager* autofill_manager) 34 AutofillManager* autofill_manager)
25 : tab_contents_wrapper_(tab_contents_wrapper), 35 : tab_contents_wrapper_(tab_contents_wrapper),
26 autofill_manager_(autofill_manager), 36 autofill_manager_(autofill_manager),
37 password_autofill_manager_(
38 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL),
27 autofill_query_id_(0), 39 autofill_query_id_(0),
28 display_warning_if_disabled_(false), 40 display_warning_if_disabled_(false),
29 has_shown_autofill_popup_for_current_edit_(false), 41 has_shown_autofill_popup_for_current_edit_(false),
30 suggestions_clear_index_(-1), 42 suggestions_clear_index_(-1),
31 suggestions_options_index_(-1) { 43 suggestions_options_index_(-1) {
32 } 44 }
33 45
34 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, 46 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id,
35 int list_index) { 47 int list_index) {
48 if (password_autofill_manager_.DidSelectAutofillSuggestion(
49 autofill_query_field_))
50 return;
51
36 if (list_index == suggestions_options_index_ || 52 if (list_index == suggestions_options_index_ ||
37 list_index == suggestions_clear_index_ || 53 list_index == suggestions_clear_index_ ||
38 unique_id == -1) 54 unique_id == kWarningId)
39 return; 55 return;
40 56
41 FillAutofillFormData(unique_id, true); 57 FillAutofillFormData(unique_id, true);
42 } 58 }
43 59
44 void AutofillExternalDelegate::OnQuery(int query_id, 60 void AutofillExternalDelegate::OnQuery(int query_id,
45 const webkit::forms::FormData& form, 61 const webkit::forms::FormData& form,
46 const webkit::forms::FormField& field, 62 const webkit::forms::FormField& field,
47 const gfx::Rect& bounds, 63 const gfx::Rect& bounds,
48 bool display_warning_if_disabled) { 64 bool display_warning_if_disabled) {
(...skipping 25 matching lines...) Expand all
74 std::vector<string16> i(icons); 90 std::vector<string16> i(icons);
75 std::vector<int> ids(unique_ids); 91 std::vector<int> ids(unique_ids);
76 int separator_index = -1; 92 int separator_index = -1;
77 93
78 DCHECK_GT(ids.size(), 0U); 94 DCHECK_GT(ids.size(), 0U);
79 if (!autofill_query_field_.should_autocomplete) { 95 if (!autofill_query_field_.should_autocomplete) {
80 // If autofill is disabled and we had suggestions, show a warning instead. 96 // If autofill is disabled and we had suggestions, show a warning instead.
81 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); 97 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
82 l.assign(1, string16()); 98 l.assign(1, string16());
83 i.assign(1, string16()); 99 i.assign(1, string16());
84 ids.assign(1, -1); 100 ids.assign(1, kWarningId);
85 } else if (ids[0] < 0 && ids.size() > 1) { 101 } else if (ids[0] < 0 && ids.size() > 1) {
86 // If we received a warning instead of suggestions from autofill but regular 102 // If we received a warning instead of suggestions from autofill but regular
87 // suggestions from autocomplete, don't show the autofill warning. 103 // suggestions from autocomplete, don't show the autofill warning.
88 v.erase(v.begin()); 104 v.erase(v.begin());
89 l.erase(l.begin()); 105 l.erase(l.begin());
90 i.erase(i.begin()); 106 i.erase(i.begin());
91 ids.erase(ids.begin()); 107 ids.erase(ids.begin());
92 } 108 }
93 109
94 // If we were about to show a warning and we shouldn't, don't. 110 // If we were about to show a warning and we shouldn't, don't.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 145
130 // Send to display. 146 // Send to display.
131 if (!v.empty() && autofill_query_field_.is_focusable) 147 if (!v.empty() && autofill_query_field_.is_focusable)
132 ApplyAutofillSuggestions(v, l, i, ids, separator_index); 148 ApplyAutofillSuggestions(v, l, i, ids, separator_index);
133 149
134 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( 150 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions(
135 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); 151 has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
136 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; 152 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
137 } 153 }
138 154
155 void AutofillExternalDelegate::OnShowPasswordSuggestions(
156 const std::vector<string16>& suggestions,
157 const webkit::forms::FormField& field,
158 const gfx::Rect& bounds) {
159 autofill_query_field_ = field;
160
161 if (suggestions.empty()) {
162 HideAutofillPopup();
163 return;
164 }
165
166 SetBounds(bounds);
167
168 std::vector<string16> empty(suggestions.size());
169 std::vector<int> password_ids(suggestions.size(), kPasswordEntryId);
170 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1);
171 }
172
139 void AutofillExternalDelegate::DidEndTextFieldEditing() { 173 void AutofillExternalDelegate::DidEndTextFieldEditing() {
140 has_shown_autofill_popup_for_current_edit_ = false; 174 has_shown_autofill_popup_for_current_edit_ = false;
141 } 175 }
142 176
143 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( 177 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
144 const string16& value, 178 const string16& value,
145 int unique_id, 179 int unique_id,
146 unsigned index) { 180 unsigned index) {
147 // If the selected element is a warning we don't want to do anything. 181 // If the selected element is a warning we don't want to do anything.
148 if (unique_id < 0) 182 if (unique_id == kWarningId)
149 return false; 183 return false;
150 184
151 // TODO(csharp): Add the password autofill manager.
152 // if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value))
153 // return;
154
155 if (suggestions_options_index_ != -1 && 185 if (suggestions_options_index_ != -1 &&
156 index == static_cast<unsigned>(suggestions_options_index_)) { 186 index == static_cast<unsigned>(suggestions_options_index_)) {
157 // User selected 'Autofill Options'. 187 // User selected 'Autofill Options'.
158 autofill_manager_->OnShowAutofillDialog(); 188 autofill_manager_->OnShowAutofillDialog();
159 } else if (suggestions_clear_index_ != -1 && 189 } else if (suggestions_clear_index_ != -1 &&
160 index == static_cast<unsigned>(suggestions_clear_index_)) { 190 index == static_cast<unsigned>(suggestions_clear_index_)) {
161 // User selected 'Clear form'. 191 // User selected 'Clear form'.
162 RenderViewHost* host = 192 RenderViewHost* host =
163 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 193 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
164 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); 194 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
195 } else if (password_autofill_manager_.DidAcceptAutofillSuggestion(
196 autofill_query_field_, value)) {
197 // DidAcceptAutofillSuggestion has already handled the work to fill in
198 // the page as required.
165 } else if (!unique_id) { 199 } else if (!unique_id) {
166 // User selected an Autocomplete entry, so we fill directly. 200 // User selected an Autocomplete, so we fill directly.
167 RenderViewHost* host = 201 RenderViewHost* host =
168 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 202 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
169 host->Send(new AutofillMsg_SetNodeText( 203 host->Send(new AutofillMsg_SetNodeText(
170 host->GetRoutingID(), 204 host->GetRoutingID(),
171 value)); 205 value));
172 } else { 206 } else {
173 FillAutofillFormData(unique_id, false); 207 FillAutofillFormData(unique_id, false);
174 } 208 }
175 209
176 HideAutofillPopup(); 210 HideAutofillPopup();
177 211
178 return true; 212 return true;
179 } 213 }
180 214
181 void AutofillExternalDelegate::ClearPreviewedForm() { 215 void AutofillExternalDelegate::ClearPreviewedForm() {
216 if (password_autofill_manager_.DidClearAutofillSelection(
217 autofill_query_field_))
218 return;
219
182 RenderViewHost* host = 220 RenderViewHost* host =
183 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 221 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
184 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); 222 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID()));
185 } 223 }
186 224
187 void AutofillExternalDelegate::HideAutofillPopup() { 225 void AutofillExternalDelegate::HideAutofillPopup() {
188 suggestions_clear_index_ = -1; 226 suggestions_clear_index_ = -1;
189 suggestions_options_index_ = -1; 227 suggestions_options_index_ = -1;
190 228
191 HideAutofillPopupInternal(); 229 HideAutofillPopupInternal();
192 } 230 }
193 231
232 void AutofillExternalDelegate::Reset() {
233 HideAutofillPopup();
234
235 password_autofill_manager_.Reset();
236 }
237
238 void AutofillExternalDelegate::AddPasswordFormMapping(
239 const webkit::forms::FormField& form,
240 const webkit::forms::PasswordFormFillData& fill_data) {
241 password_autofill_manager_.AddPasswordFormMapping(form, fill_data);
242 }
243
194 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, 244 void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
195 bool is_preview) { 245 bool is_preview) {
196 RenderViewHost* host = 246 RenderViewHost* host =
197 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 247 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
198 248
199 if (is_preview) { 249 if (is_preview) {
200 host->Send(new AutofillMsg_SetAutofillActionPreview( 250 host->Send(new AutofillMsg_SetAutofillActionPreview(
201 host->GetRoutingID())); 251 host->GetRoutingID()));
202 } else { 252 } else {
203 host->Send(new AutofillMsg_SetAutofillActionFill( 253 host->Send(new AutofillMsg_SetAutofillActionFill(
(...skipping 12 matching lines...) Expand all
216 // none, so all platforms use the default. 266 // none, so all platforms use the default.
217 267
218 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 268 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
219 269
220 AutofillExternalDelegate* AutofillExternalDelegate::Create( 270 AutofillExternalDelegate* AutofillExternalDelegate::Create(
221 TabContentsWrapper*, AutofillManager*) { 271 TabContentsWrapper*, AutofillManager*) {
222 return NULL; 272 return NULL;
223 } 273 }
224 274
225 #endif 275 #endif
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_external_delegate.h ('k') | chrome/browser/autofill/autofill_external_delegate_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698