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; return NS_OK;
} }
NS_IMETHODIMP bool
Navigator::GetDoNotTrack(nsAString &aResult) Navigator::GlobalPrivacyControl()
{ {
bool doNotTrack = nsContentUtils::DoNotTrackEnabled(); return nsContentUtils::GPCEnabled();
if (!doNotTrack) {
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(mWindow);
doNotTrack = loadContext && loadContext->UseTrackingProtection();
}
if (doNotTrack) {
aResult.AssignLiteral("1");
} else {
aResult.AssignLiteral("unspecified");
}
return NS_OK;
} }
bool bool

View file

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

View file

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

View file

@ -2432,9 +2432,9 @@ public:
static bool DOMWindowDumpEnabled(); 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. * 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)) #if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
static bool sDOMWindowDumpEnabled; static bool sDOMWindowDumpEnabled;
#endif #endif
static bool sDoNotTrackEnabled; static bool sGPCEnabled;
static mozilla::LazyLogModule sDOMDumpLog; static mozilla::LazyLogModule sDOMDumpLog;
}; };

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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