Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/browser/password_manager/save_password_infobar_delegate.cc

Issue 967193002: Credential saving clank infobar for Smart Lock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@reusable_more_button
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" 5 #include "chrome/browser/password_manager/save_password_infobar_delegate.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/infobars/infobar_service.h" 8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/ui/android/infobars/save_password_infobar.h"
10 #include "chrome/grit/chromium_strings.h" 10 #include "chrome/grit/chromium_strings.h"
11 #include "chrome/grit/generated_resources.h" 11 #include "chrome/grit/generated_resources.h"
12 #include "components/infobars/core/infobar.h" 12 #include "components/password_manager/core/browser/password_manager_client.h"
13 #include "components/password_manager/core/browser/password_form_manager.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
16 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
17 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
18 16
17 namespace {
18
19 int GetCancelButtonText(password_manager::CredentialSourceType source_type) {
20 return source_type ==
21 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API
22 ? IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_NO_THANKS_BUTTON
23 : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON;
24 }
25
26 } // namespace
27
19 // static 28 // static
20 void SavePasswordInfoBarDelegate::Create( 29 void SavePasswordInfoBarDelegate::Create(
21 content::WebContents* web_contents, 30 content::WebContents* web_contents,
22 scoped_ptr<password_manager::PasswordFormManager> form_to_save, 31 scoped_ptr<password_manager::PasswordFormManager> form_to_save,
23 const std::string& uma_histogram_suffix) { 32 const std::string& uma_histogram_suffix,
33 password_manager::CredentialSourceType source_type) {
24 InfoBarService* infobar_service = 34 InfoBarService* infobar_service =
25 InfoBarService::FromWebContents(web_contents); 35 InfoBarService::FromWebContents(web_contents);
26 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( 36 SavePasswordInfoBarDelegate* infobar_delegate =
27 scoped_ptr<ConfirmInfoBarDelegate>(new SavePasswordInfoBarDelegate( 37 new SavePasswordInfoBarDelegate(
28 form_to_save.Pass(), uma_histogram_suffix)))); 38 form_to_save.Pass(), uma_histogram_suffix, source_type);
39 #if defined(OS_ANDROID)
40 // For Android in case of smart lock we need different appearance of infobar.
41 scoped_ptr<infobars::InfoBar> infobar =
42 make_scoped_ptr(new SavePasswordInfoBar(
43 scoped_ptr<SavePasswordInfoBarDelegate>(infobar_delegate)));
44 #else
45 // For desktop we'll keep using the ConfirmInfobar.
46 scoped_ptr<infobars::InfoBar> infobar = infobar_service->CreateConfirmInfoBar(
47 scoped_ptr<ConfirmInfoBarDelegate>(infobar_delegate));
48 #endif
49 infobar_service->AddInfoBar(infobar.Pass());
29 } 50 }
30 51
31 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { 52 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() {
32 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", 53 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
33 infobar_response_, 54 infobar_response_,
34 password_manager::metrics_util::NUM_RESPONSE_TYPES); 55 password_manager::metrics_util::NUM_RESPONSE_TYPES);
35 56
36 password_manager::metrics_util::LogUIDismissalReason(infobar_response_); 57 password_manager::metrics_util::LogUIDismissalReason(infobar_response_);
37 58
38 // The shortest period for which the prompt needs to live, so that we don't 59 // The shortest period for which the prompt needs to live, so that we don't
39 // consider it killed prematurely, as might happen, e.g., if a pre-rendered 60 // consider it killed prematurely, as might happen, e.g., if a pre-rendered
40 // page gets swapped in (and the current WebContents is destroyed). 61 // page gets swapped in (and the current WebContents is destroyed).
41 const base::TimeDelta kMinimumPromptDisplayTime = 62 const base::TimeDelta kMinimumPromptDisplayTime =
42 base::TimeDelta::FromSeconds(1); 63 base::TimeDelta::FromSeconds(1);
43 64
44 if (!uma_histogram_suffix_.empty()) { 65 if (!uma_histogram_suffix_.empty()) {
45 password_manager::metrics_util::LogUMAHistogramEnumeration( 66 password_manager::metrics_util::LogUMAHistogramEnumeration(
46 "PasswordManager.SavePasswordPromptResponse_" + uma_histogram_suffix_, 67 "PasswordManager.SavePasswordPromptResponse_" + uma_histogram_suffix_,
47 infobar_response_, 68 infobar_response_,
48 password_manager::metrics_util::NUM_RESPONSE_TYPES); 69 password_manager::metrics_util::NUM_RESPONSE_TYPES);
49 password_manager::metrics_util::LogUMAHistogramBoolean( 70 password_manager::metrics_util::LogUMAHistogramBoolean(
50 "PasswordManager.SavePasswordPromptDisappearedQuickly_" + 71 "PasswordManager.SavePasswordPromptDisappearedQuickly_" +
51 uma_histogram_suffix_, 72 uma_histogram_suffix_,
52 timer_.Elapsed() < kMinimumPromptDisplayTime); 73 timer_.Elapsed() < kMinimumPromptDisplayTime);
53 } 74 }
54 } 75 }
55 76
56 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( 77 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate(
57 scoped_ptr<password_manager::PasswordFormManager> form_to_save, 78 scoped_ptr<password_manager::PasswordFormManager> form_to_save,
58 const std::string& uma_histogram_suffix) 79 const std::string& uma_histogram_suffix,
80 password_manager::CredentialSourceType source_type)
59 : ConfirmInfoBarDelegate(), 81 : ConfirmInfoBarDelegate(),
60 form_to_save_(form_to_save.Pass()), 82 form_to_save_(form_to_save.Pass()),
61 infobar_response_(password_manager::metrics_util::NO_RESPONSE), 83 infobar_response_(password_manager::metrics_util::NO_RESPONSE),
62 uma_histogram_suffix_(uma_histogram_suffix) { 84 uma_histogram_suffix_(uma_histogram_suffix),
85 source_type_(source_type) {
63 if (!uma_histogram_suffix_.empty()) { 86 if (!uma_histogram_suffix_.empty()) {
64 password_manager::metrics_util::LogUMAHistogramBoolean( 87 password_manager::metrics_util::LogUMAHistogramBoolean(
65 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, 88 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_,
66 true); 89 true);
67 } 90 }
68 } 91 }
69 92
93 bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() {
94 return source_type_ ==
95 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API;
96 }
97
70 infobars::InfoBarDelegate::Type 98 infobars::InfoBarDelegate::Type
71 SavePasswordInfoBarDelegate::GetInfoBarType() const { 99 SavePasswordInfoBarDelegate::GetInfoBarType() const {
72 return PAGE_ACTION_TYPE; 100 return PAGE_ACTION_TYPE;
73 } 101 }
74 102
75 infobars::InfoBarDelegate::InfoBarAutomationType 103 infobars::InfoBarDelegate::InfoBarAutomationType
76 SavePasswordInfoBarDelegate::GetInfoBarAutomationType() const { 104 SavePasswordInfoBarDelegate::GetInfoBarAutomationType() const {
77 return PASSWORD_INFOBAR; 105 return PASSWORD_INFOBAR;
78 } 106 }
79 107
80 int SavePasswordInfoBarDelegate::GetIconID() const { 108 int SavePasswordInfoBarDelegate::GetIconID() const {
81 return IDR_INFOBAR_SAVE_PASSWORD; 109 return IDR_INFOBAR_SAVE_PASSWORD;
82 } 110 }
83 111
84 bool SavePasswordInfoBarDelegate::ShouldExpire( 112 bool SavePasswordInfoBarDelegate::ShouldExpire(
85 const NavigationDetails& details) const { 113 const NavigationDetails& details) const {
86 return !details.is_redirect && 114 return !details.is_redirect &&
87 infobars::InfoBarDelegate::ShouldExpire(details); 115 infobars::InfoBarDelegate::ShouldExpire(details);
88 } 116 }
89 117
90 void SavePasswordInfoBarDelegate::InfoBarDismissed() { 118 void SavePasswordInfoBarDelegate::InfoBarDismissed() {
91 DCHECK(form_to_save_.get()); 119 DCHECK(form_to_save_.get());
92 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED; 120 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED;
93 } 121 }
94 122
95 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const { 123 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const {
96 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); 124 return l10n_util::GetStringUTF16(
125 (source_type_ ==
126 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)
127 ? IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_PROMPT
128 : IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
97 } 129 }
98 130
99 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( 131 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel(
100 InfoBarButton button) const { 132 InfoBarButton button) const {
101 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? 133 return l10n_util::GetStringUTF16((button == BUTTON_OK)
102 IDS_PASSWORD_MANAGER_SAVE_BUTTON : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON); 134 ? IDS_PASSWORD_MANAGER_SAVE_BUTTON
135 : GetCancelButtonText(source_type_));
103 } 136 }
104 137
105 bool SavePasswordInfoBarDelegate::Accept() { 138 bool SavePasswordInfoBarDelegate::Accept() {
106 DCHECK(form_to_save_.get()); 139 DCHECK(form_to_save_.get());
107 form_to_save_->Save(); 140 form_to_save_->Save();
108 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; 141 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD;
109 return true; 142 return true;
110 } 143 }
111 144
112 bool SavePasswordInfoBarDelegate::Cancel() { 145 bool SavePasswordInfoBarDelegate::Cancel() {
113 DCHECK(form_to_save_.get()); 146 DCHECK(form_to_save_.get());
114 form_to_save_->PermanentlyBlacklist(); 147 if (source_type_ ==
115 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; 148 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) {
149 form_to_save_->PermanentlyBlacklist();
150 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD;
151 } else {
152 InfoBarDismissed();
153 }
116 return true; 154 return true;
117 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698