tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 515eb81e07f69c38a7d98a84d7f80dd42937b036
parent 32fb24708cfbf7a526b858c2600a2d44a4a82c49
Author: Randell Jesup <rjesup@mozilla.com>
Date:   Tue,  7 Oct 2025 14:07:06 +0000

Bug 1949981: Add code to clear Compression Dictionary entries r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D258164

Diffstat:
Mnetwerk/cache2/Dictionary.cpp | 23++++++++++++++++++++++-
Mnetwerk/cache2/Dictionary.h | 12+++++++++++-
2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/netwerk/cache2/Dictionary.cpp b/netwerk/cache2/Dictionary.cpp @@ -40,13 +40,14 @@ #include "mozilla/StaticPrefs_network.h" #include "mozilla/glean/NetwerkMetrics.h" +#include "mozilla/net/MozURL.h" #include "mozilla/net/NeckoCommon.h" #include "mozilla/net/NeckoParent.h" +#include "mozilla/net/NeckoChild.h" #include "LoadContextInfo.h" #include "mozilla/ipc/URIUtils.h" #include "SerializedLoadContext.h" -#include "mozilla/net/NeckoChild.h" #include "mozilla/dom/ContentParent.h" #include "mozilla/ClearOnShutdown.h" @@ -729,6 +730,26 @@ nsresult DictionaryCache::RemoveEntry(nsIURI* aURI, const nsACString& aKey) { return NS_ERROR_FAILURE; } +void DictionaryCache::Clear() { + // There may be active Prefetch()es running, note, and active + // fetches using dictionaries. They will stay alive until the + // channels using them go away. + mDictionaryCache.Clear(); +} + +// Remove a dictionary if it exists for the key given +void DictionaryCache::RemoveDictionaryFor(const nsACString& aKey) { + RefPtr<MozURL> url; + nsresult rv = MozURL::Init(getter_AddRefs(url), aKey); + if (NS_SUCCEEDED(rv)) { + nsDependentCSubstring prepath = url->PrePath(); + + if (auto origin = mDictionaryCache.Lookup(prepath)) { + origin.Data()->RemoveEntry(aKey); + } + } +} + // Return an entry via a callback (async). // If we don't have the origin in-memory, ask the cache for the origin, and // when we get it, parse the metadata to build a DictionaryOrigin. diff --git a/netwerk/cache2/Dictionary.h b/netwerk/cache2/Dictionary.h @@ -253,7 +253,11 @@ class DictionaryOriginReader; // singleton class class DictionaryCache final { private: - DictionaryCache() { Init(); } + DictionaryCache() { + nsresult rv = Init(); + Unused << rv; + MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv)); + } ~DictionaryCache() {} friend class DictionaryOriginReader; @@ -274,8 +278,14 @@ class DictionaryCache final { already_AddRefed<DictionaryCacheEntry> AddEntry( nsIURI* aURI, bool aNewEntry, DictionaryCacheEntry* aDictEntry); + // Remove a dictionary if it exists for the key given + void RemoveDictionaryFor(const nsACString& aKey); + nsresult RemoveEntry(nsIURI* aURI, const nsACString& aKey); + // Clears all ports at host + void Clear(); + // return an entry void GetDictionaryFor( nsIURI* aURI,