[geo] Add settings interface for approximate geolocation
Add a mock interface that supplies geolocation settings to settings and page info. Bug: 418938557 Change-Id: I80e960ae4483e657688a99535962a53f1d4f8b6c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6574415 Reviewed-by: Florian Jacky <fjacky@chromium.org> Reviewed-by: Mariam Ali <alimariam@google.com> Commit-Queue: Christian Dullweber <dullweber@chromium.org> Cr-Commit-Position: refs/heads/main@{#1463946}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
7292727977
commit
b25f6c97b5
chrome/android/javatests/src/org/chromium/chrome/browser/site_settings
components
browser_ui
site_settings
android
java
src
org
chromium
components
browser_ui
site_settings
permissions
@@ -4,6 +4,9 @@
|
||||
|
||||
package org.chromium.chrome.browser.site_settings;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
@@ -19,6 +22,7 @@ import org.chromium.base.test.util.CallbackHelper;
|
||||
import org.chromium.base.test.util.CommandLineFlags;
|
||||
import org.chromium.base.test.util.CriteriaHelper;
|
||||
import org.chromium.base.test.util.Feature;
|
||||
import org.chromium.base.test.util.Features.EnableFeatures;
|
||||
import org.chromium.chrome.browser.browsing_data.BrowsingDataBridge;
|
||||
import org.chromium.chrome.browser.browsing_data.BrowsingDataType;
|
||||
import org.chromium.chrome.browser.browsing_data.TimePeriod;
|
||||
@@ -30,10 +34,12 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
||||
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
|
||||
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
|
||||
import org.chromium.components.browser_ui.site_settings.PermissionInfo;
|
||||
import org.chromium.components.browser_ui.site_settings.PermissionInfo.GeolocationSetting;
|
||||
import org.chromium.components.browser_ui.site_settings.WebsitePreferenceBridgeJni;
|
||||
import org.chromium.components.content_settings.ContentSettingValues;
|
||||
import org.chromium.components.content_settings.ContentSettingsType;
|
||||
import org.chromium.components.content_settings.SessionModel;
|
||||
import org.chromium.components.permissions.PermissionsAndroidFeatureList;
|
||||
import org.chromium.content_public.common.ContentSwitches;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -270,4 +276,45 @@ public class PermissionInfoTest {
|
||||
regularProfile,
|
||||
ContentSettingValues.ASK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
@Feature({"Preferences"})
|
||||
@EnableFeatures("ApproximateGeolocationPermission")
|
||||
public void testGeolocationPermissionMockValues() throws Throwable {
|
||||
PermissionsAndroidFeatureList.APPROXIMATE_GEOLOCATION_SAMPLE_DATA.setForTesting(true);
|
||||
Profile regularProfile = getRegularProfile();
|
||||
var permissionSiteInfo =
|
||||
new PermissionInfo(
|
||||
ContentSettingsType.GEOLOCATION,
|
||||
"https://permission.site",
|
||||
"https://permission.site",
|
||||
false,
|
||||
SessionModel.DURABLE);
|
||||
assertEquals(
|
||||
new GeolocationSetting(ContentSettingValues.ALLOW, ContentSettingValues.BLOCK),
|
||||
permissionSiteInfo.getGeolocationSetting(regularProfile));
|
||||
|
||||
GeolocationSetting allow_precise =
|
||||
new GeolocationSetting(ContentSettingValues.ALLOW, ContentSettingValues.ALLOW);
|
||||
permissionSiteInfo.setGeolocationSetting(regularProfile, allow_precise);
|
||||
assertEquals(allow_precise, permissionSiteInfo.getGeolocationSetting(regularProfile));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
@Feature({"Preferences"})
|
||||
@EnableFeatures("ApproximateGeolocationPermission")
|
||||
public void testGeolocationPermissionDefault() throws Throwable {
|
||||
PermissionsAndroidFeatureList.APPROXIMATE_GEOLOCATION_SAMPLE_DATA.setForTesting(false);
|
||||
Profile regularProfile = getRegularProfile();
|
||||
var permissionSiteInfo =
|
||||
new PermissionInfo(
|
||||
ContentSettingsType.GEOLOCATION,
|
||||
"https://permission.site",
|
||||
"https://permission.site",
|
||||
false,
|
||||
SessionModel.DURABLE);
|
||||
assertNull(permissionSiteInfo.getGeolocationSetting(regularProfile));
|
||||
}
|
||||
}
|
||||
|
@@ -9,9 +9,12 @@ import org.chromium.build.annotations.Nullable;
|
||||
import org.chromium.components.content_settings.ContentSettingValues;
|
||||
import org.chromium.components.content_settings.ContentSettingsType;
|
||||
import org.chromium.components.content_settings.SessionModel;
|
||||
import org.chromium.components.permissions.PermissionsAndroidFeatureList;
|
||||
import org.chromium.components.permissions.PermissionsAndroidFeatureMap;
|
||||
import org.chromium.content_public.browser.BrowserContextHandle;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Permission information for a given origin. */
|
||||
@NullMarked
|
||||
@@ -21,6 +24,7 @@ public class PermissionInfo implements Serializable {
|
||||
private final String mOrigin;
|
||||
private final @ContentSettingsType.EnumType int mContentSettingsType;
|
||||
private final @SessionModel.EnumType int mSessionModel;
|
||||
private static @Nullable GeolocationSetting sMockSetting;
|
||||
|
||||
public PermissionInfo(
|
||||
@ContentSettingsType.EnumType int type,
|
||||
@@ -68,7 +72,7 @@ public class PermissionInfo implements Serializable {
|
||||
@ContentSettingsType.EnumType int mContentSettingsType,
|
||||
String origin,
|
||||
@Nullable String embeddingOrigin) {
|
||||
return org.chromium.components.browser_ui.site_settings.WebsitePreferenceBridgeJni.get()
|
||||
return WebsitePreferenceBridgeJni.get()
|
||||
.getPermissionSettingForOrigin(
|
||||
browserContextHandle,
|
||||
mContentSettingsType,
|
||||
@@ -83,11 +87,36 @@ public class PermissionInfo implements Serializable {
|
||||
browserContextHandle, mContentSettingsType, mOrigin, mEmbedder);
|
||||
}
|
||||
|
||||
public static final class GeolocationSetting {
|
||||
public GeolocationSetting(
|
||||
@ContentSettingValues int approximate, @ContentSettingValues int precise) {
|
||||
mApproximate = approximate;
|
||||
mPrecise = precise;
|
||||
}
|
||||
|
||||
final @ContentSettingValues int mApproximate;
|
||||
final @ContentSettingValues int mPrecise;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
return o instanceof GeolocationSetting that
|
||||
&& mApproximate == that.mApproximate
|
||||
&& mPrecise == that.mPrecise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mApproximate, mPrecise);
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the native ContentSetting value for this origin. */
|
||||
public void setContentSetting(
|
||||
BrowserContextHandle browserContextHandle, @ContentSettingValues int value) {
|
||||
org.chromium.components.browser_ui.site_settings.WebsitePreferenceBridgeJni.get()
|
||||
WebsitePreferenceBridgeJni.get()
|
||||
.setPermissionSettingForOrigin(
|
||||
browserContextHandle,
|
||||
mContentSettingsType,
|
||||
@@ -95,4 +124,40 @@ public class PermissionInfo implements Serializable {
|
||||
getEmbedderSafe(),
|
||||
value);
|
||||
}
|
||||
|
||||
/** Returns the Geolocation permission value for this origin. */
|
||||
public @Nullable GeolocationSetting getGeolocationSetting(
|
||||
BrowserContextHandle browserContextHandle) {
|
||||
assert mContentSettingsType == ContentSettingsType.GEOLOCATION;
|
||||
assert PermissionsAndroidFeatureMap.isEnabled(
|
||||
PermissionsAndroidFeatureList.APPROXIMATE_GEOLOCATION_PERMISSION);
|
||||
// Return fake precise permission for maps.google.com and approximate for permission.site
|
||||
// until we can set create real approximate permissions.
|
||||
if (PermissionsAndroidFeatureList.APPROXIMATE_GEOLOCATION_SAMPLE_DATA.getValue()) {
|
||||
if (mOrigin.equals("https://permission.site")) {
|
||||
if (sMockSetting == null) {
|
||||
sMockSetting =
|
||||
new GeolocationSetting(
|
||||
ContentSettingValues.ALLOW, ContentSettingValues.BLOCK);
|
||||
}
|
||||
return sMockSetting;
|
||||
}
|
||||
}
|
||||
// TODO(crbug.com/418938557) Get value from content settings. We probably only want a
|
||||
// base::Value API for get/set of complex permissions to avoid adding bridge methods for
|
||||
// every such permission.
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Set the Geolocation permission value for this origin. */
|
||||
public void setGeolocationSetting(
|
||||
BrowserContextHandle browserContextHandle, GeolocationSetting setting) {
|
||||
assert mContentSettingsType == ContentSettingsType.GEOLOCATION;
|
||||
if (PermissionsAndroidFeatureList.APPROXIMATE_GEOLOCATION_SAMPLE_DATA.getValue()) {
|
||||
if (mOrigin.equals("https://permission.site")) {
|
||||
sMockSetting = setting;
|
||||
}
|
||||
}
|
||||
// TODO(crbug.com/418938557) Set new value in content settings.
|
||||
}
|
||||
}
|
||||
|
@@ -210,6 +210,7 @@ android_library("core_java") {
|
||||
deps = [
|
||||
"//base:base_java",
|
||||
"//build/android:build_java",
|
||||
"//components/cached_flags:java",
|
||||
"//components/content_settings/android:content_settings_enums_java",
|
||||
"//components/location/android:location_java",
|
||||
"//components/webxr/android:features_java",
|
||||
|
@@ -1,6 +1,7 @@
|
||||
include_rules = [
|
||||
"+components/browser_ui/util/android",
|
||||
"+components/browser_ui/widget/android",
|
||||
"+components/cached_flags",
|
||||
"+components/infobars/core",
|
||||
"+components/location/android",
|
||||
"+components/messages/android",
|
||||
|
@@ -5,6 +5,7 @@
|
||||
package org.chromium.components.permissions;
|
||||
|
||||
import org.chromium.build.annotations.NullMarked;
|
||||
import org.chromium.components.cached_flags.BooleanCachedFeatureParam;
|
||||
|
||||
/**
|
||||
* Lists base::Features that can be accessed through {@link PermissionsAndroidFeatureMap}.
|
||||
@@ -27,4 +28,8 @@ public abstract class PermissionsAndroidFeatureList {
|
||||
|
||||
public static final String APPROXIMATE_GEOLOCATION_PERMISSION =
|
||||
"ApproximateGeolocationPermission";
|
||||
|
||||
public static final BooleanCachedFeatureParam APPROXIMATE_GEOLOCATION_SAMPLE_DATA =
|
||||
PermissionsAndroidFeatureMap.newBooleanCachedFeatureParam(
|
||||
APPROXIMATE_GEOLOCATION_PERMISSION, "sample_data", false);
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import org.jni_zero.NativeMethods;
|
||||
|
||||
import org.chromium.base.FeatureMap;
|
||||
import org.chromium.build.annotations.NullMarked;
|
||||
import org.chromium.components.cached_flags.BooleanCachedFeatureParam;
|
||||
|
||||
/** Java accessor for base::Features listed in {@link PermissionsAndroidFeatureList} */
|
||||
@JNINamespace("permissions")
|
||||
@@ -30,6 +31,12 @@ public final class PermissionsAndroidFeatureMap extends FeatureMap {
|
||||
return getInstance().isEnabledInNative(featureName);
|
||||
}
|
||||
|
||||
public static BooleanCachedFeatureParam newBooleanCachedFeatureParam(
|
||||
String featureName, String variationName, boolean defaultValue) {
|
||||
return new BooleanCachedFeatureParam(
|
||||
getInstance(), featureName, variationName, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getNativeMap() {
|
||||
return PermissionsAndroidFeatureMapJni.get().getNativeMap();
|
||||
|
@@ -86,6 +86,11 @@ BASE_FEATURE(kApproximateGeolocationPermission,
|
||||
"ApproximateGeolocationPermission",
|
||||
base::FEATURE_DISABLED_BY_DEFAULT);
|
||||
|
||||
const base::FeatureParam<bool> kApproximateGeolocationPermissionSampleData(
|
||||
&features::kApproximateGeolocationPermission,
|
||||
"sample_data",
|
||||
false);
|
||||
|
||||
#else
|
||||
|
||||
// When enabled, chooser permissions grants will have a last visited timestamp
|
||||
|
@@ -56,6 +56,10 @@ BASE_DECLARE_FEATURE(kPermissionDedicatedCpssSettingAndroid);
|
||||
COMPONENT_EXPORT(PERMISSIONS_COMMON)
|
||||
BASE_DECLARE_FEATURE(kApproximateGeolocationPermission);
|
||||
|
||||
COMPONENT_EXPORT(PERMISSIONS_COMMON)
|
||||
extern const base::FeatureParam<bool>
|
||||
kApproximateGeolocationPermissionSampleData;
|
||||
|
||||
#else
|
||||
|
||||
COMPONENT_EXPORT(PERMISSIONS_COMMON)
|
||||
|
Reference in New Issue
Block a user