michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDOMOfflineResourceList_h___ michael@0: #define nsDOMOfflineResourceList_h___ michael@0: michael@0: #include "nscore.h" michael@0: #include "nsIDOMOfflineResourceList.h" michael@0: #include "nsIApplicationCache.h" michael@0: #include "nsIApplicationCacheContainer.h" michael@0: #include "nsIApplicationCacheService.h" michael@0: #include "nsIOfflineCacheUpdate.h" michael@0: #include "nsTArray.h" michael@0: #include "nsString.h" michael@0: #include "nsIURI.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsIDOMEventListener.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsIScriptContext.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsPIDOMWindow.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: michael@0: class nsIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class DOMStringList; michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: class nsDOMOfflineResourceList : public mozilla::DOMEventTargetHelper, michael@0: public nsIDOMOfflineResourceList, michael@0: public nsIObserver, michael@0: public nsIOfflineCacheUpdateObserver, michael@0: public nsSupportsWeakReference michael@0: { michael@0: typedef mozilla::ErrorResult ErrorResult; michael@0: michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSIDOMOFFLINERESOURCELIST michael@0: NS_DECL_NSIOBSERVER michael@0: NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMOfflineResourceList, michael@0: mozilla::DOMEventTargetHelper) michael@0: michael@0: nsDOMOfflineResourceList(nsIURI* aManifestURI, michael@0: nsIURI* aDocumentURI, michael@0: nsPIDOMWindow* aWindow); michael@0: virtual ~nsDOMOfflineResourceList(); michael@0: michael@0: void FirePendingEvents(); michael@0: void Disconnect(); michael@0: michael@0: nsresult Init(); michael@0: michael@0: nsPIDOMWindow* GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: uint16_t GetStatus(ErrorResult& aRv) michael@0: { michael@0: uint16_t status = 0; michael@0: aRv = GetStatus(&status); michael@0: return status; michael@0: } michael@0: void Update(ErrorResult& aRv) michael@0: { michael@0: aRv = Update(); michael@0: } michael@0: void SwapCache(ErrorResult& aRv) michael@0: { michael@0: aRv = SwapCache(); michael@0: } michael@0: michael@0: IMPL_EVENT_HANDLER(checking) michael@0: IMPL_EVENT_HANDLER(error) michael@0: IMPL_EVENT_HANDLER(noupdate) michael@0: IMPL_EVENT_HANDLER(downloading) michael@0: IMPL_EVENT_HANDLER(progress) michael@0: IMPL_EVENT_HANDLER(cached) michael@0: IMPL_EVENT_HANDLER(updateready) michael@0: IMPL_EVENT_HANDLER(obsolete) michael@0: michael@0: already_AddRefed GetMozItems(ErrorResult& aRv); michael@0: bool MozHasItem(const nsAString& aURI, ErrorResult& aRv) michael@0: { michael@0: bool hasItem = false; michael@0: aRv = MozHasItem(aURI, &hasItem); michael@0: return hasItem; michael@0: } michael@0: uint32_t GetMozLength(ErrorResult& aRv) michael@0: { michael@0: uint32_t length = 0; michael@0: aRv = GetMozLength(&length); michael@0: return length; michael@0: } michael@0: void MozItem(uint32_t aIndex, nsAString& aURI, ErrorResult& aRv) michael@0: { michael@0: aRv = MozItem(aIndex, aURI); michael@0: } michael@0: void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aURI, michael@0: ErrorResult& aRv) michael@0: { michael@0: MozItem(aIndex, aURI, aRv); michael@0: aFound = !aURI.IsVoid(); michael@0: } michael@0: uint32_t Length() michael@0: { michael@0: ErrorResult rv; michael@0: uint32_t length = GetMozLength(rv); michael@0: return rv.Failed() ? 0 : length; michael@0: } michael@0: void MozAdd(const nsAString& aURI, ErrorResult& aRv) michael@0: { michael@0: aRv = MozAdd(aURI); michael@0: } michael@0: void MozRemove(const nsAString& aURI, ErrorResult& aRv) michael@0: { michael@0: aRv = MozRemove(aURI); michael@0: } michael@0: michael@0: private: michael@0: nsresult SendEvent(const nsAString &aEventName); michael@0: michael@0: nsresult UpdateAdded(nsIOfflineCacheUpdate *aUpdate); michael@0: nsresult UpdateCompleted(nsIOfflineCacheUpdate *aUpdate); michael@0: michael@0: already_AddRefed GetDocumentAppCacheContainer(); michael@0: already_AddRefed GetDocumentAppCache(); michael@0: michael@0: nsresult GetCacheKey(const nsAString &aURI, nsCString &aKey); michael@0: nsresult GetCacheKey(nsIURI *aURI, nsCString &aKey); michael@0: michael@0: nsresult CacheKeys(); michael@0: void ClearCachedKeys(); michael@0: michael@0: bool mInitialized; michael@0: michael@0: nsCOMPtr mManifestURI; michael@0: // AsciiSpec of mManifestURI michael@0: nsCString mManifestSpec; michael@0: michael@0: nsCOMPtr mDocumentURI; michael@0: nsCOMPtr mApplicationCacheService; michael@0: nsCOMPtr mAvailableApplicationCache; michael@0: nsCOMPtr mCacheUpdate; michael@0: bool mExposeCacheUpdateStatus; michael@0: uint16_t mStatus; michael@0: michael@0: // The set of dynamic keys for this application cache object. michael@0: char **mCachedKeys; michael@0: uint32_t mCachedKeysCount; michael@0: michael@0: nsCOMArray mPendingEvents; michael@0: }; michael@0: michael@0: #endif