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

Redone SafeBrowsing by using SafeBrowsingApiHandler and SafetyNetClient #25842

Merged
merged 1 commit into from
Oct 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

import org.chromium.chrome.browser.base.SplitCompatApplication;
import org.chromium.chrome.browser.vpn.utils.BraveVpnProfileUtils;

// TODO(alexeybarabash): needs to be redone for cr130
// import org.chromium.components.safe_browsing.BraveSafeBrowsingApiHandler;
import org.chromium.components.safe_browsing.BraveSafeBrowsingApiHandler;
import org.chromium.components.safe_browsing.SafeBrowsingApiBridge;

public class BraveApplicationImplBase extends SplitCompatApplication.Impl {
@Override
Expand All @@ -27,9 +26,8 @@ public void alwaysOnTriggered() {
}
});
// Set a handler for SafeBrowsing. It has to be done only once for a process lifetime.
// TODO(alexeybarabash): needs to be redone for cr130
// SafeBrowsingApiBridge.setSafetyNetApiHandler(
// BraveSafeBrowsingApiHandler.getInstance());
SafeBrowsingApiBridge.setSafeBrowsingApiHandler(
BraveSafeBrowsingApiHandler.getInstance());
}
}
}
93 changes: 43 additions & 50 deletions android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
import org.chromium.chrome.browser.rate.BraveRateDialogFragment;
import org.chromium.chrome.browser.rate.RateUtils;
import org.chromium.chrome.browser.rewards.adaptive_captcha.AdaptiveCaptchaHelper;
import org.chromium.chrome.browser.safe_browsing.SafeBrowsingBridge;
import org.chromium.chrome.browser.safe_browsing.SafeBrowsingState;
import org.chromium.chrome.browser.set_default_browser.BraveSetDefaultBrowserUtils;
import org.chromium.chrome.browser.set_default_browser.OnBraveSetDefaultBrowserListener;
import org.chromium.chrome.browser.settings.BraveNewsPreferencesV2;
Expand Down Expand Up @@ -203,8 +205,7 @@
import org.chromium.components.browser_ui.settings.SettingsLauncher;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.embedder_support.util.UrlUtilities;
// TODO(alexeybarabash): needs to be redone for cr130
// import org.chromium.components.safe_browsing.BraveSafeBrowsingApiHandler;
import org.chromium.components.safe_browsing.BraveSafeBrowsingApiHandler;
import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.WebContents;
Expand All @@ -230,8 +231,7 @@ public abstract class BraveActivity extends ChromeActivity
OnBraveSetDefaultBrowserListener,
ConnectionErrorHandler,
PrefObserver,
// TODO(alexeybarabash): needs to be redone for cr130
// BraveSafeBrowsingApiHandler.BraveSafeBrowsingApiHandlerDelegate,
BraveSafeBrowsingApiHandler.BraveSafeBrowsingApiHandlerDelegate,
BraveNewsConnectionErrorHandler.BraveNewsConnectionErrorHandlerDelegate,
MiscAndroidMetricsConnectionErrorHandler
.MiscAndroidMetricsConnectionErrorHandlerDelegate {
Expand Down Expand Up @@ -345,17 +345,15 @@ public void onResumeWithNative() {
}
}

// TODO(alexeybarabash): needs to be redone for cr130
// BraveSafeBrowsingApiHandler.getInstance().setDelegate(
// BraveActivityJni.get().getSafeBrowsingApiKey(), this);
BraveSafeBrowsingApiHandler.getInstance()
.setDelegate(BraveActivityJni.get().getSafeBrowsingApiKey(), this);

// 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);

// TODO(alexeybarabash): needs to be redone for cr130
// executeInitSafeBrowsing(0);
executeInitSafeBrowsing(0);

