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

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

Issue 1181623004: [Password Manager] Replace "this site" in save password prompt with password's origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for Windows bot. Created 5 years, 5 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 "chrome/browser/infobars/infobar_service.h" 8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/profile_sync_service.h" 10 #include "chrome/browser/sync/profile_sync_service.h"
11 #include "chrome/browser/sync/profile_sync_service_factory.h" 11 #include "chrome/browser/sync/profile_sync_service_factory.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
12 #include "chrome/grit/chromium_strings.h" 13 #include "chrome/grit/chromium_strings.h"
13 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
14 #include "components/infobars/core/infobar.h" 15 #include "components/infobars/core/infobar.h"
15 #include "components/password_manager/core/browser/password_bubble_experiment.h" 16 #include "components/password_manager/core/browser/password_bubble_experiment.h"
16 #include "components/password_manager/core/browser/password_manager_client.h" 17 #include "components/password_manager/core/browser/password_manager_client.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 21
21 namespace { 22 namespace {
22 23
23 int GetCancelButtonText(password_manager::CredentialSourceType source_type) { 24 int GetCancelButtonText(password_manager::CredentialSourceType source_type) {
24 return source_type == 25 return source_type ==
25 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API 26 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API
26 ? IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_NO_THANKS_BUTTON 27 ? IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_NO_THANKS_BUTTON
27 : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON; 28 : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON;
28 } 29 }
29 30
30 } // namespace 31 } // namespace
31 32
32 // static 33 // static
33 void SavePasswordInfoBarDelegate::Create( 34 void SavePasswordInfoBarDelegate::Create(
34 content::WebContents* web_contents, 35 content::WebContents* web_contents,
35 scoped_ptr<password_manager::PasswordFormManager> form_to_save, 36 scoped_ptr<password_manager::PasswordFormManager> form_to_save,
36 const std::string& uma_histogram_suffix, 37 const std::string& uma_histogram_suffix,
37 password_manager::CredentialSourceType source_type) { 38 password_manager::CredentialSourceType source_type) {
38 Profile* profile = 39 Profile* profile =
39 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 40 Profile::FromBrowserContext(web_contents->GetBrowserContext());
40 InfoBarService::FromWebContents(web_contents)->AddInfoBar( 41 InfoBarService::FromWebContents(web_contents)
41 CreateSavePasswordInfoBar(make_scoped_ptr( 42 ->AddInfoBar(CreateSavePasswordInfoBar(
42 new SavePasswordInfoBarDelegate( 43 make_scoped_ptr(new SavePasswordInfoBarDelegate(
43 form_to_save.Pass(), uma_histogram_suffix, source_type, 44 web_contents, form_to_save.Pass(), uma_histogram_suffix,
44 password_bubble_experiment::IsSmartLockBrandingEnabled( 45 source_type,
45 ProfileSyncServiceFactory::GetForProfile(profile)))))); 46 password_bubble_experiment::IsSmartLockBrandingEnabled(
47 ProfileSyncServiceFactory::GetForProfile(profile))))));
46 } 48 }
47 49
48 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { 50 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() {
49 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", 51 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
50 infobar_response_, 52 infobar_response_,
51 password_manager::metrics_util::NUM_RESPONSE_TYPES); 53 password_manager::metrics_util::NUM_RESPONSE_TYPES);
52 54
53 password_manager::metrics_util::LogUIDismissalReason(infobar_response_); 55 password_manager::metrics_util::LogUIDismissalReason(infobar_response_);
54 56
55 // The shortest period for which the prompt needs to live, so that we don't 57 // The shortest period for which the prompt needs to live, so that we don't
56 // consider it killed prematurely, as might happen, e.g., if a pre-rendered 58 // consider it killed prematurely, as might happen, e.g., if a pre-rendered
57 // page gets swapped in (and the current WebContents is destroyed). 59 // page gets swapped in (and the current WebContents is destroyed).
58 const base::TimeDelta kMinimumPromptDisplayTime = 60 const base::TimeDelta kMinimumPromptDisplayTime =
59 base::TimeDelta::FromSeconds(1); 61 base::TimeDelta::FromSeconds(1);
60 62
61 if (!uma_histogram_suffix_.empty()) { 63 if (!uma_histogram_suffix_.empty()) {
62 password_manager::metrics_util::LogUMAHistogramEnumeration( 64 password_manager::metrics_util::LogUMAHistogramEnumeration(
63 "PasswordManager.SavePasswordPromptResponse_" + uma_histogram_suffix_, 65 "PasswordManager.SavePasswordPromptResponse_" + uma_histogram_suffix_,
64 infobar_response_, 66 infobar_response_,
65 password_manager::metrics_util::NUM_RESPONSE_TYPES); 67 password_manager::metrics_util::NUM_RESPONSE_TYPES);
66 password_manager::metrics_util::LogUMAHistogramBoolean( 68 password_manager::metrics_util::LogUMAHistogramBoolean(
67 "PasswordManager.SavePasswordPromptDisappearedQuickly_" + 69 "PasswordManager.SavePasswordPromptDisappearedQuickly_" +
68 uma_histogram_suffix_, 70 uma_histogram_suffix_,
69 timer_.Elapsed() < kMinimumPromptDisplayTime); 71 timer_.Elapsed() < kMinimumPromptDisplayTime);
70 } 72 }
71 } 73 }
72 74
73 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( 75 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate(
76 content::WebContents* web_contents,
74 scoped_ptr<password_manager::PasswordFormManager> form_to_save, 77 scoped_ptr<password_manager::PasswordFormManager> form_to_save,
75 const std::string& uma_histogram_suffix, 78 const std::string& uma_histogram_suffix,
76 password_manager::CredentialSourceType source_type, 79 password_manager::CredentialSourceType source_type,
77 bool is_smartlock_branding_enabled) 80 bool is_smartlock_branding_enabled)
78 : ConfirmInfoBarDelegate(), 81 : ConfirmInfoBarDelegate(),
79 form_to_save_(form_to_save.Pass()), 82 form_to_save_(form_to_save.Pass()),
80 infobar_response_(password_manager::metrics_util::NO_RESPONSE), 83 infobar_response_(password_manager::metrics_util::NO_RESPONSE),
81 uma_histogram_suffix_(uma_histogram_suffix), 84 uma_histogram_suffix_(uma_histogram_suffix),
82 source_type_(source_type) { 85 source_type_(source_type) {
83 if (!uma_histogram_suffix_.empty()) { 86 if (!uma_histogram_suffix_.empty()) {
84 password_manager::metrics_util::LogUMAHistogramBoolean( 87 password_manager::metrics_util::LogUMAHistogramBoolean(
85 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, 88 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_,
86 true); 89 true);
87 } 90 }
88 title_link_range_ = gfx::Range(); 91 title_link_range_ = gfx::Range();
89 if (is_smartlock_branding_enabled) { 92 GetSavePasswordDialogTitleTextAndLinkRange(
90 size_t offset = 0; 93 web_contents->GetVisibleURL(), form_to_save_->observed_form().origin,
91 base::string16 title_link = 94 is_smartlock_branding_enabled, &title_, &title_link_range_);
92 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK);
93 title_ = l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, title_link, &offset);
94 title_link_range_ = gfx::Range(offset, offset + title_link.length());
95 } else {
96 title_ = l10n_util::GetStringFUTF16(
97 IDS_SAVE_PASSWORD,
98 l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD_TITLE_BRAND));
99 }
100 } 95 }
101 96
102 bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() { 97 bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() {
103 return source_type_ == 98 return source_type_ ==
104 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API; 99 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API;
105 } 100 }
106 101
107 infobars::InfoBarDelegate::Type 102 infobars::InfoBarDelegate::Type
108 SavePasswordInfoBarDelegate::GetInfoBarType() const { 103 SavePasswordInfoBarDelegate::GetInfoBarType() const {
109 return PAGE_ACTION_TYPE; 104 return PAGE_ACTION_TYPE;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 WindowOpenDisposition disposition) { 157 WindowOpenDisposition disposition) {
163 InfoBarService::WebContentsFromInfoBar(infobar()) 158 InfoBarService::WebContentsFromInfoBar(infobar())
164 ->OpenURL(content::OpenURLParams( 159 ->OpenURL(content::OpenURLParams(
165 GURL(l10n_util::GetStringUTF16( 160 GURL(l10n_util::GetStringUTF16(
166 IDS_PASSWORD_MANAGER_SMART_LOCK_ARTICLE)), 161 IDS_PASSWORD_MANAGER_SMART_LOCK_ARTICLE)),
167 content::Referrer(), 162 content::Referrer(),
168 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 163 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
169 ui::PAGE_TRANSITION_LINK, false)); 164 ui::PAGE_TRANSITION_LINK, false));
170 return true; 165 return true;
171 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698