Commit 6aa8eff6 authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[Autofill Assistant] Introduce a TabHelper.

The Autofill Assistant stack's lifecycle is not using Chrome's framework
designed to provide exactly that. This patch introduces a TabHelper that
will become a proper entry point to control construction and destruction
of components of the Autofill Assistant stack that depend on a WebContents.

This initial patch only adds an empty TabHelper and test and hooks it up in the
tab_helpers registry behind a default disabled AutofillAssistantTabHelpers
feature.

Bug: b/169389571
Change-Id: I3129fd04e5e4dd6c65c1df891383cf29cad508d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521620
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825719}
parent 655b2c15
...@@ -652,6 +652,8 @@ static_library("ui") { ...@@ -652,6 +652,8 @@ static_library("ui") {
"android/autofill/card_unmask_prompt_view_android.h", "android/autofill/card_unmask_prompt_view_android.h",
"android/autofill/credit_card_scanner_view_android.cc", "android/autofill/credit_card_scanner_view_android.cc",
"android/autofill/credit_card_scanner_view_android.h", "android/autofill/credit_card_scanner_view_android.h",
"android/autofill_assistant/autofill_assistant_tab_helper.cc",
"android/autofill_assistant/autofill_assistant_tab_helper.h",
"android/chrome_http_auth_handler.cc", "android/chrome_http_auth_handler.cc",
"android/chrome_http_auth_handler.h", "android/chrome_http_auth_handler.h",
"android/chrome_javascript_app_modal_dialog_android.cc", "android/chrome_javascript_app_modal_dialog_android.cc",
...@@ -795,6 +797,8 @@ static_library("ui") { ...@@ -795,6 +797,8 @@ static_library("ui") {
"//chrome/android/features/dev_ui:buildflags", "//chrome/android/features/dev_ui:buildflags",
"//chrome/browser/image_decoder", "//chrome/browser/image_decoder",
"//chrome/browser/resources/webapks:webapks_ui_resources", "//chrome/browser/resources/webapks:webapks_ui_resources",
"//components/autofill_assistant/browser",
"//components/autofill_assistant/browser:proto",
"//components/browser_ui/client_certificate/android", "//components/browser_ui/client_certificate/android",
"//components/embedder_support/android:browser_context", "//components/embedder_support/android:browser_context",
"//components/embedder_support/android:context_menu", "//components/embedder_support/android:context_menu",
......
file://components/autofill_assistant/OWNERS
// 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 "chrome/browser/ui/android/autofill_assistant/autofill_assistant_tab_helper.h"
#include "base/time/default_tick_clock.h"
namespace autofill_assistant {
AutofillAssistantTabHelper::~AutofillAssistantTabHelper() {}
void AutofillAssistantTabHelper::WebContentsDestroyed() {}
AutofillAssistantTabHelper::AutofillAssistantTabHelper(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {}
WEB_CONTENTS_USER_DATA_KEY_IMPL(AutofillAssistantTabHelper)
} // namespace autofill_assistant
// 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.
#ifndef CHROME_BROWSER_UI_ANDROID_AUTOFILL_ASSISTANT_AUTOFILL_ASSISTANT_TAB_HELPER_H_
#define CHROME_BROWSER_UI_ANDROID_AUTOFILL_ASSISTANT_AUTOFILL_ASSISTANT_TAB_HELPER_H_
#include "components/autofill_assistant/browser/controller.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace autofill_assistant {
// AutofillAssistantTabHelper for the AutofillAssistant component.
class AutofillAssistantTabHelper
: public content::WebContentsUserData<AutofillAssistantTabHelper>,
public content::WebContentsObserver {
public:
~AutofillAssistantTabHelper() override;
AutofillAssistantTabHelper(const AutofillAssistantTabHelper&) = delete;
AutofillAssistantTabHelper& operator=(const AutofillAssistantTabHelper&) =
delete;
// content::WebContentsObserver:
void WebContentsDestroyed() override;
private:
friend class content::WebContentsUserData<AutofillAssistantTabHelper>;
explicit AutofillAssistantTabHelper(content::WebContents* web_contents);
WEB_CONTENTS_USER_DATA_KEY_DECL();
};
} // namespace autofill_assistant
#endif // CHROME_BROWSER_UI_ANDROID_AUTOFILL_ASSISTANT_AUTOFILL_ASSISTANT_TAB_HELPER_H_
// 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 "chrome/browser/ui/android/autofill_assistant/autofill_assistant_tab_helper.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/web_contents.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill_assistant {
namespace {
class AutofillAssistantTabHelperTest : public ChromeRenderViewHostTestHarness {
public:
AutofillAssistantTabHelperTest();
~AutofillAssistantTabHelperTest() override {}
void SetUp() override;
AutofillAssistantTabHelper* tab_helper() const { return tab_helper_; }
private:
AutofillAssistantTabHelper* tab_helper_; // Owned by WebContents.
};
AutofillAssistantTabHelperTest::AutofillAssistantTabHelperTest()
: tab_helper_(nullptr) {}
void AutofillAssistantTabHelperTest::SetUp() {
ChromeRenderViewHostTestHarness::SetUp();
AutofillAssistantTabHelper::CreateForWebContents(web_contents());
tab_helper_ = AutofillAssistantTabHelper::FromWebContents(web_contents());
}
// Checks the test setup.
TEST_F(AutofillAssistantTabHelperTest, InitialSetup) {
EXPECT_NE(nullptr, tab_helper());
}
} // namespace
} // namespace autofill_assistant
...@@ -120,9 +120,11 @@ ...@@ -120,9 +120,11 @@
#include "chrome/browser/android/search_permissions/search_geolocation_disclosure_tab_helper.h" #include "chrome/browser/android/search_permissions/search_geolocation_disclosure_tab_helper.h"
#include "chrome/browser/banners/app_banner_manager_android.h" #include "chrome/browser/banners/app_banner_manager_android.h"
#include "chrome/browser/flags/android/chrome_feature_list.h" #include "chrome/browser/flags/android/chrome_feature_list.h"
#include "chrome/browser/ui/android/autofill_assistant/autofill_assistant_tab_helper.h"
#include "chrome/browser/ui/android/context_menu_helper.h" #include "chrome/browser/ui/android/context_menu_helper.h"
#include "chrome/browser/ui/javascript_dialogs/javascript_tab_modal_dialog_manager_delegate_android.h" #include "chrome/browser/ui/javascript_dialogs/javascript_tab_modal_dialog_manager_delegate_android.h"
#include "chrome/browser/video_tutorials/video_tutorial_tab_helper.h" #include "chrome/browser/video_tutorials/video_tutorial_tab_helper.h"
#include "components/autofill_assistant/browser/features.h"
#else #else
#include "chrome/browser/banners/app_banner_manager_desktop.h" #include "chrome/browser/banners/app_banner_manager_desktop.h"
#include "chrome/browser/tab_contents/form_interaction_tab_helper.h" #include "chrome/browser/tab_contents/form_interaction_tab_helper.h"
...@@ -354,6 +356,11 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) { ...@@ -354,6 +356,11 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
} }
SearchGeolocationDisclosureTabHelper::CreateForWebContents(web_contents); SearchGeolocationDisclosureTabHelper::CreateForWebContents(web_contents);
video_tutorials::VideoTutorialTabHelper::CreateForWebContents(web_contents); video_tutorials::VideoTutorialTabHelper::CreateForWebContents(web_contents);
if (base::FeatureList::IsEnabled(
autofill_assistant::features::kAutofillAssistantWithTabHelper)) {
autofill_assistant::AutofillAssistantTabHelper::CreateForWebContents(
web_contents);
}
#else #else
banners::AppBannerManagerDesktop::CreateForWebContents(web_contents); banners::AppBannerManagerDesktop::CreateForWebContents(web_contents);
BookmarkTabHelper::CreateForWebContents(web_contents); BookmarkTabHelper::CreateForWebContents(web_contents);
......
...@@ -3864,6 +3864,7 @@ test("unit_tests") { ...@@ -3864,6 +3864,7 @@ test("unit_tests") {
"../browser/notifications/notification_channels_provider_android_unittest.cc", "../browser/notifications/notification_channels_provider_android_unittest.cc",
"../browser/search/contextual_search_policy_handler_android_unittest.cc", "../browser/search/contextual_search_policy_handler_android_unittest.cc",
"../browser/translate/android/translate_bridge_unittest.cc", "../browser/translate/android/translate_bridge_unittest.cc",
"../browser/ui/android/autofill_assistant/autofill_assistant_tab_helper_unittest.cc",
"../browser/ui/android/tab_model/tab_model_list_unittest.cc", "../browser/ui/android/tab_model/tab_model_list_unittest.cc",
"../browser/ui/android/toolbar/location_bar_model_android_unittest.cc", "../browser/ui/android/toolbar/location_bar_model_android_unittest.cc",
] ]
......
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