diff --git a/content/base/src/nsContentSink.cpp b/content/base/src/nsContentSink.cpp index 75a4a782cb5..6723d7e1b26 100644 --- a/content/base/src/nsContentSink.cpp +++ b/content/base/src/nsContentSink.cpp @@ -103,6 +103,7 @@ #include "nsICacheEntryDescriptor.h" #include "nsGenericHTMLElement.h" #include "nsHTMLDNSPrefetch.h" +#include "nsISupportsPrimitives.h" PRLogModuleInfo* gContentSinkLogModuleInfo; @@ -950,14 +951,15 @@ nsContentSink::GetChannelCacheKey(nsIChannel* aChannel, nsACString& aCacheKey) nsCOMPtr cachingChannel = do_QueryInterface(aChannel, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr token; - rv = cachingChannel->GetCacheToken(getter_AddRefs(token)); + nsCOMPtr cacheKey; + rv = cachingChannel->GetCacheKey(getter_AddRefs(cacheKey)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr descriptor = do_QueryInterface(token, &rv); + nsCOMPtr cacheKeyString = + do_QueryInterface(cacheKey, &rv); NS_ENSURE_SUCCESS(rv, rv); - rv = descriptor->GetKey(aCacheKey); + rv = cacheKeyString->GetData(aCacheKey); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; diff --git a/netwerk/protocol/http/src/nsHttpChannel.cpp b/netwerk/protocol/http/src/nsHttpChannel.cpp index 073a02092f6..fd898f00eea 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -5458,6 +5458,78 @@ nsHttpChannel::SetOfflineCacheToken(nsISupports *token) return NS_ERROR_NOT_IMPLEMENTED; } +class nsHttpChannelCacheKey : public nsISupportsPRUint32, + public nsISupportsCString +{ + NS_DECL_ISUPPORTS + + NS_DECL_NSISUPPORTSPRIMITIVE + NS_FORWARD_NSISUPPORTSPRUINT32(mSupportsPRUint32->) + + // Both interfaces declares toString method with the same signature. + // Thus we have to delegate only to nsISupportsPRUint32 implementation. + NS_SCRIPTABLE NS_IMETHOD GetData(nsACString & aData) + { + return mSupportsCString->GetData(aData); + } + NS_SCRIPTABLE NS_IMETHOD SetData(const nsACString & aData) + { + return mSupportsCString->SetData(aData); + } + +public: + nsresult SetData(PRUint32 aPostID, const nsACString& aKey); + +protected: + nsCOMPtr mSupportsPRUint32; + nsCOMPtr mSupportsCString; +}; + +NS_IMPL_ADDREF(nsHttpChannelCacheKey) +NS_IMPL_RELEASE(nsHttpChannelCacheKey) +NS_INTERFACE_TABLE_HEAD(nsHttpChannelCacheKey) +NS_INTERFACE_TABLE_BEGIN +NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsHttpChannelCacheKey, + nsISupports, nsISupportsPRUint32) +NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsHttpChannelCacheKey, + nsISupportsPrimitive, nsISupportsPRUint32) +NS_INTERFACE_TABLE_ENTRY(nsHttpChannelCacheKey, + nsISupportsPRUint32) +NS_INTERFACE_TABLE_ENTRY(nsHttpChannelCacheKey, + nsISupportsCString) +NS_INTERFACE_TABLE_END +NS_INTERFACE_TABLE_TAIL + +NS_IMETHODIMP nsHttpChannelCacheKey::GetType(PRUint16 *aType) +{ + NS_ENSURE_ARG_POINTER(aType); + + *aType = TYPE_PRUINT32; + return NS_OK; +} + +nsresult nsHttpChannelCacheKey::SetData(PRUint32 aPostID, + const nsACString& aKey) +{ + nsresult rv; + + mSupportsCString = + do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + mSupportsCString->SetData(aKey); + if (NS_FAILED(rv)) return rv; + + mSupportsPRUint32 = + do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + mSupportsPRUint32->SetData(aPostID); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + NS_IMETHODIMP nsHttpChannel::GetCacheKey(nsISupports **key) { @@ -5468,14 +5540,20 @@ nsHttpChannel::GetCacheKey(nsISupports **key) *key = nsnull; - nsCOMPtr container = - do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv); + nsRefPtr container = + new nsHttpChannelCacheKey(); + + if (!container) + return NS_ERROR_OUT_OF_MEMORY; + + nsCAutoString cacheKey; + rv = GenerateCacheKey(mPostID, cacheKey); if (NS_FAILED(rv)) return rv; - rv = container->SetData(mPostID); + rv = container->SetData(mPostID, cacheKey); if (NS_FAILED(rv)) return rv; - return CallQueryInterface(container, key); + return CallQueryInterface(container.get(), key); } NS_IMETHODIMP