From 4dbb2feaf157991fa76786dd2adc7f89dbee1a7a Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Wed, 13 Dec 2017 14:02:46 -0600 Subject: [PATCH] Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 19 - Resist finger-printing enabled, r=asuth --- dom/base/DOMPreferences.cpp | 1 + dom/base/DOMPreferences.h | 3 +++ dom/base/nsContentUtils.cpp | 12 +----------- dom/html/ImageDocument.cpp | 3 ++- dom/workers/WorkerNavigator.cpp | 13 +++++++------ dom/workers/WorkerPrefs.h | 1 - 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/dom/base/DOMPreferences.cpp b/dom/base/DOMPreferences.cpp index bb3118b81ffb..3b76d320cf3f 100644 --- a/dom/base/DOMPreferences.cpp +++ b/dom/base/DOMPreferences.cpp @@ -53,6 +53,7 @@ PREF(OffscreenCanvasEnabled, "gfx.offscreencanvas.enabled") PREF(WebkitBlinkDirectoryPickerEnabled, "dom.webkitBlink.dirPicker.enabled") PREF(NetworkInformationEnabled, "dom.netinfo.enabled") PREF(FetchObserverEnabled, "dom.fetchObserver.enabled") +PREF(ResistFingerprintingEnabled, "privacy.resistFingerprinting") #undef PREF diff --git a/dom/base/DOMPreferences.h b/dom/base/DOMPreferences.h index 829c9cd5cd02..d20da60ccb56 100644 --- a/dom/base/DOMPreferences.h +++ b/dom/base/DOMPreferences.h @@ -87,6 +87,9 @@ public: // Returns true if the dom.fetchObserver.enabled pref is set. static bool FetchObserverEnabled(); static bool FetchObserverEnabled(JSContext* aCx, JSObject* aObj); + + // Returns true if the privacy.resistFingerprinting pref is set. + static bool ResistFingerprintingEnabled(); }; } // dom namespace diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 8e342c05c072..71594ac1ecd0 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -2378,17 +2378,7 @@ nsContentUtils::IsCallerChrome() bool nsContentUtils::ShouldResistFingerprinting() { - if (NS_IsMainThread()) { - return nsRFPService::IsResistFingerprintingEnabled(); - } - - workers::WorkerPrivate* workerPrivate = workers::GetCurrentThreadWorkerPrivate(); - if (NS_WARN_IF(!workerPrivate)) { - return false; - } - workerPrivate->AssertIsOnWorkerThread(); - - return workerPrivate->ResistFingerprintingEnabled(); + return DOMPreferences::ResistFingerprintingEnabled(); } bool diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp index ef2991878733..13d9236b9e24 100644 --- a/dom/html/ImageDocument.cpp +++ b/dom/html/ImageDocument.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "ImageDocument.h" +#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/ImageDocumentBinding.h" #include "mozilla/dom/HTMLImageElement.h" #include "nsRect.h" @@ -49,7 +50,7 @@ //XXX A hack needed for Firefox's site specific zoom. static bool IsSiteSpecific() { - return !mozilla::Preferences::GetBool("privacy.resistFingerprinting", false) && + return !mozilla::dom::DOMPreferences::ResistFingerprintingEnabled() && mozilla::Preferences::GetBool("browser.zoom.siteSpecific", false); } diff --git a/dom/workers/WorkerNavigator.cpp b/dom/workers/WorkerNavigator.cpp index 1a22c3d45a92..eed9841dab08 100644 --- a/dom/workers/WorkerNavigator.cpp +++ b/dom/workers/WorkerNavigator.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/BindingUtils.h" +#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseWorkerProxy.h" #include "mozilla/dom/StorageManager.h" @@ -81,11 +82,11 @@ WorkerNavigator::GetAppName(nsString& aAppName, CallerType aCallerType) const MOZ_ASSERT(workerPrivate); if ((!mProperties.mAppNameOverridden.IsEmpty() || - workerPrivate->ResistFingerprintingEnabled()) && + DOMPreferences::ResistFingerprintingEnabled()) && !workerPrivate->UsesSystemPrincipal()) { // We will spoof this value when 'privacy.resistFingerprinting' is true. // See nsRFPService.h for spoofed value. - aAppName = workerPrivate->ResistFingerprintingEnabled() ? + aAppName = DOMPreferences::ResistFingerprintingEnabled() ? NS_LITERAL_STRING(SPOOFED_APPNAME) : mProperties.mAppNameOverridden; } else { aAppName = mProperties.mAppName; @@ -100,11 +101,11 @@ WorkerNavigator::GetAppVersion(nsString& aAppVersion, CallerType aCallerType, MOZ_ASSERT(workerPrivate); if ((!mProperties.mAppVersionOverridden.IsEmpty() || - workerPrivate->ResistFingerprintingEnabled()) && + DOMPreferences::ResistFingerprintingEnabled()) && !workerPrivate->UsesSystemPrincipal()) { // We will spoof this value when 'privacy.resistFingerprinting' is true. // See nsRFPService.h for spoofed value. - aAppVersion = workerPrivate->ResistFingerprintingEnabled() ? + aAppVersion = DOMPreferences::ResistFingerprintingEnabled() ? NS_LITERAL_STRING(SPOOFED_APPVERSION) : mProperties.mAppVersionOverridden; } else { aAppVersion = mProperties.mAppVersion; @@ -119,11 +120,11 @@ WorkerNavigator::GetPlatform(nsString& aPlatform, CallerType aCallerType, MOZ_ASSERT(workerPrivate); if ((!mProperties.mPlatformOverridden.IsEmpty() || - workerPrivate->ResistFingerprintingEnabled()) && + DOMPreferences::ResistFingerprintingEnabled()) && !workerPrivate->UsesSystemPrincipal()) { // We will spoof this value when 'privacy.resistFingerprinting' is true. // See nsRFPService.h for spoofed value. - aPlatform = workerPrivate->ResistFingerprintingEnabled() ? + aPlatform = DOMPreferences::ResistFingerprintingEnabled() ? NS_LITERAL_STRING(SPOOFED_PLATFORM) : mProperties.mPlatformOverridden; } else { aPlatform = mProperties.mPlatform; diff --git a/dom/workers/WorkerPrefs.h b/dom/workers/WorkerPrefs.h index be3bee301957..6be691482816 100644 --- a/dom/workers/WorkerPrefs.h +++ b/dom/workers/WorkerPrefs.h @@ -21,7 +21,6 @@ // * First argument is the name of the pref. // * The name of the function that updates the new value of a pref. -WORKER_SIMPLE_PREF("privacy.resistFingerprinting", ResistFingerprintingEnabled, RESISTFINGERPRINTING_ENABLED) WORKER_SIMPLE_PREF("devtools.enabled", DevToolsEnabled, DEVTOOLS_ENABLED) WORKER_PREF("intl.accept_languages", PrefLanguagesChanged) WORKER_PREF("general.appname.override", AppNameOverrideChanged)