Bug 1735212 - Support GPC on Workers; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D161454
This commit is contained in:
june wilde 2023-02-06 11:26:04 +00:00
parent 2f26b6d07c
commit 418f826d71
5 changed files with 27 additions and 7 deletions

View File

@ -12,12 +12,18 @@ add_task(async function testGlobalPrivacyControlDisabled() {
await SpecialPowers.pushPrefEnv({ set: [
["privacy.globalprivacycontrol.enabled", false],
["privacy.globalprivacycontrol.functionality.enabled", true],
]});
await fetch("file_gpc_server.sjs")
]})
.then(() => fetch("file_gpc_server.sjs"))
.then((response) => response.text())
.then((response) => {
is(response, "false", "GPC disabled so header unsent");
is(navigator.globalPrivacyControl, false, "GPC disabled so navigator property is 0");
let worker = new Worker(window.URL.createObjectURL(new Blob(["postMessage(navigator.globalPrivacyControl);"])));
return new Promise((resolve) => { worker.onmessage = (e) => { resolve(e.data) } });
})
.then((response) => {
is(response, false, "GPC disabled so worker's navigator property is 0");
});
});
@ -25,12 +31,18 @@ add_task(async function testGlobalPrivacyControlEnabled() {
await SpecialPowers.pushPrefEnv({ set: [
["privacy.globalprivacycontrol.enabled", true],
["privacy.globalprivacycontrol.functionality.enabled", true],
]});
await fetch("file_gpc_server.sjs")
]})
.then(() => fetch("file_gpc_server.sjs"))
.then((response) => response.text())
.then((response) => {
is(response, "true", "GPC enabled so header sent and received");
is(navigator.globalPrivacyControl, true, "GPC enabled so navigator property is 1");
let worker = new Worker(window.URL.createObjectURL(new Blob(["postMessage(navigator.globalPrivacyControl);"])));
return new Promise((resolve) => { worker.onmessage = (e) => { resolve(e.data) } });
})
.then((response) => {
is(response, true, "GPC enabled so worker's navigator property is 1");
});
});

View File

@ -41,6 +41,7 @@ Navigator includes NavigatorConcurrentHardware;
Navigator includes NavigatorStorage;
Navigator includes NavigatorAutomationInformation;
Navigator includes GPUProvider;
Navigator includes GlobalPrivacyControl;
interface mixin NavigatorID {
// WebKit/Blink/Trident/Presto support this (hardcoded "Mozilla").
@ -119,7 +120,7 @@ partial interface Navigator {
};
// https://globalprivacycontrol.github.io/gpc-spec/
partial interface Navigator {
interface mixin GlobalPrivacyControl {
[Pref="privacy.globalprivacycontrol.functionality.enabled"]
readonly attribute boolean globalPrivacyControl;
};

View File

@ -12,6 +12,7 @@ WorkerNavigator includes NavigatorLanguage;
WorkerNavigator includes NavigatorOnLine;
WorkerNavigator includes NavigatorConcurrentHardware;
WorkerNavigator includes NavigatorStorage;
WorkerNavigator includes GlobalPrivacyControl;
// http://wicg.github.io/netinfo/#extensions-to-the-navigator-interface
[Exposed=Worker]

View File

@ -14,6 +14,7 @@
#include "mozilla/RefPtr.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/workerinternals/RuntimeService.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "nsCycleCollectionParticipant.h"
#include "nsISupports.h"
#include "nsStringFwd.h"
@ -95,6 +96,11 @@ class WorkerNavigator final : public nsWrapperCache {
// Worker thread only!
void SetOnLine(bool aOnline) { mOnline = aOnline; }
bool GlobalPrivacyControl() const {
return StaticPrefs::privacy_globalprivacycontrol_enabled() &&
StaticPrefs::privacy_globalprivacycontrol_functionality_enabled();
}
void SetLanguages(const nsTArray<nsString>& aLanguages);
uint64_t HardwareConcurrency() const;

View File

@ -12728,7 +12728,7 @@
# true - Send the header with a value of 1 to indicate opting-out
# false - Do not send header to indicate opting-in
- name: privacy.globalprivacycontrol.enabled
type: bool
type: RelaxedAtomicBool
value: false
mirror: always
@ -12736,7 +12736,7 @@
# of 'undecided' by leaving the navigator property undefined and not attaching
# the Sec-GPC HTTP header.
- name: privacy.globalprivacycontrol.functionality.enabled
type: bool
type: RelaxedAtomicBool
value: false
mirror: always