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___
10 #include "nsIDOMOfflineResourceList.h"
11 #include "nsIApplicationCache.h"
12 #include "nsIApplicationCacheContainer.h"
13 #include "nsIApplicationCacheService.h"
14 #include "nsIOfflineCacheUpdate.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"
35 } // namespace mozilla
37 class nsDOMOfflineResourceList
: public mozilla::DOMEventTargetHelper
,
38 public nsIDOMOfflineResourceList
,
40 public nsIOfflineCacheUpdateObserver
,
41 public nsSupportsWeakReference
43 typedef mozilla::ErrorResult ErrorResult
;
46 NS_DECL_ISUPPORTS_INHERITED
47 NS_DECL_NSIDOMOFFLINERESOURCELIST
49 NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER
51 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMOfflineResourceList
,
52 mozilla::DOMEventTargetHelper
)
54 nsDOMOfflineResourceList(nsIURI
* aManifestURI
,
56 nsPIDOMWindow
* aWindow
);
58 void FirePendingEvents();
63 nsPIDOMWindow
* GetParentObject() const
68 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
70 uint16_t GetStatus(ErrorResult
& aRv
)
73 aRv
= GetStatus(&status
);
76 void Update(ErrorResult
& aRv
)
80 void SwapCache(ErrorResult
& aRv
)
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
)
98 aRv
= MozHasItem(aURI
, &hasItem
);
101 uint32_t GetMozLength(ErrorResult
& aRv
)
104 aRv
= GetMozLength(&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
,
114 MozItem(aIndex
, aURI
, aRv
);
115 aFound
= !aURI
.IsVoid();
120 uint32_t length
= GetMozLength(rv
);
121 return rv
.Failed() ? 0 : length
;
123 void MozAdd(const nsAString
& aURI
, ErrorResult
& aRv
)
127 void MozRemove(const nsAString
& aURI
, ErrorResult
& aRv
)
129 aRv
= MozRemove(aURI
);
133 virtual ~nsDOMOfflineResourceList();
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();
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
;
163 // The set of dynamic keys for this application cache object.
165 uint32_t mCachedKeysCount
;
167 nsCOMArray
<nsIDOMEvent
> mPendingEvents
;