1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#ifndef COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_FILL_DATA_H_ 67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_FILL_DATA_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/form_data.h" 1258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "components/autofill/core/common/password_form.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace autofill { 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Helper struct for PasswordFormFillData 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)struct UsernamesCollectionKey { 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UsernamesCollectionKey(); 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ~UsernamesCollectionKey(); 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Defined so that this struct can be used as a key in a std::map. 22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool operator<(const UsernamesCollectionKey& other) const; 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::string16 username; 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::string16 password; 26558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch std::string realm; 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}; 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 29eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochstruct PasswordAndRealm { 30eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::string16 password; 31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string realm; 32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}; 33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 34a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Structure used for autofilling password forms. Note that the realms in this 35a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// struct are only set when the password's realm differs from the realm of the 36a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// form that we are filling. 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct PasswordFormFillData { 38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch typedef std::map<base::string16, PasswordAndRealm> LoginCollection; 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) typedef std::map<UsernamesCollectionKey, 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::vector<base::string16> > UsernamesCollection; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Identifies the HTML form on the page and preferred username/password for 43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // login. 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FormData basic_data; 45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 46eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The signon realm of the preferred user/pass pair. 47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string preferred_realm; 48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // A list of other matching username->PasswordAndRealm pairs for the form. 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoginCollection additional_logins; 51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // A list of possible usernames in the case where we aren't completely sure 53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // that the original saved username is correct. This data is keyed by the 54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // saved username/password to ensure uniqueness, though the username is not 55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // used. 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UsernamesCollection other_possible_usernames; 57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Tells us whether we need to wait for the user to enter a valid username 59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // before we autofill the password. By default, this is off unless the 60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // PasswordManager determined there is an additional risk associated with this 61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // form. This can happen, for example, if action URI's of the observed form 62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // and our saved representation don't match up. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool wait_for_username; 64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PasswordFormFillData(); 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~PasswordFormFillData(); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Create a FillData structure in preparation for autofilling a form, 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// from basic_data identifying which form to fill, and a collection of 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// matching stored logins to use as username/password values. 72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// |preferred_match| should equal (address) one of matches. 73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// |wait_for_username_before_autofill| is true if we should not autofill 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// anything until the user typed in a valid username and blurred the field. 75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// If |enable_possible_usernames| is true, we will populate possible_usernames 76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// in |result|. 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void InitPasswordFormFillData( 7858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const PasswordForm& form_on_page, 7958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const PasswordFormMap& matches, 8058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const PasswordForm* const preferred_match, 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool wait_for_username_before_autofill, 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool enable_other_possible_usernames, 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PasswordFormFillData* result); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} // namespace autofill 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif // COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_FILL_DATA_H__ 88