diff --git a/netwerk/build/nsNetModule.cpp b/netwerk/build/nsNetModule.cpp index cd828f38bacf..28df96c8ff4d 100644 --- a/netwerk/build/nsNetModule.cpp +++ b/netwerk/build/nsNetModule.cpp @@ -270,7 +270,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/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index f799ac9ffecf..117b83c1f36b 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -2468,6 +2468,19 @@ nsHttpChannel::OnOfflineCacheEntryAvailable(nsICacheEntryDescriptor *aEntry, return OpenNormalCacheEntry(usingSSL); } +static void +GetAppInfo(nsIChannel* aChannel, uint32_t* aAppId, bool* aIsInBrowser) +{ + nsCOMPtr loadContext; + NS_QueryNotificationCallbacks(aChannel, loadContext); + *aAppId = NECKO_NO_APP_ID; + *aIsInBrowser = false; + if (loadContext) { + loadContext->GetAppId(aAppId); + loadContext->GetIsInBrowserElement(aIsInBrowser); + } +} + nsresult nsHttpChannel::OpenNormalCacheEntry(bool usingSSL) { @@ -2475,9 +2488,9 @@ nsHttpChannel::OpenNormalCacheEntry(bool usingSSL) nsresult rv; - uint32_t appId = NECKO_NO_APP_ID; - bool isInBrowser = false; - NS_GetAppInfo(this, &appId, &isInBrowser); + uint32_t appId; + bool isInBrowser; + GetAppInfo(this, &appId, &isInBrowser); nsCacheStoragePolicy storagePolicy = DetermineStoragePolicy(); nsAutoCString clientID; @@ -5848,9 +5861,9 @@ nsHttpChannel::DoInvalidateCacheEntry(const nsCString &key) // The logic below deviates from the original logic in OpenCacheEntry on // one point by using only READ_ONLY access-policy. I think this is safe. - uint32_t appId = NECKO_NO_APP_ID; - bool isInBrowser = false; - NS_GetAppInfo(this, &appId, &isInBrowser); + uint32_t appId; + bool isInBrowser; + GetAppInfo(this, &appId, &isInBrowser); // First, find session holding the cache-entry - use current storage-policy nsCacheStoragePolicy storagePolicy = DetermineStoragePolicy(); diff --git a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp index 1edc79c7ff26..586e4cb31e15 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp +++ b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp @@ -692,18 +692,10 @@ nsWyciwygChannel::OpenCacheEntry(const nsACString & aCacheKey, else storagePolicy = nsICache::STORE_ANYWHERE; - uint32_t appId = NECKO_NO_APP_ID; - bool isInBrowser = false; - NS_GetAppInfo(this, &appId, &isInBrowser); - nsCOMPtr cacheSession; - nsAutoCString sessionName; - nsWyciwygProtocolHandler::GetCacheSessionName(appId, isInBrowser, - mPrivateBrowsing, - sessionName); - // Open a stream based cache session. - rv = cacheService->CreateSession(sessionName.get(), storagePolicy, true, + const char* sessionName = mPrivateBrowsing ? "wyciwyg-private" : "wyciwyg"; + rv = cacheService->CreateSession(sessionName, storagePolicy, true, getter_AddRefs(cacheSession)); if (!cacheSession) return NS_ERROR_FAILURE; diff --git a/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp b/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp index e7e17256cdee..d7d250023318 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp +++ b/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.cpp @@ -13,10 +13,6 @@ #include "nsServiceManagerUtils.h" #include "plstr.h" #include "nsNetUtil.h" -#include "nsIObserverService.h" -#include "mozIApplicationClearPrivateDataParams.h" -#include "nsICacheService.h" -#include "nsICacheSession.h" #include "mozilla/net/NeckoChild.h" @@ -40,94 +36,7 @@ nsWyciwygProtocolHandler::~nsWyciwygProtocolHandler() LOG(("Deleting nsWyciwygProtocolHandler [this=%x]\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, - bool aPrivateBrowsing, - nsACString& aSessionName) -{ - if (aPrivateBrowsing) { - aSessionName.AssignLiteral("wyciwyg-private"); - } else { - aSessionName.AssignLiteral("wyciwyg"); - } - if (aAppId == NECKO_NO_APP_ID && !aInBrowser) { - return; - } - - aSessionName.Append('~'); - aSessionName.AppendInt(aAppId); - aSessionName.Append('~'); - 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..47005fd037f2 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.h +++ b/netwerk/protocol/wyciwyg/nsWyciwygProtocolHandler.h @@ -8,27 +8,16 @@ #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(); - - nsresult Init(); - - static void GetCacheSessionName(uint32_t aAppId, - bool aInBrowser, - bool aPrivateBrowsing, - nsACString& aSessionName); }; #endif /* nsWyciwygProtocolHandler_h___ */