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

Code inclusion: use inclusive terminology for content capture

No change to logic. This swaps "whitelist" for "allowlist" in
AwContentCaptureTest and components/content_capture.

Fixed: 1101006
Test: run_webview_instrumentation_test_apk -f AwContentCaptureTest.*
Change-Id: Id4c4fef7cf82c6b5ac9ba719c2ba46ca9c1b093f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285398
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Auto-Submit: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarTao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786108}
parent 7d73c8cc
......@@ -53,21 +53,21 @@ public class AwContentCaptureTest {
}
@Override
protected void pullWhitelist() {
String[] whitelist = null;
protected void pullAllowlist() {
String[] allowlist = null;
boolean[] isRegEx = null;
if (mWhiteList != null && mIsRegEx != null) {
mWhiteList.toArray(whitelist);
isRegEx = new boolean[mWhiteList.size()];
if (mAllowlist != null && mIsRegEx != null) {
mAllowlist.toArray(allowlist);
isRegEx = new boolean[mAllowlist.size()];
int i = 0;
for (boolean r : mIsRegEx) {
isRegEx[i++] = r;
}
}
setWhitelist(whitelist, isRegEx);
setAllowlist(allowlist, isRegEx);
}
private ArrayList<String> mWhiteList;
private ArrayList<String> mAllowlist;
private ArrayList<Boolean> mIsRegEx;
}
......
......@@ -35,28 +35,28 @@ ContentCaptureController* ContentCaptureController::Get() {
ContentCaptureController::ContentCaptureController() = default;
ContentCaptureController::~ContentCaptureController() = default;
void ContentCaptureController::SetWhitelist(
void ContentCaptureController::SetAllowlist(
JNIEnv* env,
const JavaParamRef<jobject>& jcaller,
const JavaParamRef<jobjectArray>& jwhitelist,
const JavaParamRef<jobjectArray>& jallowlist,
const JavaParamRef<jbooleanArray>& jisRegEx) {
DCHECK(jwhitelist && jisRegEx || !(jwhitelist || jisRegEx));
has_whitelist_ = false;
if (!jwhitelist)
DCHECK(jallowlist && jisRegEx || !(jallowlist || jisRegEx));
has_allowlist_ = false;
if (!jallowlist)
return;
std::vector<std::string> whitelist;
std::vector<std::string> allowlist;
std::vector<bool> is_regex;
AppendJavaStringArrayToStringVector(env, jwhitelist, &whitelist);
AppendJavaStringArrayToStringVector(env, jallowlist, &allowlist);
JavaBooleanArrayToBoolVector(env, jisRegEx, &is_regex);
if (whitelist.size() != is_regex.size())
if (allowlist.size() != is_regex.size())
return;
has_whitelist_ = true;
has_allowlist_ = true;
size_t index = 0;
for (auto w : whitelist) {
for (auto w : allowlist) {
if (is_regex[index++])
whitelist_regex_.push_back(std::make_unique<re2::RE2>(w));
allowlist_regex_.push_back(std::make_unique<re2::RE2>(w));
else
whitelist_.push_back(w);
allowlist_.push_back(w);
}
}
......@@ -67,26 +67,26 @@ void ContentCaptureController::SetJavaPeer(
}
bool ContentCaptureController::ShouldCapture(const GURL& url) {
if (!has_whitelist_.has_value()) {
if (!has_allowlist_.has_value()) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return false;
Java_ContentCaptureController_pullWhitelist(env, obj);
Java_ContentCaptureController_pullAllowlist(env, obj);
}
DCHECK(has_whitelist_.has_value());
DCHECK(has_allowlist_.has_value());
// Everything is whitelisted.
if (!has_whitelist_.value() || !url.has_host())
// Everything is allowed.
if (!has_allowlist_.value() || !url.has_host())
return true;
std::string host = url.host();
for (auto& w : whitelist_) {
for (auto& w : allowlist_) {
if (w == host)
return true;
}
for (auto& w : whitelist_regex_) {
for (auto& w : allowlist_regex_) {
if (re2::RE2::FullMatch(host, *w))
return true;
}
......
......@@ -29,9 +29,9 @@ class ContentCaptureController {
bool ShouldCapture(const GURL& url);
// The methods called by Java peer.
void SetWhitelist(JNIEnv* env,
void SetAllowlist(JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
const base::android::JavaParamRef<jobjectArray>& jwhitelist,
const base::android::JavaParamRef<jobjectArray>& jallowlist,
const base::android::JavaParamRef<jbooleanArray>& jtype);
void SetJavaPeer(JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller);
......@@ -39,9 +39,9 @@ class ContentCaptureController {
private:
virtual ~ContentCaptureController();
JavaObjectWeakGlobalRef java_ref_;
base::Optional<bool> has_whitelist_;
std::vector<std::string> whitelist_;
std::vector<std::unique_ptr<re2::RE2>> whitelist_regex_;
base::Optional<bool> has_allowlist_;
std::vector<std::string> allowlist_;
std::vector<std::unique_ptr<re2::RE2>> allowlist_regex_;
};
} // namespace content_capture
......
......@@ -9,7 +9,7 @@ import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
/**
* The abstract class to provide the whitelist and the runtime control of if ContentCapture should
* The abstract class to provide the allowlist and the runtime control of if ContentCapture should
* start.
*/
@JNINamespace("content_capture")
......@@ -45,29 +45,29 @@ public abstract class ContentCaptureController {
public void clearContentCaptureDataForURLs(String[] urlsToDelete) {}
/**
* Invoked by native side to pull the whitelist, the subclass should implement this and set
* the whitelist by call setWhiteList.
* Invoked by native side to pull the allowlist, the subclass should implement this and set
* the allowlist by call setAllowlist.
*/
@CalledByNative
protected abstract void pullWhitelist();
protected abstract void pullAllowlist();
/**
* Invoked by subclass to set the whitelist to native side. No whitelist (whitelist == null)
* indicates everything is whitelisted, empty whitelist (whitelist.length == 0) indicates
* nothing is whitelisted.
* Invoked by subclass to set the allowlist to native side. No allowlist (allowlist == null)
* indicates everything is allowed, empty allowlist (allowlist.length == 0) indicates
* nothing is allowed.
*
* @param whitelist the array of whitelist, it could be the hostname or the regex.
* @param isRegex to indicate that the corresponding whitelist is the regex or not.
* @param allowlist the array of allowlist, it could be the hostname or the regex.
* @param isRegex to indicate that the corresponding allowlist is the regex or not.
*/
protected void setWhitelist(String[] whitelist, boolean[] isRegex) {
ContentCaptureControllerJni.get().setWhitelist(
mNativeContentCaptureController, ContentCaptureController.this, whitelist, isRegex);
protected void setAllowlist(String[] allowlist, boolean[] isRegex) {
ContentCaptureControllerJni.get().setAllowlist(
mNativeContentCaptureController, ContentCaptureController.this, allowlist, isRegex);
}
@NativeMethods
interface Natives {
long init(Object contentCaptureController);
void setWhitelist(long nativeContentCaptureController, ContentCaptureController caller,
String[] whitelist, boolean[] isRegex);
void setAllowlist(long nativeContentCaptureController, ContentCaptureController caller,
String[] allowlist, boolean[] isRegex);
}
}
......@@ -21,7 +21,7 @@ import java.util.Set;
/**
* The implementation of ContentCaptureController to verify ContentCaptureService
* is Aiai and signed by right certificate, this class also read whitelist from
* is Aiai and signed by right certificate, this class also read allowlist from
* framework and set to native side.
*/
// TODO(crbug.com/965566): Write junit tests for this when junit supports q.
......@@ -78,22 +78,22 @@ public class ContentCaptureControllerImpl extends ContentCaptureController {
}
@Override
protected void pullWhitelist() {
protected void pullAllowlist() {
Set<ContentCaptureCondition> conditions =
mContentCaptureManager.getContentCaptureConditions();
String[] whiteList = null;
String[] allowlist = null;
boolean[] isRegEx = null;
if (conditions != null) {
whiteList = new String[conditions.size()];
allowlist = new String[conditions.size()];
isRegEx = new boolean[conditions.size()];
int index = 0;
for (ContentCaptureCondition c : conditions) {
whiteList[index] = c.getLocusId().getId();
allowlist[index] = c.getLocusId().getId();
isRegEx[index] = (c.getFlags() & ContentCaptureCondition.FLAG_IS_REGEX) != 0;
index++;
}
}
setWhitelist(whiteList, isRegEx);
setAllowlist(allowlist, isRegEx);
}
private void log(String msg) {
......
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