OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/logging.h" | 5 #include "base/logging.h" |
6 #include "components/autofill/core/browser/autofill_driver.h" | 6 #include "components/autofill/core/browser/autofill_driver.h" |
7 #include "components/autofill/core/browser/popup_item_ids.h" | 7 #include "components/autofill/core/browser/popup_item_ids.h" |
8 #include "components/autofill/core/common/autofill_data_validation.h" | 8 #include "components/autofill/core/common/autofill_data_validation.h" |
9 #include "components/password_manager/core/browser/password_autofill_manager.h" | 9 #include "components/password_manager/core/browser/password_autofill_manager.h" |
10 #include "components/password_manager/core/browser/password_manager_client.h" | 10 #include "components/password_manager/core/browser/password_manager_client.h" |
11 #include "components/password_manager/core/browser/password_manager_driver.h" | 11 #include "components/password_manager/core/browser/password_manager_driver.h" |
12 | 12 |
13 namespace password_manager { | 13 namespace password_manager { |
14 | 14 |
15 //////////////////////////////////////////////////////////////////////////////// | 15 //////////////////////////////////////////////////////////////////////////////// |
16 // PasswordAutofillManager, public: | 16 // PasswordAutofillManager, public: |
17 | 17 |
18 PasswordAutofillManager::PasswordAutofillManager( | 18 PasswordAutofillManager::PasswordAutofillManager( |
19 PasswordManagerClient* password_manager_client, | 19 PasswordManagerClient* password_manager_client, |
20 autofill::AutofillManagerDelegate* autofill_manager_delegate) | 20 autofill::AutofillManagerDelegate* autofill_manager_delegate) |
21 : password_manager_client_(password_manager_client), | 21 : password_manager_client_(password_manager_client), |
22 autofill_manager_delegate_(autofill_manager_delegate), | 22 autofill_manager_delegate_(autofill_manager_delegate), |
23 weak_ptr_factory_(this) { | 23 weak_ptr_factory_(this) { |
24 } | 24 } |
25 | 25 |
26 PasswordAutofillManager::~PasswordAutofillManager() { | 26 PasswordAutofillManager::~PasswordAutofillManager() { |
27 } | 27 } |
28 | 28 |
29 bool PasswordAutofillManager::AcceptSuggestion( | 29 bool PasswordAutofillManager::FillSuggestion( |
30 const autofill::FormFieldData& field, | 30 const autofill::FormFieldData& field, |
31 const base::string16& username) { | 31 const base::string16& username) { |
32 autofill::PasswordFormFillData fill_data; | 32 autofill::PasswordFormFillData fill_data; |
33 base::string16 password; | 33 base::string16 password; |
34 if (FindLoginInfo(field, &fill_data) && | 34 if (FindLoginInfo(field, &fill_data) && |
35 GetPasswordForUsername(username, fill_data, &password)) { | 35 GetPasswordForUsername(username, fill_data, &password)) { |
36 PasswordManagerDriver* driver = password_manager_client_->GetDriver(); | 36 PasswordManagerDriver* driver = password_manager_client_->GetDriver(); |
37 driver->AcceptPasswordAutofillSuggestion(username, password); | 37 driver->FillSuggestion(username, password); |
38 return true; | 38 return true; |
39 } | 39 } |
40 return false; | 40 return false; |
41 } | |
42 | |
43 bool PasswordAutofillManager::PreviewSuggestion( | |
44 const autofill::FormFieldData& field, | |
45 const base::string16& username) { | |
46 autofill::PasswordFormFillData fill_data; | |
47 base::string16 password; | |
48 if (FindLoginInfo(field, &fill_data) && | |
49 GetPasswordForUsername(username, fill_data, &password)) { | |
50 PasswordManagerDriver* driver = password_manager_client_->GetDriver(); | |
51 driver->PreviewSuggestion(username, password); | |
52 return true; | |
53 } | |
54 return false; | |
41 } | 55 } |
42 | 56 |
43 void PasswordAutofillManager::OnAddPasswordFormMapping( | 57 void PasswordAutofillManager::OnAddPasswordFormMapping( |
44 const autofill::FormFieldData& field, | 58 const autofill::FormFieldData& field, |
45 const autofill::PasswordFormFillData& fill_data) { | 59 const autofill::PasswordFormFillData& fill_data) { |
46 if (!autofill::IsValidFormFieldData(field) || | 60 if (!autofill::IsValidFormFieldData(field) || |
47 !autofill::IsValidPasswordFormFillData(fill_data)) | 61 !autofill::IsValidPasswordFormFillData(fill_data)) |
48 return; | 62 return; |
49 | 63 |
50 login_to_password_info_[field] = fill_data; | 64 login_to_password_info_[field] = fill_data; |
(...skipping 26 matching lines...) Expand all Loading... | |
77 realms, | 91 realms, |
78 empty, | 92 empty, |
79 password_ids, | 93 password_ids, |
80 weak_ptr_factory_.GetWeakPtr()); | 94 weak_ptr_factory_.GetWeakPtr()); |
81 } | 95 } |
82 | 96 |
83 void PasswordAutofillManager::Reset() { | 97 void PasswordAutofillManager::Reset() { |
84 login_to_password_info_.clear(); | 98 login_to_password_info_.clear(); |
85 } | 99 } |
86 | 100 |
87 bool PasswordAutofillManager::AcceptSuggestionForTest( | 101 bool PasswordAutofillManager::FillSuggestionForTest( |
88 const autofill::FormFieldData& field, | 102 const autofill::FormFieldData& field, |
89 const base::string16& username) { | 103 const base::string16& username) { |
90 return AcceptSuggestion(field, username); | 104 return FillSuggestion(field, username); |
105 } | |
106 | |
107 bool PasswordAutofillManager::PreviewSuggestionForTest( | |
108 const autofill::FormFieldData& field, | |
109 const base::string16& username) { | |
110 return PreviewSuggestion(field, username); | |
91 } | 111 } |
92 | 112 |
93 void PasswordAutofillManager::OnPopupShown() { | 113 void PasswordAutofillManager::OnPopupShown() { |
94 } | 114 } |
95 | 115 |
96 void PasswordAutofillManager::OnPopupHidden() { | 116 void PasswordAutofillManager::OnPopupHidden() { |
97 } | 117 } |
98 | 118 |
99 void PasswordAutofillManager::DidSelectSuggestion(const base::string16& value, | 119 void PasswordAutofillManager::DidSelectSuggestion(const base::string16& value, |
100 int identifier) { | 120 int identifier) { |
101 // This is called to preview an autofill suggestion, but we don't currently | 121 ClearPreviewedForm(); |
102 // do that for password forms (crbug.com/63421). If it is ever implemented, | 122 bool success = PreviewSuggestion(form_field_, value); |
103 // ClearPreviewedForm() must also be implemented(). | 123 DCHECK(success); |
104 } | 124 } |
105 | 125 |
106 void PasswordAutofillManager::DidAcceptSuggestion(const base::string16& value, | 126 void PasswordAutofillManager::DidAcceptSuggestion(const base::string16& value, |
107 int identifier) { | 127 int identifier) { |
108 if (!AcceptSuggestion(form_field_, value)) | 128 bool success = FillSuggestion(form_field_, value); |
109 NOTREACHED(); | 129 DCHECK(success); |
110 autofill_manager_delegate_->HideAutofillPopup(); | 130 autofill_manager_delegate_->HideAutofillPopup(); |
111 } | 131 } |
112 | 132 |
113 void PasswordAutofillManager::RemoveSuggestion(const base::string16& value, | 133 void PasswordAutofillManager::RemoveSuggestion(const base::string16& value, |
114 int identifier) { | 134 int identifier) { |
115 NOTREACHED(); | 135 DCHECK(false); |
Ilya Sherman
2014/05/15 21:36:09
nit: This one is clearer as a NOTREACHED(). Just
ziran.sun
2014/05/16 09:18:13
Done.
| |
116 } | 136 } |
117 | 137 |
118 void PasswordAutofillManager::ClearPreviewedForm() { | 138 void PasswordAutofillManager::ClearPreviewedForm() { |
119 // There is currently no preview for password autofill (crbug.com/63421). | 139 PasswordManagerDriver* driver = password_manager_client_->GetDriver(); |
120 // This function needs an implemention if preview is ever implemented. | 140 driver->ClearPreviewedForm(); |
121 } | 141 } |
122 | 142 |
123 //////////////////////////////////////////////////////////////////////////////// | 143 //////////////////////////////////////////////////////////////////////////////// |
124 // PasswordAutofillManager, private: | 144 // PasswordAutofillManager, private: |
125 | 145 |
126 bool PasswordAutofillManager::GetPasswordForUsername( | 146 bool PasswordAutofillManager::GetPasswordForUsername( |
127 const base::string16& current_username, | 147 const base::string16& current_username, |
128 const autofill::PasswordFormFillData& fill_data, | 148 const autofill::PasswordFormFillData& fill_data, |
129 base::string16* password) { | 149 base::string16* password) { |
130 // TODO(dubroy): When password access requires some kind of authentication | 150 // TODO(dubroy): When password access requires some kind of authentication |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 autofill::PasswordFormFillData* found_password) { | 188 autofill::PasswordFormFillData* found_password) { |
169 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | 189 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); |
170 if (iter == login_to_password_info_.end()) | 190 if (iter == login_to_password_info_.end()) |
171 return false; | 191 return false; |
172 | 192 |
173 *found_password = iter->second; | 193 *found_password = iter->second; |
174 return true; | 194 return true; |
175 } | 195 } |
176 | 196 |
177 } // namespace password_manager | 197 } // namespace password_manager |
OLD | NEW |