Bug 1372072 - Part 1: Spoofing network information API and blocking ontypechange event when 'privacy.resistFingerprinting' is true. r=arthuredelstein,baku
authorTim Huang <tihuang@mozilla.com>
Tue, 13 Jun 2017 11:10:30 +0800
changeset 366734 69970dbe2b5ac4221205c77660b9cc5f38bf5241
parent 366733 f4ecac52ecebead55f980acd2f0a06e495cd9cb1
child 366735 12f8c79dabb4b267f5f033c644295544ed82ad0c
push id32108
push usercbook@mozilla.com
push dateFri, 30 Jun 2017 10:57:12 +0000
treeherdermozilla-central@a578ce873d80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarthuredelstein, baku
bugs1372072
milestone56.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 1372072 - Part 1: Spoofing network information API and blocking ontypechange event when 'privacy.resistFingerprinting' is true. r=arthuredelstein,baku This patch makes the network information API always returns the default type 'unknown' and blocking the ontypechange event while connection type changed when 'privacy. resistFingerprinting' is true. MozReview-Commit-ID: 4eOdHgAGtyY
dom/network/Connection.cpp
dom/network/Connection.h
--- a/dom/network/Connection.cpp
+++ b/dom/network/Connection.cpp
@@ -95,17 +95,18 @@ Connection::Update(ConnectionType aType,
   NS_ASSERT_OWNINGTHREAD(Connection);
 
   ConnectionType previousType = mType;
 
   mType = aType;
   mIsWifi = aIsWifi;
   mDHCPGateway = aDHCPGateway;
 
-  if (aNotify && previousType != aType) {
+  if (aNotify && previousType != aType &&
+      !nsContentUtils::ShouldResistFingerprinting()) {
     DispatchTrustedEvent(CHANGE_EVENT_NAME);
   }
 }
 
 /* static */ bool
 Connection::IsEnabled(JSContext* aCx, JSObject* aObj)
 {
   if (NS_IsMainThread()) {
--- a/dom/network/Connection.h
+++ b/dom/network/Connection.h
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_network_Connection_h
 #define mozilla_dom_network_Connection_h
 
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/dom/NetworkInformationBinding.h"
+#include "nsContentUtils.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsINetworkProperties.h"
 
 namespace mozilla {
 
 namespace hal {
 class NetworkInformation;
 } // namespace hal
@@ -47,17 +48,21 @@ public:
 
   void Shutdown();
 
   // WebIDL
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
-  ConnectionType Type() const { return mType; }
+  ConnectionType Type() const
+  {
+    return nsContentUtils::ShouldResistFingerprinting() ?
+             static_cast<ConnectionType>(ConnectionType::Unknown) : mType;
+  }
 
   IMPL_EVENT_HANDLER(typechange)
 
 protected:
   Connection(nsPIDOMWindowInner* aWindow);
   virtual ~Connection();
 
   void Update(ConnectionType aType, bool aIsWifi, bool aDHCPGateway,