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.
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_SAVE_PASSWORD_INFOBAR_DELEGATE_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_SAVE_PASSWORD_INFOBAR_DELEGATE_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/timer/elapsed_timer.h"
11 #include "components/infobars/core/confirm_infobar_delegate.h"
12 #include "components/password_manager/core/browser/password_form_manager.h"
13 #include "components/password_manager/core/browser/password_manager_metrics_util.h"
14 #include "ui/gfx/range/range.h"
20 namespace password_manager
{
21 enum class CredentialSourceType
;
24 // After a successful *new* login attempt, we take the PasswordFormManager in
25 // provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
26 // the user makes up their mind with the "save password" infobar. Note if the
27 // login is one we already know about, the end of the line is
28 // provisional_save_manager_ because we just update it on success and so such
29 // forms never end up in an infobar.
30 class SavePasswordInfoBarDelegate
: public ConfirmInfoBarDelegate
{
32 // If we won't be showing the one-click signin infobar, creates a save
33 // password infobar and delegate and adds the infobar to the InfoBarService
34 // for |web_contents|. |uma_histogram_suffix| is empty, or one of the
35 // "group_X" suffixes used in the histogram names for infobar usage reporting;
36 // if empty, the usage is not reported, otherwise the suffix is used to choose
37 // the right histogram.
39 content::WebContents
* web_contents
,
40 scoped_ptr
<password_manager::PasswordFormManager
> form_to_save
,
41 const std::string
& uma_histogram_suffix
,
42 password_manager::CredentialSourceType source_type
);
44 ~SavePasswordInfoBarDelegate() override
;
46 const gfx::Range
& message_link_range() const { return message_link_range_
; }
48 // ConfirmInfoBarDelegate:
49 Type
GetInfoBarType() const override
;
50 InfoBarAutomationType
GetInfoBarAutomationType() const override
;
51 int GetIconId() const override
;
52 bool ShouldExpire(const NavigationDetails
& details
) const override
;
53 void InfoBarDismissed() override
;
54 base::string16
GetMessageText() const override
;
55 base::string16
GetButtonLabel(InfoBarButton button
) const override
;
56 bool LinkClicked(WindowOpenDisposition disposition
) override
;
57 bool Accept() override
;
58 bool Cancel() override
;
61 // Makes a ctor available in tests.
62 SavePasswordInfoBarDelegate(
63 content::WebContents
* web_contents
,
64 scoped_ptr
<password_manager::PasswordFormManager
> form_to_save
,
65 const std::string
& uma_histogram_suffix
,
66 password_manager::CredentialSourceType source_type
,
67 bool is_smartlock_branding_enabled
);
70 // The PasswordFormManager managing the form we're asking the user about,
71 // and should update as per her decision.
72 scoped_ptr
<password_manager::PasswordFormManager
> form_to_save_
;
74 // Used to track the results we get from the info bar.
75 password_manager::metrics_util::ResponseType infobar_response_
;
77 // Measures the "Save password?" prompt lifetime. Used to report an UMA
79 base::ElapsedTimer timer_
;
81 // The group name corresponding to the domain name of |form_to_save_| if the
82 // form is on a monitored domain. Otherwise, an empty string.
83 const std::string uma_histogram_suffix_
;
85 // Records source from where infobar was triggered.
86 // Infobar appearance (message, buttons) depends on value of this parameter.
87 password_manager::CredentialSourceType source_type_
;
89 // Infobar message: branded as a part of Google Smart Lock for signed users.
90 base::string16 message_
;
92 // If set, describes the location of the link to the help center article for
94 gfx::Range message_link_range_
;
96 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate
);
99 // Creates the platform-specific SavePassword InfoBar. This function is defined
100 // in platform-specific .cc (or .mm) files.
101 scoped_ptr
<infobars::InfoBar
> CreateSavePasswordInfoBar(
102 scoped_ptr
<SavePasswordInfoBarDelegate
> delegate
);
104 #endif // CHROME_BROWSER_PASSWORD_MANAGER_SAVE_PASSWORD_INFOBAR_DELEGATE_H_