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

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: Responding to comments 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
(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/browser/ui/tab_contents/tab_contents_wrapper.h"
7 #include "chrome/common/autofill_messages.h"
8 #include "content/browser/renderer_host/render_view_host.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/renderer/render_view.h"
11 #include "ui/base/keycodes/keyboard_codes.h"
12
13 ////////////////////////////////////////////////////////////////////////////////
14 // PasswordAutofillManager, public:
15
16 PasswordAutofillManager::PasswordAutofillManager(
17 TabContentsWrapper* tab_contents_wrapper)
18 : tab_contents_wrapper_(tab_contents_wrapper) {
19 }
20
21 PasswordAutofillManager::~PasswordAutofillManager() {
22 }
23
24 bool PasswordAutofillManager::WouldHandleKeyDown(
25 const webkit::forms::FormField& field) {
26 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field);
27 if (iter == login_to_password_info_.end())
28 return false;
29
30 return true;
31 }
32
33 bool PasswordAutofillManager::DidAcceptAutofillSuggestion(
34 const webkit::forms::FormField& field,
35 const string16& value) {
36 webkit::forms::FormField input;
37 PasswordInfo password;
38 if (!FindLoginInfo(field, &input, &password))
39 return false;
40
41 if (WillFillUserNameAndPassword(input, password.fill_data)) {
42 if (tab_contents_wrapper_ && tab_contents_wrapper_->web_contents() &&
43 tab_contents_wrapper_->web_contents()->GetRenderViewHost()) {
44 RenderViewHost* host =
45 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
46 host->Send(new AutofillMsg_PasswordAcceptAutofillSuggestion(
47 host->GetRoutingID(),
48 value));
49 }
50 return true;
51 }
52
53 return false;
54 }
55
56 bool PasswordAutofillManager::DidSelectAutofillSuggestion(
57 const webkit::forms::FormField& field) {
58 webkit::forms::FormField input;
59 PasswordInfo password;
60 return FindLoginInfo(field, &input, &password);
61 }
62
63 bool PasswordAutofillManager::DidClearAutofillSelection(
64 const webkit::forms::FormField& field) {
65 webkit::forms::FormField input;
66 PasswordInfo password;
67 return FindLoginInfo(field, &input, &password);
68 }
69
70 void PasswordAutofillManager::FillPasswordForm(
71 const webkit::forms::FormField& username_element,
72 const webkit::forms::PasswordFormFillData& fill_data,
73 int frame_id) {
74 PasswordInfo password_info;
75 password_info.frame_id = frame_id;
76 password_info.fill_data = fill_data;
77
78 login_to_password_info_[username_element] = password_info;
79 }
80
81 void PasswordAutofillManager::FrameClosing(long long frame_id) {
82 for (LoginToPasswordInfoMap::iterator iter = login_to_password_info_.begin();
83 iter != login_to_password_info_.end();) {
84 if (iter->second.frame_id == frame_id)
85 login_to_password_info_.erase(iter++);
86 else
87 ++iter;
88 }
89 }
90
91 ////////////////////////////////////////////////////////////////////////////////
92 // PasswordAutofillManager, private:
93
94 bool PasswordAutofillManager::WillFillUserNameAndPassword(
95 const webkit::forms::FormField& username_element,
96 const webkit::forms::PasswordFormFillData& fill_data) {
97 string16 current_username = username_element.value;
98
99 // Look for any suitable matches to current field text.
100 if (fill_data.basic_data.fields[0].value == current_username) {
101 return true;
102 } else {
103 // Scan additional logins for a match.
104 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter;
105 for (iter = fill_data.additional_logins.begin();
106 iter != fill_data.additional_logins.end(); ++iter) {
107 if (iter->first == current_username)
108 return true;
109 }
110 }
111
112 return false;
113 }
114
115 bool PasswordAutofillManager::FindLoginInfo(
116 const webkit::forms::FormField& field,
117 webkit::forms::FormField* found_input,
118 PasswordInfo* found_password) {
119 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field);
120 if (iter == login_to_password_info_.end())
121 return false;
122
123 *found_input = field;
124 *found_password = iter->second;
125 return true;
126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698