| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/update_password_infobar_delegate_andro
id.h" | 5 #include "chrome/browser/password_manager/update_password_infobar_delegate_andro
id.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/numerics/safe_conversions.h" | 8 #include "base/numerics/safe_conversions.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 10 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/sync/profile_sync_service_factory.h" | 12 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 13 #include "chrome/browser/ui/android/infobars/update_password_infobar.h" | 13 #include "chrome/browser/ui/android/infobars/update_password_infobar.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 "components/browser_sync/profile_sync_service.h" | 17 #include "components/browser_sync/profile_sync_service.h" |
| 18 #include "components/infobars/core/infobar.h" | 18 #include "components/infobars/core/infobar.h" |
| 19 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 19 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 20 #include "components/strings/grit/components_strings.h" | 20 #include "components/strings/grit/components_strings.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 void UpdatePasswordInfoBarDelegate::Create( | 25 void UpdatePasswordInfoBarDelegate::Create( |
| 26 content::WebContents* web_contents, | 26 content::WebContents* web_contents, |
| 27 std::unique_ptr<password_manager::PasswordFormManager> form_to_save) { | 27 scoped_refptr<password_manager::PasswordFormManager> form_to_save) { |
| 28 const bool is_smartlock_branding_enabled = | 28 const bool is_smartlock_branding_enabled = |
| 29 password_bubble_experiment::IsSmartLockUser( | 29 password_bubble_experiment::IsSmartLockUser( |
| 30 ProfileSyncServiceFactory::GetForProfile( | 30 ProfileSyncServiceFactory::GetForProfile( |
| 31 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); | 31 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); |
| 32 InfoBarService::FromWebContents(web_contents) | 32 InfoBarService::FromWebContents(web_contents) |
| 33 ->AddInfoBar(base::MakeUnique<UpdatePasswordInfoBar>( | 33 ->AddInfoBar(base::MakeUnique<UpdatePasswordInfoBar>( |
| 34 base::WrapUnique(new UpdatePasswordInfoBarDelegate( | 34 base::WrapUnique(new UpdatePasswordInfoBarDelegate( |
| 35 web_contents, std::move(form_to_save), | 35 web_contents, std::move(form_to_save), |
| 36 is_smartlock_branding_enabled)))); | 36 is_smartlock_branding_enabled)))); |
| 37 } | 37 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 return GetCurrentForms().size() > 1 && !is_password_overriden; | 52 return GetCurrentForms().size() > 1 && !is_password_overriden; |
| 53 } | 53 } |
| 54 | 54 |
| 55 const std::vector<std::unique_ptr<autofill::PasswordForm>>& | 55 const std::vector<std::unique_ptr<autofill::PasswordForm>>& |
| 56 UpdatePasswordInfoBarDelegate::GetCurrentForms() const { | 56 UpdatePasswordInfoBarDelegate::GetCurrentForms() const { |
| 57 return passwords_state_.GetCurrentForms(); | 57 return passwords_state_.GetCurrentForms(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 UpdatePasswordInfoBarDelegate::UpdatePasswordInfoBarDelegate( | 60 UpdatePasswordInfoBarDelegate::UpdatePasswordInfoBarDelegate( |
| 61 content::WebContents* web_contents, | 61 content::WebContents* web_contents, |
| 62 std::unique_ptr<password_manager::PasswordFormManager> form_to_update, | 62 scoped_refptr<password_manager::PasswordFormManager> form_to_update, |
| 63 bool is_smartlock_branding_enabled) | 63 bool is_smartlock_branding_enabled) |
| 64 : is_smartlock_branding_enabled_(is_smartlock_branding_enabled) { | 64 : is_smartlock_branding_enabled_(is_smartlock_branding_enabled) { |
| 65 base::string16 message; | 65 base::string16 message; |
| 66 gfx::Range message_link_range = gfx::Range(); | 66 gfx::Range message_link_range = gfx::Range(); |
| 67 GetSavePasswordDialogTitleTextAndLinkRange( | 67 GetSavePasswordDialogTitleTextAndLinkRange( |
| 68 web_contents->GetVisibleURL(), form_to_update->observed_form().origin, | 68 web_contents->GetVisibleURL(), form_to_update->observed_form().origin, |
| 69 is_smartlock_branding_enabled, PasswordTitleType::UPDATE_PASSWORD, | 69 is_smartlock_branding_enabled, PasswordTitleType::UPDATE_PASSWORD, |
| 70 &message, &message_link_range); | 70 &message, &message_link_range); |
| 71 SetMessage(message); | 71 SetMessage(message); |
| 72 SetMessageLinkRange(message_link_range); | 72 SetMessageLinkRange(message_link_range); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 99 if (ShowMultipleAccounts()) { | 99 if (ShowMultipleAccounts()) { |
| 100 int form_index = update_password_infobar->GetIdOfSelectedUsername(); | 100 int form_index = update_password_infobar->GetIdOfSelectedUsername(); |
| 101 DCHECK_GE(form_index, 0); | 101 DCHECK_GE(form_index, 0); |
| 102 DCHECK_LT(static_cast<size_t>(form_index), GetCurrentForms().size()); | 102 DCHECK_LT(static_cast<size_t>(form_index), GetCurrentForms().size()); |
| 103 form_manager->Update(*GetCurrentForms()[form_index]); | 103 form_manager->Update(*GetCurrentForms()[form_index]); |
| 104 } else { | 104 } else { |
| 105 form_manager->Update(form_manager->pending_credentials()); | 105 form_manager->Update(form_manager->pending_credentials()); |
| 106 } | 106 } |
| 107 return true; | 107 return true; |
| 108 } | 108 } |
| OLD | NEW |