OLD | NEW |
(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 "ui/base/keycodes/keyboard_codes.h" |
| 9 |
| 10 //////////////////////////////////////////////////////////////////////////////// |
| 11 // PasswordAutofillManager, public: |
| 12 |
| 13 PasswordAutofillManager::PasswordAutofillManager( |
| 14 content::RenderViewHost* render_view_host) |
| 15 : render_view_host_(render_view_host) { |
| 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 (render_view_host_) { |
| 31 render_view_host_->Send(new AutofillMsg_AcceptPasswordAutofillSuggestion( |
| 32 render_view_host_->GetRoutingID(), |
| 33 value)); |
| 34 } |
| 35 return true; |
| 36 } |
| 37 |
| 38 return false; |
| 39 } |
| 40 |
| 41 bool PasswordAutofillManager::DidClearAutofillSelection( |
| 42 const webkit::forms::FormField& field) { |
| 43 webkit::forms::FormField input; |
| 44 webkit::forms::PasswordFormFillData password; |
| 45 return FindLoginInfo(field, &input, &password); |
| 46 } |
| 47 |
| 48 void PasswordAutofillManager::AddPasswordFormMapping( |
| 49 const webkit::forms::FormField& username_element, |
| 50 const webkit::forms::PasswordFormFillData& password) { |
| 51 login_to_password_info_[username_element] = password; |
| 52 } |
| 53 |
| 54 void PasswordAutofillManager::Reset() { |
| 55 login_to_password_info_.clear(); |
| 56 } |
| 57 |
| 58 //////////////////////////////////////////////////////////////////////////////// |
| 59 // PasswordAutofillManager, private: |
| 60 |
| 61 bool PasswordAutofillManager::WillFillUserNameAndPassword( |
| 62 const string16& current_username, |
| 63 const webkit::forms::PasswordFormFillData& fill_data) { |
| 64 |
| 65 // Look for any suitable matches to current field text. |
| 66 if (fill_data.basic_data.fields[0].value == current_username) { |
| 67 return true; |
| 68 } else { |
| 69 // Scan additional logins for a match. |
| 70 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; |
| 71 for (iter = fill_data.additional_logins.begin(); |
| 72 iter != fill_data.additional_logins.end(); ++iter) { |
| 73 if (iter->first == current_username) |
| 74 return true; |
| 75 } |
| 76 } |
| 77 |
| 78 return false; |
| 79 } |
| 80 |
| 81 bool PasswordAutofillManager::FindLoginInfo( |
| 82 const webkit::forms::FormField& field, |
| 83 webkit::forms::FormField* found_input, |
| 84 webkit::forms::PasswordFormFillData* found_password) { |
| 85 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); |
| 86 if (iter == login_to_password_info_.end()) |
| 87 return false; |
| 88 |
| 89 *found_input = field; |
| 90 *found_password = iter->second; |
| 91 return true; |
| 92 } |
OLD | NEW |