Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Moved back simplified view prompt for regular tabs (uplift to 1.73.x) #26403

Open
wants to merge 2 commits into
base: 1.73.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
}
Loading