Bug 1372072 - Part 1: Spoofing network information API and blocking ontypechange event when 'privacy.resistFingerprinting' is true. r?baku,arthuredelstein draft
authorTim Huang <tihuang@mozilla.com>
Tue, 13 Jun 2017 11:10:30 +0800
changeset 601619 985bb67c696643e14c583da39815a3815d28d3f0
parent 601524 217b7fcf58944f927118b465769faeb1e613130a
child 601620 acb236faa781ceafc6d7537ce56fd96b02004649
push id66148
push userbmo:tihuang@mozilla.com
push dateWed, 28 Jun 2017 23:16:09 +0000
reviewersbaku, arthuredelstein
bugs1372072
milestone56.0a1
Bug 1372072 - Part 1: Spoofing network information API and blocking ontypechange event when 'privacy.resistFingerprinting' is true. r?baku,arthuredelstein 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,