|
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/. */ |
|
5 |
|
6 #ifndef nsDOMOfflineResourceList_h___ |
|
7 #define nsDOMOfflineResourceList_h___ |
|
8 |
|
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" |
|
28 |
|
29 class nsIDOMWindow; |
|
30 |
|
31 namespace mozilla { |
|
32 namespace dom { |
|
33 class DOMStringList; |
|
34 } // namespace dom |
|
35 } // namespace mozilla |
|
36 |
|
37 class nsDOMOfflineResourceList : public mozilla::DOMEventTargetHelper, |
|
38 public nsIDOMOfflineResourceList, |
|
39 public nsIObserver, |
|
40 public nsIOfflineCacheUpdateObserver, |
|
41 public nsSupportsWeakReference |
|
42 { |
|
43 typedef mozilla::ErrorResult ErrorResult; |
|
44 |
|
45 public: |
|
46 NS_DECL_ISUPPORTS_INHERITED |
|
47 NS_DECL_NSIDOMOFFLINERESOURCELIST |
|
48 NS_DECL_NSIOBSERVER |
|
49 NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER |
|
50 |
|
51 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMOfflineResourceList, |
|
52 mozilla::DOMEventTargetHelper) |
|
53 |
|
54 nsDOMOfflineResourceList(nsIURI* aManifestURI, |
|
55 nsIURI* aDocumentURI, |
|
56 nsPIDOMWindow* aWindow); |
|
57 virtual ~nsDOMOfflineResourceList(); |
|
58 |
|
59 void FirePendingEvents(); |
|
60 void Disconnect(); |
|
61 |
|
62 nsresult Init(); |
|
63 |
|
64 nsPIDOMWindow* GetParentObject() const |
|
65 { |
|
66 return GetOwner(); |
|
67 } |
|
68 virtual JSObject* |
|
69 WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
70 |
|
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 } |
|
85 |
|
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) |
|
94 |
|
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 } |
|
132 |
|
133 private: |
|
134 nsresult SendEvent(const nsAString &aEventName); |
|
135 |
|
136 nsresult UpdateAdded(nsIOfflineCacheUpdate *aUpdate); |
|
137 nsresult UpdateCompleted(nsIOfflineCacheUpdate *aUpdate); |
|
138 |
|
139 already_AddRefed<nsIApplicationCacheContainer> GetDocumentAppCacheContainer(); |
|
140 already_AddRefed<nsIApplicationCache> GetDocumentAppCache(); |
|
141 |
|
142 nsresult GetCacheKey(const nsAString &aURI, nsCString &aKey); |
|
143 nsresult GetCacheKey(nsIURI *aURI, nsCString &aKey); |
|
144 |
|
145 nsresult CacheKeys(); |
|
146 void ClearCachedKeys(); |
|
147 |
|
148 bool mInitialized; |
|
149 |
|
150 nsCOMPtr<nsIURI> mManifestURI; |
|
151 // AsciiSpec of mManifestURI |
|
152 nsCString mManifestSpec; |
|
153 |
|
154 nsCOMPtr<nsIURI> mDocumentURI; |
|
155 nsCOMPtr<nsIApplicationCacheService> mApplicationCacheService; |
|
156 nsCOMPtr<nsIApplicationCache> mAvailableApplicationCache; |
|
157 nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate; |
|
158 bool mExposeCacheUpdateStatus; |
|
159 uint16_t mStatus; |
|
160 |
|
161 // The set of dynamic keys for this application cache object. |
|
162 char **mCachedKeys; |
|
163 uint32_t mCachedKeysCount; |
|
164 |
|
165 nsCOMArray<nsIDOMEvent> mPendingEvents; |
|
166 }; |
|
167 |
|
168 #endif |