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"
14 class ManagePasswordsIconController;
20 // This model provides data for the ManagePasswordsBubble and controls the
21 // password management actions.
22 class ManagePasswordsBubbleModel : public content::WebContentsObserver {
24 enum PasswordAction { REMOVE_PASSWORD, ADD_PASSWORD };
26 // Creates a ManagePasswordsBubbleModel, which holds a raw pointer to the
27 // WebContents in which it lives. Defaults to a display disposition of
28 // AUTOMATIC_WITH_PASSWORD_PENDING, and a dismissal reason of NOT_DISPLAYED.
29 // The bubble's state is updated from the ManagePasswordsUIController
30 // associated with |web_contents| upon creation.
31 explicit ManagePasswordsBubbleModel(content::WebContents* web_contents);
32 virtual ~ManagePasswordsBubbleModel();
34 // Called by the view code when the bubble is shown.
35 void OnBubbleShown(ManagePasswordsBubble::DisplayReason reason);
37 // Called by the view code when the bubble is hidden.
38 void OnBubbleHidden();
40 // Called by the view code when the "Nope" button in clicked by the user.
43 // Called by the view code when the "Never for this site." button in clicked
45 void OnNeverForThisSiteClicked();
47 // Called by the view code when the site is unblacklisted.
48 void OnUnblacklistClicked();
50 // Called by the view code when the save button in clicked by the user.
53 // Called by the view code when the "Done" button is clicked by the user.
56 // Called by the view code when the manage link is clicked by the user.
57 void OnManageLinkClicked();
59 // Called by the view code to delete or add a password form to the
61 void OnPasswordAction(const autofill::PasswordForm& password_form,
62 PasswordAction action);
64 password_manager::ui::State state() const { return state_; }
66 const base::string16& title() const { return title_; }
67 const autofill::PasswordForm& pending_credentials() const {
68 return pending_credentials_;
70 const autofill::PasswordFormMap& best_matches() const {
73 const base::string16& manage_link() const { return manage_link_; }
75 #if defined(UNIT_TEST)
76 // Gets and sets the reason the bubble was displayed.
77 password_manager::metrics_util::UIDisplayDisposition display_disposition()
79 return display_disposition_;
82 // Gets the reason the bubble was dismissed.
83 password_manager::metrics_util::UIDismissalReason dismissal_reason() const {
84 return dismissal_reason_;
88 void set_state(password_manager::ui::State state) { state_ = state; }
92 password_manager::ui::State state_;
93 base::string16 title_;
94 autofill::PasswordForm pending_credentials_;
95 autofill::PasswordFormMap best_matches_;
96 base::string16 manage_link_;
98 password_manager::metrics_util::UIDisplayDisposition display_disposition_;
99 password_manager::metrics_util::UIDismissalReason dismissal_reason_;
101 DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleModel);
104 #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_