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
;
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 "Cancel" button in clicked by the user.
49 void OnCancelClicked();
51 // Called by the view code when the "Nope" button in clicked by the user in
53 void OnNopeUpdateClicked();
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 save button is clicked by the user.
62 // Called by the view code when the update link is clicked by the user.
63 void OnUpdateClicked(const autofill::PasswordForm
& password_form
);
65 // Called by the view code when the "Done" button is clicked by the user.
68 // Called by the view code when the "OK" button is clicked by the user.
71 // Called by the view code when the manage link is clicked by the user.
72 void OnManageLinkClicked();
74 // Called by the view code when the brand name link is clicked by the user.
75 void OnBrandLinkClicked();
77 // Called by the view code when the auto-signin toast is about to close due to
79 void OnAutoSignInToastTimeout();
81 // Called by the view code when user clicks on the auto sign-in toast in order
82 // to manage credentials.
83 void OnAutoSignInClicked();
85 // Called by the view code to delete or add a password form to the
87 void OnPasswordAction(const autofill::PasswordForm
& password_form
,
88 PasswordAction action
);
90 // Called by the view code to notify about chosen credential.
91 void OnChooseCredentials(const autofill::PasswordForm
& password_form
,
92 password_manager::CredentialType credential_type_
);
94 GURL
origin() const { return origin_
; }
96 password_manager::ui::State
state() const { return state_
; }
98 const base::string16
& title() const { return title_
; }
99 const autofill::PasswordForm
& pending_password() const {
100 return pending_password_
;
102 // Returns the available credentials which match the current site.
103 const ScopedVector
<const autofill::PasswordForm
>& local_credentials() const {
104 return local_credentials_
;
106 // Return the federated logins which may be used for logging in to the current
108 const ScopedVector
<const autofill::PasswordForm
>& federated_credentials()
110 return federated_credentials_
;
112 const base::string16
& manage_link() const { return manage_link_
; }
113 const base::string16
& save_confirmation_text() const {
114 return save_confirmation_text_
;
116 const gfx::Range
& save_confirmation_link_range() const {
117 return save_confirmation_link_range_
;
120 const gfx::Range
& title_brand_link_range() const {
121 return title_brand_link_range_
;
124 Profile
* GetProfile() const;
126 // Returns true iff the multiple account selection prompt for account update
127 // should be presented.
128 bool ShouldShowMultipleAccountUpdateUI() const;
130 #if defined(UNIT_TEST)
131 // Gets and sets the reason the bubble was displayed.
132 password_manager::metrics_util::UIDisplayDisposition
display_disposition()
134 return display_disposition_
;
137 // Gets the reason the bubble was dismissed.
138 password_manager::metrics_util::UIDismissalReason
dismissal_reason() const {
139 return dismissal_reason_
;
143 void set_state(password_manager::ui::State state
) { state_
= state
; }
146 // Upper limits on the size of the username and password fields.
147 static int UsernameFieldWidth();
148 static int PasswordFieldWidth();
151 enum UserBehaviorOnUpdateBubble
{
156 // Updates |title_| and |title_brand_link_range_| for the
157 // PENDING_PASSWORD_STATE.
158 void UpdatePendingStateTitle();
159 password_manager::metrics_util::UpdatePasswordSubmissionEvent
160 GetUpdateDismissalReason(UserBehaviorOnUpdateBubble behavior
) const;
161 // URL of the page from where this bubble was triggered.
163 password_manager::ui::State state_
;
164 base::string16 title_
;
165 // Range of characters in the title that contains the Smart Lock Brand and
166 // should point to an article. For the default title the range is empty.
167 gfx::Range title_brand_link_range_
;
168 autofill::PasswordForm pending_password_
;
169 bool password_overridden_
;
170 ScopedVector
<const autofill::PasswordForm
> local_credentials_
;
171 ScopedVector
<const autofill::PasswordForm
> federated_credentials_
;
172 base::string16 manage_link_
;
173 base::string16 save_confirmation_text_
;
174 gfx::Range save_confirmation_link_range_
;
175 password_manager::metrics_util::UIDisplayDisposition display_disposition_
;
176 password_manager::metrics_util::UIDismissalReason dismissal_reason_
;
177 password_manager::metrics_util::UpdatePasswordSubmissionEvent
178 update_password_submission_event_
;
180 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleModel
);
183 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_