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

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 up login password clearing Created 8 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
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 AutofillExternalDelegate::~AutofillExternalDelegate() { 19 AutofillExternalDelegate::~AutofillExternalDelegate() {
20 } 20 }
21 21
22 AutofillExternalDelegate::AutofillExternalDelegate( 22 AutofillExternalDelegate::AutofillExternalDelegate(
23 TabContentsWrapper* tab_contents_wrapper, 23 TabContentsWrapper* tab_contents_wrapper,
24 AutofillManager* autofill_manager) 24 AutofillManager* autofill_manager)
25 : tab_contents_wrapper_(tab_contents_wrapper), 25 : tab_contents_wrapper_(tab_contents_wrapper),
26 autofill_manager_(autofill_manager), 26 autofill_manager_(autofill_manager),
27 password_autofill_manager_(
28 tab_contents_wrapper->web_contents()->GetRenderViewHost()),
27 autofill_query_id_(0), 29 autofill_query_id_(0),
28 display_warning_if_disabled_(false), 30 display_warning_if_disabled_(false),
29 has_shown_autofill_popup_for_current_edit_(false), 31 has_shown_autofill_popup_for_current_edit_(false),
30 suggestions_clear_index_(-1), 32 suggestions_clear_index_(-1),
31 suggestions_options_index_(-1) { 33 suggestions_options_index_(-1) {
32 } 34 }
33 35
34 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, 36 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id,
35 int list_index) { 37 int list_index) {
38 if (password_autofill_manager_.DidSelectAutofillSuggestion(
39 autofill_query_field_))
40 return;
41
36 if (list_index == suggestions_options_index_ || 42 if (list_index == suggestions_options_index_ ||
37 list_index == suggestions_clear_index_ || 43 list_index == suggestions_clear_index_ ||
38 unique_id == -1) 44 unique_id == -1)
39 return; 45 return;
40 46
41 FillAutofillFormData(unique_id, true); 47 FillAutofillFormData(unique_id, true);
42 } 48 }
43 49
44 void AutofillExternalDelegate::OnQuery(int query_id, 50 void AutofillExternalDelegate::OnQuery(int query_id,
45 const webkit::forms::FormData& form, 51 const webkit::forms::FormData& form,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 147 }
142 148
143 void AutofillExternalDelegate::DidAcceptAutofillSuggestions( 149 void AutofillExternalDelegate::DidAcceptAutofillSuggestions(
144 const string16& value, 150 const string16& value,
145 int unique_id, 151 int unique_id,
146 unsigned index) { 152 unsigned index) {
147 // If the selected element is a warning we don't want to do anything. 153 // If the selected element is a warning we don't want to do anything.
148 if (unique_id < 0) 154 if (unique_id < 0)
149 return; 155 return;
150 156
151 // TODO(csharp): Add the password autofill manager. 157 if (password_autofill_manager_.DidAcceptAutofillSuggestion(
152 // if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) 158 autofill_query_field_, value)) {
153 // return; 159 // Accepting has been handled by the password manager. Just make sure
160 // to hide the popup.
161 HideAutofillPopup();
162 return;
163 }
154 164
155 if (suggestions_options_index_ != -1 && 165 if (suggestions_options_index_ != -1 &&
156 index == static_cast<unsigned>(suggestions_options_index_)) { 166 index == static_cast<unsigned>(suggestions_options_index_)) {
157 // User selected 'Autofill Options'. 167 // User selected 'Autofill Options'.
158 autofill_manager_->OnShowAutofillDialog(); 168 autofill_manager_->OnShowAutofillDialog();
159 } else if (suggestions_clear_index_ != -1 && 169 } else if (suggestions_clear_index_ != -1 &&
160 index == static_cast<unsigned>(suggestions_clear_index_)) { 170 index == static_cast<unsigned>(suggestions_clear_index_)) {
161 // User selected 'Clear form'. 171 // User selected 'Clear form'.
162 RenderViewHost* host = 172 RenderViewHost* host =
163 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 173 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
164 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); 174 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
165 } else if (!unique_id) { 175 } else if (!unique_id) {
166 // User selected an Autocomplete entry, so we fill directly. 176 // User selected an Autocomplete entry, so we fill directly.
167 RenderViewHost* host = 177 RenderViewHost* host =
168 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 178 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
169 host->Send(new AutofillMsg_SetNodeText( 179 host->Send(new AutofillMsg_SetNodeText(
170 host->GetRoutingID(), 180 host->GetRoutingID(),
171 value)); 181 value));
172 } else { 182 } else {
173 FillAutofillFormData(unique_id, false); 183 FillAutofillFormData(unique_id, false);
174 } 184 }
175 185
176 HideAutofillPopup(); 186 HideAutofillPopup();
Ilya Sherman 2012/03/12 23:46:13 nit: How about moving this up prior to the passwor
csharp 2012/03/13 18:31:14 Done.
177 } 187 }
178 188
179 void AutofillExternalDelegate::ClearPreviewedForm() { 189 void AutofillExternalDelegate::ClearPreviewedForm() {
190 if (password_autofill_manager_.DidClearAutofillSelection(
191 autofill_query_field_))
192 return;
193
180 RenderViewHost* host = 194 RenderViewHost* host =
181 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 195 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
182 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); 196 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID()));
183 } 197 }
184 198
185 void AutofillExternalDelegate::HideAutofillPopup() { 199 void AutofillExternalDelegate::HideAutofillPopup() {
186 suggestions_clear_index_ = -1; 200 suggestions_clear_index_ = -1;
187 suggestions_options_index_ = -1; 201 suggestions_options_index_ = -1;
188 202
189 HideAutofillPopupInternal(); 203 HideAutofillPopupInternal();
190 } 204 }
191 205
206 void AutofillExternalDelegate::Reset() {
207 HideAutofillPopup();
208
209 password_autofill_manager_.Reset();
210 }
211
212 void AutofillExternalDelegate::AddPasswordFormMapping(
213 const webkit::forms::FormField& form,
214 const webkit::forms::PasswordFormFillData& fill_data) {
215 password_autofill_manager_.AddPasswordFormMapping(form, fill_data);
216 }
217
192 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, 218 void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
193 bool is_preview) { 219 bool is_preview) {
194 RenderViewHost* host = 220 RenderViewHost* host =
195 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 221 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
196 222
197 if (is_preview) { 223 if (is_preview) {
198 host->Send(new AutofillMsg_SetAutofillActionPreview( 224 host->Send(new AutofillMsg_SetAutofillActionPreview(
199 host->GetRoutingID())); 225 host->GetRoutingID()));
200 } else { 226 } else {
201 host->Send(new AutofillMsg_SetAutofillActionFill( 227 host->Send(new AutofillMsg_SetAutofillActionFill(
(...skipping 12 matching lines...) Expand all
214 // none, so all platforms use the default. 240 // none, so all platforms use the default.
215 241
216 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 242 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
217 243
218 AutofillExternalDelegate* AutofillExternalDelegate::Create( 244 AutofillExternalDelegate* AutofillExternalDelegate::Create(
219 TabContentsWrapper*, AutofillManager*) { 245 TabContentsWrapper*, AutofillManager*) {
220 return NULL; 246 return NULL;
221 } 247 }
222 248
223 #endif 249 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698