Commit ae90275e authored by Honza Bambas's avatar Honza Bambas
Browse files

Bug 753990 - Allow appcache to work with a custom cache (profile) folder...

Bug 753990 - Allow appcache to work with a custom cache (profile) folder within a single application, r=michal.novotny
parent 3dcdd47a
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
#include "nsISupports.idl"

interface nsIArray;
interface nsILocalFile;

/**
 * Application caches can store a set of namespace entries that affect
@@ -78,7 +79,7 @@ interface nsIApplicationCacheNamespace : nsISupports
 * loads.  Inactive caches will be removed from the cache when they are
 * no longer referenced.
 */
[scriptable, uuid(32f83e3f-470c-4423-a86a-d35d1c215ccb)]
[scriptable, uuid(231e1e53-05c1-41b6-b9de-dbbcce9385c9)]
interface nsIApplicationCache : nsISupports
{
    /**
@@ -189,4 +190,10 @@ interface nsIApplicationCache : nsISupports
     * Get the most specific namespace matching a given key.
     */
    nsIApplicationCacheNamespace getMatchingNamespace(in ACString key);

    /**
     * If set, this offline cache is placed in a different directory
     * than the current application profile.
     */
    readonly attribute nsILocalFile cacheDirectory;
};
+18 −1
Original line number Diff line number Diff line
@@ -7,12 +7,13 @@
#include "nsISupports.idl"

interface nsIApplicationCache;
interface nsILocalFile;

/**
 * The application cache service manages the set of application cache
 * groups.
 */
[scriptable, uuid(10fdea21-1224-4c29-8507-8f3205a121d5)]
[scriptable, uuid(28adfdc7-6718-4b3e-bdb2-ecfefa3c8910)]
interface nsIApplicationCacheService : nsISupports
{
    /**
@@ -21,6 +22,22 @@ interface nsIApplicationCacheService : nsISupports
     */
    nsIApplicationCache createApplicationCache(in ACString group);

    /**
     * Create a new, empty application cache for the given cache
     * group residing in a custom directory with a custom quota.
     *
     * @param group
     *    URL of the manifest
     * @param directory
     *    Actually a reference to a profile directory where to
     *    create the OfflineCache sub-dir.
     * @param quota
     *    Optional override of the default quota.
     */
    nsIApplicationCache createCustomApplicationCache(in ACString group,
                                                     in nsILocalFile profileDir,
                                                     in PRInt32 quota);

    /**
     * Get an application cache object for the given client ID.
     */
+8 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#include "nsICacheInfoChannel.idl"

interface nsIFile;
interface nsILocalFile;

/**
 * A channel may optionally implement this interface to allow clients
@@ -17,7 +18,7 @@ interface nsIFile;
 *   3) Support for uniquely identifying cached data in cases when the URL
 *      is insufficient (e.g., HTTP form submission).
 */
[scriptable, uuid(830D4BCB-3E46-4011-9BDA-51A5D1AF891F)]
[scriptable, uuid(E2143B61-62FE-4da5-BE2E-E31981095889)]
interface nsICachingChannel : nsICacheInfoChannel
{
    /**
@@ -87,6 +88,12 @@ interface nsICachingChannel : nsICacheInfoChannel
     */
    attribute ACString offlineCacheClientID;

    /**
     * Override base (profile) directory to work with when accessing the cache.
     * When not specified, the current process' profile directory will be used.
     */
    attribute nsILocalFile profileDirectory;

    /**
     * Get the "file" where the cached data can be found.  This is valid for
     * as long as a reference to the cache token is held.  This may return
+17 −0
Original line number Diff line number Diff line
@@ -34,6 +34,23 @@ nsApplicationCacheService::CreateApplicationCache(const nsACString &group,
    return device->CreateApplicationCache(group, out);
}

NS_IMETHODIMP
nsApplicationCacheService::CreateCustomApplicationCache(const nsACString & group,
                                                        nsILocalFile *profileDir,
                                                        PRInt32 quota,
                                                        nsIApplicationCache **out)
{
    if (!mCacheService)
        return NS_ERROR_UNEXPECTED;

    nsRefPtr<nsOfflineCacheDevice> device;
    nsresult rv = mCacheService->GetCustomOfflineDevice(profileDir,
                                                        quota,
                                                        getter_AddRefs(device));
    NS_ENSURE_SUCCESS(rv, rv);
    return device->CreateApplicationCache(group, out);
}

NS_IMETHODIMP
nsApplicationCacheService::GetApplicationCache(const nsACString &clientID,
                                               nsIApplicationCache **out)
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ nsCacheEntry::nsCacheEntry(nsCString * key,
      mPredictedDataSize(-1),
      mDataSize(0),
      mCacheDevice(nsnull),
      mCustomDevice(nsnull),
      mData(nsnull)
{
    MOZ_COUNT_CTOR(nsCacheEntry);
Loading