Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / passwords / manage_passwords_bubble_model.h
blob3a26755d1a1c5907f5e03430fafa0a85d4382c04
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;
18 class Profile;
20 namespace content {
21 class WebContents;
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 {
31 public:
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
52 // update bubble.
53 void OnNopeUpdateClicked();
55 // Called by the view code when the "Never for this site." button in clicked
56 // by the user.
57 void OnNeverForThisSiteClicked();
59 // Called by the view code when the save button is clicked by the user.
60 void OnSaveClicked();
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.
66 void OnDoneClicked();
68 // Called by the view code when the "OK" button is clicked by the user.
69 void OnOKClicked();
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
78 // timeout.
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
86 // PasswordStore.
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
107 // site.
108 const ScopedVector<const autofill::PasswordForm>& federated_credentials()
109 const {
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 // True if the save bubble should display the warm welcome for Google Smart
131 // Lock.
132 bool ShouldShowGoogleSmartLockWelcome() const;
134 #if defined(UNIT_TEST)
135 // Gets and sets the reason the bubble was displayed.
136 password_manager::metrics_util::UIDisplayDisposition display_disposition()
137 const {
138 return display_disposition_;
141 // Gets the reason the bubble was dismissed.
142 password_manager::metrics_util::UIDismissalReason dismissal_reason() const {
143 return dismissal_reason_;
146 // State setter.
147 void set_state(password_manager::ui::State state) { state_ = state; }
148 #endif
150 // Upper limits on the size of the username and password fields.
151 static int UsernameFieldWidth();
152 static int PasswordFieldWidth();
154 private:
155 enum UserBehaviorOnUpdateBubble {
156 UPDATE_CLICKED,
157 NOPE_CLICKED,
158 NO_INTERACTION
160 // Updates |title_| and |title_brand_link_range_| for the
161 // PENDING_PASSWORD_STATE.
162 void UpdatePendingStateTitle();
163 // Updates |title_| for the MANAGE_STATE.
164 void UpdateManageStateTitle();
165 password_manager::metrics_util::UpdatePasswordSubmissionEvent
166 GetUpdateDismissalReason(UserBehaviorOnUpdateBubble behavior) const;
167 // URL of the page from where this bubble was triggered.
168 GURL origin_;
169 password_manager::ui::State state_;
170 base::string16 title_;
171 // Range of characters in the title that contains the Smart Lock Brand and
172 // should point to an article. For the default title the range is empty.
173 gfx::Range title_brand_link_range_;
174 autofill::PasswordForm pending_password_;
175 bool password_overridden_;
176 ScopedVector<const autofill::PasswordForm> local_credentials_;
177 ScopedVector<const autofill::PasswordForm> federated_credentials_;
178 base::string16 manage_link_;
179 base::string16 save_confirmation_text_;
180 gfx::Range save_confirmation_link_range_;
181 password_manager::metrics_util::UIDisplayDisposition display_disposition_;
182 password_manager::metrics_util::UIDismissalReason dismissal_reason_;
183 password_manager::metrics_util::UpdatePasswordSubmissionEvent
184 update_password_submission_event_;
186 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleModel);
189 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_