Commit 134c4eda authored by Andrey Zaytsev's avatar Andrey Zaytsev Committed by Chromium LUCI CQ

Privacy Sandbox Settings: created a bridge to access prefs

Bug: 1152351
Change-Id: I8afa16d818cfe1da71ec0479d9bc9d314346fd0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2637833Reviewed-by: default avatarTheodore Olsauskas-Warren <sauski@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Andrey Zaytsev <andzaytsev@google.com>
Cr-Commit-Position: refs/heads/master@{#845615}
parent dea4d6f1
......@@ -3160,6 +3160,7 @@ static_library("browser") {
"previews/android/previews_android_bridge.cc",
"previews/android/previews_android_bridge.h",
"privacy/secure_dns_bridge.cc",
"privacy_sandbox/android/privacy_sandbox_bridge.cc",
"profiles/android/profile_downloader_android.cc",
"profiles/android/profile_manager_utils.cc",
"profiles/incognito_utils_android.cc",
......@@ -3257,6 +3258,7 @@ static_library("browser") {
"//chrome/browser/payments/android:jni_headers",
"//chrome/browser/policy/android:jni_headers",
"//chrome/browser/privacy:jni_headers",
"//chrome/browser/privacy_sandbox/android:jni_headers",
"//chrome/browser/reading_list/android",
"//chrome/browser/safety_check/android",
"//chrome/browser/share",
......
......@@ -4,6 +4,10 @@
import("//build/config/android/rules.gni")
generate_jni("jni_headers") {
sources = [ "java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxBridge.java" ]
}
android_library("java") {
visibility = [
":*",
......@@ -11,18 +15,21 @@ android_library("java") {
"//chrome/android:chrome_java",
]
sources = [
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxBridge.java",
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxSettingsFragment.java",
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxSnackbarController.java",
]
deps = [
":java_resources",
"//base:base_java",
"//base:jni_java",
"//chrome/browser/ui/messages/android:java",
"//components/browser_ui/settings/android:java",
"//third_party/android_deps:androidx_fragment_fragment_java",
"//third_party/android_deps:androidx_preference_preference_java",
"//ui/android:ui_full_java",
]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
resources_package = "org.chromium.chrome.browser.privacy_sandbox"
}
......
// Copyright 2021 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.chrome.browser.privacy_sandbox;
import org.chromium.base.annotations.NativeMethods;
/** Bridge, providing access to the native-side Privacy Sandbox configuration. */
public class PrivacySandboxBridge {
boolean isPrivacySandboxEnabled() {
return PrivacySandboxBridgeJni.get().isPrivacySandboxEnabled();
}
boolean isPrivacySandboxManaged() {
return PrivacySandboxBridgeJni.get().isPrivacySandboxManaged();
}
void setPrivacySandboxEnabled(boolean enabled) {
PrivacySandboxBridgeJni.get().setPrivacySandboxEnabled(enabled);
}
@NativeMethods
interface Natives {
boolean isPrivacySandboxEnabled();
boolean isPrivacySandboxManaged();
void setPrivacySandboxEnabled(boolean enabled);
}
}
// Copyright 2021 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 "chrome/browser/privacy_sandbox/android/jni_headers/PrivacySandboxBridge_jni.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
static jboolean JNI_PrivacySandboxBridge_IsPrivacySandboxEnabled(JNIEnv* env) {
return PrivacySandboxSettingsFactory::GetForProfile(
ProfileManager::GetActiveUserProfile())
->IsPrivacySandboxEnabled();
}
static jboolean JNI_PrivacySandboxBridge_IsPrivacySandboxManaged(JNIEnv* env) {
return PrivacySandboxSettingsFactory::GetForProfile(
ProfileManager::GetActiveUserProfile())
->IsPrivacySandboxManaged();
}
static void JNI_PrivacySandboxBridge_SetPrivacySandboxEnabled(
JNIEnv* env,
jboolean enabled) {
PrivacySandboxSettingsFactory::GetForProfile(
ProfileManager::GetActiveUserProfile())
->SetPrivacySandboxEnabled(enabled);
}
......@@ -131,6 +131,22 @@ bool PrivacySandboxSettings::IsPrivacySandboxAllowed() {
return pref_service_->GetBoolean(prefs::kPrivacySandboxApisEnabled);
}
bool PrivacySandboxSettings::IsPrivacySandboxEnabled() {
return pref_service_->GetBoolean(prefs::kPrivacySandboxApisEnabled);
}
bool PrivacySandboxSettings::IsPrivacySandboxManaged() {
return pref_service_->IsManagedPreference(prefs::kPrivacySandboxApisEnabled);
}
void PrivacySandboxSettings::SetPrivacySandboxEnabled(bool enabled) {
if (!base::FeatureList::IsEnabled(features::kPrivacySandboxSettings)) {
return;
}
pref_service_->SetBoolean(prefs::kPrivacySandboxManuallyControlled, true);
pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabled, enabled);
}
void PrivacySandboxSettings::OnCookiesCleared() {
pref_service_->SetTime(prefs::kPrivacySandboxFlocDataAccessibleSince,
base::Time::Now());
......
......@@ -77,6 +77,16 @@ class PrivacySandboxSettings : public KeyedService {
// is enabled, this will check prefs::kPrivacySandboxApisEnabled instead.
bool IsPrivacySandboxAllowed();
// Used by the UI to check if the API is enabled. Unlike the method above,
// this method only checks the pref directly.
bool IsPrivacySandboxEnabled();
// Returns whether the state of the API is managed.
bool IsPrivacySandboxManaged();
// Gets invoked by the UI when the user manually changed the state of the API.
void SetPrivacySandboxEnabled(bool enabled);
// Called when there's a broad cookies clearing action. For example, this
// should be called on "Clear browsing data", but shouldn't be called on the
// Clear-Site-Data header, as it's restricted to a specific site.
......
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