Issue #1721 - Implement GlobalPrivacyControl

(and get rid of failed DoNotTrack)
This commit is contained in:
Moonchild 2021-10-07 21:38:26 +00:00 committed by roytam1
commit 50ad087351
14 changed files with 41 additions and 50 deletions

View file

@ -632,22 +632,10 @@ Navigator::GetBuildID(nsAString& aBuildID)
return NS_OK;
}
NS_IMETHODIMP
Navigator::GetDoNotTrack(nsAString &aResult)
bool
Navigator::GlobalPrivacyControl()
{
bool doNotTrack = nsContentUtils::DoNotTrackEnabled();
if (!doNotTrack) {
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(mWindow);
doNotTrack = loadContext && loadContext->UseTrackingProtection();
}
if (doNotTrack) {
aResult.AssignLiteral("1");
} else {
aResult.AssignLiteral("unspecified");
}
return NS_OK;
return nsContentUtils::GPCEnabled();
}
bool

View file

@ -131,7 +131,7 @@ public:
nsMimeTypeArray* GetMimeTypes(ErrorResult& aRv);
nsPluginArray* GetPlugins(ErrorResult& aRv);
Permissions* GetPermissions(ErrorResult& aRv);
// The XPCOM GetDoNotTrack is ok
bool GlobalPrivacyControl();
Geolocation* GetGeolocation(ErrorResult& aRv);
static void AppName(nsAString& aAppName, bool aUsePrefOverriddenValue);

View file

@ -309,7 +309,7 @@ bool nsContentUtils::sFragmentParsingActive = false;
bool nsContentUtils::sDOMWindowDumpEnabled;
#endif
bool nsContentUtils::sDoNotTrackEnabled = false;
bool nsContentUtils::sGPCEnabled = false;
mozilla::LazyLogModule nsContentUtils::sDOMDumpLog("Dump");
@ -626,8 +626,8 @@ nsContentUtils::Init()
"browser.dom.window.dump.enabled");
#endif
Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
"privacy.donottrackheader.enabled", false);
Preferences::AddBoolVarCache(&sGPCEnabled,
"privacy.GPCheader.enabled", false);
Preferences::AddBoolVarCache(&sUseActivityCursor,
"ui.use_activity_cursor", false);
@ -7337,9 +7337,9 @@ nsContentUtils::DOMWindowDumpEnabled()
}
bool
nsContentUtils::DoNotTrackEnabled()
nsContentUtils::GPCEnabled()
{
return nsContentUtils::sDoNotTrackEnabled;
return nsContentUtils::sGPCEnabled;
}
mozilla::LogModule*

View file

