From 7cdd6f0ac4b4b236ca5177e0fc5e7621fd012878 Mon Sep 17 00:00:00 2001
From: Mike Perry <mikeperry-git@torproject.org>
Date: Tue, 4 Dec 2012 16:01:42 -0800
Subject: [PATCH 04/41] Add a string-based cacheKey.

Used for isolating cache according to same-origin policy.
---
 netwerk/base/public/nsICachingChannel.idl |  7 +++++++
 netwerk/protocol/http/nsHttpChannel.cpp   | 22 ++++++++++++++++++++++
 netwerk/protocol/http/nsHttpChannel.h     |  1 +
 3 files changed, 30 insertions(+)

diff --git a/netwerk/base/public/nsICachingChannel.idl b/netwerk/base/public/nsICachingChannel.idl
index 3119dd9..fd2ec89 100644
--- a/netwerk/base/public/nsICachingChannel.idl
+++ b/netwerk/base/public/nsICachingChannel.idl
@@ -65,6 +65,13 @@ interface nsICachingChannel : nsICacheInfoChannel
     attribute nsISupports cacheKey;
 
     /**
+     * Set/get the cache domain... uniquely identifies the data in the cache
+     * for this channel.  Holding a reference to this key does NOT prevent
+     * the cached data from being removed.
+     */
+    attribute AUTF8String cacheDomain;
+
+    /**
      * Specifies whether or not the data should be cached to a file.  This
      * may fail if the disk cache is not present.  The value of this attribute
      * is usually only settable during the processing of a channel's
diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
index a1c2a1f..6242ddc 100644
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -2725,6 +2725,12 @@ nsHttpChannel::AssembleCacheKey(const char *spec, uint32_t postID,
         cacheKey.Append(buf);
     }
 
+    if (strlen(mCacheDomain.get()) > 0) {
+        cacheKey.AppendLiteral("domain=");
+        cacheKey.Append(mCacheDomain.get());
+        cacheKey.AppendLiteral("&");
+    }
+
     if (!cacheKey.IsEmpty()) {
         cacheKey.AppendLiteral("uri=");
     }
@@ -5209,6 +5215,22 @@ nsHttpChannel::SetCacheTokenCachedCharset(const nsACString &aCharset)
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
+nsHttpChannel::GetCacheDomain(nsACString &value)
+{
+    value = mCacheDomain;
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsHttpChannel::SetCacheDomain(const nsACString &value)
+{
+    mCacheDomain = value;
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
 nsHttpChannel::GetCacheToken(nsISupports **token)
 {
     NS_ENSURE_ARG_POINTER(token);
diff --git a/netwerk/protocol/http/nsHttpChannel.h b/netwerk/protocol/http/nsHttpChannel.h
index d66415f..b1f0848 100644
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -298,6 +298,7 @@ private:
     nsCacheAccessMode                 mOfflineCacheAccess;
     uint32_t                          mOfflineCacheLastModifiedTime;
     nsCOMPtr<nsIApplicationCache>     mApplicationCacheForWrite;
+    nsCString                         mCacheDomain;
 
     // auth specific data
     nsCOMPtr<nsIHttpChannelAuthProvider> mAuthProvider;
-- 
1.8.1.2

