Commit 0db946aa authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Remove Legacy Infobar Password code

Bug: 1128133
Change-Id: I1d39a7cd2ad407e68a926b0df17864ed456986d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410848Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807961}
parent e1d10724
......@@ -21,8 +21,6 @@ source_set("passwords") {
"ios_chrome_password_manager_driver.mm",
"ios_chrome_password_store_factory.cc",
"ios_chrome_password_store_factory.h",
"ios_chrome_update_password_infobar_delegate.h",
"ios_chrome_update_password_infobar_delegate.mm",
"ios_password_infobar_controller.h",
"ios_password_infobar_controller.mm",
"ios_password_requirements_service_factory.cc",
......@@ -41,8 +39,6 @@ source_set("passwords") {
"password_tab_helper.mm",
"save_passwords_consumer.h",
"save_passwords_consumer.mm",
"update_password_infobar_controller.h",
"update_password_infobar_controller.mm",
"well_known_change_password_tab_helper.h",
"well_known_change_password_tab_helper.mm",
]
......
......@@ -18,8 +18,7 @@ class PasswordFormManagerForUI;
}
// Base class for password manager infobar delegates, e.g.
// IOSChromeSavePasswordInfoBarDelegate and
// IOSChromeUpdatePasswordInfoBarDelegate.
// IOSChromeSavePasswordInfoBarDelegate.
class IOSChromePasswordManagerInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
~IOSChromePasswordManagerInfoBarDelegate() override;
......
......@@ -15,7 +15,6 @@
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/browser/password_ui_utils.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -136,24 +135,15 @@ IOSChromeSavePasswordInfoBarDelegate::IOSChromeSavePasswordInfoBarDelegate(
infobar_type_(password_update
? PasswordInfobarType::kPasswordInfobarTypeUpdate
: PasswordInfobarType::kPasswordInfobarTypeSave) {
if (!IsInfobarUIRebootEnabled()) {
RecordPresentationMetrics(form_to_save(), false /*current_password_saved*/,
false /*update_infobar*/, true /*automatic*/);
}
}
IOSChromeSavePasswordInfoBarDelegate::~IOSChromeSavePasswordInfoBarDelegate() {
if (IsInfobarUIRebootEnabled()) {
// If by any reason this delegate gets dealloc before the Infobar is
// dismissed, record the dismissal metrics.
if (infobar_presenting_) {
RecordDismissalMetrics(form_to_save(), infobar_response(),
IsUpdateInfobar(infobar_type_));
}
} else {
RecordDismissalMetrics(form_to_save(), infobar_response(),
false /*update_infobar*/);
}
}
infobars::InfoBarDelegate::InfoBarIdentifier
......@@ -162,7 +152,7 @@ IOSChromeSavePasswordInfoBarDelegate::GetIdentifier() const {
}
base::string16 IOSChromeSavePasswordInfoBarDelegate::GetMessageText() const {
if (IsInfobarUIRebootEnabled() && IsPasswordUpdate()) {
if (IsPasswordUpdate()) {
return l10n_util::GetStringUTF16(IDS_IOS_PASSWORD_MANAGER_UPDATE_PASSWORD);
}
return l10n_util::GetStringUTF16(
......@@ -171,13 +161,11 @@ base::string16 IOSChromeSavePasswordInfoBarDelegate::GetMessageText() const {
NSString* IOSChromeSavePasswordInfoBarDelegate::GetInfobarModalTitleText()
const {
DCHECK(IsInfobarUIRebootEnabled());
return l10n_util::GetNSString(IDS_IOS_PASSWORD_MANAGER_SAVE_PASSWORD_TITLE);
}
base::string16 IOSChromeSavePasswordInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
if (IsInfobarUIRebootEnabled()) {
switch (button) {
case BUTTON_OK:
return l10n_util::GetStringUTF16(
......@@ -193,11 +181,6 @@ base::string16 IOSChromeSavePasswordInfoBarDelegate::GetButtonLabel(
NOTREACHED();
return base::string16();
}
} else {
return l10n_util::GetStringUTF16(
(button == BUTTON_OK) ? IDS_IOS_PASSWORD_MANAGER_SAVE_BUTTON
: IDS_IOS_PASSWORD_MANAGER_BLOCK_BUTTON);
}
}
bool IOSChromeSavePasswordInfoBarDelegate::Accept() {
......@@ -231,7 +214,6 @@ bool IOSChromeSavePasswordInfoBarDelegate::ShouldExpire(
void IOSChromeSavePasswordInfoBarDelegate::UpdateCredentials(
NSString* username,
NSString* password) {
DCHECK(IsInfobarUIRebootEnabled());
const base::string16 username_string = base::SysNSStringToUTF16(username);
const base::string16 password_string = base::SysNSStringToUTF16(password);
UpdatePasswordFormUsernameAndPassword(username_string, password_string,
......@@ -239,7 +221,6 @@ void IOSChromeSavePasswordInfoBarDelegate::UpdateCredentials(
}
void IOSChromeSavePasswordInfoBarDelegate::InfobarPresenting(bool automatic) {
DCHECK(IsInfobarUIRebootEnabled());
if (infobar_presenting_)
return;
......@@ -249,7 +230,6 @@ void IOSChromeSavePasswordInfoBarDelegate::InfobarPresenting(bool automatic) {
}
void IOSChromeSavePasswordInfoBarDelegate::InfobarDismissed() {
DCHECK(IsInfobarUIRebootEnabled());
if (!infobar_presenting_)
return;
......@@ -261,11 +241,9 @@ void IOSChromeSavePasswordInfoBarDelegate::InfobarDismissed() {
}
bool IOSChromeSavePasswordInfoBarDelegate::IsPasswordUpdate() const {
DCHECK(IsInfobarUIRebootEnabled());
return password_update_;
}
bool IOSChromeSavePasswordInfoBarDelegate::IsCurrentPasswordSaved() const {
DCHECK(IsInfobarUIRebootEnabled());
return current_password_saved_;
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_PASSWORDS_IOS_CHROME_UPDATE_PASSWORD_INFOBAR_DELEGATE_H_
#define IOS_CHROME_BROWSER_PASSWORDS_IOS_CHROME_UPDATE_PASSWORD_INFOBAR_DELEGATE_H_
#include <memory>
#include "base/macros.h"
#include "ios/chrome/browser/passwords/ios_chrome_password_manager_infobar_delegate.h"
@protocol ApplicationCommands;
@class UIViewController;
namespace password_manager {
class PasswordFormManagerForUI;
}
namespace infobars {
class InfoBarManager;
}
@class NSArray;
class IOSChromeUpdatePasswordInfoBarDelegate
: public IOSChromePasswordManagerInfoBarDelegate {
public:
// Creates the infobar for |form_to_save| and adds it to |infobar_manager|.
// |is_sync_user| controls the footer text. |baseViewController| is the base
// view controller from which to present UI, and is not retained.
// |dispatcher| is not retained.
static void Create(
bool is_sync_user,
infobars::InfoBarManager* infobar_manager,
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save,
UIViewController* baseViewController,
id<ApplicationCommands> handler);
~IOSChromeUpdatePasswordInfoBarDelegate() override;
bool ShouldExpire(const NavigationDetails& details) const override;
// Returns whether the user has multiple saved credentials, of which the
// infobar affects just one. If so, the infobar should clarify which
// credential is being affected.
bool ShowMultipleAccounts() const;
// Returns an array of credentials. Applicable if the user has multiple
// saved credentials for the site |form_to_save| is applied to.
NSArray* GetAccounts() const;
base::string16 selected_account() const { return selected_account_; }
void set_selected_account(base::string16 account) {
selected_account_ = account;
}
private:
IOSChromeUpdatePasswordInfoBarDelegate(
bool is_sync_user,
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save);
// ConfirmInfoBarDelegate implementation.
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
base::string16 GetLinkText() const override;
void InfoBarDismissed() override;
base::string16 GetMessageText() const override;
int GetButtons() const override;
base::string16 GetButtonLabel(InfoBarButton button) const override;
bool Accept() override;
// The credential that should be displayed in the infobar, and for which the
// password will be updated.
base::string16 selected_account_;
};
#endif // IOS_CHROME_BROWSER_PASSWORDS_IOS_CHROME_UPDATE_PASSWORD_INFOBAR_DELEGATE_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.h"
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_manager.h"
#include "components/password_manager/core/browser/password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_form_metrics_recorder.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/browser/password_ui_utils.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/infobars/infobar_ios.h"
#import "ios/chrome/browser/passwords/update_password_infobar_controller.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using password_manager::PasswordFormManagerForUI;
// static
void IOSChromeUpdatePasswordInfoBarDelegate::Create(
bool is_sync_user,
infobars::InfoBarManager* infobar_manager,
std::unique_ptr<PasswordFormManagerForUI> form_manager,
UIViewController* baseViewController,
id<ApplicationCommands> handler) {
DCHECK(infobar_manager);
auto delegate = base::WrapUnique(new IOSChromeUpdatePasswordInfoBarDelegate(
is_sync_user, std::move(form_manager)));
delegate->set_handler(handler);
UpdatePasswordInfoBarController* controller =
[[UpdatePasswordInfoBarController alloc]
initWithBaseViewController:baseViewController
infoBarDelegate:delegate.get()];
infobar_manager->AddInfoBar(
std::make_unique<InfoBarIOS>(controller, std::move(delegate)));
}
IOSChromeUpdatePasswordInfoBarDelegate::
~IOSChromeUpdatePasswordInfoBarDelegate() {
password_manager::metrics_util::LogUpdateUIDismissalReason(
infobar_response());
form_to_save()->GetMetricsRecorder()->RecordUIDismissalReason(
infobar_response());
}
bool IOSChromeUpdatePasswordInfoBarDelegate::ShouldExpire(
const NavigationDetails& details) const {
return !details.is_form_submission && !details.is_redirect &&
ConfirmInfoBarDelegate::ShouldExpire(details);
}
IOSChromeUpdatePasswordInfoBarDelegate::IOSChromeUpdatePasswordInfoBarDelegate(
bool is_sync_user,
std::unique_ptr<PasswordFormManagerForUI> form_manager)
: IOSChromePasswordManagerInfoBarDelegate(is_sync_user,
std::move(form_manager)) {
selected_account_ = form_to_save()->GetPendingCredentials().username_value;
form_to_save()->GetMetricsRecorder()->RecordPasswordBubbleShown(
form_to_save()->GetCredentialSource(),
password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING_UPDATE);
password_manager::metrics_util::LogUIDisplayDisposition(
password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING_UPDATE);
}
bool IOSChromeUpdatePasswordInfoBarDelegate::ShowMultipleAccounts() const {
return form_to_save()->GetBestMatches().size() > 1;
}
NSArray* IOSChromeUpdatePasswordInfoBarDelegate::GetAccounts() const {
NSMutableArray* usernames = [NSMutableArray array];
for (const auto* match : form_to_save()->GetBestMatches()) {
[usernames addObject:base::SysUTF16ToNSString(match->username_value)];
}
return usernames;
}
infobars::InfoBarDelegate::InfoBarIdentifier
IOSChromeUpdatePasswordInfoBarDelegate::GetIdentifier() const {
return UPDATE_PASSWORD_INFOBAR_DELEGATE_MOBILE;
}
base::string16 IOSChromeUpdatePasswordInfoBarDelegate::GetLinkText() const {
return ShowMultipleAccounts() ? selected_account_ : base::string16();
}
void IOSChromeUpdatePasswordInfoBarDelegate::InfoBarDismissed() {
DCHECK(form_to_save());
set_infobar_response(password_manager::metrics_util::CLICKED_CANCEL);
}
base::string16 IOSChromeUpdatePasswordInfoBarDelegate::GetMessageText() const {
return selected_account_.length() > 0
? l10n_util::GetStringFUTF16(
IDS_IOS_PASSWORD_MANAGER_UPDATE_PASSWORD_FOR_ACCOUNT,
selected_account_)
: l10n_util::GetStringUTF16(
IDS_IOS_PASSWORD_MANAGER_UPDATE_PASSWORD);
}
int IOSChromeUpdatePasswordInfoBarDelegate::GetButtons() const {
return BUTTON_OK;
}
base::string16 IOSChromeUpdatePasswordInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
DCHECK_EQ(BUTTON_OK, button);
return l10n_util::GetStringUTF16(IDS_IOS_PASSWORD_MANAGER_UPDATE_BUTTON);
}
bool IOSChromeUpdatePasswordInfoBarDelegate::Accept() {
DCHECK(form_to_save());
UpdatePasswordFormUsernameAndPassword(
selected_account_, form_to_save()->GetPendingCredentials().password_value,
form_to_save());
form_to_save()->Save();
set_infobar_response(password_manager::metrics_util::CLICKED_ACCEPT);
return true;
}
......@@ -54,7 +54,6 @@
#import "ios/chrome/browser/infobars/infobar_type.h"
#import "ios/chrome/browser/main/browser.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/ios_password_infobar_controller.h"
#import "ios/chrome/browser/passwords/notify_auto_signin_view_controller.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
......@@ -380,8 +379,6 @@ constexpr int kNotifyAutoSigninDuration = 3; // seconds
}
- (void)removeInfoBarOfType:(PasswordInfoBarType)type manual:(BOOL)manual {
if (!IsInfobarUIRebootEnabled())
return;
InfoBarIOS* infobar = nil;
switch (type) {
......@@ -423,7 +420,6 @@ constexpr int kNotifyAutoSigninDuration = 3; // seconds
isSyncUser, /*password_update*/ false, std::move(form));
delegate->set_handler(self.applicationCommandsHandler);
if (IsInfobarUIRebootEnabled()) {
// Count only new infobar showings, not replacements.
if (![self findInfobarOfType:InfobarType::kInfobarTypePasswordSave
manual:manual]) {
......@@ -449,17 +445,9 @@ constexpr int kNotifyAutoSigninDuration = 3; // seconds
}
infoBarManager->AddInfoBar(std::move(infobar),
/*replace_existing=*/true);
} else if (!manual) {
IOSPasswordInfoBarController* controller =
[[IOSPasswordInfoBarController alloc]
initWithInfoBarDelegate:delegate.get()];
infoBarManager->AddInfoBar(
std::make_unique<InfoBarIOS>(controller, std::move(delegate)));
}
break;
}
case PasswordInfoBarType::UPDATE: {
if (IsInfobarUIRebootEnabled()) {
// Count only new infobar showings, not replacements.
if (![self findInfobarOfType:InfobarType::kInfobarTypePasswordUpdate
manual:manual]) {
......@@ -479,11 +467,6 @@ constexpr int kNotifyAutoSigninDuration = 3; // seconds
coordinator, std::move(delegate), /*skip_banner=*/manual);
infoBarManager->AddInfoBar(std::move(infobar),
/*replace_existing=*/true);
} else if (!manual) {
IOSChromeUpdatePasswordInfoBarDelegate::Create(
isSyncUser, infoBarManager, std::move(form),
self.baseViewController, self.applicationCommandsHandler);
}
break;
}
}
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_PASSWORDS_UPDATE_PASSWORD_INFOBAR_CONTROLLER_H_
#define IOS_CHROME_BROWSER_PASSWORDS_UPDATE_PASSWORD_INFOBAR_CONTROLLER_H_
#import "ios/chrome/browser/passwords/ios_password_infobar_controller.h"
class IOSChromeUpdatePasswordInfoBarDelegate;
// Controller for the Update Password info bar. Presents an info bar that asks
// the user whether they want to update their password.
@interface UpdatePasswordInfoBarController : IOSPasswordInfoBarController
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)
initWithBaseViewController:(UIViewController*)baseViewController
infoBarDelegate:(IOSChromeUpdatePasswordInfoBarDelegate*)delegate;
@end
#endif // IOS_CHROME_BROWSER_PASSWORDS_UPDATE_PASSWORD_INFOBAR_CONTROLLER_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/passwords/update_password_infobar_controller.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/infobars/confirm_infobar_controller+protected.h"
#import "ios/chrome/browser/infobars/infobar_controller+protected.h"
#include "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.h"
#import "ios/chrome/browser/ui/elements/selector_coordinator.h"
#import "ios/chrome/browser/ui/infobars/confirm_infobar_view.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface UpdatePasswordInfoBarController ()<SelectorCoordinatorDelegate> {
IOSChromeUpdatePasswordInfoBarDelegate* _delegate;
}
// The base view controller from which to present UI.
@property(nonatomic, readwrite, weak) UIViewController* baseViewController;
@property(nonatomic, strong) SelectorCoordinator* selectorCoordinator;
// Action for any of the user defined links.
- (void)infobarLinkDidPress:(NSUInteger)tag;
@end
@implementation UpdatePasswordInfoBarController
@synthesize baseViewController = _baseViewController;
@synthesize selectorCoordinator = _selectorCoordinator;
- (instancetype)
initWithBaseViewController:(UIViewController*)baseViewController
infoBarDelegate:(IOSChromeUpdatePasswordInfoBarDelegate*)delegate {
self = [super initWithInfoBarDelegate:delegate];
if (self) {
_baseViewController = baseViewController;
_delegate = delegate;
}
return self;
}
- (void)infobarLinkDidPress:(NSUInteger)tag {
DCHECK(self.baseViewController);
// TODO(crbug.com/1058340): Provide a Browser for the coordinator.
self.selectorCoordinator = [[SelectorCoordinator alloc]
initWithBaseViewController:self.baseViewController
browser:nullptr];
self.selectorCoordinator.delegate = self;
self.selectorCoordinator.options =
[NSOrderedSet orderedSetWithArray:_delegate->GetAccounts()];
self.selectorCoordinator.defaultOption =
base::SysUTF16ToNSString(_delegate->selected_account());
[self.selectorCoordinator start];
}
#pragma mark SelectorCoordinatorDelegate
- (void)selectorCoordinator:(SelectorCoordinator*)coordinator
didCompleteWithSelection:(NSString*)selection {
_delegate->set_selected_account(base::SysNSStringToUTF16(selection));
[self updateInfobarLabel:self.view];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment