Commit 39e3841c authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[Mfill Android] Add manual generation button in the bottom sheet

This change is part of the Android Password Manager UI.

This CL adds a button to the accessory sheet, meant to allow users
to manually trigger password generation. The change is flag guarded
by #manual-password-generation-android.

Bug: 835234
Change-Id: Ie651d51c53ee28a943fd06f6f93396a495720354
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1479996
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658695}
parent 5e3c6036
...@@ -36,8 +36,8 @@ class MockPasswordAccessoryController : public PasswordAccessoryController { ...@@ -36,8 +36,8 @@ class MockPasswordAccessoryController : public PasswordAccessoryController {
void(const std::map<base::string16, const autofill::PasswordForm*>&, void(const std::map<base::string16, const autofill::PasswordForm*>&,
const url::Origin&)); const url::Origin&));
MOCK_METHOD1(OnFilledIntoFocusedField, void(autofill::FillingStatus)); MOCK_METHOD1(OnFilledIntoFocusedField, void(autofill::FillingStatus));
MOCK_METHOD3(RefreshSuggestionsForField, MOCK_METHOD4(RefreshSuggestionsForField,
void(const url::Origin&, bool, bool)); void(const url::Origin&, bool, bool, bool));
MOCK_METHOD0(DidNavigateMainFrame, void()); MOCK_METHOD0(DidNavigateMainFrame, void());
MOCK_METHOD2(GetFavicon, MOCK_METHOD2(GetFavicon,
void(int, base::OnceCallback<void(const gfx::Image&)>)); void(int, base::OnceCallback<void(const gfx::Image&)>));
......
...@@ -6,13 +6,12 @@ ...@@ -6,13 +6,12 @@
#include <utility> #include <utility>
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace autofill { namespace autofill {
AccessorySheetData CreateAccessorySheetData(base::string16 title, AccessorySheetData CreateAccessorySheetData(
std::vector<UserInfo> user_info) { base::string16 title,
std::vector<UserInfo> user_info,
std::vector<FooterCommand> footer_commands) {
// TODO(crbug.com/902425): Remove hard-coded enum value // TODO(crbug.com/902425): Remove hard-coded enum value
AccessorySheetData data(FallbackSheetType::PASSWORD, std::move(title)); AccessorySheetData data(FallbackSheetType::PASSWORD, std::move(title));
for (auto& i : user_info) { for (auto& i : user_info) {
...@@ -21,9 +20,9 @@ AccessorySheetData CreateAccessorySheetData(base::string16 title, ...@@ -21,9 +20,9 @@ AccessorySheetData CreateAccessorySheetData(base::string16 title,
// TODO(crbug.com/902425): Generalize options (both adding to footer, and // TODO(crbug.com/902425): Generalize options (both adding to footer, and
// handling selection). // handling selection).
base::string16 manage_passwords_title = l10n_util::GetStringUTF16( for (auto& footer_command : footer_commands) {
IDS_PASSWORD_MANAGER_ACCESSORY_ALL_PASSWORDS_LINK); data.add_footer_command(std::move(footer_command));
data.add_footer_command(FooterCommand(manage_passwords_title)); }
return data; return data;
} }
......
...@@ -11,8 +11,10 @@ namespace autofill { ...@@ -11,8 +11,10 @@ namespace autofill {
// Creates an AccessorySheetData defining the data to be shown in the filling // Creates an AccessorySheetData defining the data to be shown in the filling
// UI. // UI.
AccessorySheetData CreateAccessorySheetData(base::string16 title, AccessorySheetData CreateAccessorySheetData(
std::vector<UserInfo> user_info); base::string16 title,
std::vector<UserInfo> user_info,
std::vector<FooterCommand> footer_commands);
} // namespace autofill } // namespace autofill
......
...@@ -1020,14 +1020,23 @@ void ChromePasswordManagerClient::ShowPasswordGenerationPopup( ...@@ -1020,14 +1020,23 @@ void ChromePasswordManagerClient::ShowPasswordGenerationPopup(
} }
void ChromePasswordManagerClient::FocusedInputChanged( void ChromePasswordManagerClient::FocusedInputChanged(
const url::Origin& last_committed_origin, password_manager::PasswordManagerDriver* driver,
bool is_fillable, bool is_fillable,
bool is_password_field) { bool is_password_field) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
if (PasswordAccessoryController::AllowedForWebContents(web_contents())) { if (PasswordAccessoryController::AllowedForWebContents(web_contents())) {
bool is_manual_generation_available =
password_manager_util::ManualPasswordGenerationEnabled(driver);
password_manager::ContentPasswordManagerDriver* content_driver =
static_cast<password_manager::ContentPasswordManagerDriver*>(driver);
url::Origin last_committed_origin =
content_driver->render_frame_host()->GetLastCommittedOrigin();
PasswordAccessoryController::GetOrCreate(web_contents()) PasswordAccessoryController::GetOrCreate(web_contents())
->RefreshSuggestionsForField(last_committed_origin, is_fillable, ->RefreshSuggestionsForField(last_committed_origin, is_fillable,
is_password_field); is_password_field,
is_manual_generation_available);
} }
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
} }
......
...@@ -72,7 +72,7 @@ class ChromePasswordManagerClient ...@@ -72,7 +72,7 @@ class ChromePasswordManagerClient
bool has_generated_password, bool has_generated_password,
bool is_update) override; bool is_update) override;
void HideManualFallbackForSaving() override; void HideManualFallbackForSaving() override;
void FocusedInputChanged(const url::Origin& last_committed_origin, void FocusedInputChanged(password_manager::PasswordManagerDriver* driver,
bool is_fillable, bool is_fillable,
bool is_password_field) override; bool is_password_field) override;
bool PromptUserToChooseCredentials( bool PromptUserToChooseCredentials(
......
...@@ -72,9 +72,11 @@ class PasswordAccessoryController ...@@ -72,9 +72,11 @@ class PasswordAccessoryController
// Makes sure, that all shown suggestions are appropriate for the currently // Makes sure, that all shown suggestions are appropriate for the currently
// focused field and for fields that lost the focus. If a field lost focus, // focused field and for fields that lost the focus. If a field lost focus,
// |is_fillable| will be false. // |is_fillable| will be false.
virtual void RefreshSuggestionsForField(const url::Origin& origin, virtual void RefreshSuggestionsForField(
bool is_fillable, const url::Origin& origin,
bool is_password_field) = 0; bool is_fillable,
bool is_password_field,
bool is_manual_generation_available) = 0;
// Reacts to a navigation on the main frame, e.g. by clearing caches. // Reacts to a navigation on the main frame, e.g. by clearing caches.
virtual void DidNavigateMainFrame() = 0; virtual void DidNavigateMainFrame() = 0;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "components/password_manager/content/browser/content_password_manager_driver.h" #include "components/password_manager/content/browser/content_password_manager_driver.h"
#include "components/password_manager/content/browser/content_password_manager_driver_factory.h" #include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
#include "components/password_manager/core/browser/password_manager_driver.h" #include "components/password_manager/core/browser/password_manager_driver.h"
#include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/common/password_manager_features.h" #include "components/password_manager/core/common/password_manager_features.h"
#include "components/url_formatter/elide_url.h" #include "components/url_formatter/elide_url.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -181,8 +182,10 @@ void PasswordAccessoryControllerImpl::OnOptionSelected( ...@@ -181,8 +182,10 @@ void PasswordAccessoryControllerImpl::OnOptionSelected(
void PasswordAccessoryControllerImpl::RefreshSuggestionsForField( void PasswordAccessoryControllerImpl::RefreshSuggestionsForField(
const url::Origin& origin, const url::Origin& origin,
bool is_fillable, bool is_fillable,
bool is_password_field) { bool is_password_field,
bool is_manual_generation_available) {
std::vector<UserInfo> info_to_add; std::vector<UserInfo> info_to_add;
std::vector<FooterCommand> footer_commands_to_add;
if (is_fillable) { if (is_fillable) {
const std::vector<PasswordAccessorySuggestion> suggestions = const std::vector<PasswordAccessorySuggestion> suggestions =
...@@ -192,16 +195,27 @@ void PasswordAccessoryControllerImpl::RefreshSuggestionsForField( ...@@ -192,16 +195,27 @@ void PasswordAccessoryControllerImpl::RefreshSuggestionsForField(
[is_password_field](const auto& x) { [is_password_field](const auto& x) {
return Translate(is_password_field, x); return Translate(is_password_field, x);
}); });
if (is_password_field && is_manual_generation_available) {
base::string16 generate_password_title = l10n_util::GetStringUTF16(
IDS_PASSWORD_MANAGER_ACCESSORY_GENERATE_PASSWORD_BUTTON_TITLE);
footer_commands_to_add.push_back(FooterCommand(generate_password_title));
}
} }
base::string16 manage_passwords_title = l10n_util::GetStringUTF16(
IDS_PASSWORD_MANAGER_ACCESSORY_ALL_PASSWORDS_LINK);
footer_commands_to_add.push_back(FooterCommand(manage_passwords_title));
bool has_suggestions = !info_to_add.empty(); bool has_suggestions = !info_to_add.empty();
GetManualFillingController()->RefreshSuggestionsForField( GetManualFillingController()->RefreshSuggestionsForField(
is_fillable, autofill::CreateAccessorySheetData( is_fillable,
GetTitle(has_suggestions, GetFocusedFrameOrigin()), autofill::CreateAccessorySheetData(
std::move(info_to_add))); GetTitle(has_suggestions, GetFocusedFrameOrigin()),
std::move(info_to_add), std::move(footer_commands_to_add)));
if (is_password_field) { if (is_password_field && is_fillable) {
GetManualFillingController()->ShowWhenKeyboardIsVisible( GetManualFillingController()->ShowWhenKeyboardIsVisible(
FillingSource::PASSWORD_FALLBACKS); FillingSource::PASSWORD_FALLBACKS);
} else { } else {
......
...@@ -69,7 +69,8 @@ class PasswordAccessoryControllerImpl ...@@ -69,7 +69,8 @@ class PasswordAccessoryControllerImpl
void OnFilledIntoFocusedField(autofill::FillingStatus status) override; void OnFilledIntoFocusedField(autofill::FillingStatus status) override;
void RefreshSuggestionsForField(const url::Origin& origin, void RefreshSuggestionsForField(const url::Origin& origin,
bool is_fillable, bool is_fillable,
bool is_password_field) override; bool is_password_field,
bool is_manual_generation_available) override;
void DidNavigateMainFrame() override; void DidNavigateMainFrame() override;
void GetFavicon( void GetFavicon(
int desired_size_in_pixel, int desired_size_in_pixel,
......
...@@ -300,8 +300,7 @@ void ContentPasswordManagerDriver::CheckSafeBrowsingReputation( ...@@ -300,8 +300,7 @@ void ContentPasswordManagerDriver::CheckSafeBrowsingReputation(
void ContentPasswordManagerDriver::FocusedInputChanged(bool is_fillable, void ContentPasswordManagerDriver::FocusedInputChanged(bool is_fillable,
bool is_password_field) { bool is_password_field) {
client_->FocusedInputChanged(render_frame_host_->GetLastCommittedOrigin(), client_->FocusedInputChanged(this, is_fillable, is_password_field);
is_fillable, is_password_field);
} }
void ContentPasswordManagerDriver::LogFirstFillingResult( void ContentPasswordManagerDriver::LogFirstFillingResult(
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/macros.h"
#include "components/password_manager/core/browser/password_manager_client.h" #include "components/password_manager/core/browser/password_manager_client.h"
namespace password_manager { namespace password_manager {
......
...@@ -42,6 +42,7 @@ namespace password_manager { ...@@ -42,6 +42,7 @@ namespace password_manager {
class LogManager; class LogManager;
class PasswordFormManagerForUI; class PasswordFormManagerForUI;
class PasswordManager; class PasswordManager;
class PasswordManagerDriver;
class PasswordManagerMetricsRecorder; class PasswordManagerMetricsRecorder;
class PasswordRequirementsService; class PasswordRequirementsService;
class PasswordStore; class PasswordStore;
...@@ -126,9 +127,10 @@ class PasswordManagerClient { ...@@ -126,9 +127,10 @@ class PasswordManagerClient {
// Informs the embedder that the focus changed to a different input in the // Informs the embedder that the focus changed to a different input in the
// same frame (e.g. tabbed from email to password field). // same frame (e.g. tabbed from email to password field).
virtual void FocusedInputChanged(const url::Origin& last_committed_origin, virtual void FocusedInputChanged(
bool is_fillable, password_manager::PasswordManagerDriver* driver,
bool is_password_field) = 0; bool is_fillable,
bool is_password_field) = 0;
// Informs the embedder of a password forms that the user should choose from. // Informs the embedder of a password forms that the user should choose from.
// Returns true if the prompt is indeed displayed. If the prompt is not // Returns true if the prompt is indeed displayed. If the prompt is not
......
...@@ -132,6 +132,11 @@ bool IsLoggingActive(const password_manager::PasswordManagerClient* client) { ...@@ -132,6 +132,11 @@ bool IsLoggingActive(const password_manager::PasswordManagerClient* client) {
bool ManualPasswordGenerationEnabled( bool ManualPasswordGenerationEnabled(
password_manager::PasswordManagerDriver* driver) { password_manager::PasswordManagerDriver* driver) {
#if defined(OS_ANDROID)
if (!base::FeatureList::IsEnabled(
password_manager::features::kManualPasswordGenerationAndroid))
return false;
#endif // defined(OS_ANDROID)
password_manager::PasswordGenerationFrameHelper* password_generation_manager = password_manager::PasswordGenerationFrameHelper* password_generation_manager =
driver ? driver->GetPasswordGenerationHelper() : nullptr; driver ? driver->GetPasswordGenerationHelper() : nullptr;
if (!password_generation_manager || if (!password_generation_manager ||
......
...@@ -30,7 +30,7 @@ void StubPasswordManagerClient::ShowManualFallbackForSaving( ...@@ -30,7 +30,7 @@ void StubPasswordManagerClient::ShowManualFallbackForSaving(
void StubPasswordManagerClient::HideManualFallbackForSaving() {} void StubPasswordManagerClient::HideManualFallbackForSaving() {}
void StubPasswordManagerClient::FocusedInputChanged( void StubPasswordManagerClient::FocusedInputChanged(
const url::Origin& last_committed_origin, password_manager::PasswordManagerDriver* driver,
bool is_fillable, bool is_fillable,
bool is_password_field) {} bool is_password_field) {}
......
...@@ -32,7 +32,7 @@ class StubPasswordManagerClient : public PasswordManagerClient { ...@@ -32,7 +32,7 @@ class StubPasswordManagerClient : public PasswordManagerClient {
bool has_generated_password, bool has_generated_password,
bool update_password) override; bool update_password) override;
void HideManualFallbackForSaving() override; void HideManualFallbackForSaving() override;
void FocusedInputChanged(const url::Origin& last_committed_origin, void FocusedInputChanged(password_manager::PasswordManagerDriver* driver,
bool is_fillable, bool is_fillable,
bool is_password_field) override; bool is_password_field) override;
bool PromptUserToChooseCredentials( bool PromptUserToChooseCredentials(
......
...@@ -20,6 +20,7 @@ class LogManager; ...@@ -20,6 +20,7 @@ class LogManager;
namespace password_manager { namespace password_manager {
class PasswordFormManagerForUI; class PasswordFormManagerForUI;
class PasswordManagerDriver;
} }
namespace web { namespace web {
...@@ -73,7 +74,7 @@ class IOSChromePasswordManagerClient ...@@ -73,7 +74,7 @@ class IOSChromePasswordManagerClient
bool has_generated_password, bool has_generated_password,
bool is_update) override; bool is_update) override;
void HideManualFallbackForSaving() override; void HideManualFallbackForSaving() override;
void FocusedInputChanged(const url::Origin& last_committed_origin, void FocusedInputChanged(password_manager::PasswordManagerDriver* driver,
bool is_fillable, bool is_fillable,
bool is_password_field) override; bool is_password_field) override;
bool PromptUserToChooseCredentials( bool PromptUserToChooseCredentials(
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "components/password_manager/core/browser/password_form_manager_for_ui.h" #include "components/password_manager/core/browser/password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_manager.h" #include "components/password_manager/core/browser/password_manager.h"
#include "components/password_manager/core/browser/password_manager_constants.h" #include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/browser/password_manager_driver.h"
#include "components/password_manager/core/browser/password_manager_internals_service.h" #include "components/password_manager/core/browser/password_manager_internals_service.h"
#include "components/password_manager/core/browser/password_manager_util.h" #include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/browser/password_requirements_service.h" #include "components/password_manager/core/browser/password_requirements_service.h"
...@@ -121,7 +122,7 @@ void IOSChromePasswordManagerClient::HideManualFallbackForSaving() { ...@@ -121,7 +122,7 @@ void IOSChromePasswordManagerClient::HideManualFallbackForSaving() {
} }
void IOSChromePasswordManagerClient::FocusedInputChanged( void IOSChromePasswordManagerClient::FocusedInputChanged(
const url::Origin& last_committed_origin, password_manager::PasswordManagerDriver* driver,
bool is_fillable, bool is_fillable,
bool is_password_field) { bool is_password_field) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
......
...@@ -18,6 +18,7 @@ class WebViewBrowserState; ...@@ -18,6 +18,7 @@ class WebViewBrowserState;
namespace password_manager { namespace password_manager {
class PasswordFormManagerForUI; class PasswordFormManagerForUI;
class PasswordManagerDriver;
} }
@protocol CWVPasswordManagerClientDelegate @protocol CWVPasswordManagerClientDelegate
...@@ -64,7 +65,7 @@ class WebViewPasswordManagerClient ...@@ -64,7 +65,7 @@ class WebViewPasswordManagerClient
bool has_generated_password, bool has_generated_password,
bool is_update) override; bool is_update) override;
void HideManualFallbackForSaving() override; void HideManualFallbackForSaving() override;
void FocusedInputChanged(const url::Origin& last_committed_origin, void FocusedInputChanged(password_manager::PasswordManagerDriver* driver,
bool is_fillable, bool is_fillable,
bool is_password_field) override; bool is_password_field) override;
bool PromptUserToChooseCredentials( bool PromptUserToChooseCredentials(
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "components/password_manager/core/browser/log_manager.h" #include "components/password_manager/core/browser/log_manager.h"
#include "components/password_manager/core/browser/password_form_manager_for_ui.h" #include "components/password_manager/core/browser/password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_manager.h" #include "components/password_manager/core/browser/password_manager.h"
#include "components/password_manager/core/browser/password_manager_driver.h"
#include "components/password_manager/core/browser/password_manager_internals_service.h" #include "components/password_manager/core/browser/password_manager_internals_service.h"
#include "components/password_manager/core/browser/password_manager_util.h" #include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/common/password_manager_pref_names.h" #include "components/password_manager/core/common/password_manager_pref_names.h"
...@@ -92,7 +93,7 @@ void WebViewPasswordManagerClient::HideManualFallbackForSaving() { ...@@ -92,7 +93,7 @@ void WebViewPasswordManagerClient::HideManualFallbackForSaving() {
} }
void WebViewPasswordManagerClient::FocusedInputChanged( void WebViewPasswordManagerClient::FocusedInputChanged(
const url::Origin& last_committed_origin, password_manager::PasswordManagerDriver* driver,
bool is_fillable, bool is_fillable,
bool is_password_field) { bool is_password_field) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
......
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