Bug 543726 - [HTML5] dom/tests/mochitest/ajax/offline/test_foreign.html fails, r=bz

This commit is contained in:
Honza Bambas 2010-04-28 13:40:15 +02:00
parent 892105dff5
commit 48e46430ec
2 changed files with 88 additions and 8 deletions

View File

@ -103,6 +103,7 @@
#include "nsICacheEntryDescriptor.h" #include "nsICacheEntryDescriptor.h"
#include "nsGenericHTMLElement.h" #include "nsGenericHTMLElement.h"
#include "nsHTMLDNSPrefetch.h" #include "nsHTMLDNSPrefetch.h"
#include "nsISupportsPrimitives.h"
PRLogModuleInfo* gContentSinkLogModuleInfo; PRLogModuleInfo* gContentSinkLogModuleInfo;
@ -950,14 +951,15 @@ nsContentSink::GetChannelCacheKey(nsIChannel* aChannel, nsACString& aCacheKey)
nsCOMPtr<nsICachingChannel> cachingChannel = do_QueryInterface(aChannel, &rv); nsCOMPtr<nsICachingChannel> cachingChannel = do_QueryInterface(aChannel, &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupports> token; nsCOMPtr<nsISupports> cacheKey;
rv = cachingChannel->GetCacheToken(getter_AddRefs(token)); rv = cachingChannel->GetCacheKey(getter_AddRefs(cacheKey));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICacheEntryDescriptor> descriptor = do_QueryInterface(token, &rv); nsCOMPtr<nsISupportsCString> cacheKeyString =
do_QueryInterface(cacheKey, &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = descriptor->GetKey(aCacheKey); rv = cacheKeyString->GetData(aCacheKey);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return NS_OK; return NS_OK;

View File

@ -5458,6 +5458,78 @@ nsHttpChannel::SetOfflineCacheToken(nsISupports *token)
return NS_ERROR_NOT_IMPLEMENTED; 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<nsISupportsPRUint32> mSupportsPRUint32;
nsCOMPtr<nsISupportsCString> 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 NS_IMETHODIMP
nsHttpChannel::GetCacheKey(nsISupports **key) nsHttpChannel::GetCacheKey(nsISupports **key)
{ {
@ -5468,14 +5540,20 @@ nsHttpChannel::GetCacheKey(nsISupports **key)
*key = nsnull; *key = nsnull;
nsCOMPtr<nsISupportsPRUint32> container = nsRefPtr<nsHttpChannelCacheKey> container =
do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv); new nsHttpChannelCacheKey();
if (!container)
return NS_ERROR_OUT_OF_MEMORY;
nsCAutoString cacheKey;
rv = GenerateCacheKey(mPostID, cacheKey);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = container->SetData(mPostID); rv = container->SetData(mPostID, cacheKey);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
return CallQueryInterface(container, key); return CallQueryInterface(container.get(), key);
} }
NS_IMETHODIMP NS_IMETHODIMP