Index: ios/chrome/browser/passwords/password_controller.mm |
diff --git a/ios/chrome/browser/passwords/password_controller.mm b/ios/chrome/browser/passwords/password_controller.mm |
index fc5d885b3bc2553709c48354ab7457b59e3033a7..cc76d60349b9c27efa3a3d99a239a37d91e083d8 100644 |
--- a/ios/chrome/browser/passwords/password_controller.mm |
+++ b/ios/chrome/browser/passwords/password_controller.mm |
@@ -34,6 +34,7 @@ |
#include "ios/chrome/browser/experimental_flags.h" |
#include "ios/chrome/browser/infobars/infobar_manager_impl.h" |
#import "ios/chrome/browser/passwords/ios_chrome_save_password_infobar_delegate.h" |
+#import "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.h" |
#import "ios/chrome/browser/passwords/js_password_manager.h" |
#import "ios/chrome/browser/passwords/password_generation_agent.h" |
#include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
@@ -48,6 +49,11 @@ using password_manager::PasswordManager; |
using password_manager::PasswordManagerClient; |
using password_manager::PasswordManagerDriver; |
+namespace { |
+// Types of password infobars to display. |
+enum class PasswordInfoBarType { SAVE, UPDATE }; |
+} |
+ |
@interface PasswordController () |
// This is set to YES as soon as the associated WebState is destroyed. |
@@ -106,6 +112,12 @@ using password_manager::PasswordManagerDriver; |
fromDictionary:(const base::DictionaryValue*)dictionary |
pageURL:(const GURL&)pageLocation; |
+// Displays infobar for |form| with |type|. If |type| is UPDATE, the user |
+// is prompted to update the password. If |type| is SAVE, the user is prompted |
+// to save the password. |
+- (void)showInfoBarForForm:(std::unique_ptr<PasswordFormManager>)form |
+ infoBarType:(PasswordInfoBarType)type; |
+ |
@end |
namespace { |
@@ -616,6 +628,20 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
} |
} |
+#pragma mark - PasswordManagerClientDelegate |
+ |
+- (void)showSavePasswordInfoBar: |
+ (std::unique_ptr<PasswordFormManager>)formToSave { |
+ [self showInfoBarForForm:std::move(formToSave) |
+ infoBarType:PasswordInfoBarType::SAVE]; |
+} |
+ |
+- (void)showUpdatePasswordInfoBar: |
+ (std::unique_ptr<PasswordFormManager>)formToUpdate { |
+ [self showInfoBarForForm:std::move(formToUpdate) |
+ infoBarType:PasswordInfoBarType::UPDATE]; |
+} |
+ |
#pragma mark - |
#pragma mark WebPasswordFormData Adaptation |
@@ -754,26 +780,6 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
return YES; |
} |
-- (void)showSavePasswordInfoBar: |
- (std::unique_ptr<PasswordFormManager>)formToSave { |
- if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) |
- return; |
- |
- bool isSmartLockBrandingEnabled = false; |
- if (self.browserState) { |
- sync_driver::SyncService* sync_service = |
- IOSChromeProfileSyncServiceFactory::GetForBrowserState( |
- self.browserState); |
- isSmartLockBrandingEnabled = |
- password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( |
- sync_service); |
- } |
- infobars::InfoBarManager* infoBarManager = |
- InfoBarManagerImpl::FromWebState(webStateObserverBridge_->web_state()); |
- IOSChromeSavePasswordInfoBarDelegate::Create( |
- isSmartLockBrandingEnabled, infoBarManager, std::move(formToSave)); |
-} |
- |
- (void)fillPasswordForm:(const autofill::PasswordFormFillData&)formData |
withUsername:(const base::string16&)username |
password:(const base::string16&)password |
@@ -829,4 +835,36 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
return passwordJsManager_; |
} |
+#pragma mark - Private methods |
+ |
+- (void)showInfoBarForForm:(std::unique_ptr<PasswordFormManager>)form |
+ infoBarType:(PasswordInfoBarType)type { |
+ if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) |
+ return; |
+ |
+ bool isSmartLockBrandingEnabled = false; |
+ if (self.browserState) { |
+ sync_driver::SyncService* sync_service = |
+ IOSChromeProfileSyncServiceFactory::GetForBrowserState( |
+ self.browserState); |
+ isSmartLockBrandingEnabled = |
+ password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( |
+ sync_service); |
+ } |
+ infobars::InfoBarManager* infoBarManager = |
+ InfoBarManagerImpl::FromWebState(webStateObserverBridge_->web_state()); |
+ |
+ switch (type) { |
+ case PasswordInfoBarType::SAVE: |
+ IOSChromeSavePasswordInfoBarDelegate::Create( |
+ isSmartLockBrandingEnabled, infoBarManager, std::move(form)); |
+ break; |
+ |
+ case PasswordInfoBarType::UPDATE: |
+ IOSChromeUpdatePasswordInfoBarDelegate::Create( |
+ isSmartLockBrandingEnabled, infoBarManager, std::move(form)); |
+ break; |
+ } |
+} |
+ |
@end |