Skip to content

Commit

Permalink
Default-enable global desktop site setting for premium tablets - part 2
Browse files Browse the repository at this point in the history
Implement a message to notify the user and provide an option to opt-out of the default desktop site global setting update.
Screenshot: https://screenshot.googleplex.com/87MQYyWFEovVVMq.png

On FRE launch of a ChromeTabbedActivity (CTA), the message will be prioritized after the existing first-run prompts (last in this list being the LanguageAsk prompt) and before the blue tooltips. On CCT, the message will be triggered in a deferred startup task.

This can cause a delay until subsequent launches in showing the message in CTA if higher-priority eligible prompts are triggered, and to track if the message needs to be shown, a SharedPreference key will be added when the setting is default-enabled and subsequently removed once the message is shown, since the message is required to be shown at most once.

Bug: 1343916
Change-Id: Ib9ad043ca191361f477cf538d6ae7130136a44a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3812362
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Commit-Queue: Aishwarya Rajesh <aishwaryarj@google.com>
Reviewed-by: Shu Yang <shuyng@google.com>
Cr-Commit-Position: refs/heads/main@{#1035063}
  • Loading branch information
Aishwarya Rajesh authored and Chromium LUCI CQ committed Aug 15, 2022
1 parent ab0f15b commit 0c464ac
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1682,16 +1682,6 @@ private void maybeRemoveWindowBackground() {
mRemoveWindowBackgroundDone = true;
}

/**
* @return The primary display size of the device, in inches.
*/
private double getPrimaryDisplaySizeInInches() {
DisplayAndroid display = DisplayAndroid.getNonMultiDisplay(this);
double xInches = display.getDisplayWidth() / display.getXdpi();
double yInches = display.getDisplayHeight() / display.getYdpi();
return Math.sqrt(Math.pow(xInches, 2) + Math.pow(yInches, 2));
}

@Override
public void finishNativeInitialization() {
mNativeInitialized = true;
Expand All @@ -1718,14 +1708,6 @@ public void finishNativeInitialization() {

super.finishNativeInitialization();

if (RequestDesktopUtils.maybeDefaultEnableGlobalSetting(
getPrimaryDisplaySizeInInches(), Profile.getLastUsedRegularProfile())) {
// TODO(crbug.com/1350274): Remove this explicit load when this bug is addressed.
if (getActivityTab() != null) {
getActivityTab().loadIfNeeded(LoadIfNeededCaller.OTHER);
}
}

mManualFillingComponentSupplier.get().initialize(getWindowAndroid(),
mRootUiCoordinator.getBottomSheetController(),
(ChromeKeyboardVisibilityDelegate) getWindowAndroid().getKeyboardDelegate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeApplicationImpl;
import org.chromium.chrome.browser.DeferredStartupHandler;
import org.chromium.chrome.browser.KeyboardShortcuts;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.app.tabmodel.TabModelOrchestrator;
Expand Down Expand Up @@ -496,6 +497,8 @@ public void initDeferredStartupForActivity() {
if (mWebappActivityCoordinator != null) {
mWebappActivityCoordinator.initDeferredStartupForActivity();
}
DeferredStartupHandler.getInstance().addDeferredTask(
() -> { mBaseCustomTabRootUiCoordinator.onDeferredStartup(); });
super.initDeferredStartupForActivity();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.chromium.chrome.browser.reengagement.ReengagementNotificationController;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.browser.tab.RequestDesktopUtils;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.ui.RootUiCoordinator;
Expand Down Expand Up @@ -314,4 +315,12 @@ public boolean changeBackgroundColorForResizing() {
void handleCloseAnimation(Runnable finishRunnable) {
mCustomTabHeightStrategy.handleCloseAnimation(finishRunnable);
}

/**
* Runs a set of deferred startup tasks.
*/
void onDeferredStartup() {
RequestDesktopUtils.maybeShowDefaultEnableGlobalSettingMessage(
Profile.getLastUsedRegularProfile(), mMessageDispatcher, mActivity);
}
}
5 changes: 4 additions & 1 deletion chrome/android/java/src/org/chromium/chrome/browser/tab/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ specific_include_rules = {
"+chrome/android/java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java",
"+chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java",
],
'RequestDesktopUtils\.java': [
"+chrome/android/java/src/org/chromium/chrome/browser/page_info/SiteSettingsHelper.java"
],
'TabImpl\.java': [
"+chrome/android/features/vr/java/src/org/chromium/chrome/browser/vr/VrModuleProvider.java",
"+chrome/android/java/src/org/chromium/chrome/browser/app/ChromeActivity.java",
Expand Down Expand Up @@ -110,5 +113,5 @@ specific_include_rules = {
],
'TabWebContentsObserver\.java': [
"+chrome/android/java/src/org/chromium/chrome/browser/display_cutout/DisplayCutoutTabHelper.java",
]
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// found in the LICENSE file.
package org.chromium.chrome.browser.tab;

import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;

import androidx.annotation.IntDef;
Expand All @@ -11,17 +13,25 @@
import org.chromium.base.SysUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.page_info.SiteSettingsHelper;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.browser_ui.site_settings.SingleCategorySettings;
import org.chromium.components.browser_ui.site_settings.SiteSettingsCategory;
import org.chromium.components.browser_ui.site_settings.WebsitePreferenceBridge;
import org.chromium.components.content_settings.ContentSettingValues;
import org.chromium.components.content_settings.ContentSettingsType;
import org.chromium.components.embedder_support.util.UrlUtilities;
import org.chromium.components.messages.MessageBannerProperties;
import org.chromium.components.messages.MessageDispatcher;
import org.chromium.components.messages.MessageIdentifier;
import org.chromium.components.messages.PrimaryActionClickBehavior;
import org.chromium.components.ukm.UkmRecorder;
import org.chromium.content_public.browser.BrowserContextHandle;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.url.GURL;

import java.lang.annotation.Retention;
Expand All @@ -39,6 +49,8 @@ public class RequestDesktopUtils {
static final double DEFAULT_GLOBAL_SETTING_DEFAULT_ON_DISPLAY_SIZE_THRESHOLD_INCHES = 12.0;
static final String PARAM_GLOBAL_SETTING_DEFAULT_ON_ON_LOW_END_DEVICES =
"default_on_on_low_end_devices";
static final String PARAM_SHOW_MESSAGE_ON_GLOBAL_SETTING_DEFAULT_ON =
"show_message_on_default_on";

// Note: these values must match the UserAgentRequestType enum in enums.xml.
@IntDef({UserAgentRequestType.REQUEST_DESKTOP, UserAgentRequestType.REQUEST_MOBILE})
Expand Down Expand Up @@ -186,6 +198,73 @@ public static boolean maybeDefaultEnableGlobalSetting(
profile, ContentSettingsType.REQUEST_DESKTOP_SITE, true);
SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.DEFAULT_ENABLED_DESKTOP_SITE_GLOBAL_SETTING, true);
// This key will be added only once, since this method will be invoked only once on a
// device. Once the corresponding message is shown, the key will be removed since the
// message will also be shown at most once.
SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.DEFAULT_ENABLED_DESKTOP_SITE_GLOBAL_SETTING_SHOW_MESSAGE,
true);
return true;
}

/**
* Creates and shows a message to notify the user of a default update to the desktop site global
* setting.
* @param profile The current {@link Profile}.
* @param messageDispatcher The {@link MessageDispatcher} to enqueue the message.
* @param context The current context.
* @return Whether the message was shown.
*/
public static boolean maybeShowDefaultEnableGlobalSettingMessage(
Profile profile, MessageDispatcher messageDispatcher, Context context) {
if (messageDispatcher == null) return false;

// Present the message only if the global setting has been default-enabled.
if (!SharedPreferencesManager.getInstance().contains(
ChromePreferenceKeys
.DEFAULT_ENABLED_DESKTOP_SITE_GLOBAL_SETTING_SHOW_MESSAGE)) {
return false;
}

// Since there might be a delay in triggering this message after the desktop site global
// setting is default-enabled, it could be possible that the user subsequently disabled the
// setting. Present the message only if the setting is enabled.
if (!WebsitePreferenceBridge.isCategoryEnabled(
profile, ContentSettingsType.REQUEST_DESKTOP_SITE)) {
SharedPreferencesManager.getInstance().removeKey(
ChromePreferenceKeys.DEFAULT_ENABLED_DESKTOP_SITE_GLOBAL_SETTING_SHOW_MESSAGE);
return false;
}

// Do not show the message if disabled through Finch.
if (!ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean(
ChromeFeatureList.REQUEST_DESKTOP_SITE_DEFAULTS,
PARAM_SHOW_MESSAGE_ON_GLOBAL_SETTING_DEFAULT_ON, true)) {
return false;
}

Resources resources = context.getResources();
PropertyModel message =
new PropertyModel.Builder(MessageBannerProperties.ALL_KEYS)
.with(MessageBannerProperties.MESSAGE_IDENTIFIER,
MessageIdentifier.DESKTOP_SITE_GLOBAL_DEFAULT_OPT_OUT)
.with(MessageBannerProperties.TITLE,
resources.getString(R.string.rds_global_default_on_message_title))
.with(MessageBannerProperties.ICON_RESOURCE_ID,
R.drawable.ic_desktop_windows)
.with(MessageBannerProperties.PRIMARY_BUTTON_TEXT,
resources.getString(R.string.rds_global_default_on_message_button))
.with(MessageBannerProperties.ON_PRIMARY_ACTION,
() -> {
SiteSettingsHelper.showCategorySettings(context,
SiteSettingsCategory.Type.REQUEST_DESKTOP_SITE);
return PrimaryActionClickBehavior.DISMISS_IMMEDIATELY;
})
.build();

messageDispatcher.enqueueWindowScopedMessage(message, false);
SharedPreferencesManager.getInstance().removeKey(
ChromePreferenceKeys.DEFAULT_ENABLED_DESKTOP_SITE_GLOBAL_SETTING_SHOW_MESSAGE);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ public class TabUtils {
*/
@IntDef({LoadIfNeededCaller.SET_TAB, LoadIfNeededCaller.ON_ACTIVITY_SHOWN,
LoadIfNeededCaller.ON_ACTIVITY_SHOWN_THEN_SHOW, LoadIfNeededCaller.REQUEST_TO_SHOW_TAB,
LoadIfNeededCaller.REQUEST_TO_SHOW_TAB_THEN_SHOW, LoadIfNeededCaller.OTHER})
LoadIfNeededCaller.REQUEST_TO_SHOW_TAB_THEN_SHOW,
LoadIfNeededCaller.ON_FINISH_NATIVE_INITIALIZATION, LoadIfNeededCaller.OTHER})
@Retention(RetentionPolicy.SOURCE)
public @interface LoadIfNeededCaller {
int SET_TAB = 0;
int ON_ACTIVITY_SHOWN = 1;
int ON_ACTIVITY_SHOWN_THEN_SHOW = 2;
int REQUEST_TO_SHOW_TAB = 3;
int REQUEST_TO_SHOW_TAB_THEN_SHOW = 4;
int OTHER = 5;
int ON_FINISH_NATIVE_INITIALIZATION = 5;
int OTHER = 6;
}

// Do not instantiate this class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.chromium.chrome.browser.status_indicator.StatusIndicatorCoordinator;
import org.chromium.chrome.browser.subscriptions.CommerceSubscriptionsService;
import org.chromium.chrome.browser.subscriptions.CommerceSubscriptionsServiceFactory;
import org.chromium.chrome.browser.tab.RequestDesktopUtils;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabAssociatedApp;
import org.chromium.chrome.browser.tab.TabLaunchType;
Expand Down Expand Up @@ -656,6 +657,11 @@ private void initializeIPH(boolean intentWithEffect) {
didTriggerPromo = triggerPromo(intentWithEffect);
}

if (!didTriggerPromo) {
didTriggerPromo = RequestDesktopUtils.maybeShowDefaultEnableGlobalSettingMessage(
Profile.getLastUsedRegularProfile(), mMessageDispatcher, mActivity);
}

if (!didTriggerPromo) {
mToolbarButtonInProductHelpController.showColdStartIPH();
mReadLaterIPHController.showColdStartIPH();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@
import org.chromium.chrome.browser.subscriptions.CommerceSubscriptionsServiceFactory;
import org.chromium.chrome.browser.tab.AccessibilityVisibilityHandler;
import org.chromium.chrome.browser.tab.AutofillSessionLifetimeController;
import org.chromium.chrome.browser.tab.RequestDesktopUtils;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tab.TabUtils.LoadIfNeededCaller;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tasks.ReturnToChromeUtil;
Expand Down Expand Up @@ -160,6 +162,7 @@
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.IntentRequestTracker;
import org.chromium.ui.base.PageTransition;
import org.chromium.ui.display.DisplayAndroid;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogManager.ModalDialogManagerObserver;
import org.chromium.ui.modelutil.PropertyModel;
Expand Down Expand Up @@ -789,6 +792,15 @@ public void onHideMessageContainer() {}
}

new OneShotCallback<>(mProfileSupplier, this::initHistoryClustersCoordinator);

if (RequestDesktopUtils.maybeDefaultEnableGlobalSetting(
getPrimaryDisplaySizeInInches(), Profile.getLastUsedRegularProfile())) {
// TODO(crbug.com/1350274): Remove this explicit load when this bug is addressed.
if (mActivityTabProvider != null && mActivityTabProvider.get() != null) {
mActivityTabProvider.get().loadIfNeeded(
LoadIfNeededCaller.ON_FINISH_NATIVE_INITIALIZATION);
}
}
}

private void initIncognitoReauthController() {
Expand All @@ -803,6 +815,16 @@ private void initIncognitoReauthController() {
mIncognitoReauthControllerOneshotSupplier.set(incognitoReauthController);
}

/**
* @return The primary display size of the device, in inches.
*/
private double getPrimaryDisplaySizeInInches() {
DisplayAndroid display = DisplayAndroid.getNonMultiDisplay(mActivity);
double xInches = display.getDisplayWidth() / display.getXdpi();
double yInches = display.getDisplayHeight() / display.getYdpi();
return Math.sqrt(Math.pow(xInches, 2) + Math.pow(yInches, 2));
}

/**
* This method is meant to be overridden for sub-classes which needs to provide an
* incognito re-auth view.
Expand Down

0 comments on commit 0c464ac

Please sign in to comment.