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

Enables Safe Browsing flag on Android by default #16540

Merged
merged 1 commit into from
Jan 6, 2023
Merged
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
30 changes: 20 additions & 10 deletions android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
import org.chromium.components.safe_browsing.SafeBrowsingApiBridge;
import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.browser.WebContents;
import org.chromium.mojo.bindings.ConnectionErrorHandler;
import org.chromium.mojo.system.MojoException;
Expand Down Expand Up @@ -270,6 +271,7 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
private boolean isProcessingPendingDappsTxRequest;
private int mLastTabId;
private boolean mNativeInitialized;
private boolean mSafeBrowsingFlagEnabled;
private NewTabPageManager mNewTabPageManager;
private NotificationPermissionController mNotificationPermissionController;
private BraveNewsController mBraveNewsController;
Expand Down Expand Up @@ -307,15 +309,13 @@ public void onResumeWithNative() {
}
updateWalletBadgeVisibility();
}
boolean safeBrowsingFlagEnabled =

// We can store a state of that flag as a browser has to be restarted
// when the flag state is changed in any case
mSafeBrowsingFlagEnabled =
ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_ANDROID_SAFE_BROWSING);
boolean safeBrowsingPrefEnabled =
SafeBrowsingBridge.getSafeBrowsingState() != SafeBrowsingState.NO_SAFE_BROWSING;
if (safeBrowsingFlagEnabled && safeBrowsingPrefEnabled) {
executeInitSafeBrowsing(0);
} else if (!safeBrowsingFlagEnabled && safeBrowsingPrefEnabled) {
SafeBrowsingBridge.setSafeBrowsingState(SafeBrowsingState.NO_SAFE_BROWSING);
}

executeInitSafeBrowsing(0);
}

@Override
Expand Down Expand Up @@ -830,6 +830,11 @@ public void turnSafeBrowsingOff() {
SafeBrowsingBridge.setSafeBrowsingState(SafeBrowsingState.NO_SAFE_BROWSING);
}

@Override
public boolean isSafeBrowsingEnabled() {
return mSafeBrowsingFlagEnabled;
}

@Override
public Activity getActivity() {
return this;
Expand Down Expand Up @@ -1995,8 +2000,13 @@ public void addOrEditBookmark(final Tab tabToBookmark) {
// BraveSafeBrowsingApiHandler.SAFE_BROWSING_INIT_INTERVAL_MS,
// as upstream does, to keep the GmsCore process alive.
private void executeInitSafeBrowsing(long delay) {
PostTask.postDelayedTask(TaskTraits.USER_VISIBLE_MAY_BLOCK, () -> {
BraveSafeBrowsingApiHandler.getInstance().initSafeBrowsing();
// SafeBrowsingBridge.getSafeBrowsingState() has to be executed on a main thread
PostTask.postDelayedTask(UiThreadTaskTraits.DEFAULT, () -> {
if (SafeBrowsingBridge.getSafeBrowsingState() != SafeBrowsingState.NO_SAFE_BROWSING) {
// initSafeBrowsing could be executed on a background thread
PostTask.postTask(TaskTraits.USER_VISIBLE_MAY_BLOCK,
() -> { BraveSafeBrowsingApiHandler.getInstance().initSafeBrowsing(); });
}
executeInitSafeBrowsing(BraveSafeBrowsingApiHandler.SAFE_BROWSING_INIT_INTERVAL_MS);
}, delay);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public void testParentItems() {
checkPreferenceExists(PREF_CLEAR_BROWSING_DATA);
checkPreferenceExists(PREF_DO_NOT_TRACK);
checkPreferenceExists(PREF_HTTPS_FIRST_MODE);
// TODO : Need to add back the test once we have fix ready for safe browsing
// checkPreferenceExists(PREF_SAFE_BROWSING);
checkPreferenceExists(PREF_SAFE_BROWSING);
checkPreferenceExists(PREF_SECURE_DNS);
checkPreferenceExists(PREF_INCOGNITO_LOCK);
checkPreferenceExists(PREF_PHONE_AS_A_SECURITY_KEY);
Expand Down
2 changes: 1 addition & 1 deletion browser/android/safe_browsing/features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace features {

BASE_FEATURE(kBraveAndroidSafeBrowsing,
"BraveAndroidSafeBrowsing",
base::FEATURE_DISABLED_BY_DEFAULT);
base::FEATURE_ENABLED_BY_DEFAULT);

} // namespace features
} // namespace safe_browsing
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class BraveSafeBrowsingApiHandler implements SafeBrowsingApiHandler {

public interface BraveSafeBrowsingApiHandlerDelegate {
default void turnSafeBrowsingOff() {}
default boolean isSafeBrowsingEnabled() {
return true;
}
Activity getActivity();
}

Expand Down Expand Up @@ -72,7 +75,10 @@ public boolean init(Observer observer) {

@Override
public void startUriLookup(final long callbackId, String uri, int[] threatsOfInterest) {
if (mBraveSafeBrowsingApiHandlerDelegate == null) {
if (mBraveSafeBrowsingApiHandlerDelegate == null
|| !mBraveSafeBrowsingApiHandlerDelegate.isSafeBrowsingEnabled()) {
mObserver.onUrlCheckDone(
callbackId, SafeBrowsingResult.TIMEOUT, "{}", DEFAULT_CHECK_DELTA);
return;
}
mTriesCount++;
Expand Down