Home | History | Annotate | Download | only in passwords
      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.
      4 
      5 #ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
      6 #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
      7 
      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 
     14 class ManagePasswordsIconController;
     15 
     16 namespace content {
     17 class WebContents;
     18 }
     19 
     20 // This model provides data for the ManagePasswordsBubble and controls the
     21 // password management actions.
     22 class ManagePasswordsBubbleModel : public content::WebContentsObserver {
     23  public:
     24   enum PasswordAction { REMOVE_PASSWORD, ADD_PASSWORD };
     25 
     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();
     33 
     34   // Called by the view code when the bubble is shown.
     35   void OnBubbleShown(ManagePasswordsBubble::DisplayReason reason);
     36 
     37   // Called by the view code when the bubble is hidden.
     38   void OnBubbleHidden();
     39 
     40   // Called by the view code when the "Nope" button in clicked by the user.
     41   void OnNopeClicked();
     42 
     43   // Called by the view code when the "Never for this site." button in clicked
     44   // by the user.
     45   void OnNeverForThisSiteClicked();
     46 
     47   // Called by the view code when the site is unblacklisted.
     48   void OnUnblacklistClicked();
     49 
     50   // Called by the view code when the save button in clicked by the user.
     51   void OnSaveClicked();
     52 
     53   // Called by the view code when the "Done" button is clicked by the user.
     54   void OnDoneClicked();
     55 
     56   // Called by the view code when the manage link is clicked by the user.
     57   void OnManageLinkClicked();
     58 
     59   // Called by the view code to delete or add a password form to the
     60   // PasswordStore.
     61   void OnPasswordAction(const autofill::PasswordForm& password_form,
     62                         PasswordAction action);
     63 
     64   password_manager::ui::State state() const { return state_; }
     65 
     66   const base::string16& title() const { return title_; }
     67   const autofill::PasswordForm& pending_credentials() const {
     68     return pending_credentials_;
     69   }
     70   const autofill::PasswordFormMap& best_matches() const {
     71     return best_matches_;
     72   }
     73   const base::string16& manage_link() const { return manage_link_; }
     74 
     75 #if defined(UNIT_TEST)
     76   // Gets and sets the reason the bubble was displayed.
     77   password_manager::metrics_util::UIDisplayDisposition display_disposition()
     78       const {
     79     return display_disposition_;
     80   }
     81 
     82   // Gets the reason the bubble was dismissed.
     83   password_manager::metrics_util::UIDismissalReason dismissal_reason() const {
     84     return dismissal_reason_;
     85   }
     86 
     87   // State setter.
     88   void set_state(password_manager::ui::State state) { state_ = state; }
     89 #endif
     90 
     91  private:
     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_;
     97 
     98   password_manager::metrics_util::UIDisplayDisposition display_disposition_;
     99   password_manager::metrics_util::UIDismissalReason dismissal_reason_;
    100 
    101   DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleModel);
    102 };
    103 
    104 #endif  // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
    105