diff --git a/android/java/org/chromium/chrome/browser/app/BraveActivity.java b/android/java/org/chromium/chrome/browser/app/BraveActivity.java index a5a964733193..7f21c406a244 100644 --- a/android/java/org/chromium/chrome/browser/app/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/app/BraveActivity.java @@ -316,6 +316,7 @@ public abstract class BraveActivity extends ChromeActivity private MiscAndroidMetricsConnectionErrorHandler mMiscAndroidMetricsConnectionErrorHandler; private AppUpdateManager mAppUpdateManager; private boolean mWalletBadgeVisible; + private boolean mSpoofCustomTab; /** Serves as a general exception for failed attempts to get BraveActivity. */ public static class BraveActivityNotFoundException extends Exception { @@ -2467,4 +2468,21 @@ public MultiInstanceManager getMultiInstanceManager() { BraveReflectionUtil.getField( ChromeTabbedActivity.class, "mMultiInstanceManager", this); } + + /* + * Whether we want to pretend to be a custom tab. May be usefull to avoid certain patches, + * when we want to have the same behaviour as in custom tabs. + */ + public void spoofCustomTab(boolean spoof) { + mSpoofCustomTab = spoof; + } + + @Override + public boolean isCustomTab() { + if (mSpoofCustomTab) { + return true; + } + + return super.isCustomTab(); + } } diff --git a/android/java/org/chromium/chrome/browser/dom_distiller/BraveReaderModeManager.java b/android/java/org/chromium/chrome/browser/dom_distiller/BraveReaderModeManager.java index 4744f3b70fec..8a51cf987e10 100644 --- a/android/java/org/chromium/chrome/browser/dom_distiller/BraveReaderModeManager.java +++ b/android/java/org/chromium/chrome/browser/dom_distiller/BraveReaderModeManager.java @@ -5,12 +5,16 @@ package org.chromium.chrome.browser.dom_distiller; +import android.app.Activity; + import androidx.annotation.VisibleForTesting; import org.chromium.base.supplier.Supplier; +import org.chromium.chrome.browser.app.BraveActivity; import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.tab.Tab; +import org.chromium.chrome.browser.tab.TabUtils; import org.chromium.components.messages.MessageDispatcher; import org.chromium.components.user_prefs.UserPrefs; @@ -31,6 +35,24 @@ void tryShowingPrompt() { if (profile == null || !UserPrefs.get(profile).getBoolean(Pref.READER_FOR_ACCESSIBILITY)) return; + // If it is regular tab, we pretend to be a custom tab to show the prompt if applicable. + spoofCustomTab(!mTab.isCustomTab() && !mTab.isIncognito()); + super.tryShowingPrompt(); + + // There is no need to spoof custom tab after showing the prompt. + spoofCustomTab(false); + } + + /* + * Whether we want to pretend to be a custom tab. Used here to avoid patch in the middle of `ReaderModeManager#tryShowingPrompt`. + */ + void spoofCustomTab(boolean spoof) { + Activity activity = TabUtils.getActivity(mTab); + BraveActivity braveActivity = + activity instanceof BraveActivity ? (BraveActivity) activity : null; + if (braveActivity != null) { + braveActivity.spoofCustomTab(spoof); + } } }