Backed out changeset b99c87fb77d3 (bug 829043)

This commit is contained in:
Josh Matthews 2013-01-10 22:50:27 +01:00
parent 0f55bbfb73
commit a0eced1fb7
5 changed files with 24 additions and 121 deletions

View File

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

View File

@ -2468,6 +2468,19 @@ nsHttpChannel::OnOfflineCacheEntryAvailable(nsICacheEntryDescriptor *aEntry,
return OpenNormalCacheEntry(usingSSL);
}
static void
GetAppInfo(nsIChannel* aChannel, uint32_t* aAppId, bool* aIsInBrowser)
{
nsCOMPtr<nsILoadContext> 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();

View File

@ -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<nsICacheSession> 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;

View File

@ -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<nsIObserverService> 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<nsICacheService> serv =
do_GetService(NS_CACHESERVICE_CONTRACTID);
nsCOMPtr<nsICacheSession> 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<mozIApplicationClearPrivateDataParams> 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:

View File

@ -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___ */