OLD | NEW |
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 "chrome/browser/autofill/password_autofill_manager.h" | 5 #include "chrome/browser/autofill/password_autofill_manager.h" |
6 #include "chrome/common/autofill_messages.h" | 6 #include "chrome/common/autofill_messages.h" |
7 #include "content/public/browser/render_view_host.h" | 7 #include "content/public/browser/render_view_host.h" |
8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
9 #include "ui/base/keycodes/keyboard_codes.h" | 9 #include "ui/base/keycodes/keyboard_codes.h" |
10 | 10 |
11 //////////////////////////////////////////////////////////////////////////////// | 11 //////////////////////////////////////////////////////////////////////////////// |
12 // PasswordAutofillManager, public: | 12 // PasswordAutofillManager, public: |
13 | 13 |
14 PasswordAutofillManager::PasswordAutofillManager( | 14 PasswordAutofillManager::PasswordAutofillManager( |
15 content::WebContents* web_contents) : web_contents_(web_contents) { | 15 content::WebContents* web_contents) : web_contents_(web_contents) { |
16 } | 16 } |
17 | 17 |
18 PasswordAutofillManager::~PasswordAutofillManager() { | 18 PasswordAutofillManager::~PasswordAutofillManager() { |
19 } | 19 } |
20 | 20 |
21 bool PasswordAutofillManager::DidAcceptAutofillSuggestion( | 21 bool PasswordAutofillManager::DidAcceptAutofillSuggestion( |
22 const webkit::forms::FormField& field, | 22 const FormFieldData& field, |
23 const string16& value) { | 23 const string16& value) { |
24 webkit::forms::PasswordFormFillData password; | 24 PasswordFormFillData password; |
25 if (!FindLoginInfo(field, &password)) | 25 if (!FindLoginInfo(field, &password)) |
26 return false; | 26 return false; |
27 | 27 |
28 if (WillFillUserNameAndPassword(value, password)) { | 28 if (WillFillUserNameAndPassword(value, password)) { |
29 if (web_contents_) { | 29 if (web_contents_) { |
30 content::RenderViewHost* render_view_host = | 30 content::RenderViewHost* render_view_host = |
31 web_contents_->GetRenderViewHost(); | 31 web_contents_->GetRenderViewHost(); |
32 render_view_host->Send(new AutofillMsg_AcceptPasswordAutofillSuggestion( | 32 render_view_host->Send(new AutofillMsg_AcceptPasswordAutofillSuggestion( |
33 render_view_host->GetRoutingID(), | 33 render_view_host->GetRoutingID(), |
34 value)); | 34 value)); |
35 } | 35 } |
36 return true; | 36 return true; |
37 } | 37 } |
38 | 38 |
39 return false; | 39 return false; |
40 } | 40 } |
41 | 41 |
42 void PasswordAutofillManager::AddPasswordFormMapping( | 42 void PasswordAutofillManager::AddPasswordFormMapping( |
43 const webkit::forms::FormField& username_element, | 43 const FormFieldData& username_element, |
44 const webkit::forms::PasswordFormFillData& password) { | 44 const PasswordFormFillData& password) { |
45 login_to_password_info_[username_element] = password; | 45 login_to_password_info_[username_element] = password; |
46 } | 46 } |
47 | 47 |
48 void PasswordAutofillManager::Reset() { | 48 void PasswordAutofillManager::Reset() { |
49 login_to_password_info_.clear(); | 49 login_to_password_info_.clear(); |
50 } | 50 } |
51 | 51 |
52 //////////////////////////////////////////////////////////////////////////////// | 52 //////////////////////////////////////////////////////////////////////////////// |
53 // PasswordAutofillManager, private: | 53 // PasswordAutofillManager, private: |
54 | 54 |
55 bool PasswordAutofillManager::WillFillUserNameAndPassword( | 55 bool PasswordAutofillManager::WillFillUserNameAndPassword( |
56 const string16& current_username, | 56 const string16& current_username, |
57 const webkit::forms::PasswordFormFillData& fill_data) { | 57 const PasswordFormFillData& fill_data) { |
58 // Look for any suitable matches to current field text. | 58 // Look for any suitable matches to current field text. |
59 if (fill_data.basic_data.fields[0].value == current_username) { | 59 if (fill_data.basic_data.fields[0].value == current_username) { |
60 return true; | 60 return true; |
61 } else { | 61 } else { |
62 // Scan additional logins for a match. | 62 // Scan additional logins for a match. |
63 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; | 63 PasswordFormFillData::LoginCollection::const_iterator iter; |
64 for (iter = fill_data.additional_logins.begin(); | 64 for (iter = fill_data.additional_logins.begin(); |
65 iter != fill_data.additional_logins.end(); ++iter) { | 65 iter != fill_data.additional_logins.end(); ++iter) { |
66 if (iter->first == current_username) | 66 if (iter->first == current_username) |
67 return true; | 67 return true; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 return false; | 71 return false; |
72 } | 72 } |
73 | 73 |
74 bool PasswordAutofillManager::FindLoginInfo( | 74 bool PasswordAutofillManager::FindLoginInfo( |
75 const webkit::forms::FormField& field, | 75 const FormFieldData& field, |
76 webkit::forms::PasswordFormFillData* found_password) { | 76 PasswordFormFillData* found_password) { |
77 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | 77 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); |
78 if (iter == login_to_password_info_.end()) | 78 if (iter == login_to_password_info_.end()) |
79 return false; | 79 return false; |
80 | 80 |
81 *found_password = iter->second; | 81 *found_password = iter->second; |
82 return true; | 82 return true; |
83 } | 83 } |
OLD | NEW |