Skip to content

Commit

Permalink
[gbb-cct] PageInsights module skeleton
Browse files Browse the repository at this point in the history
This CL introduces a new module under  chrome/browser/ui/android/page_insights and the UI skeleton based on bottom sheet. Its entry for now is via a new item in 3-dot menu.

Bug: b/282739536
Change-Id: I145a2ae4e596799d567c90c3e4107b41e4eb2641
Low-Coverage-Reason: Main changes are covered with tests. RootUiCoordinator contains a simple invocation of the new module.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4557624
Reviewed-by: Kevin Grosu <kgrosu@google.com>
Reviewed-by: Matthew Jones <mdjones@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150510}
  • Loading branch information
JinsukKim authored and Chromium LUCI CQ committed May 30, 2023
1 parent e72c7dc commit bbb62dc
Show file tree
Hide file tree
Showing 25 changed files with 924 additions and 15 deletions.
2 changes: 2 additions & 0 deletions chrome/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ if (current_toolchain == default_toolchain) {
"//chrome/browser/ui/android/night_mode:java",
"//chrome/browser/ui/android/omnibox:java",
"//chrome/browser/ui/android/page_info:java",
"//chrome/browser/ui/android/page_insights:java",
"//chrome/browser/ui/android/quickactionsearchwidget:java",
"//chrome/browser/ui/android/searchactivityutils:java",
"//chrome/browser/ui/android/signin:java",
Expand Down Expand Up @@ -2650,6 +2651,7 @@ if (current_toolchain == default_toolchain) {
"//chrome/browser/ui/android/appmenu/internal:unit_device_javatests",
"//chrome/browser/ui/android/night_mode:unit_device_javatests",
"//chrome/browser/ui/android/omnibox:unit_device_javatests",
"//chrome/browser/ui/android/page_insights:unit_device_javatests",
"//chrome/browser/ui/android/searchactivityutils:unit_device_javatests",
"//chrome/browser/ui/android/signin:unit_device_javatests",
"//chrome/browser/ui/messages/android:unit_device_javatests",
Expand Down
1 change: 1 addition & 0 deletions chrome/android/chrome_java_resources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ chrome_java_resources = [
"java/res/layout/optional_toolbar_button.xml",
"java/res/layout/os_version_unsupported_text.xml",
"java/res/layout/other_forms_of_history_dialog.xml",
"java/res/layout/page_insights_hub_container.xml",
"java/res/layout/password_generation_dialog.xml",
"java/res/layout/password_generation_popup_explanation.xml",
"java/res/layout/password_manager_dialog.xml",
Expand Down
12 changes: 12 additions & 0 deletions chrome/android/java/res/layout/page_insights_hub_container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2023 The Chromium Authors
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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false" />
7 changes: 7 additions & 0 deletions chrome/android/java/res_app/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ found in the LICENSE file.
android:inflatedId="@+id/status_indicator"
android:layout="@layout/status_indicator_container" />

<ViewStub
android:id="@+id/page_insights_hub_container_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/page_insights_hub_container"
android:layout="@layout/page_insights_hub_container" />

<FrameLayout
android:id="@+id/sheet_container"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected RootUiCoordinator createRootUiCoordinator() {
/* statusBarColorProvider= */ this, getIntentRequestTracker(),
() -> mToolbarCoordinator, () -> mNavigationController, () -> mIntentDataProvider,
() -> mDelegateFactory.getEphemeralTabCoordinator(), mBackPressManager,
() -> mTabController);
() -> mTabController, this::isPageInsightsHubEnabled);
// clang-format on
return mBaseCustomTabRootUiCoordinator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewStub;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -53,6 +54,7 @@
import org.chromium.chrome.browser.incognito.reauth.IncognitoReauthCoordinatorFactory;
import org.chromium.chrome.browser.incognito.reauth.IncognitoReauthManager;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.page_insights.PageInsightsCoordinator;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.reengagement.ReengagementNotificationController;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
Expand All @@ -67,6 +69,8 @@
import org.chromium.chrome.browser.ui.appmenu.AppMenuDelegate;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.chrome.browser.ui.system.StatusBarColorController.StatusBarColorProvider;
import org.chromium.chrome.browser.util.ChromeAccessibilityUtil;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetControllerFactory;
import org.chromium.components.browser_ui.widget.MenuOrKeyboardActionController;
import org.chromium.components.feature_engagement.Tracker;
import org.chromium.ui.base.ActivityWindowAndroid;
Expand All @@ -84,6 +88,7 @@ public class BaseCustomTabRootUiCoordinator extends RootUiCoordinator {
private final Supplier<CustomTabActivityNavigationController> mNavigationController;
private final Supplier<BrowserServicesIntentDataProvider> mIntentDataProvider;
private final Supplier<CustomTabActivityTabController> mTabController;
private final BooleanSupplier mPageInsightsHubEnabledSupplier;

private CustomTabHeightStrategy mCustomTabHeightStrategy;

Expand All @@ -93,6 +98,8 @@ public class BaseCustomTabRootUiCoordinator extends RootUiCoordinator {

private @Nullable DesktopSiteSettingsIPHController mDesktopSiteSettingsIPHController;

private @Nullable PageInsightsCoordinator mPageInsightsCoordinator;

/**
* Construct a new BaseCustomTabRootUiCoordinator.
* @param activity The activity whose UI the coordinator is responsible for.
Expand Down Expand Up @@ -128,6 +135,7 @@ public class BaseCustomTabRootUiCoordinator extends RootUiCoordinator {
* @param customTabNavigationController Controls the custom tab navigation.
* @param intentDataProvider Contains intent information used to start the Activity.
* @param tabController Activity tab controller.
* @param pageInsightsHubEnabledSupplier Supplies whether PageInsights Hub is enabled.
*/
public BaseCustomTabRootUiCoordinator(@NonNull AppCompatActivity activity,
@NonNull ObservableSupplier<ShareDelegate> shareDelegateSupplier,
Expand Down Expand Up @@ -162,7 +170,8 @@ public BaseCustomTabRootUiCoordinator(@NonNull AppCompatActivity activity,
@NonNull Supplier<BrowserServicesIntentDataProvider> intentDataProvider,
@NonNull Supplier<EphemeralTabCoordinator> ephemeralTabCoordinatorSupplier,
@NonNull BackPressManager backPressManager,
@NonNull Supplier<CustomTabActivityTabController> tabController) {
@NonNull Supplier<CustomTabActivityTabController> tabController,
@NonNull BooleanSupplier pageInsightsHubEnabledSupplier) {
// clang-format off
super(activity, null, shareDelegateSupplier, tabProvider,
profileSupplier, bookmarkModelSupplier, tabBookmarkerSupplier,
Expand Down Expand Up @@ -197,6 +206,10 @@ public BaseCustomTabRootUiCoordinator(@NonNull AppCompatActivity activity,
activity, packageName, appName, new ChromePureJavaExceptionReporter());
}
mTabController = tabController;

// This is passed as a supplier as the value takes effect after the native is initialized,
// which has not happened yet.
mPageInsightsHubEnabledSupplier = pageInsightsHubEnabledSupplier;
}

@Override
Expand Down Expand Up @@ -242,6 +255,9 @@ public void didFirstVisuallyNonEmptyPaint(Tab tab) {
@Override
public void onFinishNativeInitialization() {
super.onFinishNativeInitialization();

maybeCreatePageInsightsCoordinator();

if (!ReengagementNotificationController.isEnabled()) return;
new OneShotCallback<>(mProfileSupplier, mCallbackController.makeCancelable(profile -> {
assert profile != null : "Unexpectedly null profile from TabModel.";
Expand All @@ -253,6 +269,30 @@ public void onFinishNativeInitialization() {
}));
}

private void maybeCreatePageInsightsCoordinator() {
assert mPageInsightsCoordinator == null;

if (!mPageInsightsHubEnabledSupplier.getAsBoolean()) return;

ViewStub containerStub = mActivity.findViewById(R.id.page_insights_hub_container_stub);
if (containerStub != null) containerStub.inflate();
var controller = BottomSheetControllerFactory.createFullWidthBottomSheetController(
this::getScrimCoordinator,
(v)
-> mPageInsightsCoordinator.initView(v),
mActivity.getWindow(), mWindowAndroid.getKeyboardDelegate(),
() -> mActivity.findViewById(R.id.page_insights_hub_container));
controller.setAccessibilityUtil(ChromeAccessibilityUtil.get());

mPageInsightsCoordinator = new PageInsightsCoordinator(mActivity, mActivityTabProvider,
controller, mBrowserControlsManager, mBrowserControlsManager);
}

@Nullable
public PageInsightsCoordinator getPageInsightsCoordinator() {
return mPageInsightsCoordinator;
}

@Override
protected IncognitoReauthCoordinatorFactory getIncognitoReauthCoordinatorFactory() {
Intent showRegularOverviewIntent = new Intent(Intent.ACTION_MAIN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public boolean onMenuOrKeyboardAction(int id, boolean fromMenu) {
.show(tab, ChromePageInfoHighlight.noHighlight());
return true;
} else if (id == R.id.page_insights_id) {
// TODO(b/282739536): Open PageInsights Hub.
assert mBaseCustomTabRootUiCoordinator.getPageInsightsCoordinator() != null;
mBaseCustomTabRootUiCoordinator.getPageInsightsCoordinator().launch();
return true;
}
return super.onMenuOrKeyboardAction(id, fromMenu);
Expand Down
72 changes: 72 additions & 0 deletions chrome/browser/ui/android/page_insights/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")

android_library("java") {
sources = [
"java/src/org/chromium/chrome/browser/page_insights/PageInsightsCoordinator.java",
"java/src/org/chromium/chrome/browser/page_insights/PageInsightsMediator.java",
"java/src/org/chromium/chrome/browser/page_insights/PageInsightsSheetContent.java",
]

deps = [
":java_resources",
"//base:base_java",
"//chrome/browser/browser_controls/android:java",
"//chrome/browser/tab:java",
"//components/browser_ui/bottomsheet/android:java",
"//components/browser_ui/bottomsheet/android:manager_java",
"//components/browser_ui/widget/android:java",
"//third_party/androidx:androidx_annotation_annotation_java",
"//ui/android:ui_no_recycler_view_java",
"//url:gurl_java",
]
resources_package = "org.chromium.chrome.browser.page_insights"
}

android_resources("java_resources") {
sources = [
"java/res/drawable/page_insights_icon.xml",
"java/res/layout/page_insights_sheet_toolbar.xml",
]
deps = [
"//chrome/browser/ui/android/strings:ui_strings_grd",
"//components/browser_ui/bottomsheet/android:java_resources",
"//components/browser_ui/widget/android:java_resources",
]
}

android_library("unit_device_javatests") {
testonly = true
resources_package = "org.chromium.chrome.browser.page_insights"

sources = [
"java/src/org/chromium/chrome/browser/page_insights/PageInsightsCoordinatorTest.java",
"java/src/org/chromium/chrome/browser/page_insights/PageInsightsSheetContentTest.java",
]
deps = [
":java",
":java_resources",
"//base:base_java",
"//base:base_java_test_support",
"//chrome/android:chrome_java",
"//chrome/browser/browser_controls/android:java",
"//chrome/browser/flags:java",
"//chrome/browser/tab:java",
"//chrome/test/android:chrome_java_integration_test_support",
"//components/browser_ui/bottomsheet/android:factory_java",
"//components/browser_ui/bottomsheet/android:java",
"//components/browser_ui/bottomsheet/android:manager_java",
"//components/browser_ui/bottomsheet/android/test:java",
"//components/browser_ui/widget/android:java",
"//content/public/test/android:content_java_test_support",
"//third_party/androidx:androidx_test_runner_java",
"//third_party/junit:junit",
"//third_party/mockito:mockito_java",
"//ui/android:ui_java_test_support",
"//ui/android:ui_utils_java",
]
}
11 changes: 11 additions & 0 deletions chrome/browser/ui/android/page_insights/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include_rules = [
"+chrome/browser/browser_controls/android",
"+chrome/browser/tab",
"+chrome/browser/tabmodel",
"+components/browser_ui/bottomsheet/android",
"+components/browser_ui/widget/android",
"+components/embedder_support/android",
"+content/public/android",
"+ui/android",
"+url/android",
]
3 changes: 3 additions & 0 deletions chrome/browser/ui/android/page_insights/DIR_METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
monorail {
component: "UI>Browser>Mobile>CustomTabs"
}
2 changes: 2 additions & 0 deletions chrome/browser/ui/android/page_insights/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jinsukkim@chromium.org
kgrosu@google.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2023 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12.8909 10.99H11.2559V17.065H12.8909V10.99Z"
android:fillColor="#4285F4"/>
<path
android:pathData="M12.0009 9.2299C12.2609 9.2299 12.4759 9.1449 12.6559 8.9749C12.8309 8.8049 12.9209 8.5899 12.9209 8.3399C12.9209 8.0699 12.8309 7.8449 12.6559 7.6649C12.4809 7.4849 12.2609 7.3999 12.0009 7.3999C11.7359 7.3999 11.5159 7.4899 11.3459 7.6649C11.1709 7.8449 11.0859 8.0649 11.0859 8.3349C11.0859 8.5899 11.1759 8.8049 11.3509 8.9749C11.5209 9.1399 11.7409 9.2299 12.0009 9.2299Z"
android:fillColor="#4285F4"/>
<path
android:pathData="M18.3491 10.6749C18.3491 9.22992 17.8441 8.00492 16.8391 6.99992C15.8341 5.99492 14.6041 5.48992 13.1641 5.48992C14.6091 5.48992 15.8341 4.98492 16.8391 3.97992C17.8441 2.97492 18.3491 1.74492 18.3491 0.294922C18.3491 1.74492 18.8541 2.96992 19.8591 3.97992C20.8641 4.98492 22.0941 5.48992 23.5441 5.48992C22.0941 5.48992 20.8691 5.99492 19.8591 6.99992C18.8541 8.00492 18.3491 9.22992 18.3491 10.6749Z"
android:fillColor="#4285F4"/>
<path
android:pathData="M6.0107 5.99007C7.6607 4.35007 9.6557 3.53007 11.9957 3.53007C12.7557 3.53007 13.4807 3.61507 14.1657 3.78507L15.5007 2.43007C14.4007 2.02507 13.2407 1.82007 12.0107 1.82007C10.6007 1.82007 9.2807 2.08507 8.0507 2.62007C6.8157 3.15507 5.7357 3.88007 4.8157 4.79507C4.1957 5.41007 3.6657 6.11007 3.2207 6.87007L4.6707 7.71507C5.0307 7.10507 5.4707 6.52507 6.0107 5.99007Z"
android:fillColor="#EA4335"/>
<path
android:pathData="M21.3703 15.945C21.9053 14.71 22.1703 13.39 22.1703 11.985C22.1703 10.755 21.9653 9.58999 21.5603 8.48999L20.2103 9.83999C20.3753 10.515 20.4603 11.23 20.4603 11.98C20.4603 13.575 20.0753 15.005 19.3203 16.275L20.7703 17.12C20.9853 16.745 21.1953 16.355 21.3703 15.945Z"
android:fillColor="#4285F4"/>
<path
android:pathData="M17.9955 17.9799C16.3505 19.63 14.3555 20.455 12.0105 20.455C9.66055 20.455 7.66055 19.63 6.01055 17.9799C5.45555 17.4249 5.00555 16.83 4.64055 16.2L3.18555 17.03C3.63555 17.82 4.17555 18.5349 4.81555 19.1749C5.74055 20.0999 6.81555 20.825 8.05055 21.36C9.28555 21.89 10.6005 22.16 12.0105 22.16C13.4155 22.16 14.7355 21.8899 15.9755 21.3549C17.2105 20.82 18.2855 20.09 19.2055 19.17C19.8155 18.555 20.3355 17.865 20.7755 17.115L19.3255 16.27C18.9605 16.88 18.5255 17.4499 17.9955 17.9799Z"
android:fillColor="#34A853"/>
<path
android:pathData="M3.53422 11.9951C3.53422 10.4051 3.91922 8.98012 4.66422 7.71512L3.21422 6.87012C2.99922 7.24012 2.79922 7.61512 2.62422 8.02012C2.09422 9.25512 1.82422 10.5751 1.82422 11.9801C1.82422 13.3851 2.08922 14.7101 2.62422 15.9401C2.78922 16.3201 2.97922 16.6801 3.17922 17.0301L4.63422 16.2001C3.90922 14.9501 3.53422 13.5501 3.53422 11.9951Z"
android:fillColor="#FBBC04"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2023 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<!-- A toolbar layout designed for page insight bottom-sheet -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/sheet_tab_toolbar_height"
android:orientation="vertical">

<View
android:layout_width="match_parent"
android:layout_height="4dp" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="62dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:orientation="horizontal">

<ImageView
android:id="@+id/drag_handlebar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:importantForAccessibility="no"
android:src="@drawable/drag_handlebar" />

<LinearLayout
android:id="@+id/buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="12dp"
android:layout_marginBottom="8dp"
android:importantForAccessibility="no"
android:orientation="horizontal" >

<org.chromium.ui.widget.ChromeImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:src="@drawable/page_insights_icon"
android:contentDescription="@string/close"/>
</LinearLayout>

</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="4dp" />
</LinearLayout>

0 comments on commit bbb62dc

Please sign in to comment.