Commit 22599773 authored by Robbie McElrath's avatar Robbie McElrath Committed by Commit Bot

[WebLayer] Move SUBRESOURCE_FILTER feature to //components/subresource_filter

This CL moves the Java-side definition of the
kSafeBrowsingSubresourceFilter Feature from ChromeFeatureList to a new
SubresourceFilterFeatureList class that lives in
//components/subresource_filter/java. This will allow non-Chrome
embedders to query the status of the Feature from Java.

Bug: 1058597
Change-Id: If9c618216110c1e005e645a0351ee79577211844
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095860
Commit-Queue: Robbie McElrath <rmcelrath@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749402}
parent ab129e5a
...@@ -331,6 +331,7 @@ android_library("chrome_java") { ...@@ -331,6 +331,7 @@ android_library("chrome_java") {
"//components/signin/core/browser/android:java", "//components/signin/core/browser/android:java",
"//components/signin/public/android:java", "//components/signin/public/android:java",
"//components/spellcheck/browser/android:java", "//components/spellcheck/browser/android:java",
"//components/subresource_filter/android:java",
"//components/sync/android:sync_java", "//components/sync/android:sync_java",
"//components/sync/protocol:protocol_java", "//components/sync/protocol:protocol_java",
"//components/url_formatter/android:url_formatter_java", "//components/url_formatter/android:url_formatter_java",
......
...@@ -24,6 +24,7 @@ include_rules = [ ...@@ -24,6 +24,7 @@ include_rules = [
"+components/signin/core/browser/android", "+components/signin/core/browser/android",
"+components/signin/public/android", "+components/signin/public/android",
"+components/spellcheck/browser", "+components/spellcheck/browser",
"+components/subresource_filter/android",
"+components/viz/common/java", "+components/viz/common/java",
"+jni", "+jni",
"+media/base/android/java", "+media/base/android/java",
......
...@@ -28,6 +28,7 @@ import org.chromium.base.ApiCompatibilityUtils; ...@@ -28,6 +28,7 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.components.content_settings.ContentSettingsType; import org.chromium.components.content_settings.ContentSettingsType;
import org.chromium.components.subresource_filter.SubresourceFilterFeatureList;
import org.chromium.ui.text.SpanApplier; import org.chromium.ui.text.SpanApplier;
import org.chromium.ui.text.SpanApplier.SpanInfo; import org.chromium.ui.text.SpanApplier.SpanInfo;
...@@ -274,7 +275,8 @@ public class SiteSettingsCategory { ...@@ -274,7 +275,8 @@ public class SiteSettingsCategory {
* Returns whether the Ads category is enabled via an experiment flag. * Returns whether the Ads category is enabled via an experiment flag.
*/ */
public static boolean adsCategoryEnabled() { public static boolean adsCategoryEnabled() {
return ChromeFeatureList.isEnabled(ChromeFeatureList.SUBRESOURCE_FILTER); return SubresourceFilterFeatureList.isEnabled(
SubresourceFilterFeatureList.SUBRESOURCE_FILTER);
} }
/** /**
......
...@@ -3014,6 +3014,7 @@ jumbo_static_library("browser") { ...@@ -3014,6 +3014,7 @@ jumbo_static_library("browser") {
"//components/security_state/content/android", "//components/security_state/content/android",
"//components/send_tab_to_self", "//components/send_tab_to_self",
"//components/signin/internal/identity_manager", # cf android/signin/DEPS "//components/signin/internal/identity_manager", # cf android/signin/DEPS
"//components/subresource_filter/android",
"//components/viz/common", "//components/viz/common",
"//media/mojo/clients", "//media/mojo/clients",
"//rlz:rlz_utils", "//rlz:rlz_utils",
......
...@@ -389,7 +389,6 @@ public abstract class ChromeFeatureList { ...@@ -389,7 +389,6 @@ public abstract class ChromeFeatureList {
public static final String START_SURFACE_ANDROID = "StartSurfaceAndroid"; public static final String START_SURFACE_ANDROID = "StartSurfaceAndroid";
public static final String STRICT_HAS_ENROLLED_AUTOFILL_INSTRUMENT = public static final String STRICT_HAS_ENROLLED_AUTOFILL_INSTRUMENT =
"StrictHasEnrolledAutofillInstrument"; "StrictHasEnrolledAutofillInstrument";
public static final String SUBRESOURCE_FILTER = "SubresourceFilter";
public static final String SWAP_PIXEL_FORMAT_TO_FIX_CONVERT_FROM_TRANSLUCENT = public static final String SWAP_PIXEL_FORMAT_TO_FIX_CONVERT_FROM_TRANSLUCENT =
"SwapPixelFormatToFixConvertFromTranslucent"; "SwapPixelFormatToFixConvertFromTranslucent";
public static final String SYNC_USE_SESSIONS_UNREGISTER_DELAY = public static final String SYNC_USE_SESSIONS_UNREGISTER_DELAY =
......
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/rules.gni")
generate_jni("subresource_filter_jni_headers") {
sources = [ "java/src/org/chromium/components/subresource_filter/SubresourceFilterFeatureList.java" ]
}
android_library("java") {
sources = [ "java/src/org/chromium/components/subresource_filter/SubresourceFilterFeatureList.java" ]
deps = [
":subresource_filter_jni_headers",
"//base:base_java",
"//base:jni_java",
]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
}
source_set("android") {
sources = [ "subresource_filter_feature_list.cc" ]
deps = [
":subresource_filter_jni_headers",
"//base",
"//components/subresource_filter/core/browser",
]
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.subresource_filter;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryLoader;
/**
* Provides an API for querying the status of subresource_filter component Features.
*/
// TODO(crbug.com/1060097): Remove/update this once a generalized FeatureList exists.
@JNINamespace("subresource_filter")
@MainDex
public class SubresourceFilterFeatureList {
public static final String SUBRESOURCE_FILTER = "SubresourceFilter";
private SubresourceFilterFeatureList() {}
/**
* Returns whether the specified feature is enabled or not.
*
* Note: Features queried through this API must be added to the array
* |kFeaturesExposedToJava| in
* //components/subresource_filter/core/browser/subresource_filter_feature_list.cc.
*
* @param featureName The name of the feature to query.
* @return Whether the feature is enabled or not.
*/
public static boolean isEnabled(String featureName) {
assert isNativeInitialized();
return SubresourceFilterFeatureListJni.get().isEnabled(featureName);
}
/**
* @return Whether the native FeatureList is initialized or not.
*/
private static boolean isNativeInitialized() {
if (!LibraryLoader.getInstance().isInitialized()) return false;
// Even if the native library is loaded, the C++ FeatureList might not be initialized yet.
// In that case, accessing it will not immediately fail, but instead cause a crash later
// when it is initialized. Return whether the native FeatureList has been initialized,
// so the return value can be tested, or asserted for a more actionable stack trace
// on failure.
//
// The FeatureList is however guaranteed to be initialized by the time
// AsyncInitializationActivity#finishNativeInitialization is called.
return SubresourceFilterFeatureListJni.get().isInitialized();
}
@NativeMethods
interface Natives {
boolean isInitialized();
boolean isEnabled(String featureName);
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/android/jni_string.h"
#include "base/feature_list.h"
#include "base/stl_util.h"
#include "components/subresource_filter/android/subresource_filter_jni_headers/SubresourceFilterFeatureList_jni.h"
#include "components/subresource_filter/core/browser/subresource_filter_features.h"
using base::android::ConvertJavaStringToUTF8;
using base::android::JavaParamRef;
namespace subresource_filter {
namespace {
// Array of features exposed through the Java ContentFeatureList API. Entries in
// this array may either refer to features defined in the header of this file or
// in other locations in the code base (e.g. content_features.h).
const base::Feature* kFeaturesExposedToJava[] = {
&kSafeBrowsingSubresourceFilter,
};
// TODO(crbug.com/1060097): Removethis once a generalized FeatureList exists.
const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) {
for (size_t i = 0; i < base::size(kFeaturesExposedToJava); ++i) {
if (kFeaturesExposedToJava[i]->name == feature_name)
return kFeaturesExposedToJava[i];
}
NOTREACHED() << "Queried feature not found in SubresourceFilterFeatureList: "
<< feature_name;
return nullptr;
}
} // namespace
static jboolean JNI_SubresourceFilterFeatureList_IsInitialized(JNIEnv* env) {
return !!base::FeatureList::GetInstance();
}
static jboolean JNI_SubresourceFilterFeatureList_IsEnabled(
JNIEnv* env,
const JavaParamRef<jstring>& jfeature_name) {
const base::Feature* feature =
FindFeatureExposedToJava(ConvertJavaStringToUTF8(env, jfeature_name));
return base::FeatureList::IsEnabled(*feature);
}
} // namespace subresource_filter
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