[Android] Fix stale verified publisher checkmark on tab switch (#34449)

The verified publisher checkmark could persist when switching tabs
because brave:// URLs were not treated as internal URLs and
OnPanelPublisherInfo silently dropped null publisher info without
notifying the Java layer.

- Treat brave:// URLs as internal alongside chrome:// so they
  clear the checkmark instead of querying getPublisherInfo.
- Notify Java with an empty publisher ID when OnPanelPublisherInfo
  receives null info, so the UI clears stale state.
- Reset the checkmark immediately in didSelectTab as a safety net
  before the async publisher query completes.

Resolves: https://github.com/brave/brave-browser/issues/53332
This commit is contained in:
Serg
2026-03-04 20:59:29 -05:00
committed by GitHub
parent bd45e25ceb
commit e9ae9e7377
3 changed files with 21 additions and 3 deletions
@@ -16,6 +16,7 @@ import org.jni_zero.JNINamespace;
import org.jni_zero.NativeMethods;
import org.json.JSONException;
import org.chromium.base.BraveUrlConstants;
import org.chromium.brave_rewards.mojom.PublisherStatus;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.components.embedder_support.util.UrlConstants;
@@ -120,9 +121,14 @@ public class BraveRewardsNativeWorker {
}
public void onNotifyFrontTabUrlChanged(int tabId, String url) {
boolean chromeUrl = url.startsWith(UrlConstants.CHROME_SCHEME);
// Check both chrome:// and brave:// schemes. brave:// URLs (e.g.
// brave://version) are not recognized by the publisher lookup and
// would leave a stale verified-publisher checkmark from a previous tab.
boolean internalUrl =
url.startsWith(UrlConstants.CHROME_SCHEME)
|| url.startsWith(BraveUrlConstants.BRAVE_SCHEME);
boolean newUrl = (mFrontTabUrl == null || !mFrontTabUrl.equals(url));
if (chromeUrl) {
if (internalUrl) {
// Don't query 'GetPublisherInfo' and post response now.
sHandler.post(
new Runnable() {
@@ -618,6 +618,13 @@ public abstract class BraveToolbarLayoutImpl extends ToolbarLayout
@Override
public void didSelectTab(Tab tab, @TabSelectionType int type, int lastId) {
showYouTubePipIcon(tab);
// Reset verified publisher checkmark immediately on tab
// switch. The correct state will be restored asynchronously
// by onFrontTabPublisherChanged once the publisher query
// for the new tab completes.
mIsPublisherVerified = false;
mPublisherId = "";
updateVerifiedPublisherMark();
if (mBraveRewardsNativeWorker != null && !tab.isIncognito()) {
mBraveRewardsNativeWorker.onNotifyFrontTabUrlChanged(
tab.getId(), tab.getUrl().getSpec());
@@ -256,12 +256,17 @@ void BraveRewardsNativeWorker::OnPanelPublisherInfo(
const brave_rewards::mojom::Result result,
const brave_rewards::mojom::PublisherInfo* info,
uint64_t tabId) {
JNIEnv* env = base::android::AttachCurrentThread();
if (!info) {
// Notify Java with an empty publisher ID so the UI clears any stale
// verified-publisher checkmark from a previously visited tab/site.
Java_BraveRewardsNativeWorker_onPublisherInfo(
env, weak_java_brave_rewards_native_worker_.get(env), tabId,
base::android::ConvertUTF8ToJavaString(env, ""));
return;
}
brave_rewards::mojom::PublisherInfoPtr pi = info->Clone();
map_publishers_info_[tabId] = std::move(pi);
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jstring> res =
base::android::ConvertUTF8ToJavaString(env, info->id);
Java_BraveRewardsNativeWorker_onPublisherInfo(