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

Side by Side Diff: chrome/browser/autofill/password_autofill_manager.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 FindLoginInfo 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/autofill/password_autofill_manager.h"
6 #include "chrome/common/autofill_messages.h"
7 #include "content/public/browser/render_view_host.h"
8 #include "content/public/browser/web_contents.h"
9 #include "ui/base/keycodes/keyboard_codes.h"
10
11 ////////////////////////////////////////////////////////////////////////////////
12 // PasswordAutofillManager, public:
13
14 PasswordAutofillManager::PasswordAutofillManager(
15 content::WebContents* web_contents) : web_contents_(web_contents) {
Ilya Sherman 2012/04/02 22:07:29 nit: Can we store a pointer just to the RenderView
csharp 2012/04/03 12:25:55 Ya, I had passed in a pointer to the RenderViewHos
16 }
17
18 PasswordAutofillManager::~PasswordAutofillManager() {
19 }
20
21 bool PasswordAutofillManager::DidAcceptAutofillSuggestion(
22 const webkit::forms::FormField& field,
23 const string16& value) {
24 webkit::forms::FormField input;
25 webkit::forms::PasswordFormFillData password;
26 if (!FindLoginInfo(field, &input, &password))
27 return false;
28
29 if (WillFillUserNameAndPassword(value, password)) {
30 if (web_contents_) {
31 content::RenderViewHost* render_view_host =
32 web_contents_->GetRenderViewHost();
33 render_view_host->Send(new AutofillMsg_AcceptPasswordAutofillSuggestion(
34 render_view_host->GetRoutingID(),
35 value));
36 }
37 return true;
38 }
39
40 return false;
41 }
42
43 bool PasswordAutofillManager::DidSelectAutofillSuggestion(
44 const webkit::forms::FormField& field) {
45 webkit::forms::FormField input;
46 webkit::forms::PasswordFormFillData password;
47 return FindLoginInfo(field, &input, &password);
48 }
49
50 bool PasswordAutofillManager::DidClearAutofillSelection(
51 const webkit::forms::FormField& field) {
52 webkit::forms::FormField input;
53 webkit::forms::PasswordFormFillData password;
54 return FindLoginInfo(field, &input, &password);
55 }
56
57 void PasswordAutofillManager::AddPasswordFormMapping(
58 const webkit::forms::FormField& username_element,
59 const webkit::forms::PasswordFormFillData& password) {
60 login_to_password_info_[username_element] = password;
61 }
62
63 void PasswordAutofillManager::Reset() {
64 login_to_password_info_.clear();
65 }
66
67 ////////////////////////////////////////////////////////////////////////////////
68 // PasswordAutofillManager, private:
69
70 bool PasswordAutofillManager::WillFillUserNameAndPassword(
71 const string16& current_username,
72 const webkit::forms::PasswordFormFillData& fill_data) {
73
Ilya Sherman 2012/04/02 22:07:29 nit: No need for this blank line (line 73)
csharp 2012/04/03 12:25:55 Done.
74 // Look for any suitable matches to current field text.
75 if (fill_data.basic_data.fields[0].value == current_username) {
76 return true;
77 } else {
78 // Scan additional logins for a match.
79 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter;
80 for (iter = fill_data.additional_logins.begin();
81 iter != fill_data.additional_logins.end(); ++iter) {
82 if (iter->first == current_username)
83 return true;
84 }
85 }
86
87 return false;
88 }
89
90 bool PasswordAutofillManager::FindLoginInfo(
91 const webkit::forms::FormField& field,
92 webkit::forms::FormField* found_input,
93 webkit::forms::PasswordFormFillData* found_password) {
94 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field);
95 if (iter == login_to_password_info_.end())
96 return false;
97
98 *found_input = field;
Ilya Sherman 2012/04/02 22:07:29 nit: It looks like the caller always knows the val
csharp 2012/04/03 12:25:55 Done.
99 *found_password = iter->second;
100 return true;
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698