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.
5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_AUTOFILL_MANAGER_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_AUTOFILL_MANAGER_H_
10 #include "base/gtest_prod_util.h"
11 #include "base/i18n/rtl.h"
12 #include "components/autofill/core/browser/autofill_client.h"
13 #include "components/autofill/core/browser/autofill_popup_delegate.h"
14 #include "components/autofill/core/common/password_form_fill_data.h"
20 namespace password_manager {
22 class PasswordManagerClient;
24 // This class is responsible for filling password forms.
25 class PasswordAutofillManager : public autofill::AutofillPopupDelegate {
27 PasswordAutofillManager(PasswordManagerClient* password_manager_client,
28 autofill::AutofillClient* autofill_client);
29 virtual ~PasswordAutofillManager();
31 // AutofillPopupDelegate implementation.
32 void OnPopupShown() override;
33 void OnPopupHidden() override;
34 void DidSelectSuggestion(const base::string16& value,
35 int identifier) override;
36 void DidAcceptSuggestion(const base::string16& value,
37 int identifier) override;
38 void RemoveSuggestion(const base::string16& value, int identifier) override;
39 void ClearPreviewedForm() override;
41 // Invoked when a password mapping is added.
42 void OnAddPasswordFormMapping(
44 const autofill::PasswordFormFillData& fill_data);
46 // Handles a request from the renderer to show a popup with the given
47 // |suggestions| from the password manager.
48 void OnShowPasswordSuggestions(int key,
49 base::i18n::TextDirection text_direction,
50 const base::string16& typed_username,
52 const gfx::RectF& bounds);
54 // Invoked to clear any page specific cached values.
57 // A public version of FillSuggestion(), only for use in tests.
58 bool FillSuggestionForTest(int key, const base::string16& username);
60 // A public version of PreviewSuggestion(), only for use in tests.
61 bool PreviewSuggestionForTest(int key, const base::string16& username);
64 typedef std::map<int, autofill::PasswordFormFillData> LoginToPasswordInfoMap;
66 // Attempts to fill the password associated with user name |username|, and
67 // returns true if it was successful.
68 bool FillSuggestion(int key, const base::string16& username);
70 // Attempts to preview the password associated with user name |username|, and
71 // returns true if it was successful.
72 bool PreviewSuggestion(int key, const base::string16& username);
74 // If |current_username| matches a username for one of the login mappings in
75 // |fill_data|, returns true and assigns the password to |out_password|.
76 // Otherwise, returns false and leaves |out_password| untouched.
77 bool GetPasswordForUsername(
78 const base::string16& current_username,
79 const autofill::PasswordFormFillData& fill_data,
80 base::string16* out_password);
82 // Finds login information for a |node| that was previously filled.
83 bool FindLoginInfo(int key, autofill::PasswordFormFillData* found_password);
85 // The logins we have filled so far with their associated info.
86 LoginToPasswordInfoMap login_to_password_info_;
88 // When the autofill popup should be shown, |form_data_key_| identifies the
89 // right password info in |login_to_password_info_|.
92 // Provides embedder-level operations on passwords. Must outlive |this|.
93 PasswordManagerClient* const password_manager_client_; // weak
95 autofill::AutofillClient* const autofill_client_; // weak
97 base::WeakPtrFactory<PasswordAutofillManager> weak_ptr_factory_;
99 DISALLOW_COPY_AND_ASSIGN(PasswordAutofillManager);
102 } // namespace password_manager
104 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_AUTOFILL_MANAGER_H_