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 "chrome/browser/ui/passwords/manage_passwords_bubble.h"
9 #include "components/autofill/core/common/password_form.h"
10 #include "components/password_manager/core/browser/password_manager_metrics_util.h"
11 #include "components/password_manager/core/common/password_manager_ui.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "ui/gfx/range/range.h"
15 class ManagePasswordsIconController
;
21 // This model provides data for the ManagePasswordsBubble and controls the
22 // password management actions.
23 class ManagePasswordsBubbleModel
: public content::WebContentsObserver
{
25 enum PasswordAction
{ REMOVE_PASSWORD
, ADD_PASSWORD
};
27 // Creates a ManagePasswordsBubbleModel, which holds a raw pointer to the
28 // WebContents in which it lives. Defaults to a display disposition of
29 // AUTOMATIC_WITH_PASSWORD_PENDING, and a dismissal reason of NOT_DISPLAYED.
30 // The bubble's state is updated from the ManagePasswordsUIController
31 // associated with |web_contents| upon creation.
32 explicit ManagePasswordsBubbleModel(content::WebContents
* web_contents
);
33 virtual ~ManagePasswordsBubbleModel();
35 // Called by the view code when the bubble is shown.
36 void OnBubbleShown(ManagePasswordsBubble::DisplayReason reason
);
38 // Called by the view code when the bubble is hidden.
39 void OnBubbleHidden();
41 // Called by the view code when the "Nope" button in clicked by the user.
44 // Called by the view code when the "Never for this site." button in clicked
46 void OnNeverForThisSiteClicked();
48 // Called by the view code when the site is unblacklisted.
49 void OnUnblacklistClicked();
51 // Called by the view code when the save button in clicked by the user.
54 // Called by the view code when the "Done" button is clicked by the user.
57 // Called by the view code when the "OK" button is clicked by the user.
60 // Called by the view code when the manage link is clicked by the user.
61 void OnManageLinkClicked();
63 // Called by the view code when the manage in Google link is clicked by the
65 void OnRemoteManageLinkClicked();
67 // Called by the view code to delete or add a password form to the
69 void OnPasswordAction(const autofill::PasswordForm
& password_form
,
70 PasswordAction action
);
72 password_manager::ui::State
state() const { return state_
; }
74 const base::string16
& title() const { return title_
; }
75 const autofill::PasswordForm
& pending_credentials() const {
76 return pending_credentials_
;
78 const autofill::ConstPasswordFormMap
& best_matches() const {
81 const base::string16
& manage_link() const { return manage_link_
; }
82 const base::string16
& save_confirmation_text() const {
83 return save_confirmation_text_
;
85 const gfx::Range
& save_confirmation_link_range() const {
86 return save_confirmation_link_range_
;
89 #if defined(UNIT_TEST)
90 // Gets and sets the reason the bubble was displayed.
91 password_manager::metrics_util::UIDisplayDisposition
display_disposition()
93 return display_disposition_
;
96 // Gets the reason the bubble was dismissed.
97 password_manager::metrics_util::UIDismissalReason
dismissal_reason() const {
98 return dismissal_reason_
;
102 void set_state(password_manager::ui::State state
) { state_
= state
; }
105 // Upper limits on the size of the username and password fields.
106 static int UsernameFieldWidth();
107 static int PasswordFieldWidth();
110 password_manager::ui::State state_
;
111 base::string16 title_
;
112 autofill::PasswordForm pending_credentials_
;
113 autofill::ConstPasswordFormMap best_matches_
;
114 base::string16 manage_link_
;
115 base::string16 save_confirmation_text_
;
116 gfx::Range save_confirmation_link_range_
;
118 password_manager::metrics_util::UIDisplayDisposition display_disposition_
;
119 password_manager::metrics_util::UIDismissalReason dismissal_reason_
;
121 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleModel
);
124 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_