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 CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
6 #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
8 #include "base/memory/scoped_vector.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
10 #include "components/autofill/core/common/password_form.h"
11 #include "components/password_manager/core/browser/password_manager_metrics_util.h"
12 #include "components/password_manager/core/common/password_manager_ui.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "ui/gfx/range/range.h"
16 class ManagePasswordsIconController
;
17 class ManagePasswordsUIController
;
24 namespace password_manager
{
25 enum class CredentialType
: unsigned int;
28 // This model provides data for the ManagePasswordsBubble and controls the
29 // password management actions.
30 class ManagePasswordsBubbleModel
: public content::WebContentsObserver
{
32 enum PasswordAction
{ REMOVE_PASSWORD
, ADD_PASSWORD
};
34 // Creates a ManagePasswordsBubbleModel, which holds a raw pointer to the
35 // WebContents in which it lives. Defaults to a display disposition of
36 // AUTOMATIC_WITH_PASSWORD_PENDING, and a dismissal reason of NOT_DISPLAYED.
37 // The bubble's state is updated from the ManagePasswordsUIController
38 // associated with |web_contents| upon creation.
39 explicit ManagePasswordsBubbleModel(content::WebContents
* web_contents
);
40 ~ManagePasswordsBubbleModel() override
;
42 // Called by the view code when the bubble is shown.
43 void OnBubbleShown(ManagePasswordsBubble::DisplayReason reason
);
45 // Called by the view code when the bubble is hidden.
46 void OnBubbleHidden();
48 // Called by the view code when the "Never for this site." button in clicked
49 // by the user and user gets confirmation bubble.
50 void OnConfirmationForNeverForThisSite();
52 // Called by the view code when the "Nope" button in clicked by the user.
55 // Called by the view code when the "Never for this site." button in clicked
57 void OnNeverForThisSiteClicked();
59 // Called by the view code when the "Undo" button is clicked in
60 // "Never for this site." confirmation bubble by the user.
61 void OnUndoNeverForThisSite();
63 // Called by the view code when the site is unblacklisted.
64 void OnUnblacklistClicked();
66 // Called by the view code when the save button in clicked by the user.
69 // Called by the view code when the "Done" button is clicked by the user.
72 // Called by the view code when the "OK" button is clicked by the user.
75 // Called by the view code when the manage link is clicked by the user.
76 void OnManageLinkClicked();
78 // Called by the view code when the auto-signin toast is about to close due to
80 void OnAutoSignInToastTimeout();
82 // Called by the view code when user clicks on the auto sign-in toast in order
83 // to manage credentials.
84 void OnAutoSignInClicked();
86 // Called by the view code to delete or add a password form to the
88 void OnPasswordAction(const autofill::PasswordForm
& password_form
,
89 PasswordAction action
);
91 // Called by the view code to notify about chosen credential.
92 void OnChooseCredentials(const autofill::PasswordForm
& password_form
,
93 password_manager::CredentialType credential_type_
);
95 GURL
origin() const { return origin_
; }
97 password_manager::ui::State
state() const { return state_
; }
99 const base::string16
& title() const { return title_
; }
100 const autofill::PasswordForm
& pending_password() const {
101 return pending_password_
;
103 // Returns the available credentials which match the current site.
104 const ScopedVector
<const autofill::PasswordForm
>& local_credentials() const {
105 return local_credentials_
;
107 // Return the federated logins which may be used for logging in to the current
109 const ScopedVector
<const autofill::PasswordForm
>& federated_credentials()
111 return federated_credentials_
;
113 const base::string16
& manage_link() const { return manage_link_
; }
114 bool never_save_passwords() const { return never_save_passwords_
; }
115 const base::string16
& save_confirmation_text() const {
116 return save_confirmation_text_
;
118 const gfx::Range
& save_confirmation_link_range() const {
119 return save_confirmation_link_range_
;
122 Profile
* GetProfile() const;
124 // Returns true iff the new UI should be presented to user for managing and
125 // saving the passwords.
126 bool IsNewUIActive() const;
128 #if defined(UNIT_TEST)
129 // Gets and sets the reason the bubble was displayed.
130 password_manager::metrics_util::UIDisplayDisposition
display_disposition()
132 return display_disposition_
;
135 // Gets the reason the bubble was dismissed.
136 password_manager::metrics_util::UIDismissalReason
dismissal_reason() const {
137 return dismissal_reason_
;
141 void set_state(password_manager::ui::State state
) { state_
= state
; }
144 // Upper limits on the size of the username and password fields.
145 static int UsernameFieldWidth();
146 static int PasswordFieldWidth();
149 // Returns the title for the PENDING_PASSWORD_STATE.
150 base::string16
PendingStateTitleBasedOnSavePasswordPref() const;
151 // URL of the page from where this bubble was triggered.
153 password_manager::ui::State state_
;
154 base::string16 title_
;
155 autofill::PasswordForm pending_password_
;
156 ScopedVector
<const autofill::PasswordForm
> local_credentials_
;
157 ScopedVector
<const autofill::PasswordForm
> federated_credentials_
;
158 base::string16 manage_link_
;
159 base::string16 save_confirmation_text_
;
160 gfx::Range save_confirmation_link_range_
;
161 // If true upon destruction, the user has confirmed that she never wants to
162 // save passwords for a particular site.
163 bool never_save_passwords_
;
164 password_manager::metrics_util::UIDisplayDisposition display_disposition_
;
165 password_manager::metrics_util::UIDismissalReason dismissal_reason_
;
167 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleModel
);
170 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_