Bug 543726 - [HTML5] dom/tests/mochitest/ajax/offline/test_foreign.html fails, r=bz
authorHonza Bambas <honzab.moz@firemni.cz>
Wed, 28 Apr 2010 13:40:15 +0200
changeset 41466 64250317a586d3819ca923832eb304726840cb43
parent 41465 a0d1abb96859b765e8e70b8d42e69347d7886cea
child 41467 c19d06de5c5cb88b095122c8e212352da337a0ce
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs543726
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 543726 - [HTML5] dom/tests/mochitest/ajax/offline/test_foreign.html fails, r=bz
content/base/src/nsContentSink.cpp
netwerk/protocol/http/src/nsHttpChannel.cpp
--- a/content/base/src/nsContentSink.cpp
+++ b/content/base/src/nsContentSink.cpp
@@ -98,16 +98,17 @@
 #include "nsPIDOMWindow.h"
 #include "mozAutoDocUpdate.h"
 #include "nsIWebNavigation.h"
 #include "nsIDocumentLoader.h"
 #include "nsICachingChannel.h"
 #include "nsICacheEntryDescriptor.h"
 #include "nsGenericHTMLElement.h"
 #include "nsHTMLDNSPrefetch.h"
+#include "nsISupportsPrimitives.h"
 
 PRLogModuleInfo* gContentSinkLogModuleInfo;
 
 class nsScriptLoaderObserverProxy : public nsIScriptLoaderObserver
 {
 public:
   nsScriptLoaderObserverProxy(nsIScriptLoaderObserver* aInner)
     : mInner(do_GetWeakReference(aInner))
@@ -945,24 +946,25 @@ nsresult
 nsContentSink::GetChannelCacheKey(nsIChannel* aChannel, nsACString& aCacheKey)
 {
   aCacheKey.Truncate();
 
   nsresult rv;
   nsCOMPtr<nsICachingChannel> cachingChannel = do_QueryInterface(aChannel, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsISupports> token;
-  rv = cachingChannel->GetCacheToken(getter_AddRefs(token));
+  nsCOMPtr<nsISupports> cacheKey;
+  rv = cachingChannel->GetCacheKey(getter_AddRefs(cacheKey));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsICacheEntryDescriptor> descriptor = do_QueryInterface(token, &rv);
+  nsCOMPtr<nsISupportsCString> 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;
 }
 
 nsresult
 nsContentSink::SelectDocAppCache(nsIApplicationCache *aLoadApplicationCache,
                                  nsIURI *aManifestURI,
--- a/netwerk/protocol/http/src/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/src/nsHttpChannel.cpp
@@ -5453,34 +5453,112 @@ nsHttpChannel::GetOfflineCacheToken(nsIS
 }
 
 NS_IMETHODIMP
 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<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
 nsHttpChannel::GetCacheKey(nsISupports **key)
 {
     nsresult rv;
     NS_ENSURE_ARG_POINTER(key);
 
     LOG(("nsHttpChannel::GetCacheKey [this=%p]\n", this));
 
     *key = nsnull;
 
-    nsCOMPtr<nsISupportsPRUint32> container =
-        do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv);
+    nsRefPtr<nsHttpChannelCacheKey> 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
 nsHttpChannel::SetCacheKey(nsISupports *key)
 {
     nsresult rv;
 
     LOG(("nsHttpChannel::SetCacheKey [this=%p key=%p]\n", this, key));