dom/src/offline/nsDOMOfflineResourceList.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     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 nsDOMOfflineResourceList_h___
     7 #define nsDOMOfflineResourceList_h___
     9 #include "nscore.h"
    10 #include "nsIDOMOfflineResourceList.h"
    11 #include "nsIApplicationCache.h"
    12 #include "nsIApplicationCacheContainer.h"
    13 #include "nsIApplicationCacheService.h"
    14 #include "nsIOfflineCacheUpdate.h"
    15 #include "nsTArray.h"
    16 #include "nsString.h"
    17 #include "nsIURI.h"
    18 #include "nsCOMPtr.h"
    19 #include "nsWeakReference.h"
    20 #include "nsCOMArray.h"
    21 #include "nsIDOMEventListener.h"
    22 #include "nsIObserver.h"
    23 #include "nsIScriptContext.h"
    24 #include "nsCycleCollectionParticipant.h"
    25 #include "nsPIDOMWindow.h"
    26 #include "mozilla/DOMEventTargetHelper.h"
    27 #include "mozilla/ErrorResult.h"
    29 class nsIDOMWindow;
    31 namespace mozilla {
    32 namespace dom {
    33 class DOMStringList;
    34 } // namespace dom
    35 } // namespace mozilla
    37 class nsDOMOfflineResourceList : public mozilla::DOMEventTargetHelper,
    38                                  public nsIDOMOfflineResourceList,
    39                                  public nsIObserver,
    40                                  public nsIOfflineCacheUpdateObserver,
    41                                  public nsSupportsWeakReference
    42 {
    43   typedef mozilla::ErrorResult ErrorResult;
    45 public:
    46   NS_DECL_ISUPPORTS_INHERITED
    47   NS_DECL_NSIDOMOFFLINERESOURCELIST
    48   NS_DECL_NSIOBSERVER
    49   NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER
    51   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMOfflineResourceList,
    52                                            mozilla::DOMEventTargetHelper)
    54   nsDOMOfflineResourceList(nsIURI* aManifestURI,
    55                            nsIURI* aDocumentURI,
    56                            nsPIDOMWindow* aWindow);
    57   virtual ~nsDOMOfflineResourceList();
    59   void FirePendingEvents();
    60   void Disconnect();
    62   nsresult Init();
    64   nsPIDOMWindow* GetParentObject() const
    65   {
    66     return GetOwner();
    67   }
    68   virtual JSObject*
    69   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    71   uint16_t GetStatus(ErrorResult& aRv)
    72   {
    73     uint16_t status = 0;
    74     aRv = GetStatus(&status);
    75     return status;
    76   }
    77   void Update(ErrorResult& aRv)
    78   {
    79     aRv = Update();
    80   }
    81   void SwapCache(ErrorResult& aRv)
    82   {
    83     aRv = SwapCache();
    84   }
    86   IMPL_EVENT_HANDLER(checking)
    87   IMPL_EVENT_HANDLER(error)
    88   IMPL_EVENT_HANDLER(noupdate)
    89   IMPL_EVENT_HANDLER(downloading)
    90   IMPL_EVENT_HANDLER(progress)
    91   IMPL_EVENT_HANDLER(cached)
    92   IMPL_EVENT_HANDLER(updateready)
    93   IMPL_EVENT_HANDLER(obsolete)
    95   already_AddRefed<mozilla::dom::DOMStringList> GetMozItems(ErrorResult& aRv);
    96   bool MozHasItem(const nsAString& aURI, ErrorResult& aRv)
    97   {
    98     bool hasItem = false;
    99     aRv = MozHasItem(aURI, &hasItem);
   100     return hasItem;
   101   }
   102   uint32_t GetMozLength(ErrorResult& aRv)
   103   {
   104     uint32_t length = 0;
   105     aRv = GetMozLength(&length);
   106     return length;
   107   }
   108   void MozItem(uint32_t aIndex, nsAString& aURI, ErrorResult& aRv)
   109   {
   110     aRv = MozItem(aIndex, aURI);
   111   }
   112   void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aURI,
   113                      ErrorResult& aRv)
   114   {
   115     MozItem(aIndex, aURI, aRv);
   116     aFound = !aURI.IsVoid();
   117   }
   118   uint32_t Length()
   119   {
   120     ErrorResult rv;
   121     uint32_t length = GetMozLength(rv);
   122     return rv.Failed() ? 0 : length;
   123   }
   124   void MozAdd(const nsAString& aURI, ErrorResult& aRv)
   125   {
   126     aRv = MozAdd(aURI);
   127   }
   128   void MozRemove(const nsAString& aURI, ErrorResult& aRv)
   129   {
   130     aRv = MozRemove(aURI);
   131   }
   133 private:
   134   nsresult SendEvent(const nsAString &aEventName);
   136   nsresult UpdateAdded(nsIOfflineCacheUpdate *aUpdate);
   137   nsresult UpdateCompleted(nsIOfflineCacheUpdate *aUpdate);
   139   already_AddRefed<nsIApplicationCacheContainer> GetDocumentAppCacheContainer();
   140   already_AddRefed<nsIApplicationCache> GetDocumentAppCache();
   142   nsresult GetCacheKey(const nsAString &aURI, nsCString &aKey);
   143   nsresult GetCacheKey(nsIURI *aURI, nsCString &aKey);
   145   nsresult CacheKeys();
   146   void ClearCachedKeys();
   148   bool mInitialized;
   150   nsCOMPtr<nsIURI> mManifestURI;
   151   // AsciiSpec of mManifestURI
   152   nsCString mManifestSpec;
   154   nsCOMPtr<nsIURI> mDocumentURI;
   155   nsCOMPtr<nsIApplicationCacheService> mApplicationCacheService;
   156   nsCOMPtr<nsIApplicationCache> mAvailableApplicationCache;
   157   nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate;
   158   bool mExposeCacheUpdateStatus;
   159   uint16_t mStatus;
   161   // The set of dynamic keys for this application cache object.
   162   char **mCachedKeys;
   163   uint32_t mCachedKeysCount;
   165   nsCOMArray<nsIDOMEvent> mPendingEvents;
   166 };
   168 #endif

mercurial