Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / password_manager / account_chooser_infobar_delegate_android.cc
blobe4d08c45e1303abdd2475989e12fcf5b86cafe0b
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/password_manager/account_chooser_infobar_delegate_android.h"
7 #include "chrome/browser/infobars/infobar_service.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/profile_sync_service.h"
11 #include "chrome/browser/sync/profile_sync_service_factory.h"
12 #include "chrome/browser/ui/android/infobars/account_chooser_infobar.h"
13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/autofill/core/common/password_form.h"
16 #include "components/password_manager/core/browser/password_bubble_experiment.h"
17 #include "components/password_manager/core/common/credential_manager_types.h"
18 #include "content/public/browser/web_contents.h"
19 #include "ui/base/l10n/l10n_util.h"
21 // static
22 void AccountChooserInfoBarDelegateAndroid::Create(
23 content::WebContents* web_contents,
24 ManagePasswordsUIController* ui_controller) {
25 InfoBarService::FromWebContents(web_contents)
26 ->AddInfoBar(make_scoped_ptr(new AccountChooserInfoBar(
27 make_scoped_ptr(new AccountChooserInfoBarDelegateAndroid(
28 web_contents, ui_controller)))));
31 AccountChooserInfoBarDelegateAndroid::AccountChooserInfoBarDelegateAndroid(
32 content::WebContents* web_contents,
33 ManagePasswordsUIController* ui_controller)
34 : ui_controller_(ui_controller) {
35 bool is_smartlock_branding_enabled =
36 password_bubble_experiment::IsSmartLockBrandingEnabled(
37 ProfileSyncServiceFactory::GetForProfile(
38 Profile::FromBrowserContext(web_contents->GetBrowserContext())));
39 message_link_range_ = gfx::Range();
40 GetAccountChooserDialogTitleTextAndLinkRange(is_smartlock_branding_enabled,
41 &message_, &message_link_range_);
44 AccountChooserInfoBarDelegateAndroid::~AccountChooserInfoBarDelegateAndroid() {
47 void AccountChooserInfoBarDelegateAndroid::ChooseCredential(
48 size_t credential_index,
49 password_manager::CredentialType credential_type) {
50 using namespace password_manager;
51 if (credential_type == CredentialType::CREDENTIAL_TYPE_EMPTY) {
52 ui_controller_->ChooseCredential(autofill::PasswordForm(), credential_type);
53 return;
55 DCHECK(credential_type == CredentialType::CREDENTIAL_TYPE_PASSWORD ||
56 credential_type == CredentialType::CREDENTIAL_TYPE_FEDERATED);
57 const auto& credentials_forms =
58 (credential_type == CredentialType::CREDENTIAL_TYPE_PASSWORD)
59 ? ui_controller_->GetCurrentForms()
60 : ui_controller_->GetFederatedForms();
61 if (credential_index < credentials_forms.size()) {
62 ui_controller_->ChooseCredential(*credentials_forms[credential_index],
63 credential_type);
67 void AccountChooserInfoBarDelegateAndroid::LinkClicked() {
68 InfoBarService::WebContentsFromInfoBar(infobar())
69 ->OpenURL(content::OpenURLParams(
70 GURL(l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK_PAGE)),
71 content::Referrer(), NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
72 false /* is_renderer_initiated */));
75 void AccountChooserInfoBarDelegateAndroid::InfoBarDismissed() {
76 ChooseCredential(-1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY);
79 infobars::InfoBarDelegate::Type
80 AccountChooserInfoBarDelegateAndroid::GetInfoBarType() const {
81 return PAGE_ACTION_TYPE;