| OLD | NEW |
| 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_android
.h" | 5 #include "chrome/browser/password_manager/save_password_infobar_delegate_android
.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sync/profile_sync_service_factory.h" | 13 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 14 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 14 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 15 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
| 16 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 17 #include "chrome/grit/theme_resources.h" | 17 #include "chrome/grit/theme_resources.h" |
| 18 #include "components/browser_sync/profile_sync_service.h" | 18 #include "components/browser_sync/profile_sync_service.h" |
| 19 #include "components/infobars/core/infobar.h" | 19 #include "components/infobars/core/infobar.h" |
| 20 #include "components/infobars/core/infobar_manager.h" |
| 20 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 21 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "url/origin.h" | 24 #include "url/origin.h" |
| 24 | 25 |
| 25 // static | 26 // static |
| 26 void SavePasswordInfoBarDelegate::Create( | 27 void SavePasswordInfoBarDelegate::Create( |
| 27 content::WebContents* web_contents, | 28 content::WebContents* web_contents, |
| 28 std::unique_ptr<password_manager::PasswordFormManager> form_to_save) { | 29 std::unique_ptr<password_manager::PasswordFormManager> form_to_save) { |
| 29 Profile* profile = | 30 Profile* profile = |
| 30 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 31 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 31 syncer::SyncService* sync_service = | 32 syncer::SyncService* sync_service = |
| 32 ProfileSyncServiceFactory::GetForProfile(profile); | 33 ProfileSyncServiceFactory::GetForProfile(profile); |
| 33 bool is_smartlock_branding_enabled = | 34 bool is_smartlock_branding_enabled = |
| 34 password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( | 35 password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( |
| 35 sync_service); | 36 sync_service); |
| 36 bool should_show_first_run_experience = | 37 InfoBarService* infobar_service = |
| 37 password_bubble_experiment::ShouldShowSavePromptFirstRunExperience( | 38 InfoBarService::FromWebContents(web_contents); |
| 38 sync_service, profile->GetPrefs()); | 39 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
| 39 InfoBarService::FromWebContents(web_contents) | 40 std::unique_ptr<ConfirmInfoBarDelegate>( |
| 40 ->AddInfoBar(CreateSavePasswordInfoBar(base::WrapUnique( | |
| 41 new SavePasswordInfoBarDelegate(web_contents, std::move(form_to_save), | 41 new SavePasswordInfoBarDelegate(web_contents, std::move(form_to_save), |
| 42 is_smartlock_branding_enabled, | 42 is_smartlock_branding_enabled)))); |
| 43 should_show_first_run_experience)))); | |
| 44 } | 43 } |
| 45 | 44 |
| 46 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { | 45 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { |
| 47 password_manager::metrics_util::LogUIDismissalReason(infobar_response_); | 46 password_manager::metrics_util::LogUIDismissalReason(infobar_response_); |
| 48 | |
| 49 if (should_show_first_run_experience_) { | |
| 50 Profile* profile = | |
| 51 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
| 52 password_bubble_experiment::RecordSavePromptFirstRunExperienceWasShown( | |
| 53 profile->GetPrefs()); | |
| 54 } | |
| 55 } | 47 } |
| 56 | 48 |
| 57 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( | 49 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
| 58 content::WebContents* web_contents, | 50 content::WebContents* web_contents, |
| 59 std::unique_ptr<password_manager::PasswordFormManager> form_to_save, | 51 std::unique_ptr<password_manager::PasswordFormManager> form_to_save, |
| 60 bool is_smartlock_branding_enabled, | 52 bool is_smartlock_branding_enabled) |
| 61 bool should_show_first_run_experience) | |
| 62 : PasswordManagerInfoBarDelegate(), | 53 : PasswordManagerInfoBarDelegate(), |
| 63 form_to_save_(std::move(form_to_save)), | 54 form_to_save_(std::move(form_to_save)), |
| 64 infobar_response_(password_manager::metrics_util::NO_DIRECT_INTERACTION), | 55 infobar_response_(password_manager::metrics_util::NO_DIRECT_INTERACTION) { |
| 65 should_show_first_run_experience_(should_show_first_run_experience), | |
| 66 web_contents_(web_contents) { | |
| 67 base::string16 message; | 56 base::string16 message; |
| 68 gfx::Range message_link_range = gfx::Range(); | 57 gfx::Range message_link_range = gfx::Range(); |
| 69 PasswordTittleType type = | 58 PasswordTittleType type = |
| 70 form_to_save_->pending_credentials().federation_origin.unique() | 59 form_to_save_->pending_credentials().federation_origin.unique() |
| 71 ? PasswordTittleType::SAVE_PASSWORD | 60 ? PasswordTittleType::SAVE_PASSWORD |
| 72 : PasswordTittleType::SAVE_ACCOUNT; | 61 : PasswordTittleType::SAVE_ACCOUNT; |
| 73 GetSavePasswordDialogTitleTextAndLinkRange( | 62 GetSavePasswordDialogTitleTextAndLinkRange( |
| 74 web_contents->GetVisibleURL(), form_to_save_->observed_form().origin, | 63 web_contents->GetVisibleURL(), form_to_save_->observed_form().origin, |
| 75 is_smartlock_branding_enabled, type, | 64 is_smartlock_branding_enabled, type, |
| 76 &message, &message_link_range); | 65 &message, &message_link_range); |
| 77 SetMessage(message); | 66 SetMessage(message); |
| 78 SetMessageLinkRange(message_link_range); | 67 SetMessageLinkRange(message_link_range); |
| 79 } | 68 } |
| 80 | 69 |
| 81 base::string16 SavePasswordInfoBarDelegate::GetFirstRunExperienceMessage() { | |
| 82 return should_show_first_run_experience_ | |
| 83 ? l10n_util::GetStringUTF16( | |
| 84 IDS_PASSWORD_MANAGER_SAVE_PROMPT_FIRST_RUN_EXPERIENCE) | |
| 85 : base::string16(); | |
| 86 } | |
| 87 | |
| 88 infobars::InfoBarDelegate::InfoBarIdentifier | 70 infobars::InfoBarDelegate::InfoBarIdentifier |
| 89 SavePasswordInfoBarDelegate::GetIdentifier() const { | 71 SavePasswordInfoBarDelegate::GetIdentifier() const { |
| 90 return SAVE_PASSWORD_INFOBAR_DELEGATE; | 72 return SAVE_PASSWORD_INFOBAR_DELEGATE; |
| 91 } | 73 } |
| 92 | 74 |
| 93 void SavePasswordInfoBarDelegate::InfoBarDismissed() { | 75 void SavePasswordInfoBarDelegate::InfoBarDismissed() { |
| 94 DCHECK(form_to_save_.get()); | 76 DCHECK(form_to_save_.get()); |
| 95 infobar_response_ = password_manager::metrics_util::CLICKED_CANCEL; | 77 infobar_response_ = password_manager::metrics_util::CLICKED_CANCEL; |
| 96 } | 78 } |
| 97 | 79 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 108 infobar_response_ = password_manager::metrics_util::CLICKED_SAVE; | 90 infobar_response_ = password_manager::metrics_util::CLICKED_SAVE; |
| 109 return true; | 91 return true; |
| 110 } | 92 } |
| 111 | 93 |
| 112 bool SavePasswordInfoBarDelegate::Cancel() { | 94 bool SavePasswordInfoBarDelegate::Cancel() { |
| 113 DCHECK(form_to_save_.get()); | 95 DCHECK(form_to_save_.get()); |
| 114 form_to_save_->PermanentlyBlacklist(); | 96 form_to_save_->PermanentlyBlacklist(); |
| 115 infobar_response_ = password_manager::metrics_util::CLICKED_NEVER; | 97 infobar_response_ = password_manager::metrics_util::CLICKED_NEVER; |
| 116 return true; | 98 return true; |
| 117 } | 99 } |
| OLD | NEW |