Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / password_manager / save_password_infobar_delegate.h
1 // Copyright 2014 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_PASSWORD_MANAGER_SAVE_PASSWORD_INFOBAR_DELEGATE_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_SAVE_PASSWORD_INFOBAR_DELEGATE_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/timer/elapsed_timer.h"
12 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
13 #include "chrome/browser/infobars/infobar_delegate.h"
14 #include "chrome/browser/password_manager/password_form_manager.h"
15 #include "content/public/browser/navigation_details.h"
16
17 namespace content {
18 class WebContents;
19 }
20
21 // After a successful *new* login attempt, we take the PasswordFormManager in
22 // provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
23 // the user makes up their mind with the "save password" infobar. Note if the
24 // login is one we already know about, the end of the line is
25 // provisional_save_manager_ because we just update it on success and so such
26 // forms never end up in an infobar.
27 class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
28  public:
29   // If we won't be showing the one-click signin infobar, creates a save
30   // password infobar and delegate and adds the infobar to the InfoBarService
31   // for |web_contents|.  |uma_histogram_suffix| is empty, or one of the
32   // "group_X" suffixes used in the histogram names for infobar usage reporting;
33   // if empty, the usage is not reported, otherwise the suffix is used to choose
34   // the right histogram.
35   static void Create(content::WebContents* web_contents,
36                      PasswordFormManager* form_to_save,
37                      const std::string& uma_histogram_suffix);
38
39   virtual ~SavePasswordInfoBarDelegate();
40
41   // Specifies whether additional authentication (as defined by the OS) should
42   // be required before autofilling this password.
43   void SetUseAdditionalPasswordAuthentication(
44       bool use_additional_authentication);
45
46  private:
47   enum ResponseType {
48     NO_RESPONSE = 0,
49     REMEMBER_PASSWORD,
50     NEVER_REMEMBER_PASSWORD,
51     INFOBAR_DISMISSED,
52     NUM_RESPONSE_TYPES,
53   };
54
55   SavePasswordInfoBarDelegate(PasswordFormManager* form_to_save,
56                               const std::string& uma_histogram_suffix);
57
58   // Returns a save password infobar that owns |delegate|.
59   static scoped_ptr<InfoBar> CreateInfoBar(
60       scoped_ptr<SavePasswordInfoBarDelegate> delegate);
61
62   // InfoBarDelegate
63   virtual bool ShouldExpire(const content::LoadCommittedDetails& details)
64       const OVERRIDE;
65
66   // ConfirmInfoBarDelegate
67   virtual int GetIconID() const OVERRIDE;
68   virtual Type GetInfoBarType() const OVERRIDE;
69   virtual base::string16 GetMessageText() const OVERRIDE;
70   virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
71   virtual bool Accept() OVERRIDE;
72   virtual bool Cancel() OVERRIDE;
73   virtual void InfoBarDismissed() OVERRIDE;
74
75   virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE;
76
77   // The PasswordFormManager managing the form we're asking the user about,
78   // and should update as per her decision.
79   scoped_ptr<PasswordFormManager> form_to_save_;
80
81   // Used to track the results we get from the info bar.
82   ResponseType infobar_response_;
83
84   // Measures the "Save password?" prompt lifetime. Used to report an UMA
85   // signal.
86   base::ElapsedTimer timer_;
87
88   // The group name corresponding to the domain name of |form_to_save_| if the
89   // form is on a monitored domain. Otherwise, an empty string.
90   const std::string uma_histogram_suffix_;
91
92   DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
93 };
94
95 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_SAVE_PASSWORD_INFOBAR_DELEGATE_H_