Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/logging.h" | |
| 6 #include "components/autofill/core/browser/autofill_driver.h" | |
| 7 #include "components/autofill/core/browser/popup_item_ids.h" | |
| 8 #include "components/password_manager/core/browser/password_autofill_manager.h" | |
| 9 #include "components/password_manager/core/browser/password_manager_client.h" | |
| 10 #include "components/password_manager/core/browser/password_manager_driver.h" | |
| 11 | |
| 12 //////////////////////////////////////////////////////////////////////////////// | |
| 13 // PasswordAutofillManager, public: | |
| 14 | |
| 15 PasswordAutofillManager::PasswordAutofillManager( | |
| 16 PasswordManagerClient* password_manager_client, | |
| 17 autofill::AutofillManagerDelegate* autofill_manager_delegate) | |
| 18 : password_manager_client_(password_manager_client), | |
| 19 autofill_manager_delegate_(autofill_manager_delegate), | |
| 20 weak_ptr_factory_(this) { | |
| 21 } | |
| 22 | |
| 23 PasswordAutofillManager::~PasswordAutofillManager() { | |
| 24 } | |
| 25 | |
| 26 bool PasswordAutofillManager::AcceptAutofillSuggestion( | |
| 27 const autofill::FormFieldData& field, | |
| 28 const base::string16& username) { | |
| 29 autofill::PasswordFormFillData fill_data; | |
| 30 base::string16 password; | |
| 31 if (FindLoginInfo(field, &fill_data) && | |
| 32 GetPasswordForUsername(username, fill_data, &password)) { | |
| 33 PasswordManagerDriver* driver = password_manager_client_->GetDriver(); | |
| 34 driver->AcceptPasswordAutofillSuggestion(username, password); | |
| 35 return true; | |
| 36 } | |
| 37 return false; | |
| 38 } | |
| 39 | |
| 40 void PasswordAutofillManager::AddPasswordFormMapping( | |
| 41 const autofill::FormFieldData& username_element, | |
| 42 const autofill::PasswordFormFillData& password) { | |
| 43 login_to_password_info_[username_element] = password; | |
| 44 } | |
| 45 | |
| 46 void PasswordAutofillManager::ShowPasswordSuggestions( | |
| 47 const autofill::FormFieldData& field, | |
| 48 const gfx::RectF& bounds, | |
| 49 const std::vector<base::string16>& suggestions, | |
| 50 const std::vector<base::string16>& realms) { | |
| 51 form_field_ = field; | |
| 52 | |
| 53 if (suggestions.empty()) { | |
| 54 autofill_manager_delegate_->HideAutofillPopup(); | |
| 55 return; | |
| 56 } | |
| 57 | |
| 58 std::vector<base::string16> empty(suggestions.size()); | |
| 59 std::vector<int> password_ids(suggestions.size(), | |
| 60 autofill::POPUP_ITEM_ID_PASSWORD_ENTRY); | |
| 61 autofill_manager_delegate_->ShowAutofillPopup( | |
| 62 bounds, | |
| 63 field.text_direction, | |
| 64 suggestions, | |
| 65 realms, | |
| 66 empty, | |
| 67 password_ids, | |
| 68 weak_ptr_factory_.GetWeakPtr()); | |
| 69 } | |
| 70 | |
| 71 void PasswordAutofillManager::Reset() { | |
| 72 login_to_password_info_.clear(); | |
| 73 } | |
| 74 | |
| 75 void PasswordAutofillManager::OnPopupShown() { | |
| 76 /* FIXME: Do we need this? It's only used for metrics logging. | |
|
Garrett Casto
2014/03/14 08:25:22
Having some logging here might eventually be inter
Patrick Dubroy
2014/03/14 12:07:19
Done.
| |
| 77 manager_->DidShowSuggestions( | |
| 78 has_suggestion_ && !has_shown_popup_for_current_edit_); | |
| 79 has_shown_popup_for_current_edit_ |= has_suggestion_; | |
| 80 */ | |
| 81 } | |
| 82 | |
| 83 void PasswordAutofillManager::OnPopupHidden() { | |
| 84 } | |
| 85 | |
| 86 bool PasswordAutofillManager::ShouldRepostEvent(const ui::MouseEvent& event) { | |
| 87 // FIXME: Can we get rid of this? | |
|
Garrett Casto
2014/03/14 08:25:22
If you mean this interface function, I don't think
Patrick Dubroy
2014/03/14 12:07:19
Ah, I see. That's kind of unfortunate, but what ca
| |
| 88 NOTREACHED(); | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 92 void PasswordAutofillManager::DidSelectSuggestion(int identifier) { | |
| 93 // This is called to preview an autofill suggestion, but we don't currently | |
| 94 // do that for password forms. | |
| 95 } | |
| 96 | |
| 97 void PasswordAutofillManager::DidAcceptSuggestion(const base::string16& value, | |
| 98 int identifier) { | |
| 99 if (!AcceptAutofillSuggestion(form_field_, value)) | |
| 100 NOTREACHED(); | |
| 101 autofill_manager_delegate_->HideAutofillPopup(); | |
| 102 } | |
| 103 | |
| 104 void PasswordAutofillManager::RemoveSuggestion(const base::string16& value, | |
| 105 int identifier) { | |
| 106 NOTREACHED(); | |
| 107 } | |
| 108 | |
| 109 void PasswordAutofillManager::ClearPreviewedForm() { | |
| 110 NOTREACHED(); | |
| 111 // driver_->RendererShouldClearPreviewedForm(); // FIXME: Do we need this? | |
|
Garrett Casto
2014/03/14 08:25:22
No, password autofill doesn't preview at the momen
Patrick Dubroy
2014/03/14 12:07:19
Done.
| |
| 112 } | |
| 113 | |
| 114 //////////////////////////////////////////////////////////////////////////////// | |
| 115 // PasswordAutofillManager, private: | |
| 116 | |
| 117 bool PasswordAutofillManager::GetPasswordForUsername( | |
| 118 const base::string16& current_username, | |
| 119 const autofill::PasswordFormFillData& fill_data, | |
| 120 base::string16* password) { | |
| 121 // TODO(dubroy): When password access requires some kind of authentication | |
| 122 // (e.g. Keychain access on Mac OS), use |password_manager_client_| here to | |
| 123 // fetch the actual password. See crbug.com/178358 for more context. | |
| 124 | |
| 125 // Look for any suitable matches to current field text. | |
| 126 if (fill_data.basic_data.fields[0].value == current_username) { | |
| 127 *password = fill_data.basic_data.fields[1].value; | |
| 128 return true; | |
| 129 } | |
| 130 | |
| 131 // Scan additional logins for a match. | |
| 132 for (autofill::PasswordFormFillData::LoginCollection::const_iterator iter = | |
| 133 fill_data.additional_logins.begin(); | |
| 134 iter != fill_data.additional_logins.end(); ++iter) { | |
| 135 if (iter->first == current_username) { | |
| 136 *password = iter->second.password; | |
| 137 return true; | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 for (autofill::PasswordFormFillData::UsernamesCollection::const_iterator | |
| 142 usernames_iter = fill_data.other_possible_usernames.begin(); | |
| 143 usernames_iter != fill_data.other_possible_usernames.end(); | |
| 144 ++usernames_iter) { | |
| 145 for (size_t i = 0; i < usernames_iter->second.size(); ++i) { | |
| 146 if (usernames_iter->second[i] == current_username) { | |
| 147 *password = usernames_iter->first.password; | |
| 148 return true; | |
| 149 } | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 return false; | |
| 154 } | |
| 155 | |
| 156 bool PasswordAutofillManager::FindLoginInfo( | |
| 157 const autofill::FormFieldData& field, | |
| 158 autofill::PasswordFormFillData* found_password) { | |
| 159 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | |
| 160 if (iter == login_to_password_info_.end()) | |
| 161 return false; | |
| 162 | |
| 163 *found_password = iter->second; | |
| 164 return true; | |
| 165 } | |
| OLD | NEW |