uriloader/prefetch/OfflineCacheUpdateGlue.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsOfflineCacheUpdateGlue_h
     7 #define nsOfflineCacheUpdateGlue_h
     9 #include "nsIOfflineCacheUpdate.h"
    11 #include "nsCOMPtr.h"
    12 #include "nsAutoPtr.h"
    13 #include "nsString.h"
    14 #include "nsWeakReference.h"
    15 #include "mozilla/Attributes.h"
    17 class nsOfflineCacheUpdate;
    19 namespace mozilla {
    20 namespace docshell {
    22 // Like FORWARD_SAFE except methods:
    23 //    Schedule
    24 //    Init
    25 #define NS_ADJUSTED_FORWARD_NSIOFFLINECACHEUPDATE(_to) \
    26   NS_IMETHOD GetStatus(uint16_t *aStatus) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetStatus(aStatus); } \
    27   NS_IMETHOD GetPartial(bool *aPartial) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetPartial(aPartial); } \
    28   NS_IMETHOD GetIsUpgrade(bool *aIsUpgrade) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetIsUpgrade(aIsUpgrade); } \
    29   NS_IMETHOD GetUpdateDomain(nsACString & aUpdateDomain) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetUpdateDomain(aUpdateDomain); } \
    30   NS_IMETHOD GetManifestURI(nsIURI **aManifestURI) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetManifestURI(aManifestURI); } \
    31   NS_IMETHOD GetSucceeded(bool *aSucceeded) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetSucceeded(aSucceeded); } \
    32   NS_IMETHOD InitPartial(nsIURI *aManifestURI, const nsACString & aClientID, nsIURI *aDocumentURI) { return !_to ? NS_ERROR_NULL_POINTER : _to->InitPartial(aManifestURI, aClientID, aDocumentURI); } \
    33   NS_IMETHOD InitForUpdateCheck(nsIURI *aManifestURI, uint32_t aAppID, bool aInBrowser, nsIObserver *aObserver) { return !_to ? NS_ERROR_NULL_POINTER : _to->InitForUpdateCheck(aManifestURI, aAppID, aInBrowser, aObserver); } \
    34   NS_IMETHOD AddDynamicURI(nsIURI *aURI) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddDynamicURI(aURI); } \
    35   NS_IMETHOD AddObserver(nsIOfflineCacheUpdateObserver *aObserver, bool aHoldWeak) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddObserver(aObserver, aHoldWeak); } \
    36   NS_IMETHOD RemoveObserver(nsIOfflineCacheUpdateObserver *aObserver) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveObserver(aObserver); } \
    37   NS_IMETHOD GetByteProgress(uint64_t * _result) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetByteProgress(_result); } \
    38   NS_IMETHOD Cancel() { return !_to ? NS_ERROR_NULL_POINTER : _to->Cancel(); }
    40 class OfflineCacheUpdateGlue MOZ_FINAL : public nsSupportsWeakReference
    41                                        , public nsIOfflineCacheUpdate
    42                                        , public nsIOfflineCacheUpdateObserver
    43 {
    44 public:
    45     NS_DECL_ISUPPORTS
    47 private:
    48     nsIOfflineCacheUpdate* EnsureUpdate();
    50 public:
    51     NS_ADJUSTED_FORWARD_NSIOFFLINECACHEUPDATE(EnsureUpdate())
    52     NS_IMETHOD Schedule(void);
    53     NS_IMETHOD Init(nsIURI *aManifestURI, 
    54                     nsIURI *aDocumentURI,
    55                     nsIDOMDocument *aDocument,
    56                     nsIFile *aCustomProfileDir,
    57                     uint32_t aAppID,
    58                     bool aInBrowser);
    60     NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER
    62     OfflineCacheUpdateGlue();
    63     ~OfflineCacheUpdateGlue();
    65     void SetDocument(nsIDOMDocument *aDocument);
    67 private:
    68     nsRefPtr<nsOfflineCacheUpdate> mUpdate;
    70     /* Document that requested this update */
    71     nsCOMPtr<nsIDOMDocument> mDocument;
    72     nsCOMPtr<nsIURI> mDocumentURI;
    73 };
    75 }
    76 }
    78 #endif

mercurial