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

Unified Diff: ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.mm

Issue 2108643002: IOSChromeUpdatePasswordInfoBarDelegate for update password UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@update_metrics
Patch Set: Rebase Created 4 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.mm
diff --git a/ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.mm b/ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.mm
new file mode 100644
index 0000000000000000000000000000000000000000..4b1dde1fddc47a14caa402fc37b5c3913b17a521
--- /dev/null
+++ b/ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.mm
@@ -0,0 +1,111 @@
+// 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.h"
+#include "components/password_manager/core/browser/password_manager_constants.h"
+#include "components/strings/grit/components_strings.h"
+#import "ios/chrome/browser/infobars/confirm_infobar_controller.h"
+#include "ios/chrome/browser/infobars/infobar.h"
+#include "ios/chrome/grit/ios_chromium_strings.h"
+#include "ios/chrome/grit/ios_google_chrome_strings.h"
+#include "ios/chrome/grit/ios_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+
+using password_manager::PasswordFormManager;
+
+// static
+void IOSChromeUpdatePasswordInfoBarDelegate::Create(
+ bool is_smart_lock_branding_enabled,
+ infobars::InfoBarManager* infobar_manager,
+ std::unique_ptr<PasswordFormManager> form_manager) {
+ DCHECK(infobar_manager);
+ auto delegate = base::WrapUnique(new IOSChromeUpdatePasswordInfoBarDelegate(
+ is_smart_lock_branding_enabled, std::move(form_manager)));
+ std::unique_ptr<InfoBarIOS> infobar(new InfoBarIOS(std::move(delegate)));
+ // TODO(crbug.com/622244): Replace ConfirmInfoBarController with update
+ // password controller class.
+ base::scoped_nsobject<ConfirmInfoBarController> controller(
+ [[ConfirmInfoBarController alloc] initWithDelegate:infobar.get()]);
+ infobar->SetController(controller);
+ infobar_manager->AddInfoBar(std::move(infobar));
+}
+
+IOSChromeUpdatePasswordInfoBarDelegate::
+ ~IOSChromeUpdatePasswordInfoBarDelegate() {}
+
+IOSChromeUpdatePasswordInfoBarDelegate::IOSChromeUpdatePasswordInfoBarDelegate(
+ bool is_smart_lock_branding_enabled,
+ std::unique_ptr<PasswordFormManager> form_manager)
+ : IOSChromePasswordManagerInfoBarDelegate(is_smart_lock_branding_enabled,
+ std::move(form_manager)) {
+ selected_account_ = form_to_save()->preferred_match()->username_value;
+}
+
+bool IOSChromeUpdatePasswordInfoBarDelegate::ShowMultipleAccounts() const {
+ // If a password is overriden, we know that the preferred match account is
+ // correct, so should not provide the option to choose a different account.
+ return form_to_save()->best_matches().size() > 1 &&
+ !form_to_save()->password_overridden();
+}
+
+NSArray* IOSChromeUpdatePasswordInfoBarDelegate::GetAccounts() const {
+ NSMutableArray* usernames = [NSMutableArray array];
+ const autofill::PasswordFormMap& matches = form_to_save()->best_matches();
+ for (const auto& match : matches) {
+ [usernames addObject:base::SysUTF16ToNSString(match.first)];
+ }
+ return usernames;
+}
+
+base::string16 IOSChromeUpdatePasswordInfoBarDelegate::GetBranding() const {
+ return l10n_util::GetStringUTF16(
+ is_smart_lock_branding_enabled()
+ ? IDS_IOS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS
+ : IDS_IOS_PASSWORD_MANAGER_TITLE_BRAND);
+}
+
+infobars::InfoBarDelegate::InfoBarIdentifier
+IOSChromeUpdatePasswordInfoBarDelegate::GetIdentifier() const {
+ return UPDATE_PASSWORD_INFOBAR_DELEGATE;
+}
+
+base::string16 IOSChromeUpdatePasswordInfoBarDelegate::GetMessageText() const {
+ return selected_account_.length() > 0
+ ? l10n_util::GetStringFUTF16(
+ IDS_IOS_PASSWORD_MANAGER_UPDATE_PASSWORD_FOR_ACCOUNT,
+ GetBranding(), selected_account_)
+ : l10n_util::GetStringFUTF16(
+ IDS_IOS_PASSWORD_MANAGER_UPDATE_PASSWORD, GetBranding());
+}
+
+base::string16 IOSChromeUpdatePasswordInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ return l10n_util::GetStringUTF16(
+ (button == BUTTON_OK) ? IDS_IOS_PASSWORD_MANAGER_UPDATE_BUTTON
+ : IDS_IOS_PASSWORD_MANAGER_CANCEL_BUTTON);
+}
+
+bool IOSChromeUpdatePasswordInfoBarDelegate::Accept() {
+ DCHECK(form_to_save());
+ if (ShowMultipleAccounts()) {
+ form_to_save()->Update(
+ *form_to_save()->best_matches().at(selected_account_).get());
+ } else {
+ form_to_save()->Update(form_to_save()->pending_credentials());
+ }
+ return true;
+}
+
+bool IOSChromeUpdatePasswordInfoBarDelegate::Cancel() {
+ return true;
+}
« no previous file with comments | « ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698