@ -2432,9 +2432,9 @@ public:
static bool DOMWindowDumpEnabled();
/**
* Returns true if the privacy.donottrackheader.enabled pref is set.
* Returns true if the privacy.GPCheader.enabled pref is set.
*/
static bool DoNotTrackEnabled();
static bool GPCEnabled();
/**
* Returns a LogModule that dump calls from content script are logged to.
@ -2971,7 +2971,7 @@ private:
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
static bool sDOMWindowDumpEnabled;
#endif
static bool sDoNotTrackEnabled;
static bool sGPCEnabled;
static mozilla::LazyLogModule sDOMDumpLog;
};

View file

@ -22,5 +22,4 @@ interface nsIDOMNavigator : nsISupports
readonly attribute DOMString productSub;
readonly attribute DOMString userAgent;
readonly attribute DOMString buildID;
readonly attribute DOMString doNotTrack;
};

View file

@ -30,6 +30,7 @@ Navigator implements NavigatorContentUtils;
Navigator implements NavigatorStorageUtils;
Navigator implements NavigatorConcurrentHardware;
Navigator implements NavigatorStorage;
Navigator implements NavigatorGlobalPrivacyControl;
[NoInterfaceObject, Exposed=(Window,Worker)]
interface NavigatorID {
@ -111,9 +112,10 @@ partial interface Navigator {
readonly attribute PluginArray plugins;
};
// http://www.w3.org/TR/tracking-dnt/ sort of
partial interface Navigator {
readonly attribute DOMString doNotTrack;
// https://globalprivacycontrol.github.io/gpc-spec/
[NoInterfaceObject, Exposed=(Window,Worker)]
interface NavigatorGlobalPrivacyControl {
readonly attribute boolean globalPrivacyControl;
};
// http://www.w3.org/TR/geolocation-API/#geolocation_interface

View file

@ -12,3 +12,4 @@ WorkerNavigator implements NavigatorLanguage;
WorkerNavigator implements NavigatorOnLine;
WorkerNavigator implements NavigatorConcurrentHardware;
WorkerNavigator implements NavigatorStorage;
WorkerNavigator implements NavigatorGlobalPrivacyControl;

View file

@ -8,6 +8,7 @@
#include "Workers.h"
#include "RuntimeService.h"
#include "nsContentUtils.h"
#include "nsString.h"
#include "nsWrapperCache.h"
#include "mozilla/dom/StorageManager.h"
@ -100,6 +101,11 @@ public:
mOnline = aOnline;
}
bool GlobalPrivacyControl() const
{
return nsContentUtils::GPCEnabled();
}
void SetLanguages(const nsTArray<nsString>& aLanguages);
uint64_t HardwareConcurrency() const;

View file

@ -1231,8 +1231,8 @@ pref("content.sink.pending_event_mode", 0);
// 2 = openAbused
pref("privacy.popups.disable_from_plugins", 2);
// send "do not track" HTTP header, disabled by default
pref("privacy.donottrackheader.enabled", false);
// Send "Sec-GPC" HTTP header, disabled by default
pref("privacy.GPCheader.enabled", false);
// Enforce tracking protection in all modes
pref("privacy.trackingprotection.enabled", false);
// Enforce tracking protection in Private Browsing mode

View file

@ -45,11 +45,11 @@ HTTP_ATOM(Date, "Date")
HTTP_ATOM(DAV, "DAV")
HTTP_ATOM(Depth, "Depth")
HTTP_ATOM(Destination, "Destination")
HTTP_ATOM(DoNotTrack, "DNT")
HTTP_ATOM(ETag, "Etag")
HTTP_ATOM(Expect, "Expect")
HTTP_ATOM(Expires, "Expires")
HTTP_ATOM(From, "From")
HTTP_ATOM(GlobalPrivacyControl, "Sec-GPC")
HTTP_ATOM(Host, "Host")
HTTP_ATOM(If, "If")
HTTP_ATOM(If_Match, "If-Match")

View file

@ -5711,7 +5711,7 @@ nsHttpChannel::BeginConnect()
mRequestHead.SetOrigin(scheme, host, port);
SetOriginHeader();
SetDoNotTrack();
SetGPC();
NeckoOriginAttributes originAttributes;
NS_GetOriginAttributes(this, originAttributes);
@ -8051,18 +8051,13 @@ nsHttpChannel::SetOriginHeader()
}
void
nsHttpChannel::SetDoNotTrack()
nsHttpChannel::SetGPC()
{
/**
* 'DoNotTrack' header should be added if 'privacy.donottrackheader.enabled'
* is true or tracking protection is enabled. See bug 1258033.
* 'Sec-GPC: 1' header should be added if 'privacy.GPCheader.enabled' is true.
*/
nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(this, loadContext);
if ((loadContext && loadContext->UseTrackingProtection()) ||
nsContentUtils::DoNotTrackEnabled()) {
mRequestHead.SetHeader(nsHttp::DoNotTrack,
if (nsContentUtils::GPCEnabled()) {
mRequestHead.SetHeader(nsHttp::GlobalPrivacyControl,
NS_LITERAL_CSTRING("1"),
false);
}

View file

@ -453,7 +453,7 @@ private:
void SetPushedStream(Http2PushedStreamWrapper *stream);
void SetOriginHeader();
void SetDoNotTrack();
void SetGPC();
private:
nsCOMPtr<nsICancelable> mProxyRequest;

View file

@ -87,7 +87,7 @@
#define HTTP_PREF_PREFIX "network.http."
#define INTL_ACCEPT_LANGUAGES "intl.accept_languages"
#define BROWSER_PREF_PREFIX "browser.cache."
#define DONOTTRACK_HEADER_ENABLED "privacy.donottrackheader.enabled"
#define GPC_HEADER_ENABLED "privacy.GPCheader.enabled"
#define H2MANDATORY_SUITE "security.ssl3.ecdhe_rsa_aes_128_gcm_sha256"
#define ALLOW_EXPERIMENTS "network.allow-experiments"
#define SAFE_HINT_HEADER_VALUE "safeHint.enabled"
@ -181,7 +181,7 @@ nsHttpHandler::nsHttpHandler()
, mAcceptLanguagesIsDirty(true)
, mPromptTempRedirect(true)
, mEnablePersistentHttpsCaching(false)
, mDoNotTrackEnabled(false)
, mGPCEnabled(false)
, mSafeHintEnabled(false)
, mParentalControlEnabled(false)
, mHandlerActive(false)
@ -279,7 +279,7 @@ nsHttpHandler::Init()
prefBranch->AddObserver(UA_PREF_PREFIX, this, true);
prefBranch->AddObserver(INTL_ACCEPT_LANGUAGES, this, true);
prefBranch->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, true);
prefBranch->AddObserver(DONOTTRACK_HEADER_ENABLED, this, true);
prefBranch->AddObserver(GPC_HEADER_ENABLED, this, true);
prefBranch->AddObserver(H2MANDATORY_SUITE, this, true);
prefBranch->AddObserver(HTTP_PREF("tcp_keepalive.short_lived_connections"), this, true);
prefBranch->AddObserver(HTTP_PREF("tcp_keepalive.long_lived_connections"), this, true);
@ -1497,11 +1497,11 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
// Tracking options
//
if (PREF_CHANGED(DONOTTRACK_HEADER_ENABLED)) {
if (PREF_CHANGED(GPC_HEADER_ENABLED)) {
cVar = false;
rv = prefs->GetBoolPref(DONOTTRACK_HEADER_ENABLED, &cVar);
rv = prefs->GetBoolPref(GPC_HEADER_ENABLED, &cVar);
if (NS_SUCCEEDED(rv)) {
mDoNotTrackEnabled = cVar;
mGPCEnabled = cVar;
}
}
// Hint option

View file

@ -515,8 +515,8 @@ private:
// Persistent HTTPS caching flag
bool mEnablePersistentHttpsCaching;
// For broadcasting tracking preference
bool mDoNotTrackEnabled;
// For broadcasting Global Privacy Control preference
bool mGPCEnabled;
// for broadcasting safe hint;
bool mSafeHintEnabled;