From b7254935b587b068eec2fdf766f886ff61832f85 Mon Sep 17 00:00:00 2001 From: asharma Date: Wed, 2 Mar 2022 21:27:46 +0000 Subject: [PATCH] Bug 1755372: Cut Over Connection to finer-grained RFP Check r=tjr Differential Revision: https://phabricator.services.mozilla.com/D138707 --- dom/base/Navigator.cpp | 4 +++- dom/network/Connection.cpp | 12 +++++++----- dom/network/Connection.h | 10 ++++++++-- dom/network/ConnectionMainThread.cpp | 5 +++-- dom/network/ConnectionMainThread.h | 3 ++- dom/network/ConnectionWorker.cpp | 7 +++++-- dom/network/ConnectionWorker.h | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-) diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 20f4863e6f93..0aad479540a8 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -1801,7 +1801,9 @@ network::Connection* Navigator::GetConnection(ErrorResult& aRv) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } - mConnection = network::Connection::CreateForWindow(mWindow); + nsCOMPtr doc = mWindow->GetExtantDoc(); + mConnection = network::Connection::CreateForWindow( + mWindow, nsContentUtils::ShouldResistFingerprinting(doc)); } return mConnection; diff --git a/dom/network/Connection.cpp b/dom/network/Connection.cpp index 63a30406b287..217a937cf6c5 100644 --- a/dom/network/Connection.cpp +++ b/dom/network/Connection.cpp @@ -23,8 +23,10 @@ namespace mozilla::dom::network { // we're not the only class with that name. NS_IMPL_ISUPPORTS_INHERITED0(dom::network::Connection, DOMEventTargetHelper) -Connection::Connection(nsPIDOMWindowInner* aWindow) +Connection::Connection(nsPIDOMWindowInner* aWindow, + bool aShouldResistFingerprinting) : DOMEventTargetHelper(aWindow), + mShouldResistFingerprinting(aShouldResistFingerprinting), mType(static_cast(kDefaultType)), mIsWifi(kDefaultIsWifi), mDHCPGateway(kDefaultDHCPGateway), @@ -63,16 +65,16 @@ void Connection::Update(ConnectionType aType, bool aIsWifi, mIsWifi = aIsWifi; mDHCPGateway = aDHCPGateway; - if (aNotify && previousType != aType && - !nsContentUtils::ShouldResistFingerprinting()) { + if (aNotify && previousType != aType && !mShouldResistFingerprinting) { DispatchTrustedEvent(CHANGE_EVENT_NAME); } } /* static */ -Connection* Connection::CreateForWindow(nsPIDOMWindowInner* aWindow) { +Connection* Connection::CreateForWindow(nsPIDOMWindowInner* aWindow, + bool aShouldResistFingerprinting) { MOZ_ASSERT(aWindow); - return new ConnectionMainThread(aWindow); + return new ConnectionMainThread(aWindow, aShouldResistFingerprinting); } /* static */ diff --git a/dom/network/Connection.h b/dom/network/Connection.h index ce51d5b64ed8..569bb603efb0 100644 --- a/dom/network/Connection.h +++ b/dom/network/Connection.h @@ -28,7 +28,8 @@ class Connection : public DOMEventTargetHelper { public: NS_DECL_ISUPPORTS_INHERITED - static Connection* CreateForWindow(nsPIDOMWindowInner* aWindow); + static Connection* CreateForWindow(nsPIDOMWindowInner* aWindow, + bool aShouldResistFingerprinting); static already_AddRefed CreateForWorker( WorkerPrivate* aWorkerPrivate, ErrorResult& aRv); @@ -60,7 +61,7 @@ class Connection : public DOMEventTargetHelper { IMPL_EVENT_HANDLER(typechange) protected: - Connection(nsPIDOMWindowInner* aWindow); + Connection(nsPIDOMWindowInner* aWindow, bool aShouldResistFingerprinting); virtual ~Connection(); void Update(ConnectionType aType, bool aIsWifi, uint32_t aDHCPGateway, @@ -69,6 +70,11 @@ class Connection : public DOMEventTargetHelper { virtual void ShutdownInternal() = 0; private: + /** + * If ResistFingerprinting is enabled or disabled. + */ + bool mShouldResistFingerprinting; + /** * The type of current connection. */ diff --git a/dom/network/ConnectionMainThread.cpp b/dom/network/ConnectionMainThread.cpp index cf04a6f84493..210cbaf01567 100644 --- a/dom/network/ConnectionMainThread.cpp +++ b/dom/network/ConnectionMainThread.cpp @@ -10,8 +10,9 @@ namespace mozilla::dom::network { -ConnectionMainThread::ConnectionMainThread(nsPIDOMWindowInner* aWindow) - : Connection(aWindow) { +ConnectionMainThread::ConnectionMainThread(nsPIDOMWindowInner* aWindow, + bool aShouldResistFingerprinting) + : Connection(aWindow, aShouldResistFingerprinting) { hal::RegisterNetworkObserver(this); hal::NetworkInformation networkInfo; diff --git a/dom/network/ConnectionMainThread.h b/dom/network/ConnectionMainThread.h index a10a00902363..b6ba587c811a 100644 --- a/dom/network/ConnectionMainThread.h +++ b/dom/network/ConnectionMainThread.h @@ -18,7 +18,8 @@ namespace network { class ConnectionMainThread final : public Connection, public hal::NetworkObserver { public: - explicit ConnectionMainThread(nsPIDOMWindowInner* aWindow); + explicit ConnectionMainThread(nsPIDOMWindowInner* aWindow, + bool aShouldResistFingerprinting); // For IObserver void Notify(const hal::NetworkInformation& aNetworkInfo) override; diff --git a/dom/network/ConnectionWorker.cpp b/dom/network/ConnectionWorker.cpp index 48e53c8f7fcd..c1b76a024456 100644 --- a/dom/network/ConnectionWorker.cpp +++ b/dom/network/ConnectionWorker.cpp @@ -140,7 +140,9 @@ class NotifyRunnable : public WorkerRunnable { /* static */ already_AddRefed ConnectionWorker::Create( WorkerPrivate* aWorkerPrivate, ErrorResult& aRv) { - RefPtr c = new ConnectionWorker(); + bool shouldResistFingerprinting = + aWorkerPrivate->ShouldResistFingerprinting(); + RefPtr c = new ConnectionWorker(shouldResistFingerprinting); c->mProxy = ConnectionProxy::Create(aWorkerPrivate, c); if (!c->mProxy) { aRv.ThrowTypeError("The Worker thread is shutting down."); @@ -161,7 +163,8 @@ already_AddRefed ConnectionWorker::Create( return c.forget(); } -ConnectionWorker::ConnectionWorker() : Connection(nullptr) { +ConnectionWorker::ConnectionWorker(bool aShouldResistFingerprinting) + : Connection(nullptr, aShouldResistFingerprinting) { MOZ_ASSERT(IsCurrentThreadRunningWorker()); } diff --git a/dom/network/ConnectionWorker.h b/dom/network/ConnectionWorker.h index 20831702f077..65a6087ae5b6 100644 --- a/dom/network/ConnectionWorker.h +++ b/dom/network/ConnectionWorker.h @@ -23,7 +23,7 @@ class ConnectionWorker final : public Connection { WorkerPrivate* aWorkerPrivate, ErrorResult& aRv); private: - ConnectionWorker(); + explicit ConnectionWorker(bool aShouldResistFingerprinting); ~ConnectionWorker(); virtual void ShutdownInternal() override;