[M47_2526] Chromium upversion to m47_2526 branch
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / browser / password_manager / password_manager.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright 2014 Samsung Electronics. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #ifndef PASSWORD_MANAGER_H
7 #define PASSWORD_MANAGER_H
8
9 #if defined(TIZEN_AUTOFILL_SUPPORT)
10
11 #include <vector>
12
13 #include "base/callback.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/observer_list.h"
17 #include "base/prefs/pref_member.h"
18 #include "base/stl_util.h"
19 #include "browser/password_manager/password_form_manager.h"
20 #include "components/autofill/core/common/password_form.h"
21 #include "components/autofill/core/common/password_form_fill_data.h"
22 #include "components/password_manager/core/browser/login_model.h"
23
24 class PrefRegistrySimple;
25
26 namespace content {
27 class WebContents;
28 }
29
30 namespace user_prefs {
31 class PrefRegistrySyncable;
32 }
33
34 // Per-tab password manager. Handles creation and management of UI elements,
35 // receiving password form data from the renderer and managing the password
36 // database through the PasswordStore. The PasswordManager is a LoginModel
37 // for purposes of supporting HTTP authentication dialogs.
38 namespace password_manager {
39 class PasswordManager : public LoginModel {
40 public:
41   static const char kOtherPossibleUsernamesExperiment[];
42
43   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
44
45   explicit PasswordManager(PasswordManagerClient* client);
46   virtual ~PasswordManager();
47
48   typedef base::Callback<void(const autofill::PasswordForm&)>
49       PasswordSubmittedCallback;
50
51   // There is no corresponding remove function as currently all of the
52   // owners of these callbacks have sufficient lifetimes so that the callbacks
53   // should always be valid when called.
54   void AddSubmissionCallback(const PasswordSubmittedCallback& callback);
55
56   // Is password manager enabled for autofill password
57   bool IsPasswordManagerSavingEnabled() const;
58
59   // Set password manager enabled for autofill password
60   void SetPasswordManagerSavingEnabled(bool enabled);
61
62   bool IsPasswordManagerFillingEnabled() const;
63   void SetPasswordManagerFillingEnabled(bool enabled);
64
65   // Called by a PasswordFormManager when it decides a form can be autofilled
66   // on the page.
67   virtual void Autofill(const autofill::PasswordForm& form_for_autofill,
68                         const autofill::PasswordFormMap& best_matches,
69                         const autofill::PasswordForm& preferred_match,
70                         bool wait_for_username) const;
71
72   // LoginModel implementation.
73   virtual void AddObserver(LoginModelObserver* observer) override;
74   virtual void RemoveObserver(LoginModelObserver* observer) override;
75
76   // Mark this form as having a generated password.
77   void SetFormHasGeneratedPassword(const autofill::PasswordForm& form);
78
79   // TODO(isherman): This should not be public, but is currently being used by
80   // the LoginPrompt code.
81   // When a form is submitted, we prepare to save the password but wait
82   // until we decide the user has successfully logged in. This is step 1
83   // of 2 (see SavePassword).
84   void ProvisionallySavePassword(const autofill::PasswordForm& form);
85
86   // Should be called when the user navigates the main frame.
87   void DidNavigateMainFrame(bool is_in_page);
88
89   // Handles password forms being parsed.
90   void OnPasswordFormsParsed(
91       const std::vector<autofill::PasswordForm>& forms);
92
93   // Handles password forms being rendered.
94   void OnPasswordFormsRendered(
95       const std::vector<autofill::PasswordForm>& visible_forms,
96       bool did_stop_loading);
97
98   // Handles a password form being submitted.
99   virtual void OnPasswordFormSubmitted(
100       const autofill::PasswordForm& password_form);
101
102 private:
103   enum ProvisionalSaveFailure {
104     SAVING_DISABLED,
105     EMPTY_PASSWORD,
106     NO_MATCHING_FORM,
107     MATCHING_NOT_COMPLETE,
108     FORM_BLACKLISTED,
109     INVALID_FORM,
110     AUTOCOMPLETE_OFF,
111     MAX_FAILURE_VALUE
112   };
113
114   // Log failure for UMA. Logs additional metrics if the |form_origin|
115   // corresponds to one of the top, explicitly monitored websites.
116   void RecordFailure(ProvisionalSaveFailure failure,
117                      const std::string& form_origin);
118
119   // Possibly set up FieldTrial for testing other possible usernames. This only
120   // happens if there are other_possible_usernames to be shown and the
121   // experiment hasn't already been initialized. We setup the experiment at
122   // such a late time because this experiment will only affect a small number
123   // of users so we want to include a larger fraction of these users than the
124   // normal 10%.
125   void PossiblyInitializeUsernamesExperiment(
126       const autofill::PasswordFormMap& matches) const;
127
128   // Returns true if we can show possible usernames to users in cases where
129   // the username for the form is ambigious.
130   bool OtherPossibleUsernamesEnabled() const;
131
132   // Returns true if the user needs to be prompted before a password can be
133   // saved (instead of automatically saving
134   // the password), based on inspecting the state of
135   // |provisional_save_manager_|.
136   bool ShouldPromptUserToSavePassword() const;
137
138   // Note about how a PasswordFormManager can transition from
139   // pending_login_managers_ to provisional_save_manager_ and the infobar.
140   //
141   // 1. form "seen"
142   //       |                                             new
143   //       |                                               ___ Infobar
144   // pending_login -- form submit --> provisional_save ___/
145   //             ^                            |           \___ (update DB)
146   //             |                           fail
147   //             |-----------<------<---------|          !new
148   //
149   // When a form is "seen" on a page, a PasswordFormManager is created
150   // and stored in this collection until user navigates away from page.
151
152   ScopedVector<PasswordFormManager> pending_login_managers_;
153
154   // When the user submits a password/credential, this contains the
155   // PasswordFormManager for the form in question until we deem the login
156   // attempt to have succeeded (as in valid credentials). If it fails, we
157   // send the PasswordFormManager back to the pending_login_managers_ set.
158   // Scoped in case PasswordManager gets deleted (e.g tab closes) between the
159   // time a user submits a login form and gets to the next page.
160   scoped_ptr<PasswordFormManager> provisional_save_manager_;
161
162   // The embedder-level client. Must outlive this class.
163   PasswordManagerClient* const client_;
164
165   // The platform-level driver. Must outlive this class.
166   PasswordManagerDriver* const driver_;
167
168   // Set to false to disable the password manager (will no longer ask if you
169   // want to save passwords but will continue to fill passwords).
170   bool password_manager_saving_enabled_;
171
172   bool password_manager_filling_enabled_;
173
174   // Observers to be notified of LoginModel events.  This is mutable to allow
175   // notification in const member functions.
176   mutable base::ObserverList<LoginModelObserver> observers_;
177
178   // Callbacks to be notified when a password form has been submitted.
179   std::vector<PasswordSubmittedCallback> submission_callbacks_;
180
181   DISALLOW_COPY_AND_ASSIGN(PasswordManager);
182 };
183 }
184
185 #endif // TIZEN_AUTOFILL_SUPPORT
186
187 #endif  // PASSWORD_MANAGER_H