Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / password_manager / core / browser / password_autofill_manager.h
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 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_AUTOFILL_MANAGER_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_AUTOFILL_MANAGER_H_
7
8 #include <map>
9
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"
15
16 namespace gfx {
17 class RectF;
18 }
19
20 namespace password_manager {
21
22 class PasswordManagerClient;
23
24 // This class is responsible for filling password forms.
25 class PasswordAutofillManager : public autofill::AutofillPopupDelegate {
26  public:
27   PasswordAutofillManager(PasswordManagerClient* password_manager_client,
28                           autofill::AutofillClient* autofill_client);
29   virtual ~PasswordAutofillManager();
30
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;
40
41   // Invoked when a password mapping is added.
42   void OnAddPasswordFormMapping(
43       int key,
44       const autofill::PasswordFormFillData& fill_data);
45
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,
51                                  bool show_all,
52                                  const gfx::RectF& bounds);
53
54   // Invoked to clear any page specific cached values.
55   void Reset();
56
57   // A public version of FillSuggestion(), only for use in tests.
58   bool FillSuggestionForTest(int key, const base::string16& username);
59
60   // A public version of PreviewSuggestion(), only for use in tests.
61   bool PreviewSuggestionForTest(int key, const base::string16& username);
62
63  private:
64   typedef std::map<int, autofill::PasswordFormFillData> LoginToPasswordInfoMap;
65
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);
69
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);
73
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);
81
82   // Finds login information for a |node| that was previously filled.
83   bool FindLoginInfo(int key, autofill::PasswordFormFillData* found_password);
84
85   // The logins we have filled so far with their associated info.
86   LoginToPasswordInfoMap login_to_password_info_;
87
88   // When the autofill popup should be shown, |form_data_key_| identifies the
89   // right password info in |login_to_password_info_|.
90   int form_data_key_;
91
92   // Provides embedder-level operations on passwords. Must outlive |this|.
93   PasswordManagerClient* const password_manager_client_;  // weak
94
95   autofill::AutofillClient* const autofill_client_;  // weak
96
97   base::WeakPtrFactory<PasswordAutofillManager> weak_ptr_factory_;
98
99   DISALLOW_COPY_AND_ASSIGN(PasswordAutofillManager);
100 };
101
102 }  // namespace password_manager
103
104 #endif  // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_AUTOFILL_MANAGER_H_