Commit e55e1db6 authored by Michael Bai's avatar Michael Bai Committed by Chromium LUCI CQ

Autofill: Add interfaces to Propagate the predications

Adds PropagateAutofillPredictions method in AutofillHandler, it is
invoked by ContentAutofillDriver, this seems detour, but reasonable
consider AutofillDriver::PropagateAutofillPrediction also applies
to ios.

Adds OnServerPredictionsAvailable to AutofillProvider and test.

Add parameter to enable the autofill download in AutofillHandlerProxy,
the download still disabled.

Bug: 1151542
Change-Id: I2feb36d57f17ee04bd152ce02f493074ba99419d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2574532
Commit-Queue: Michael Bai <michaelbai@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834591}
parent b339e4a1
...@@ -355,6 +355,11 @@ void AutofillProviderAndroid::OnHidePopup(AutofillHandlerProxy* handler) { ...@@ -355,6 +355,11 @@ void AutofillProviderAndroid::OnHidePopup(AutofillHandlerProxy* handler) {
} }
} }
void AutofillProviderAndroid::OnServerPredictionsAvailable(
AutofillHandlerProxy* handler) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
void AutofillProviderAndroid::Reset(AutofillHandlerProxy* handler) { void AutofillProviderAndroid::Reset(AutofillHandlerProxy* handler) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (handler == handler_.get()) { if (handler == handler_.get()) {
......
...@@ -68,6 +68,7 @@ class AutofillProviderAndroid : public AutofillProvider { ...@@ -68,6 +68,7 @@ class AutofillProviderAndroid : public AutofillProvider {
void OnFormsSeen(AutofillHandlerProxy* handler, void OnFormsSeen(AutofillHandlerProxy* handler,
const std::vector<FormData>& forms) override; const std::vector<FormData>& forms) override;
void OnHidePopup(AutofillHandlerProxy* handler) override; void OnHidePopup(AutofillHandlerProxy* handler) override;
void OnServerPredictionsAvailable(AutofillHandlerProxy* handler) override;
void Reset(AutofillHandlerProxy* handler) override; void Reset(AutofillHandlerProxy* handler) override;
......
...@@ -61,7 +61,7 @@ ContentAutofillDriver::ContentAutofillDriver( ...@@ -61,7 +61,7 @@ ContentAutofillDriver::ContentAutofillDriver(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
AutofillClient* client, AutofillClient* client,
const std::string& app_locale, const std::string& app_locale,
AutofillManager::AutofillDownloadManagerState enable_download_manager, AutofillHandler::AutofillDownloadManagerState enable_download_manager,
AutofillProvider* provider) AutofillProvider* provider)
: render_frame_host_(render_frame_host), : render_frame_host_(render_frame_host),
autofill_manager_(nullptr), autofill_manager_(nullptr),
...@@ -70,7 +70,7 @@ ContentAutofillDriver::ContentAutofillDriver( ...@@ -70,7 +70,7 @@ ContentAutofillDriver::ContentAutofillDriver(
// AutofillManager isn't used if provider is valid, Autofill provider is // AutofillManager isn't used if provider is valid, Autofill provider is
// currently used by Android WebView only. // currently used by Android WebView only.
if (provider) { if (provider) {
SetAutofillProvider(provider); SetAutofillProvider(provider, enable_download_manager);
} else { } else {
SetAutofillManager(std::make_unique<AutofillManager>( SetAutofillManager(std::make_unique<AutofillManager>(
this, client, app_locale, enable_download_manager)); this, client, app_locale, enable_download_manager));
...@@ -158,8 +158,10 @@ void ContentAutofillDriver::SendFormDataToRenderer( ...@@ -158,8 +158,10 @@ void ContentAutofillDriver::SendFormDataToRenderer(
void ContentAutofillDriver::PropagateAutofillPredictions( void ContentAutofillDriver::PropagateAutofillPredictions(
const std::vector<FormStructure*>& forms) { const std::vector<FormStructure*>& forms) {
autofill_manager_->client()->PropagateAutofillPredictions(render_frame_host_, AutofillHandler* handler =
forms); autofill_manager_ ? autofill_manager_ : autofill_handler_.get();
DCHECK(handler);
handler->PropagateAutofillPredictions(render_frame_host_, forms);
} }
void ContentAutofillDriver::HandleParsedForms( void ContentAutofillDriver::HandleParsedForms(
...@@ -402,9 +404,11 @@ void ContentAutofillDriver::RemoveHandler( ...@@ -402,9 +404,11 @@ void ContentAutofillDriver::RemoveHandler(
view->GetRenderWidgetHost()->RemoveKeyPressEventCallback(handler); view->GetRenderWidgetHost()->RemoveKeyPressEventCallback(handler);
} }
void ContentAutofillDriver::SetAutofillProvider(AutofillProvider* provider) { void ContentAutofillDriver::SetAutofillProvider(
autofill_handler_ = AutofillProvider* provider,
std::make_unique<AutofillHandlerProxy>(this, log_manager_, provider); AutofillHandler::AutofillDownloadManagerState enable_download_manager) {
autofill_handler_ = std::make_unique<AutofillHandlerProxy>(
this, log_manager_, provider, enable_download_manager);
GetAutofillAgent()->SetUserGestureRequired(false); GetAutofillAgent()->SetUserGestureRequired(false);
GetAutofillAgent()->SetSecureContextRequired(true); GetAutofillAgent()->SetSecureContextRequired(true);
GetAutofillAgent()->SetFocusRequiresScroll(false); GetAutofillAgent()->SetFocusRequiresScroll(false);
...@@ -450,7 +454,8 @@ void ContentAutofillDriver::ReportAutofillWebOTPMetrics( ...@@ -450,7 +454,8 @@ void ContentAutofillDriver::ReportAutofillWebOTPMetrics(
void ContentAutofillDriver::SetAutofillProviderForTesting( void ContentAutofillDriver::SetAutofillProviderForTesting(
AutofillProvider* provider) { AutofillProvider* provider) {
SetAutofillProvider(provider); SetAutofillProvider(provider, AutofillHandler::AutofillDownloadManagerState::
DISABLE_AUTOFILL_DOWNLOAD_MANAGER);
// AutofillManager isn't used if provider is valid. // AutofillManager isn't used if provider is valid.
autofill_manager_ = nullptr; autofill_manager_ = nullptr;
} }
......
...@@ -63,7 +63,7 @@ class ContentAutofillDriver : public AutofillDriver, ...@@ -63,7 +63,7 @@ class ContentAutofillDriver : public AutofillDriver,
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
AutofillClient* client, AutofillClient* client,
const std::string& app_locale, const std::string& app_locale,
AutofillManager::AutofillDownloadManagerState enable_download_manager, AutofillHandler::AutofillDownloadManagerState enable_download_manager,
AutofillProvider* provider); AutofillProvider* provider);
~ContentAutofillDriver() override; ~ContentAutofillDriver() override;
...@@ -181,7 +181,9 @@ class ContentAutofillDriver : public AutofillDriver, ...@@ -181,7 +181,9 @@ class ContentAutofillDriver : public AutofillDriver,
void RemoveHandler( void RemoveHandler(
const content::RenderWidgetHost::KeyPressEventCallback& handler) override; const content::RenderWidgetHost::KeyPressEventCallback& handler) override;
void SetAutofillProvider(AutofillProvider* provider); void SetAutofillProvider(
AutofillProvider* provider,
AutofillHandler::AutofillDownloadManagerState enable_download_manager);
// Returns whether navigator.credentials.get({otp: {transport:"sms"}}) has // Returns whether navigator.credentials.get({otp: {transport:"sms"}}) has
// been used. // been used.
......
...@@ -623,6 +623,7 @@ source_set("unit_tests") { ...@@ -623,6 +623,7 @@ source_set("unit_tests") {
"autofill_profile_sync_util_unittest.cc", "autofill_profile_sync_util_unittest.cc",
"autofill_profile_validation_util_unittest.cc", "autofill_profile_validation_util_unittest.cc",
"autofill_profile_validator_unittest.cc", "autofill_profile_validator_unittest.cc",
"autofill_provider_unittest.cc",
"autofill_regexes_unittest.cc", "autofill_regexes_unittest.cc",
"autofill_subject_unittest.cc", "autofill_subject_unittest.cc",
"autofill_type_unittest.cc", "autofill_type_unittest.cc",
......
...@@ -123,6 +123,12 @@ class AutofillHandler : public AutofillDownloadManager::Observer { ...@@ -123,6 +123,12 @@ class AutofillHandler : public AutofillDownloadManager::Observer {
// Invoked when the options of a select element in the |form| changed. // Invoked when the options of a select element in the |form| changed.
virtual void SelectFieldOptionsDidChange(const FormData& form) = 0; virtual void SelectFieldOptionsDidChange(const FormData& form) = 0;
// Invoked when the field type predictions are downloaded from the autofill
// server.
virtual void PropagateAutofillPredictions(
content::RenderFrameHost* rfh,
const std::vector<FormStructure*>& forms) = 0;
// Resets cache. // Resets cache.
virtual void Reset(); virtual void Reset();
......
...@@ -10,12 +10,14 @@ namespace autofill { ...@@ -10,12 +10,14 @@ namespace autofill {
using base::TimeTicks; using base::TimeTicks;
AutofillHandlerProxy::AutofillHandlerProxy(AutofillDriver* driver, AutofillHandlerProxy::AutofillHandlerProxy(
LogManager* log_manager, AutofillDriver* driver,
AutofillProvider* provider) LogManager* log_manager,
AutofillProvider* provider,
AutofillHandler::AutofillDownloadManagerState enable_download_manager)
: AutofillHandler(driver, : AutofillHandler(driver,
log_manager, log_manager,
DISABLE_AUTOFILL_DOWNLOAD_MANAGER, enable_download_manager,
version_info::Channel::UNKNOWN), version_info::Channel::UNKNOWN),
provider_(provider) {} provider_(provider) {}
...@@ -90,7 +92,16 @@ void AutofillHandlerProxy::OnHidePopup() { ...@@ -90,7 +92,16 @@ void AutofillHandlerProxy::OnHidePopup() {
void AutofillHandlerProxy::SelectFieldOptionsDidChange(const FormData& form) {} void AutofillHandlerProxy::SelectFieldOptionsDidChange(const FormData& form) {}
void AutofillHandlerProxy::PropagateAutofillPredictions(
content::RenderFrameHost* rfh,
const std::vector<FormStructure*>& forms) {
has_server_prediction_ = true;
provider_->OnServerPredictionsAvailable(this);
}
void AutofillHandlerProxy::Reset() { void AutofillHandlerProxy::Reset() {
AutofillHandler::Reset();
has_server_prediction_ = false;
provider_->Reset(this); provider_->Reset(this);
} }
......
...@@ -15,9 +15,11 @@ class AutofillProvider; ...@@ -15,9 +15,11 @@ class AutofillProvider;
// This class forwards AutofillHandler calls to AutofillProvider. // This class forwards AutofillHandler calls to AutofillProvider.
class AutofillHandlerProxy : public AutofillHandler { class AutofillHandlerProxy : public AutofillHandler {
public: public:
AutofillHandlerProxy(AutofillDriver* driver, AutofillHandlerProxy(
LogManager* log_manager, AutofillDriver* driver,
AutofillProvider* provider); LogManager* log_manager,
AutofillProvider* provider,
AutofillHandler::AutofillDownloadManagerState enable_download_manager);
~AutofillHandlerProxy() override; ~AutofillHandlerProxy() override;
void OnFocusNoLongerOnForm(bool had_interacted_form) override; void OnFocusNoLongerOnForm(bool had_interacted_form) override;
...@@ -36,6 +38,8 @@ class AutofillHandlerProxy : public AutofillHandler { ...@@ -36,6 +38,8 @@ class AutofillHandlerProxy : public AutofillHandler {
return weak_ptr_factory_.GetWeakPtr(); return weak_ptr_factory_.GetWeakPtr();
} }
bool has_server_prediction() const { return has_server_prediction_; }
protected: protected:
void OnFormSubmittedImpl(const FormData& form, void OnFormSubmittedImpl(const FormData& form,
bool known_success, bool known_success,
...@@ -74,7 +78,12 @@ class AutofillHandlerProxy : public AutofillHandler { ...@@ -74,7 +78,12 @@ class AutofillHandlerProxy : public AutofillHandler {
void OnAfterProcessParsedForms( void OnAfterProcessParsedForms(
const std::set<FormType>& form_types) override {} const std::set<FormType>& form_types) override {}
void PropagateAutofillPredictions(
content::RenderFrameHost* rfh,
const std::vector<FormStructure*>& forms) override;
private: private:
bool has_server_prediction_ = false;
AutofillProvider* provider_; AutofillProvider* provider_;
base::WeakPtrFactory<AutofillHandlerProxy> weak_ptr_factory_{this}; base::WeakPtrFactory<AutofillHandlerProxy> weak_ptr_factory_{this};
......
...@@ -1388,6 +1388,12 @@ void AutofillManager::SelectFieldOptionsDidChange(const FormData& form) { ...@@ -1388,6 +1388,12 @@ void AutofillManager::SelectFieldOptionsDidChange(const FormData& form) {
TriggerRefill(form); TriggerRefill(form);
} }
void AutofillManager::PropagateAutofillPredictions(
content::RenderFrameHost* rfh,
const std::vector<FormStructure*>& forms) {
client_->PropagateAutofillPredictions(rfh, forms);
}
void AutofillManager::OnCreditCardFetched(bool did_succeed, void AutofillManager::OnCreditCardFetched(bool did_succeed,
const CreditCard* credit_card, const CreditCard* credit_card,
const base::string16& cvc) { const base::string16& cvc) {
......
...@@ -219,6 +219,9 @@ class AutofillManager : public AutofillHandler, ...@@ -219,6 +219,9 @@ class AutofillManager : public AutofillHandler,
void OnDidEndTextFieldEditing() override; void OnDidEndTextFieldEditing() override;
void OnHidePopup() override; void OnHidePopup() override;
void SelectFieldOptionsDidChange(const FormData& form) override; void SelectFieldOptionsDidChange(const FormData& form) override;
void PropagateAutofillPredictions(
content::RenderFrameHost* rfh,
const std::vector<FormStructure*>& forms) override;
void Reset() override; void Reset() override;
// AutocompleteHistoryManager::SuggestionsHandler: // AutocompleteHistoryManager::SuggestionsHandler:
......
...@@ -69,6 +69,8 @@ class AutofillProvider { ...@@ -69,6 +69,8 @@ class AutofillProvider {
virtual void OnHidePopup(AutofillHandlerProxy* handler) = 0; virtual void OnHidePopup(AutofillHandlerProxy* handler) = 0;
virtual void OnServerPredictionsAvailable(AutofillHandlerProxy* handler) = 0;
virtual void Reset(AutofillHandlerProxy* handler) = 0; virtual void Reset(AutofillHandlerProxy* handler) = 0;
void SendFormDataToRenderer(AutofillHandlerProxy* handler, void SendFormDataToRenderer(AutofillHandlerProxy* handler,
......
// Copyright 2020 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 "components/autofill/core/browser/autofill_handler_proxy.h"
#include "components/autofill/core/browser/test_autofill_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
class AutofillHandlerProxyTestHelper : public AutofillHandlerProxy {
public:
explicit AutofillHandlerProxyTestHelper(AutofillProvider* autofill_provider)
: AutofillHandlerProxy(nullptr,
nullptr,
autofill_provider,
DISABLE_AUTOFILL_DOWNLOAD_MANAGER) {}
void SimulatePropagateAutofillPredictions() {
PropagateAutofillPredictions(nullptr, std::vector<FormStructure*>());
}
void SimulateOnQueryFormFieldAutofillImpl() {
OnQueryFormFieldAutofillImpl(0, FormData(), FormFieldData(), gfx::RectF(),
/*autoselect_first_suggestion=*/false);
}
};
class AutofillProviderTestHelper : public TestAutofillProvider {
public:
bool HasServerPrediction() const { return handler_->has_server_prediction(); }
private:
// AutofillProvider
void OnQueryFormFieldAutofill(AutofillHandlerProxy* handler,
int32_t id,
const FormData& form,
const FormFieldData& field,
const gfx::RectF& bounding_box,
bool autoselect_first_suggestion) override {
handler_ = handler;
}
AutofillHandlerProxy* handler_;
};
class AutofillProviderTest : public testing::Test {
public:
void SetUp() override {
autofill_provider_test_helper_ =
std::make_unique<AutofillProviderTestHelper>();
autofill_handler_proxy_test_helper_ =
std::make_unique<AutofillHandlerProxyTestHelper>(
autofill_provider_test_helper_.get());
}
AutofillProviderTestHelper* autofill_provider_test_helper() {
return autofill_provider_test_helper_.get();
}
AutofillHandlerProxyTestHelper* autofill_handler_proxy_test_helper() {
return autofill_handler_proxy_test_helper_.get();
}
private:
std::unique_ptr<AutofillProviderTestHelper> autofill_provider_test_helper_;
std::unique_ptr<AutofillHandlerProxyTestHelper>
autofill_handler_proxy_test_helper_;
};
TEST_F(AutofillProviderTest, HasServerPredictionAfterQuery) {
// Simulate the result arrives after starting autofill.
autofill_handler_proxy_test_helper()->SimulateOnQueryFormFieldAutofillImpl();
EXPECT_FALSE(autofill_provider_test_helper()->HasServerPrediction());
autofill_handler_proxy_test_helper()->SimulatePropagateAutofillPredictions();
EXPECT_TRUE(autofill_provider_test_helper()->HasServerPrediction());
autofill_handler_proxy_test_helper()->Reset();
EXPECT_FALSE(autofill_provider_test_helper()->HasServerPrediction());
}
TEST_F(AutofillProviderTest, HasServerPredictionBeforeQuery) {
// Simulate the result arrives before starting autofill.
autofill_handler_proxy_test_helper()->SimulatePropagateAutofillPredictions();
autofill_handler_proxy_test_helper()->SimulateOnQueryFormFieldAutofillImpl();
EXPECT_TRUE(autofill_provider_test_helper()->HasServerPrediction());
autofill_handler_proxy_test_helper()->Reset();
EXPECT_FALSE(autofill_provider_test_helper()->HasServerPrediction());
}
} // namespace autofill
...@@ -49,6 +49,8 @@ class TestAutofillProvider : public AutofillProvider { ...@@ -49,6 +49,8 @@ class TestAutofillProvider : public AutofillProvider {
void OnFormsSeen(AutofillHandlerProxy* handler, void OnFormsSeen(AutofillHandlerProxy* handler,
const std::vector<FormData>& forms) override {} const std::vector<FormData>& forms) override {}
void OnHidePopup(AutofillHandlerProxy* handler) override {} void OnHidePopup(AutofillHandlerProxy* handler) override {}
void OnServerPredictionsAvailable(AutofillHandlerProxy* handler) override {}
void Reset(AutofillHandlerProxy* handler) override {} void Reset(AutofillHandlerProxy* handler) override {}
}; };
......
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