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
--- 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,