Bug 1532402 - Part 1: Pass a docshell pointer to nsContentUtils::ShouldResistFingerprinting() in the user-agent spoofing code for the Navigator properties; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 05 Mar 2019 23:13:32 +0000
changeset 520384 975cde7ee79a3dc935a0f13497cb1ff80d5537f5
parent 520383 641501728149842df11bc6353b629bad83b8f204
child 520385 ae40b04ca98b76683278c04f5720911c41e2d116
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1532402
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1532402 - Part 1: Pass a docshell pointer to nsContentUtils::ShouldResistFingerprinting() in the user-agent spoofing code for the Navigator properties; r=baku Differential Revision: https://phabricator.services.mozilla.com/D21990
dom/base/Navigator.cpp
dom/base/Navigator.h
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -376,17 +376,17 @@ void Navigator::GetPlatform(nsAString& a
   }
 }
 
 void Navigator::GetOscpu(nsAString& aOSCPU, CallerType aCallerType,
                          ErrorResult& aRv) const {
   if (aCallerType != CallerType::System) {
     // If fingerprinting resistance is on, we will spoof this value. See
     // nsRFPService.h for details about spoofed values.
-    if (nsContentUtils::ShouldResistFingerprinting()) {
+    if (nsContentUtils::ShouldResistFingerprinting(GetDocShell())) {
       aOSCPU.AssignLiteral(SPOOFED_OSCPU);
       return;
     }
 
     nsAutoString override;
     nsresult rv = Preferences::GetString("general.oscpu.override", override);
     if (NS_SUCCEEDED(rv)) {
       aOSCPU = override;
@@ -512,17 +512,17 @@ bool Navigator::CookieEnabled() {
 
 bool Navigator::OnLine() { return !NS_IsOffline(); }
 
 void Navigator::GetBuildID(nsAString& aBuildID, CallerType aCallerType,
                            ErrorResult& aRv) const {
   if (aCallerType != CallerType::System) {
     // If fingerprinting resistance is on, we will spoof this value. See
     // nsRFPService.h for details about spoofed values.
-    if (nsContentUtils::ShouldResistFingerprinting()) {
+    if (nsContentUtils::ShouldResistFingerprinting(GetDocShell())) {
       aBuildID.AssignLiteral(LEGACY_BUILD_ID);
       return;
     }
 
     nsAutoString override;
     nsresult rv = Preferences::GetString("general.buildID.override", override);
     if (NS_SUCCEEDED(rv)) {
       aBuildID = override;
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -233,16 +233,20 @@ class Navigator final : public nsISuppor
 
   // This enum helps SendBeaconInternal to apply different behaviors to body
   // types.
   enum BeaconType { eBeaconTypeBlob, eBeaconTypeArrayBuffer, eBeaconTypeOther };
 
   bool SendBeaconInternal(const nsAString& aUrl, BodyExtractorBase* aBody,
                           BeaconType aType, ErrorResult& aRv);
 
+  nsIDocShell* GetDocShell() const {
+    return mWindow ? mWindow->GetDocShell() : nullptr;
+  }
+
   RefPtr<nsMimeTypeArray> mMimeTypes;
   RefPtr<nsPluginArray> mPlugins;
   RefPtr<Permissions> mPermissions;
   RefPtr<Geolocation> mGeolocation;
   RefPtr<battery::BatteryManager> mBatteryManager;
   RefPtr<Promise> mBatteryPromise;
   RefPtr<network::Connection> mConnection;
   RefPtr<CredentialsContainer> mCredentials;