if (ENABLE_IN_APP_UPDATE) {
if (mAppUpdateManager == null) {
Expand Down Expand Up @@ -479,8 +477,8 @@ protected void onDestroyInternal() {
NotificationPermissionController.detach(mNotificationPermissionController);
mNotificationPermissionController = null;
}
// TODO(alexeybarabash): needs to be redone for cr130
// BraveSafeBrowsingApiHandler.getInstance().shutdownSafeBrowsing();

BraveSafeBrowsingApiHandler.getInstance().shutdownSafeBrowsing();
if (ENABLE_IN_APP_UPDATE && mAppUpdateManager != null) {
mAppUpdateManager.unregisterListener(mInstallStateUpdatedListener);
}
Expand Down Expand Up @@ -973,24 +971,21 @@ public void onPreferenceChange() {
maybeSolveAdaptiveCaptcha();
}

// TODO(alexeybarabash): needs to be redone for cr130
// @Override
// public void turnSafeBrowsingOff() {
// SafeBrowsingBridge safeBrowsingBridge = new SafeBrowsingBridge(getCurrentProfile());
// safeBrowsingBridge.setSafeBrowsingState(SafeBrowsingState.NO_SAFE_BROWSING);
// }
@Override
public void turnSafeBrowsingOff() {
SafeBrowsingBridge safeBrowsingBridge = new SafeBrowsingBridge(getCurrentProfile());
safeBrowsingBridge.setSafeBrowsingState(SafeBrowsingState.NO_SAFE_BROWSING);
}

// TODO(alexeybarabash): needs to be redone for cr130
// @Override
// public boolean isSafeBrowsingEnabled() {
// return mSafeBrowsingFlagEnabled;
// }
@Override
public boolean isSafeBrowsingEnabled() {
return mSafeBrowsingFlagEnabled;
}

// TODO(alexeybarabash): needs to be redone for cr130
// @Override
// public Activity getActivity() {
// return this;
// }
@Override
public Activity getActivity() {
return this;
}

public void maybeSolveAdaptiveCaptcha() {
String captchaID =
Expand Down Expand Up @@ -2394,29 +2389,27 @@ public void addOrEditBookmark(final Tab tabToBookmark) {
// We call that method with an interval
// BraveSafeBrowsingApiHandler.SAFE_BROWSING_INIT_INTERVAL_MS,
// as upstream does, to keep the GmsCore process alive.

// TODO(alexeybarabash): needs to be redone for cr130
// private void executeInitSafeBrowsing(long delay) {
// // SafeBrowsingBridge.getSafeBrowsingState() has to be executed on a main thread
// PostTask.postDelayedTask(
// TaskTraits.UI_DEFAULT,
// () -> {
// SafeBrowsingBridge safeBrowsingBridge =
// new SafeBrowsingBridge(getCurrentProfile());
// 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);
// }
private void executeInitSafeBrowsing(long delay) {
// SafeBrowsingBridge.getSafeBrowsingState() has to be executed on a main thread
PostTask.postDelayedTask(
TaskTraits.UI_DEFAULT,
() -> {
SafeBrowsingBridge safeBrowsingBridge =
new SafeBrowsingBridge(getCurrentProfile());
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);
}

public void updateBottomSheetPosition(int orientation) {
if (BottomToolbarConfiguration.isBottomToolbarEnabled()) {
Expand Down
4 changes: 1 addition & 3 deletions build/android/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ brave_chrome_java_deps = [
"//brave/components/browser_ui/site_settings/android:java",
"//brave/components/misc_metrics/common:mojom_java",
"//brave/components/playlist/common/mojom:mojom_java",

# TODO(alexeybarabash): needs to be redone for cr130
#"//brave/components/safe_browsing/android:brave_safe_browsing_java",
"//brave/components/safe_browsing/android:brave_safe_browsing_java",
"//brave/components/url_sanitizer/common/mojom:mojom_java",
"//brave/components/variations/android:java",
"//brave/components/version_info/android:java",
Expand Down
8 changes: 5 additions & 3 deletions components/safe_browsing/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ android_library("brave_safe_browsing_java") {
"//components/safe_browsing/android:safe_browsing_java",
"//third_party/android_deps:google_play_services_basement_java",
"//third_party/android_deps:google_play_services_tasks_java",
"//third_party/androidx:androidx_annotation_annotation_java",
]

# TODO(alexeybarabash): needs to be redone for cr130
# https://github.com/brave/brave-browser/issues/41165
sources = [ "java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingApiHandler.java" ]
sources = [
"java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingApiHandler.java",
"java/src/org/chromium/components/safe_browsing/BraveSafeBrowsingUtils.java",
]
}
Loading
Loading