From 4a18021827f075687c45b8fb7d0d1cfaac719957 Mon Sep 17 00:00:00 2001 From: Honza Bambas Date: Wed, 20 Nov 2013 23:20:16 +0100 Subject: [PATCH] Bug 917432 - hook to webapps-clear-data notification, r=michal --- netwerk/build/nsNetModule.cpp | 2 +- netwerk/cache2/AppCacheStorage.cpp | 6 +- netwerk/cache2/CacheObserver.cpp | 96 ++++++++++ netwerk/cache2/CacheStorage.cpp | 6 +- netwerk/cache2/OldWrappers.cpp | 167 ++++++++++++++---- netwerk/cache2/OldWrappers.h | 7 +- netwerk/protocol/http/nsHttpHandler.cpp | 102 ----------- .../wyciwyg/nsWyciwygProtocolHandler.cpp | 69 +------- .../wyciwyg/nsWyciwygProtocolHandler.h | 5 - 9 files changed, 245 insertions(+), 215 deletions(-) diff --git a/netwerk/build/nsNetModule.cpp b/netwerk/build/nsNetModule.cpp index 5edab6ae6fec..2dedec0b4eb4 100644 --- a/netwerk/build/nsNetModule.cpp +++ b/netwerk/build/nsNetModule.cpp @@ -269,7 +269,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsViewSourceHandler) #ifdef NECKO_PROTOCOL_wyciwyg #include "nsWyciwygProtocolHandler.h" -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWyciwygProtocolHandler, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsWyciwygProtocolHandler) #endif #ifdef NECKO_PROTOCOL_websocket diff --git a/netwerk/cache2/AppCacheStorage.cpp b/netwerk/cache2/AppCacheStorage.cpp index a8b46878f033..f951fa6120f7 100644 --- a/netwerk/cache2/AppCacheStorage.cpp +++ b/netwerk/cache2/AppCacheStorage.cpp @@ -71,8 +71,12 @@ NS_IMETHODIMP AppCacheStorage::AsyncOpenURI(nsIURI *aURI, rv = noRefURI->GetAsciiSpec(cacheKey); NS_ENSURE_SUCCESS(rv, rv); + nsAutoCString scheme; + rv = noRefURI->GetScheme(scheme); + NS_ENSURE_SUCCESS(rv, rv); + nsRefPtr<_OldCacheLoad> appCacheLoad = - new _OldCacheLoad(cacheKey, aCallback, appCache, + new _OldCacheLoad(scheme, cacheKey, aCallback, appCache, LoadInfo(), WriteToDisk(), aFlags); rv = appCacheLoad->Start(); NS_ENSURE_SUCCESS(rv, rv); diff --git a/netwerk/cache2/CacheObserver.cpp b/netwerk/cache2/CacheObserver.cpp index 9df5cfb6da8c..6a4926ba65ef 100644 --- a/netwerk/cache2/CacheObserver.cpp +++ b/netwerk/cache2/CacheObserver.cpp @@ -6,7 +6,10 @@ #include "CacheStorageService.h" #include "CacheFileIOManager.h" +#include "LoadContextInfo.h" +#include "nsICacheStorage.h" #include "nsIObserverService.h" +#include "mozIApplicationClearPrivateDataParams.h" #include "mozilla/Services.h" #include "mozilla/Preferences.h" #include "nsServiceManagerUtils.h" @@ -46,6 +49,7 @@ CacheObserver::Init() obs->AddObserver(sSelf, "profile-before-change", true); obs->AddObserver(sSelf, "xpcom-shutdown", true); obs->AddObserver(sSelf, "last-pb-context-exited", true); + obs->AddObserver(sSelf, "webapps-clear-data", true); obs->AddObserver(sSelf, "memory-pressure", true); return NS_OK; @@ -91,6 +95,83 @@ bool const CacheObserver::UseNewCache() return true; } +namespace { // anon + +class CacheStorageEvictHelper +{ +public: + nsresult Run(mozIApplicationClearPrivateDataParams* aParams); + +private: + uint32_t mAppId; + nsresult ClearStorage(bool const aPrivate, + bool const aInBrowser, + bool const aAnonymous); +}; + +nsresult +CacheStorageEvictHelper::Run(mozIApplicationClearPrivateDataParams* aParams) +{ + nsresult rv; + + rv = aParams->GetAppId(&mAppId); + NS_ENSURE_SUCCESS(rv, rv); + + bool aBrowserOnly; + rv = aParams->GetBrowserOnly(&aBrowserOnly); + NS_ENSURE_SUCCESS(rv, rv); + + MOZ_ASSERT(mAppId != nsILoadContextInfo::UNKNOWN_APP_ID); + + // Clear all [private X anonymous] combinations + rv = ClearStorage(false, aBrowserOnly, false); + NS_ENSURE_SUCCESS(rv, rv); + rv = ClearStorage(false, aBrowserOnly, true); + NS_ENSURE_SUCCESS(rv, rv); + rv = ClearStorage(true, aBrowserOnly, false); + NS_ENSURE_SUCCESS(rv, rv); + rv = ClearStorage(true, aBrowserOnly, true); + NS_ENSURE_SUCCESS(rv, rv); + + return NS_OK; +} + +nsresult +CacheStorageEvictHelper::ClearStorage(bool const aPrivate, + bool const aInBrowser, + bool const aAnonymous) +{ + nsresult rv; + + nsRefPtr info = GetLoadContextInfo( + aPrivate, mAppId, aInBrowser, aAnonymous); + + nsCOMPtr storage; + nsRefPtr service = CacheStorageService::Self(); + NS_ENSURE_TRUE(service, NS_ERROR_FAILURE); + + // Clear disk storage + rv = service->DiskCacheStorage(info, false, getter_AddRefs(storage)); + NS_ENSURE_SUCCESS(rv, rv); + rv = storage->AsyncEvictStorage(nullptr); + NS_ENSURE_SUCCESS(rv, rv); + + // Clear memory storage + rv = service->MemoryCacheStorage(info, getter_AddRefs(storage)); + NS_ENSURE_SUCCESS(rv, rv); + rv = storage->AsyncEvictStorage(nullptr); + NS_ENSURE_SUCCESS(rv, rv); + + if (!aInBrowser) { + rv = ClearStorage(aPrivate, true, aAnonymous); + NS_ENSURE_SUCCESS(rv, rv); + } + + return NS_OK; +} + +} // anon + NS_IMETHODIMP CacheObserver::Observe(nsISupports* aSubject, const char* aTopic, @@ -133,6 +214,21 @@ CacheObserver::Observe(nsISupports* aSubject, return NS_OK; } + if (!strcmp(aTopic, "webapps-clear-data")) { + nsCOMPtr params = + do_QueryInterface(aSubject); + if (!params) { + NS_ERROR("'webapps-clear-data' notification's subject should be a mozIApplicationClearPrivateDataParams"); + return NS_ERROR_UNEXPECTED; + } + + CacheStorageEvictHelper helper; + nsresult rv = helper.Run(params); + NS_ENSURE_SUCCESS(rv, rv); + + return NS_OK; + } + if (!strcmp(aTopic, "memory-pressure")) { nsRefPtr service = CacheStorageService::Self(); if (service) diff --git a/netwerk/cache2/CacheStorage.cpp b/netwerk/cache2/CacheStorage.cpp index 29b4e04e16c7..d659d14a0ade 100644 --- a/netwerk/cache2/CacheStorage.cpp +++ b/netwerk/cache2/CacheStorage.cpp @@ -67,8 +67,12 @@ NS_IMETHODIMP CacheStorage::AsyncOpenURI(nsIURI *aURI, rv = noRefURI->GetAsciiSpec(cacheKey); NS_ENSURE_SUCCESS(rv, rv); + nsAutoCString scheme; + rv = noRefURI->GetScheme(scheme); + NS_ENSURE_SUCCESS(rv, rv); + nsRefPtr<_OldCacheLoad> appCacheLoad = - new _OldCacheLoad(cacheKey, aCallback, appCache, + new _OldCacheLoad(scheme, cacheKey, aCallback, appCache, LoadInfo(), WriteToDisk(), aFlags); rv = appCacheLoad->Start(); NS_ENSURE_SUCCESS(rv, rv); diff --git a/netwerk/cache2/OldWrappers.cpp b/netwerk/cache2/OldWrappers.cpp index 02405e4bbf87..b0c0c56938ff 100644 --- a/netwerk/cache2/OldWrappers.cpp +++ b/netwerk/cache2/OldWrappers.cpp @@ -361,8 +361,9 @@ NS_IMETHODIMP _OldCacheEntryWrapper::HasWriteAccess(bool aWriteAllowed_unused, b namespace { // anon -void +nsresult GetCacheSessionNameForStoragePolicy( + nsCSubstring const &scheme, nsCacheStoragePolicy storagePolicy, bool isPrivate, uint32_t appId, @@ -371,27 +372,67 @@ GetCacheSessionNameForStoragePolicy( { MOZ_ASSERT(!isPrivate || storagePolicy == nsICache::STORE_IN_MEMORY); - switch (storagePolicy) { + // HTTP + if (scheme.Equals(NS_LITERAL_CSTRING("http")) || + scheme.Equals(NS_LITERAL_CSTRING("https"))) { + switch (storagePolicy) { case nsICache::STORE_IN_MEMORY: - sessionName.AssignASCII(isPrivate ? "HTTP-memory-only-PB" : "HTTP-memory-only"); + if (isPrivate) + sessionName.Assign(NS_LITERAL_CSTRING("HTTP-memory-only-PB")); + else + sessionName.Assign(NS_LITERAL_CSTRING("HTTP-memory-only")); break; case nsICache::STORE_OFFLINE: - sessionName.AssignLiteral("HTTP-offline"); + // XXX This is actually never used, only added to prevent + // any compatibility damage. + sessionName.Assign(NS_LITERAL_CSTRING("HTTP-offline")); break; default: - sessionName.AssignLiteral("HTTP"); + sessionName.Assign(NS_LITERAL_CSTRING("HTTP")); break; + } } + // WYCIWYG + else if (scheme.Equals(NS_LITERAL_CSTRING("wyciwyg"))) { + if (isPrivate) + sessionName.Assign(NS_LITERAL_CSTRING("wyciwyg-private")); + else + sessionName.Assign(NS_LITERAL_CSTRING("wyciwyg")); + } + // FTP + else if (scheme.Equals(NS_LITERAL_CSTRING("ftp"))) { + if (isPrivate) + sessionName.Assign(NS_LITERAL_CSTRING("FTP-private")); + else + sessionName.Assign(NS_LITERAL_CSTRING("FTP")); + } + // all remaining URL scheme + else { + // Since with the new API a consumer cannot specify its own session name + // and partitioning of the cache is handled stricly only by the cache + // back-end internally, we will use a separate session name to pretend + // functionality of the new API wrapping the Darin's cache for all other + // URL schemes. + // Deliberately omitting |anonymous| since other session types don't + // recognize it too. + sessionName.Assign(NS_LITERAL_CSTRING("other")); + if (isPrivate) + sessionName.Append(NS_LITERAL_CSTRING("-private")); + } + if (appId != nsILoadContextInfo::NO_APP_ID || inBrowser) { sessionName.Append('~'); sessionName.AppendInt(appId); sessionName.Append('~'); sessionName.AppendInt(inBrowser); } + + return NS_OK; } nsresult -GetCacheSession(bool aWriteToDisk, +GetCacheSession(nsCSubstring const &aScheme, + bool aWriteToDisk, nsILoadContextInfo* aLoadInfo, nsIApplicationCache* aAppCache, nsICacheSession** _result) @@ -411,12 +452,14 @@ GetCacheSession(bool aWriteToDisk, aAppCache->GetClientID(clientId); } else { - GetCacheSessionNameForStoragePolicy( + rv = GetCacheSessionNameForStoragePolicy( + aScheme, storagePolicy, aLoadInfo->IsPrivate(), aLoadInfo->AppId(), aLoadInfo->IsInBrowserElement(), clientId); + NS_ENSURE_SUCCESS(rv, rv); } LOG((" GetCacheSession for client=%s, policy=%d", clientId.get(), storagePolicy)); @@ -455,13 +498,15 @@ GetCacheSession(bool aWriteToDisk, NS_IMPL_ISUPPORTS_INHERITED1(_OldCacheLoad, nsRunnable, nsICacheListener) -_OldCacheLoad::_OldCacheLoad(nsCSubstring const& aCacheKey, +_OldCacheLoad::_OldCacheLoad(nsCSubstring const& aScheme, + nsCSubstring const& aCacheKey, nsICacheEntryOpenCallback* aCallback, nsIApplicationCache* aAppCache, nsILoadContextInfo* aLoadInfo, bool aWriteToDisk, uint32_t aFlags) - : mCacheKey(aCacheKey) + : mScheme(aScheme) + , mCacheKey(aCacheKey) , mCallback(aCallback) , mLoadInfo(GetLoadContextInfo(aLoadInfo)) , mFlags(aFlags) @@ -528,7 +573,8 @@ _OldCacheLoad::Run() if (!NS_IsMainThread()) { nsCOMPtr session; - rv = GetCacheSession(mWriteToDisk, mLoadInfo, mAppCache, getter_AddRefs(session)); + rv = GetCacheSession(mScheme, mWriteToDisk, mLoadInfo, mAppCache, + getter_AddRefs(session)); if (NS_SUCCEEDED(rv)) { // AsyncOpenCacheEntry isn't really async when its called on the // cache service thread. @@ -697,8 +743,8 @@ NS_IMETHODIMP _OldStorage::AsyncOpenURI(nsIURI *aURI, nsresult rv; - nsAutoCString cacheKey; - rv = AssembleCacheKey(aURI, aIdExtension, cacheKey); + nsAutoCString cacheKey, scheme; + rv = AssembleCacheKey(aURI, aIdExtension, cacheKey, scheme); NS_ENSURE_SUCCESS(rv, rv); if (!mAppCache && (mLookupAppCache || mOfflineStorage)) { @@ -712,7 +758,7 @@ NS_IMETHODIMP _OldStorage::AsyncOpenURI(nsIURI *aURI, } nsRefPtr<_OldCacheLoad> cacheLoad = - new _OldCacheLoad(cacheKey, aCallback, mAppCache, + new _OldCacheLoad(scheme, cacheKey, aCallback, mAppCache, mLoadInfo, mWriteToDisk, aFlags); rv = cacheLoad->Start(); @@ -728,12 +774,13 @@ NS_IMETHODIMP _OldStorage::AsyncDoomURI(nsIURI *aURI, const nsACString & aIdExte nsresult rv; - nsAutoCString cacheKey; - rv = AssembleCacheKey(aURI, aIdExtension, cacheKey); + nsAutoCString cacheKey, scheme; + rv = AssembleCacheKey(aURI, aIdExtension, cacheKey, scheme); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr session; - rv = GetCacheSession(mWriteToDisk, mLoadInfo, mAppCache, getter_AddRefs(session)); + rv = GetCacheSession(scheme, mWriteToDisk, mLoadInfo, mAppCache, + getter_AddRefs(session)); NS_ENSURE_SUCCESS(rv, rv); nsRefPtr cb = aCallback @@ -776,12 +823,44 @@ NS_IMETHODIMP _OldStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCallbac } } else { - nsCOMPtr session; - rv = GetCacheSession(mWriteToDisk, mLoadInfo, mAppCache, getter_AddRefs(session)); - NS_ENSURE_SUCCESS(rv, rv); + if (mAppCache) { + nsCOMPtr session; + rv = GetCacheSession(EmptyCString(), + mWriteToDisk, mLoadInfo, mAppCache, + getter_AddRefs(session)); + NS_ENSURE_SUCCESS(rv, rv); - rv = session->EvictEntries(); - NS_ENSURE_SUCCESS(rv, rv); + rv = session->EvictEntries(); + NS_ENSURE_SUCCESS(rv, rv); + } + else { + // Oh, I'll be so happy when session names are gone... + nsCOMPtr session; + rv = GetCacheSession(NS_LITERAL_CSTRING("http"), + mWriteToDisk, mLoadInfo, mAppCache, + getter_AddRefs(session)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = session->EvictEntries(); + NS_ENSURE_SUCCESS(rv, rv); + + rv = GetCacheSession(NS_LITERAL_CSTRING("wyciwyg"), + mWriteToDisk, mLoadInfo, mAppCache, + getter_AddRefs(session)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = session->EvictEntries(); + NS_ENSURE_SUCCESS(rv, rv); + + // This clears any data from scheme other then http, wyciwyg or ftp + rv = GetCacheSession(EmptyCString(), + mWriteToDisk, mLoadInfo, mAppCache, + getter_AddRefs(session)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = session->EvictEntries(); + NS_ENSURE_SUCCESS(rv, rv); + } } if (aCallback) { @@ -841,33 +920,49 @@ NS_IMETHODIMP _OldStorage::AsyncVisitStorage(nsICacheStorageVisitor* aVisitor, nsresult _OldStorage::AssembleCacheKey(nsIURI *aURI, nsACString const & aIdExtension, - nsACString & aCacheKey) + nsACString & aCacheKey, + nsACString & aScheme) { // Copied from nsHttpChannel::AssembleCacheKey aCacheKey.Truncate(); - if (mLoadInfo->IsAnonymous()) { - aCacheKey.AssignLiteral("anon&"); - } - - if (!aIdExtension.IsEmpty()) { - aCacheKey.AppendPrintf("id=%s&", aIdExtension.BeginReading()); - } - nsresult rv; - nsCOMPtr noRefURI; - rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI)); + rv = aURI->GetScheme(aScheme); NS_ENSURE_SUCCESS(rv, rv); nsAutoCString uriSpec; - rv = noRefURI->GetAsciiSpec(uriSpec); - NS_ENSURE_SUCCESS(rv, rv); + if (aScheme.Equals(NS_LITERAL_CSTRING("http")) || + aScheme.Equals(NS_LITERAL_CSTRING("https"))) { + if (mLoadInfo->IsAnonymous()) { + aCacheKey.AssignLiteral("anon&"); + } - if (!aCacheKey.IsEmpty()) { - aCacheKey.AppendLiteral("uri="); + if (!aIdExtension.IsEmpty()) { + aCacheKey.AppendPrintf("id=%s&", aIdExtension.BeginReading()); + } + + nsCOMPtr noRefURI; + rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = noRefURI->GetAsciiSpec(uriSpec); + NS_ENSURE_SUCCESS(rv, rv); + + if (!aCacheKey.IsEmpty()) { + aCacheKey.AppendLiteral("uri="); + } } + else if (aScheme.Equals(NS_LITERAL_CSTRING("wyciwyg"))) { + rv = aURI->GetSpec(uriSpec); + NS_ENSURE_SUCCESS(rv, rv); + } + else { + rv = aURI->GetAsciiSpec(uriSpec); + NS_ENSURE_SUCCESS(rv, rv); + } + aCacheKey.Append(uriSpec); return NS_OK; diff --git a/netwerk/cache2/OldWrappers.h b/netwerk/cache2/OldWrappers.h index 8b1eb4416bf2..229c3567bf21 100644 --- a/netwerk/cache2/OldWrappers.h +++ b/netwerk/cache2/OldWrappers.h @@ -61,7 +61,8 @@ public: NS_DECL_NSIRUNNABLE NS_DECL_NSICACHELISTENER - _OldCacheLoad(nsCSubstring const& aCacheKey, + _OldCacheLoad(nsCSubstring const& aScheme, + nsCSubstring const& aCacheKey, nsICacheEntryOpenCallback* aCallback, nsIApplicationCache* aAppCache, nsILoadContextInfo* aLoadInfo, @@ -76,6 +77,7 @@ private: nsCOMPtr mCacheThread; + nsCString mScheme; nsCString mCacheKey; nsCOMPtr mCallback; nsCOMPtr mLoadInfo; @@ -108,7 +110,8 @@ public: private: virtual ~_OldStorage(); - nsresult AssembleCacheKey(nsIURI *aURI, nsACString const & aIdExtension, nsACString & _result); + nsresult AssembleCacheKey(nsIURI *aURI, nsACString const & aIdExtension, + nsACString & aCacheKey, nsACString & aScheme); nsresult ChooseApplicationCache(nsCSubstring const &cacheKey, nsIApplicationCache** aCache); nsCOMPtr mLoadInfo; diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 6a8c8f207130..f7d2608591f7 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -20,8 +20,6 @@ #include "nsIHttpChannel.h" #include "nsIStandardURL.h" #include "LoadContextInfo.h" -#include "nsICacheStorageService.h" -#include "nsICacheStorage.h" #include "nsCategoryManagerUtils.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" @@ -357,7 +355,6 @@ nsHttpHandler::Init() mObserverService->AddObserver(this, "net:prune-dead-connections", true); mObserverService->AddObserver(this, "net:failed-to-process-uri-content", true); mObserverService->AddObserver(this, "last-pb-context-exited", true); - mObserverService->AddObserver(this, "webapps-clear-data", true); } MakeNewRequestTokenBucket(); @@ -1748,84 +1745,6 @@ nsHttpHandler::GetCacheSessionNameForStoragePolicy( // nsHttpHandler::nsIObserver //----------------------------------------------------------------------------- -namespace { // anon - -class CacheStorageEvictHelper -{ -public: - CacheStorageEvictHelper(uint32_t appId, bool browserOnly) - : mAppId(appId), mBrowserOnly(browserOnly) { } - - nsresult Run(); - -private: - nsCOMPtr mCacheStorageService; - uint32_t mAppId; - bool mBrowserOnly; - - nsresult ClearStorage(bool const aPrivate, - bool const aInBrowser, - bool const aAnonymous); -}; - -nsresult -CacheStorageEvictHelper::Run() -{ - nsresult rv; - - mCacheStorageService = do_GetService( - "@mozilla.org/netwerk/cache-storage-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - // Clear all [private X anonymous] combinations - rv = ClearStorage(false, mBrowserOnly, false); - NS_ENSURE_SUCCESS(rv, rv); - rv = ClearStorage(false, mBrowserOnly, true); - NS_ENSURE_SUCCESS(rv, rv); - rv = ClearStorage(true, mBrowserOnly, false); - NS_ENSURE_SUCCESS(rv, rv); - rv = ClearStorage(true, mBrowserOnly, true); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -nsresult -CacheStorageEvictHelper::ClearStorage(bool const aPrivate, - bool const aInBrowser, - bool const aAnonymous) -{ - nsresult rv; - - nsRefPtr info = GetLoadContextInfo( - aPrivate, mAppId, aInBrowser, aAnonymous); - - nsCOMPtr storage; - - // Clear disk storage - rv = mCacheStorageService->DiskCacheStorage(info, false, - getter_AddRefs(storage)); - NS_ENSURE_SUCCESS(rv, rv); - rv = storage->AsyncEvictStorage(nullptr); - NS_ENSURE_SUCCESS(rv, rv); - - // Clear memory storage - rv = mCacheStorageService->MemoryCacheStorage(info, - getter_AddRefs(storage)); - NS_ENSURE_SUCCESS(rv, rv); - rv = storage->AsyncEvictStorage(nullptr); - NS_ENSURE_SUCCESS(rv, rv); - - if (!aInBrowser) { - rv = ClearStorage(aPrivate, true, aAnonymous); - NS_ENSURE_SUCCESS(rv, rv); - } - - return NS_OK; -} - -} // anon - NS_IMETHODIMP nsHttpHandler::Observe(nsISupports *subject, const char *topic, @@ -1878,27 +1797,6 @@ nsHttpHandler::Observe(nsISupports *subject, else if (strcmp(topic, "last-pb-context-exited") == 0) { mPrivateAuthCache.ClearAll(); } - else if (strcmp(topic, "webapps-clear-data") == 0) { - nsCOMPtr params = - do_QueryInterface(subject); - if (!params) { - NS_ERROR("'webapps-clear-data' notification's subject should be a mozIApplicationClearPrivateDataParams"); - return NS_ERROR_UNEXPECTED; - } - - uint32_t appId; - bool browserOnly; - nsresult rv = params->GetAppId(&appId); - NS_ENSURE_SUCCESS(rv, rv); - rv = params->GetBrowserOnly(&browserOnly); - NS_ENSURE_SUCCESS(rv, rv); - - MOZ_ASSERT(appId != NECKO_UNKNOWN_APP_ID); - - CacheStorageEvictHelper helper(appId, browserOnly); - rv = helper.Run(); - NS_ENSURE_SUCCESS(rv, rv); - } return NS_OK; } diff --git a/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp b/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp index 74b04bcd628d..0d6610144c05 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp +++ b/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp @@ -38,37 +38,6 @@ nsWyciwygProtocolHandler::~nsWyciwygProtocolHandler() LOG(("Deleting nsWyciwygProtocolHandler [this=%p]\n", this)); } -nsresult -nsWyciwygProtocolHandler::Init() -{ - nsCOMPtr obs = mozilla::services::GetObserverService(); - if (obs) { - obs->AddObserver(this, "webapps-clear-data", true); - } - return NS_OK; -} - -static void -EvictCacheSession(uint32_t aAppId, - bool aInBrowser, - bool aPrivateBrowsing) -{ - nsAutoCString clientId; - nsWyciwygProtocolHandler::GetCacheSessionName(aAppId, aInBrowser, - aPrivateBrowsing, - clientId); - nsCOMPtr serv = - do_GetService(NS_CACHESERVICE_CONTRACTID); - nsCOMPtr session; - nsresult rv = serv->CreateSession(clientId.get(), - nsICache::STORE_ANYWHERE, - nsICache::STREAM_BASED, - getter_AddRefs(session)); - if (NS_SUCCEEDED(rv) && session) { - session->EvictEntries(); - } -} - void nsWyciwygProtocolHandler::GetCacheSessionName(uint32_t aAppId, bool aInBrowser, @@ -90,42 +59,8 @@ nsWyciwygProtocolHandler::GetCacheSessionName(uint32_t aAppId, aSessionName.AppendInt(aInBrowser); } -NS_IMETHODIMP -nsWyciwygProtocolHandler::Observe(nsISupports *subject, - const char *topic, - const PRUnichar *data) -{ - if (strcmp(topic, "webapps-clear-data") == 0) { - nsCOMPtr params = - do_QueryInterface(subject); - if (!params) { - NS_ERROR("'webapps-clear-data' notification's subject should be a mozIApplicationClearPrivateDataParams"); - return NS_ERROR_UNEXPECTED; - } - - uint32_t appId; - bool browserOnly; - nsresult rv = params->GetAppId(&appId); - NS_ENSURE_SUCCESS(rv, rv); - rv = params->GetBrowserOnly(&browserOnly); - NS_ENSURE_SUCCESS(rv, rv); - - MOZ_ASSERT(appId != NECKO_UNKNOWN_APP_ID); - - EvictCacheSession(appId, browserOnly, false); - EvictCacheSession(appId, browserOnly, true); - if (!browserOnly) { - EvictCacheSession(appId, true, false); - EvictCacheSession(appId, true, true); - } - } - return NS_OK; -} - -NS_IMPL_ISUPPORTS3(nsWyciwygProtocolHandler, - nsIProtocolHandler, - nsIObserver, - nsISupportsWeakReference) +NS_IMPL_ISUPPORTS1(nsWyciwygProtocolHandler, + nsIProtocolHandler) //////////////////////////////////////////////////////////////////////////////// // nsIProtocolHandler methods: diff --git a/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.h b/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.h index 1a402fa78525..4b79d694ed1d 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.h +++ b/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.h @@ -8,17 +8,12 @@ #define nsWyciwygProtocolHandler_h___ #include "nsIProtocolHandler.h" -#include "nsIObserver.h" -#include "nsWeakReference.h" class nsWyciwygProtocolHandler : public nsIProtocolHandler - , public nsIObserver - , public nsSupportsWeakReference { public: NS_DECL_ISUPPORTS NS_DECL_NSIPROTOCOLHANDLER - NS_DECL_NSIOBSERVER nsWyciwygProtocolHandler(); virtual ~nsWyciwygProtocolHandler();