Commit ca57a51b authored by melandory's avatar melandory Committed by Commit bot

Credentials chooser.

Infobar which allows user to choose Credentials.
Infobar is triggered via Credentials Manager API.

R=vabr@chromium.org,brettw@chromium.org,newt@chromium.org
BUG=454815

Review URL: https://codereview.chromium.org/861103002

Cr-Commit-Position: refs/heads/master@{#317368}
parent 4fc28962
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 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. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/profile_image"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:contentDescription="@null"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 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. -->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/account_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"/>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 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. -->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/learn_more"
android:title="@string/learn_more"/>
<item android:id="@+id/settings"
android:title="@string/preferences"/>
</menu>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<!-- TabSwitcher - The minimum distance from the edge to commit a side swap. --> <!-- TabSwitcher - The minimum distance from the edge to commit a side swap. -->
<dimen name="swipe_commit_distance">120dp</dimen> <dimen name="swipe_commit_distance">120dp</dimen>
<!-- Tab title --> <!-- Tab title -->
<dimen name="border_texture_title_fade">24dp</dimen> <!-- 40px hdpi --> <dimen name="border_texture_title_fade">24dp</dimen> <!-- 40px hdpi -->
<dimen name="tab_title_favicon_start_padding">10dp</dimen> <dimen name="tab_title_favicon_start_padding">10dp</dimen>
...@@ -101,4 +101,8 @@ ...@@ -101,4 +101,8 @@
<dimen name="badged_user_picture_width">46dp</dimen> <dimen name="badged_user_picture_width">46dp</dimen>
<dimen name="badge_radius">10dp</dimen> <dimen name="badge_radius">10dp</dimen>
<dimen name="badge_border_size">1.3dp</dimen> <dimen name="badge_border_size">1.3dp</dimen>
<!-- Account Chooser infobar Dimensions -->
<dimen name="account_chooser_infobar_item_height">80dp</dimen>
</resources> </resources>
// Copyright 2015 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.
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.TextView;
import org.chromium.base.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ResourceId;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.widget.ButtonCompat;
/**
* An infobar offers the user the ability to choose credentials for
* authentication. User is presented with username along with avatar and
* full name in case they are available.
*/
public class AccountChooserInfoBar extends InfoBar implements OnMenuItemClickListener {
private enum CredentialType {
EMPTY(0),
LOCAL(1),
FEDERATED(2);
private final int mType;
private CredentialType(int type) {
mType = type;
};
public int getValue() {
return mType;
}
}
private final String[] mUsernames;
/**
* Creates and shows the infobar wich allows user to choose credentials for login.
* @param nativeInfoBar Pointer to the native infobar.
* @param enumeratedIconId Enum ID corresponding to the icon that the infobar will show.
* @param usernames Usernames to display in the infobar.
*/
@CalledByNative
private static InfoBar show(long nativeInfoBar, int enumeratedIconId, String[] usernames) {
return new AccountChooserInfoBar(
nativeInfoBar, ResourceId.mapToDrawableId(enumeratedIconId), usernames);
}
/**
* Creates and shows the infobar which allows user to choose credentials.
* @param nativeInfoBar Pointer to the native infobar.
* @param iconDrawableId Drawable ID corresponding to the icon that the infobar will show.
* @param usernames list of usernames to display in infobar.
*/
public AccountChooserInfoBar(long nativeInfoBar, int iconDrawableId, String[] usernames) {
super(null /* Infobar Listener */, iconDrawableId, null /* bitmap*/,
null /* message to show */);
setNativeInfoBar(nativeInfoBar);
mUsernames = usernames.clone();
}
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.settings) {
PreferencesLauncher.launchSettingsPage(getContext(), null);
return true;
}
// TODO(melandory): Learn more should open link to help center
// article which is not ready yet.
return false;
}
@Override
public void onCloseButtonClicked() {
// Notifies the native infobar, which closes the infobar.
nativeOnCloseButtonClicked(mNativeInfoBarPtr);
}
@Override
public void onButtonClicked(boolean isPrimaryButton) {
onCloseButtonClicked();
}
@Override
public void createContent(InfoBarLayout layout) {
layout.setMessage(getContext().getString(R.string.account_chooser_infobar_title));
createAccountsView(layout);
createCustomButtonsView(layout);
}
private void createAccountsView(InfoBarLayout layout) {
ViewGroup accountsView = (ViewGroup) LayoutInflater.from(getContext()).inflate(
R.layout.account_chooser_infobar_list, null, false);
ArrayAdapter<String> adapter = generateAccountsArrayAdapter(getContext(), mUsernames);
ListView listView = (ListView) accountsView.findViewById(R.id.account_list);
listView.setAdapter(adapter);
float numVisibleItems = adapter.getCount() > 2 ? 2.5f : adapter.getCount();
int listViewHeight = (int) (numVisibleItems * getContext().getResources().getDimension(
R.dimen.account_chooser_infobar_item_height));
listView.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, listViewHeight));
layout.setCustomContent(accountsView);
}
private ArrayAdapter<String> generateAccountsArrayAdapter(Context context, String[] usernames) {
return new ArrayAdapter<String>(context, 0, usernames) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = (LinearLayout) LayoutInflater.from(getContext()).inflate(
R.layout.account_chooser_infobar_item, parent, false);
}
ImageView avatarView = (ImageView) convertView.findViewById(R.id.profile_image);
TextView usernameView = (TextView) convertView.findViewById(R.id.username);
TextView displayNameView = (TextView) convertView.findViewById(R.id.display_name);
String username = getItem(position);
usernameView.setText(username);
// TODO(melandory): View should show the full name. Temporarily the view shows
// username.
displayNameView.setText(username);
// TODO(melandory): View should show proper avatar. Temporarily the view shows
// blue man icon.
avatarView.setImageResource(R.drawable.account_management_no_picture);
final int currentCredentialIndex = position;
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
passCredentialsToNative(currentCredentialIndex);
}
});
return convertView;
}
};
}
/**
* Creates button row which consists of "No thanks" button and "More" button.
* "No thanks" buttons dismisses infobar. "More" button opens a popup menu,
* which allows to go to help center article or Settings.
*/
private void createCustomButtonsView(InfoBarLayout layout) {
layout.setButtons(getContext().getString(R.string.no_thanks), null);
Button moreButton = ButtonCompat.createBorderlessButton(getContext());
moreButton.setText(getContext().getString(R.string.more));
// TODO(melandory): Looks like spinner in mocks.
moreButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
showMorePopup(view);
}
});
layout.setCustomViewInButtonRow(moreButton);
}
private void passCredentialsToNative(int credentialIndex) {
// TODO(melandory): Adding federated login support should change this
// code.
nativeOnCredentialClicked(
mNativeInfoBarPtr, credentialIndex, CredentialType.LOCAL.getValue());
}
/** Pops up menu with two items: Setting and Learn More when user clicks More button. */
private void showMorePopup(View v) {
PopupMenu popup = new PopupMenu(getContext(), v);
popup.setOnMenuItemClickListener(this);
popup.inflate(R.menu.account_chooser_infobar_more_menu_popup);
popup.show();
}
private native void nativeOnCredentialClicked(
long nativeAccountChooserInfoBar, int credentialId, int credentialType);
}
...@@ -624,6 +624,9 @@ public class InfoBarLayout extends ViewGroup implements View.OnClickListener { ...@@ -624,6 +624,9 @@ public class InfoBarLayout extends ViewGroup implements View.OnClickListener {
measureChildWithFixedWidth(view1, view1.getMeasuredWidth() + extraWidth1); measureChildWithFixedWidth(view1, view1.getMeasuredWidth() + extraWidth1);
} }
} }
if (row == ROW_OTHER && mCustomGroup.views.length == 1) {
mCustomGroup.gravity = Gravity.FILL_HORIZONTAL;
}
} }
/** /**
......
...@@ -120,8 +120,7 @@ public class TranslateInfoBar extends InfoBar implements SubPanelListener { ...@@ -120,8 +120,7 @@ public class TranslateInfoBar extends InfoBar implements SubPanelListener {
String translated = context.getString( String translated = context.getString(
R.string.translate_infobar_translation_done, mOptions.targetLanguage()); R.string.translate_infobar_translation_done, mOptions.targetLanguage());
if (needsAlwaysPanel()) { if (needsAlwaysPanel()) {
String moreOptions = context.getString( String moreOptions = context.getString(R.string.more);
R.string.translate_infobar_translation_more_options);
return formatAfterTranslateInfoBarMessage(translated, moreOptions, return formatAfterTranslateInfoBarMessage(translated, moreOptions,
ALWAYS_PANEL); ALWAYS_PANEL);
} else { } else {
......
...@@ -115,6 +115,9 @@ ...@@ -115,6 +115,9 @@
<message name="IDS_LEARN_MORE" desc="Generic label for menu item to learn more about a feature. [CHAR-LIMIT=32]"> <message name="IDS_LEARN_MORE" desc="Generic label for menu item to learn more about a feature. [CHAR-LIMIT=32]">
Learn more Learn more
</message> </message>
<message name="IDS_MORE" desc="Generic label for a button to show more items or options. [CHAR-LIMIT=20]">
More
</message>
<message name="IDS_CLOSE" desc="Content description for a button to close a dialog or popup" > <message name="IDS_CLOSE" desc="Content description for a button to close a dialog or popup" >
Close Close
</message> </message>
...@@ -865,6 +868,11 @@ You are signing in with a managed account and giving its administrator control o ...@@ -865,6 +868,11 @@ You are signing in with a managed account and giving its administrator control o
Close Close
</message> </message>
<!-- Account chooser infobar strings. -->
<message name="IDS_ACCOUNT_CHOOSER_INFOBAR_TITLE" desc="The title text for Account chooser infobar.">
Choose an account from your Google Smart Lock.
</message>
<!-- TranslateInfoBar --> <!-- TranslateInfoBar -->
<message name="IDS_TRANSLATE_INFOBAR_TEXT" desc="Text to display on the translate infobar to offer a translate. [CHAR-LIMIT=64]" meaning="Android"> <message name="IDS_TRANSLATE_INFOBAR_TEXT" desc="Text to display on the translate infobar to offer a translate. [CHAR-LIMIT=64]" meaning="Android">
This page is in <ph name="SOURCE_LANGUAGE">^1<ex>English</ex></ph>. Translate it to <ph name="TARGET_LANGUAGE">^2<ex>FRENCH</ex></ph>? This page is in <ph name="SOURCE_LANGUAGE">^1<ex>English</ex></ph>. Translate it to <ph name="TARGET_LANGUAGE">^2<ex>FRENCH</ex></ph>?
...@@ -875,9 +883,6 @@ You are signing in with a managed account and giving its administrator control o ...@@ -875,9 +883,6 @@ You are signing in with a managed account and giving its administrator control o
<message name="IDS_TRANSLATE_INFOBAR_TRANSLATION_DONE"> <message name="IDS_TRANSLATE_INFOBAR_TRANSLATION_DONE">
Translated to <ph name="TARGET_LANGUAGE">%1$s<ex>FRENCH</ex></ph>. Translated to <ph name="TARGET_LANGUAGE">%1$s<ex>FRENCH</ex></ph>.
</message> </message>
<message name="IDS_TRANSLATE_INFOBAR_TRANSLATION_MORE_OPTIONS" desc="Text link that will provide more options after a translate [CHAR-LIMIT=24]">
More
</message>
<message name="IDS_TRANSLATE_INFOBAR_TRANSLATING"> <message name="IDS_TRANSLATE_INFOBAR_TRANSLATING">
Translating page to <ph name="SOURCE_LANGUAGE">%1$s<ex>English</ex></ph>... Translating page to <ph name="SOURCE_LANGUAGE">%1$s<ex>English</ex></ph>...
</message> </message>
......
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
#include "chrome/browser/ui/android/autofill/password_generation_popup_view_android.h" #include "chrome/browser/ui/android/autofill/password_generation_popup_view_android.h"
#include "chrome/browser/ui/android/chrome_http_auth_handler.h" #include "chrome/browser/ui/android/chrome_http_auth_handler.h"
#include "chrome/browser/ui/android/context_menu_helper.h" #include "chrome/browser/ui/android/context_menu_helper.h"
#include "chrome/browser/ui/android/infobars/account_chooser_infobar.h"
#include "chrome/browser/ui/android/infobars/app_banner_infobar.h" #include "chrome/browser/ui/android/infobars/app_banner_infobar.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h" #include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/data_reduction_proxy_infobar.h" #include "chrome/browser/ui/android/infobars/data_reduction_proxy_infobar.h"
...@@ -124,6 +125,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = { ...@@ -124,6 +125,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
web_contents_delegate_android::RegisterWebContentsDelegateAndroidJni}, web_contents_delegate_android::RegisterWebContentsDelegateAndroidJni},
// Register JNI for chrome classes. // Register JNI for chrome classes.
{"AccessibilityUtils", AccessibilityUtil::Register}, {"AccessibilityUtils", AccessibilityUtil::Register},
{"AccountChooserInfoBar", RegisterAccountChooserInfoBar},
{"AccountManagementScreenHelper", AccountManagementScreenHelper::Register}, {"AccountManagementScreenHelper", AccountManagementScreenHelper::Register},
{"AndroidProfileOAuth2TokenService", {"AndroidProfileOAuth2TokenService",
AndroidProfileOAuth2TokenService::Register}, AndroidProfileOAuth2TokenService::Register},
......
// Copyright 2015 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 "chrome/browser/password_manager/account_chooser_infobar_delegate_android.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/ui/android/infobars/account_chooser_infobar.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/content/common/credential_manager_types.h"
// static
void AccountChooserInfoBarDelegateAndroid::Create(
InfoBarService* infobar_service,
ManagePasswordsUIController* ui_controller) {
infobar_service->AddInfoBar(
make_scoped_ptr(new AccountChooserInfoBar(make_scoped_ptr(
new AccountChooserInfoBarDelegateAndroid(ui_controller)))));
}
AccountChooserInfoBarDelegateAndroid::AccountChooserInfoBarDelegateAndroid(
ManagePasswordsUIController* ui_controller)
: ui_controller_(ui_controller) {
}
AccountChooserInfoBarDelegateAndroid::~AccountChooserInfoBarDelegateAndroid() {
}
void AccountChooserInfoBarDelegateAndroid::ChooseCredential(
size_t credential_index,
password_manager::CredentialType credential_type) {
using namespace password_manager;
if (credential_type == CredentialType::CREDENTIAL_TYPE_EMPTY) {
ui_controller_->ChooseCredential(autofill::PasswordForm(), credential_type);
return;
}
DCHECK(credential_type == CredentialType::CREDENTIAL_TYPE_LOCAL ||
credential_type == CredentialType::CREDENTIAL_TYPE_FEDERATED);
auto& credentials_forms =
(credential_type == CredentialType::CREDENTIAL_TYPE_LOCAL)
? ui_controller_->local_credentials_forms()
: ui_controller_->federated_credentials_forms();
if (credential_index < credentials_forms.size()) {
ui_controller_->ChooseCredential(*credentials_forms[credential_index],
credential_type);
}
}
void AccountChooserInfoBarDelegateAndroid::InfoBarDismissed() {
ChooseCredential(-1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY);
}
infobars::InfoBarDelegate::Type
AccountChooserInfoBarDelegateAndroid::GetInfoBarType() const {
return PAGE_ACTION_TYPE;
}
// Copyright 2015 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 CHROME_BROWSER_PASSWORD_MANAGER_ACCOUNT_CHOOSER_INFOBAR_DELEGATE_ANDROID_H_
#define CHROME_BROWSER_PASSWORD_MANAGER_ACCOUNT_CHOOSER_INFOBAR_DELEGATE_ANDROID_H_
#include "base/macros.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include "components/infobars/core/infobar_delegate.h"
class InfoBarService;
namespace password_manager {
enum class CredentialType : unsigned int;
}
namespace autofill {
struct PasswordForm;
}
// Android-only infobar delegate to allow user to choose credentials for login.
class AccountChooserInfoBarDelegateAndroid : public infobars::InfoBarDelegate {
public:
// Creates an account chooser infobar and delegate and adds the infobar to
// |infobar_service|.
static void Create(InfoBarService* infobar_service,
ManagePasswordsUIController* ui_controller);
~AccountChooserInfoBarDelegateAndroid() override;
const ScopedVector<autofill::PasswordForm>& local_credentials_forms() const {
return ui_controller_->local_credentials_forms();
}
void ChooseCredential(size_t credential_index,
password_manager::CredentialType credential_type);
private:
explicit AccountChooserInfoBarDelegateAndroid(
ManagePasswordsUIController* ui_controller);
// infobars::InfoBarDelegate:
void InfoBarDismissed() override;
Type GetInfoBarType() const override;
// Owned by WebContents.
ManagePasswordsUIController* ui_controller_;
DISALLOW_COPY_AND_ASSIGN(AccountChooserInfoBarDelegateAndroid);
};
#endif // CHROME_BROWSER_PASSWORD_MANAGER_ACCOUNT_CHOOSER_INFOBAR_DELEGATE_ANDROID_H_
// Copyright 2015 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 "chrome/browser/ui/android/infobars/account_chooser_infobar.h"
#include "base/android/jni_android.h"
#include "base/android/jni_array.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/password_manager/account_chooser_infobar_delegate_android.h"
#include "components/password_manager/content/common/credential_manager_types.h"
#include "jni/AccountChooserInfoBar_jni.h"
AccountChooserInfoBar::AccountChooserInfoBar(
scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate)
: InfoBarAndroid(delegate.Pass()) {
}
AccountChooserInfoBar::~AccountChooserInfoBar() {
}
base::android::ScopedJavaLocalRef<jobject>
AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) {
std::vector<base::string16> usernames;
// TODO(melandory): Federated credentials should be processed also.
for (auto password_form : GetDelegate()->local_credentials_forms())
usernames.push_back(password_form->username_value);
base::android::ScopedJavaLocalRef<jobjectArray> java_usernames =
base::android::ToJavaArrayOfStrings(env, usernames);
return Java_AccountChooserInfoBar_show(env, reinterpret_cast<intptr_t>(this),
GetEnumeratedIconId(),
java_usernames.obj());
}
void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env,
jobject obj,
jint credential_item,
jint credential_type) {
GetDelegate()->ChooseCredential(
credential_item,
static_cast<password_manager::CredentialType>(credential_type));
RemoveSelf();
}
void AccountChooserInfoBar::ProcessButton(int action,
const std::string& action_value) {
if (!owner())
return; // We're closing; don't call anything, it might access the owner.
GetDelegate()->ChooseCredential(
-1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY);
RemoveSelf();
}
AccountChooserInfoBarDelegateAndroid* AccountChooserInfoBar::GetDelegate() {
return static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate());
}
bool RegisterAccountChooserInfoBar(JNIEnv* env) {
return RegisterNativesImpl(env);
}
// Copyright 2015 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 CHROME_BROWSER_UI_ANDROID_INFOBARS_ACCOUNT_CHOOSER_INFOBAR_H_
#define CHROME_BROWSER_UI_ANDROID_INFOBARS_ACCOUNT_CHOOSER_INFOBAR_H_
#include <jni.h>
#include <string>
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/infobar_android.h"
class AccountChooserInfoBarDelegateAndroid;
// The Android infobar that allows user to choose credentials for login.
class AccountChooserInfoBar : public InfoBarAndroid {
public:
explicit AccountChooserInfoBar(
scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate);
~AccountChooserInfoBar() override;
void OnCredentialClicked(JNIEnv* env,
jobject obj,
jint credential_item,
jint credential_type);
private:
// InfoBarAndroid:
base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
JNIEnv* env) override;
void ProcessButton(int action, const std::string& action_value) override;
AccountChooserInfoBarDelegateAndroid* GetDelegate();
DISALLOW_COPY_AND_ASSIGN(AccountChooserInfoBar);
};
// Registers native methods.
bool RegisterAccountChooserInfoBar(JNIEnv* env);
#endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_ACCOUNT_CHOOSER_INFOBAR_H_
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "chrome/browser/android/chromium_application.h" #include "chrome/browser/android/chromium_application.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/password_manager/account_chooser_infobar_delegate_android.h"
#endif #endif
using autofill::PasswordFormMap; using autofill::PasswordFormMap;
...@@ -95,6 +97,15 @@ void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { ...@@ -95,6 +97,15 @@ void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() {
#endif #endif
} }
void ManagePasswordsUIController::
UpdateAndroidAccountChooserInfoBarVisibility() {
#if defined(OS_ANDROID)
AccountChooserInfoBarDelegateAndroid::Create(
InfoBarService::FromWebContents(web_contents()), this);
should_pop_up_bubble_ = false;
#endif
}
base::TimeDelta ManagePasswordsUIController::Elapsed() const { base::TimeDelta ManagePasswordsUIController::Elapsed() const {
return timer_ ? timer_->Elapsed() : base::TimeDelta::Max(); return timer_ ? timer_->Elapsed() : base::TimeDelta::Max();
} }
...@@ -128,7 +139,11 @@ bool ManagePasswordsUIController::OnChooseCredentials( ...@@ -128,7 +139,11 @@ bool ManagePasswordsUIController::OnChooseCredentials(
origin_ = origin; origin_ = origin;
SetState(password_manager::ui::CREDENTIAL_REQUEST_STATE); SetState(password_manager::ui::CREDENTIAL_REQUEST_STATE);
base::AutoReset<bool> resetter(&should_pop_up_bubble_, true); base::AutoReset<bool> resetter(&should_pop_up_bubble_, true);
#if defined(OS_ANDROID)
UpdateAndroidAccountChooserInfoBarVisibility();
#else
UpdateBubbleAndIconVisibility(); UpdateBubbleAndIconVisibility();
#endif
if (!should_pop_up_bubble_) { if (!should_pop_up_bubble_) {
credentials_callback_ = callback; credentials_callback_ = callback;
return true; return true;
......
...@@ -182,6 +182,10 @@ class ManagePasswordsUIController ...@@ -182,6 +182,10 @@ class ManagePasswordsUIController
void SaveForms(ScopedVector<autofill::PasswordForm> local_forms, void SaveForms(ScopedVector<autofill::PasswordForm> local_forms,
ScopedVector<autofill::PasswordForm> federated_forms); ScopedVector<autofill::PasswordForm> federated_forms);
// Shows infobar which allows user to choose credentials. Placing this
// code to separate method allows mocking.
virtual void UpdateAndroidAccountChooserInfoBarVisibility();
// The current state of the password manager UI. // The current state of the password manager UI.
password_manager::ui::State state_; password_manager::ui::State state_;
......
...@@ -44,6 +44,11 @@ void ManagePasswordsUIControllerMock::UpdateBubbleAndIconVisibility() { ...@@ -44,6 +44,11 @@ void ManagePasswordsUIControllerMock::UpdateBubbleAndIconVisibility() {
OnBubbleShown(); OnBubbleShown();
} }
void ManagePasswordsUIControllerMock::
UpdateAndroidAccountChooserInfoBarVisibility() {
OnBubbleShown();
}
base::TimeDelta ManagePasswordsUIControllerMock::Elapsed() const { base::TimeDelta ManagePasswordsUIControllerMock::Elapsed() const {
return elapsed_; return elapsed_;
} }
......
...@@ -53,6 +53,8 @@ class ManagePasswordsUIControllerMock ...@@ -53,6 +53,8 @@ class ManagePasswordsUIControllerMock
void UpdateBubbleAndIconVisibility() override; void UpdateBubbleAndIconVisibility() override;
void UpdateAndroidAccountChooserInfoBarVisibility() override;
base::TimeDelta Elapsed() const override; base::TimeDelta Elapsed() const override;
// Sneaky setters for testing. // Sneaky setters for testing.
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/find_bar/find_tab_helper.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h"
#include "chrome/browser/ui/navigation_correction_tab_observer.h" #include "chrome/browser/ui/navigation_correction_tab_observer.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h" #include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/browser/ui/search/search_tab_helper.h" #include "chrome/browser/ui/search/search_tab_helper.h"
...@@ -49,7 +50,6 @@ ...@@ -49,7 +50,6 @@
#include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
#include "chrome/browser/thumbnails/thumbnail_tab_helper.h" #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
#include "chrome/browser/ui/hung_plugin_tab_helper.h" #include "chrome/browser/ui/hung_plugin_tab_helper.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include "chrome/browser/ui/sad_tab_helper.h" #include "chrome/browser/ui/sad_tab_helper.h"
#include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
#include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h"
...@@ -149,6 +149,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) { ...@@ -149,6 +149,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
FindTabHelper::CreateForWebContents(web_contents); FindTabHelper::CreateForWebContents(web_contents);
HistoryTabHelper::CreateForWebContents(web_contents); HistoryTabHelper::CreateForWebContents(web_contents);
InfoBarService::CreateForWebContents(web_contents); InfoBarService::CreateForWebContents(web_contents);
ManagePasswordsUIController::CreateForWebContents(web_contents);
NavigationCorrectionTabObserver::CreateForWebContents(web_contents); NavigationCorrectionTabObserver::CreateForWebContents(web_contents);
NavigationMetricsRecorder::CreateForWebContents(web_contents); NavigationMetricsRecorder::CreateForWebContents(web_contents);
PopupBlockerTabHelper::CreateForWebContents(web_contents); PopupBlockerTabHelper::CreateForWebContents(web_contents);
...@@ -172,7 +173,6 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) { ...@@ -172,7 +173,6 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
extensions::WebNavigationTabObserver::CreateForWebContents(web_contents); extensions::WebNavigationTabObserver::CreateForWebContents(web_contents);
ExternalProtocolObserver::CreateForWebContents(web_contents); ExternalProtocolObserver::CreateForWebContents(web_contents);
HungPluginTabHelper::CreateForWebContents(web_contents); HungPluginTabHelper::CreateForWebContents(web_contents);
ManagePasswordsUIController::CreateForWebContents(web_contents);
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
web_contents, web_contents,
scoped_ptr<pdf::PDFWebContentsHelperClient>( scoped_ptr<pdf::PDFWebContentsHelperClient>(
......
...@@ -698,6 +698,8 @@ ...@@ -698,6 +698,8 @@
'browser/media/protected_media_identifier_permission_context_factory.h', 'browser/media/protected_media_identifier_permission_context_factory.h',
'browser/metrics/android_metrics_provider.cc', 'browser/metrics/android_metrics_provider.cc',
'browser/metrics/android_metrics_provider.h', 'browser/metrics/android_metrics_provider.h',
'browser/password_manager/account_chooser_infobar_delegate_android.cc',
'browser/password_manager/account_chooser_infobar_delegate_android.h',
'browser/password_manager/generated_password_saved_infobar_delegate_android.cc', 'browser/password_manager/generated_password_saved_infobar_delegate_android.cc',
'browser/password_manager/generated_password_saved_infobar_delegate_android.h', 'browser/password_manager/generated_password_saved_infobar_delegate_android.h',
'browser/sessions/in_memory_tab_restore_service.cc', 'browser/sessions/in_memory_tab_restore_service.cc',
...@@ -1630,6 +1632,7 @@ ...@@ -1630,6 +1632,7 @@
'android/java/src/org/chromium/chrome/browser/VoiceSearchTabHelper.java', 'android/java/src/org/chromium/chrome/browser/VoiceSearchTabHelper.java',
'android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java', 'android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java',
'android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBar.java', 'android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBar.java',
'android/java/src/org/chromium/chrome/browser/infobar/AccountChooserInfoBar.java',
'android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegate.java', 'android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegate.java',
'android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBarDelegate.java', 'android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBarDelegate.java',
'android/java/src/org/chromium/chrome/browser/infobar/DataReductionProxyInfoBarDelegate.java', 'android/java/src/org/chromium/chrome/browser/infobar/DataReductionProxyInfoBarDelegate.java',
......
...@@ -1110,6 +1110,8 @@ ...@@ -1110,6 +1110,8 @@
'chrome_browser_ui_android_sources': [ 'chrome_browser_ui_android_sources': [
'browser/ui/android/autofill/credit_card_scanner_view_android.cc', 'browser/ui/android/autofill/credit_card_scanner_view_android.cc',
'browser/ui/android/autofill/credit_card_scanner_view_android.h', 'browser/ui/android/autofill/credit_card_scanner_view_android.h',
'browser/ui/android/infobars/account_chooser_infobar.cc',
'browser/ui/android/infobars/account_chooser_infobar.h',
'browser/ui/android/infobars/generated_password_saved_infobar.cc', 'browser/ui/android/infobars/generated_password_saved_infobar.cc',
'browser/ui/android/infobars/generated_password_saved_infobar.h', 'browser/ui/android/infobars/generated_password_saved_infobar.h',
'browser/ui/auto_login_infobar_delegate.cc', 'browser/ui/auto_login_infobar_delegate.cc',
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<!-- <!--
14.5 = Seekbar thumb width - border width, but it depends on the width 14.5 = Seekbar thumb width - border width, but it depends on the width
of the seek bar icon. of the seek bar icon.
--> -->
<dimen name="color_picker_gradient_margin">14.5dp</dimen> <dimen name="color_picker_gradient_margin">14.5dp</dimen>
<dimen name="color_button_height">60dp</dimen> <dimen name="color_button_height">60dp</dimen>
...@@ -22,5 +22,4 @@ ...@@ -22,5 +22,4 @@
--> -->
<dimen name="config_min_scaling_span">27.0mm</dimen> <dimen name="config_min_scaling_span">27.0mm</dimen>
<dimen name="config_min_scaling_touch_major">48.0dp</dimen> <dimen name="config_min_scaling_touch_major">48.0dp</dimen>
</resources> </resources>
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