Bumping gaia.json for 8 gaia revision(s) a=gaia-bump
[gecko.git] / dom / offline / nsDOMOfflineResourceList.h
blobe5498b747ddccb927dd8fd8afda6c0c24bc23f3a
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 MOZ_FINAL : public mozilla::DOMEventTargetHelper,
38 public nsIDOMOfflineResourceList,
39 public nsIObserver,
40 public nsIOfflineCacheUpdateObserver,
41 public nsSupportsWeakReference
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);
58 void FirePendingEvents();
59 void Disconnect();
61 nsresult Init();
63 nsPIDOMWindow* GetParentObject() const
65 return GetOwner();
67 virtual JSObject*
68 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
70 uint16_t GetStatus(ErrorResult& aRv)
72 uint16_t status = 0;
73 aRv = GetStatus(&status);
74 return status;
76 void Update(ErrorResult& aRv)
78 aRv = Update();
80 void SwapCache(ErrorResult& aRv)
82 aRv = SwapCache();
85 IMPL_EVENT_HANDLER(checking)
86 IMPL_EVENT_HANDLER(error)
87 IMPL_EVENT_HANDLER(noupdate)
88 IMPL_EVENT_HANDLER(downloading)
89 IMPL_EVENT_HANDLER(progress)
90 IMPL_EVENT_HANDLER(cached)
91 IMPL_EVENT_HANDLER(updateready)
92 IMPL_EVENT_HANDLER(obsolete)
94 already_AddRefed<mozilla::dom::DOMStringList> GetMozItems(ErrorResult& aRv);
95 bool MozHasItem(const nsAString& aURI, ErrorResult& aRv)
97 bool hasItem = false;
98 aRv = MozHasItem(aURI, &hasItem);
99 return hasItem;
101 uint32_t GetMozLength(ErrorResult& aRv)
103 uint32_t length = 0;
104 aRv = GetMozLength(&length);
105 return length;
107 void MozItem(uint32_t aIndex, nsAString& aURI, ErrorResult& aRv)
109 aRv = MozItem(aIndex, aURI);
111 void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aURI,
112 ErrorResult& aRv)
114 MozItem(aIndex, aURI, aRv);
115 aFound = !aURI.IsVoid();
117 uint32_t Length()
119 ErrorResult rv;
120 uint32_t length = GetMozLength(rv);
121 return rv.Failed() ? 0 : length;
123 void MozAdd(const nsAString& aURI, ErrorResult& aRv)
125 aRv = MozAdd(aURI);
127 void MozRemove(const nsAString& aURI, ErrorResult& aRv)
129 aRv = MozRemove(aURI);
132 protected:
133 virtual ~nsDOMOfflineResourceList();
135 private:
136 nsresult SendEvent(const nsAString &aEventName);
138 nsresult UpdateAdded(nsIOfflineCacheUpdate *aUpdate);
139 nsresult UpdateCompleted(nsIOfflineCacheUpdate *aUpdate);
141 already_AddRefed<nsIApplicationCacheContainer> GetDocumentAppCacheContainer();
142 already_AddRefed<nsIApplicationCache> GetDocumentAppCache();
144 nsresult GetCacheKey(const nsAString &aURI, nsCString &aKey);
145 nsresult GetCacheKey(nsIURI *aURI, nsCString &aKey);
147 nsresult CacheKeys();
148 void ClearCachedKeys();
150 bool mInitialized;
152 nsCOMPtr<nsIURI> mManifestURI;
153 // AsciiSpec of mManifestURI
154 nsCString mManifestSpec;
156 nsCOMPtr<nsIURI> mDocumentURI;
157 nsCOMPtr<nsIApplicationCacheService> mApplicationCacheService;
158 nsCOMPtr<nsIApplicationCache> mAvailableApplicationCache;
159 nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate;
160 bool mExposeCacheUpdateStatus;
161 uint16_t mStatus;
163 // The set of dynamic keys for this application cache object.
164 char **mCachedKeys;
165 uint32_t mCachedKeysCount;
167 nsCOMArray<nsIDOMEvent> mPendingEvents;
170 #endif