Commit e8fcf2a4 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: Adjust precedence for Safe Browsing flag

This adjusts the precedence for the
--webview-enable-safebrowsing-support switch, ensuring that application
opt-out always has higher precedence.

The switch value will only be used if the application specifies no
opt-in preference.

Bug: 773798
Test: Manual - apply flag, start application with opt-out & with no opt-in preference
Change-Id: I514179e6b51ec90dc0bfefe13236d66e9bfbc14b
Reviewed-on: https://chromium-review.googlesource.com/726950Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510212}
parent 4e26f5e3
......@@ -112,7 +112,7 @@ public final class AwBrowserProcess {
CombinedPolicyProvider.get().registerProvider(new AwPolicyProvider(appContext));
// Check android settings but only when safebrowsing is enabled.
AwSafeBrowsingConfigHelper.maybeInitSafeBrowsingFromSettings(appContext);
AwSafeBrowsingConfigHelper.maybeEnableSafeBrowsingFromManifest(appContext);
try {
BrowserStartupController.get(LibraryProcessType.PROCESS_WEBVIEW)
......
......@@ -7,11 +7,13 @@ package org.chromium.android_webview;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.support.annotation.Nullable;
import org.chromium.base.Callback;
import org.chromium.base.CommandLine;
import org.chromium.base.Log;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.SuppressFBWarnings;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
......@@ -28,12 +30,14 @@ public class AwSafeBrowsingConfigHelper {
private static Boolean sSafeBrowsingUserOptIn;
@SuppressWarnings("unchecked")
public static void maybeInitSafeBrowsingFromSettings(final Context appContext) {
public static void maybeEnableSafeBrowsingFromManifest(final Context appContext) {
Boolean appOptIn = getAppOptInPreference(appContext);
// If the app specifies something, fallback to the app's preference, otherwise check for the
// existence of the CLI switch.
AwContentsStatics.setSafeBrowsingEnabledByManifest(
CommandLine.getInstance().hasSwitch(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
|| CommandLine.getInstance().hasSwitch(
AwSwitches.WEBVIEW_SAFEBROWSING_BLOCK_ALL_RESOURCES)
|| appHasOptedIn(appContext));
appOptIn == null ? getCommandLineOptIn() : appOptIn);
// If GMS is available, we will figure out if the user has opted-in to Safe Browsing and set
// the correct value for sSafeBrowsingUserOptIn.
final String getUserOptInPreferenceMethodName = "getUserOptInPreference";
......@@ -58,17 +62,31 @@ public class AwSafeBrowsingConfigHelper {
}
}
private static boolean appHasOptedIn(Context appContext) {
private static boolean getCommandLineOptIn() {
CommandLine cli = CommandLine.getInstance();
return cli.hasSwitch(AwSwitches.WEBVIEW_ENABLE_SAFEBROWSING_SUPPORT)
|| cli.hasSwitch(AwSwitches.WEBVIEW_SAFEBROWSING_BLOCK_ALL_RESOURCES);
}
/**
* Checks the application manifest for Safe Browsing opt-in preference.
*
* @param appContext application context.
* @return true if app has opted in, false if opted out, and null if no preference specified.
*/
@Nullable
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
private static Boolean getAppOptInPreference(Context appContext) {
try {
ApplicationInfo info = appContext.getPackageManager().getApplicationInfo(
appContext.getPackageName(), PackageManager.GET_META_DATA);
if (info.metaData == null) {
// null means no such tag was found.
return false;
// No <meta-data> tag was found.
return null;
}
return info.metaData.containsKey(OPT_IN_META_DATA_STR)
? info.metaData.getBoolean(OPT_IN_META_DATA_STR)
: false;
: null;
} catch (PackageManager.NameNotFoundException e) {
// This should never happen.
Log.e(TAG, "App could not find itself by package name!");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment