Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsDOMOfflineResourceList_h___ |
michael@0 | 7 | #define nsDOMOfflineResourceList_h___ |
michael@0 | 8 | |
michael@0 | 9 | #include "nscore.h" |
michael@0 | 10 | #include "nsIDOMOfflineResourceList.h" |
michael@0 | 11 | #include "nsIApplicationCache.h" |
michael@0 | 12 | #include "nsIApplicationCacheContainer.h" |
michael@0 | 13 | #include "nsIApplicationCacheService.h" |
michael@0 | 14 | #include "nsIOfflineCacheUpdate.h" |
michael@0 | 15 | #include "nsTArray.h" |
michael@0 | 16 | #include "nsString.h" |
michael@0 | 17 | #include "nsIURI.h" |
michael@0 | 18 | #include "nsCOMPtr.h" |
michael@0 | 19 | #include "nsWeakReference.h" |
michael@0 | 20 | #include "nsCOMArray.h" |
michael@0 | 21 | #include "nsIDOMEventListener.h" |
michael@0 | 22 | #include "nsIObserver.h" |
michael@0 | 23 | #include "nsIScriptContext.h" |
michael@0 | 24 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 25 | #include "nsPIDOMWindow.h" |
michael@0 | 26 | #include "mozilla/DOMEventTargetHelper.h" |
michael@0 | 27 | #include "mozilla/ErrorResult.h" |
michael@0 | 28 | |
michael@0 | 29 | class nsIDOMWindow; |
michael@0 | 30 | |
michael@0 | 31 | namespace mozilla { |
michael@0 | 32 | namespace dom { |
michael@0 | 33 | class DOMStringList; |
michael@0 | 34 | } // namespace dom |
michael@0 | 35 | } // namespace mozilla |
michael@0 | 36 | |
michael@0 | 37 | class nsDOMOfflineResourceList : public mozilla::DOMEventTargetHelper, |
michael@0 | 38 | public nsIDOMOfflineResourceList, |
michael@0 | 39 | public nsIObserver, |
michael@0 | 40 | public nsIOfflineCacheUpdateObserver, |
michael@0 | 41 | public nsSupportsWeakReference |
michael@0 | 42 | { |
michael@0 | 43 | typedef mozilla::ErrorResult ErrorResult; |
michael@0 | 44 | |
michael@0 | 45 | public: |
michael@0 | 46 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 47 | NS_DECL_NSIDOMOFFLINERESOURCELIST |
michael@0 | 48 | NS_DECL_NSIOBSERVER |
michael@0 | 49 | NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER |
michael@0 | 50 | |
michael@0 | 51 | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMOfflineResourceList, |
michael@0 | 52 | mozilla::DOMEventTargetHelper) |
michael@0 | 53 | |
michael@0 | 54 | nsDOMOfflineResourceList(nsIURI* aManifestURI, |
michael@0 | 55 | nsIURI* aDocumentURI, |
michael@0 | 56 | nsPIDOMWindow* aWindow); |
michael@0 | 57 | virtual ~nsDOMOfflineResourceList(); |
michael@0 | 58 | |
michael@0 | 59 | void FirePendingEvents(); |
michael@0 | 60 | void Disconnect(); |
michael@0 | 61 | |
michael@0 | 62 | nsresult Init(); |
michael@0 | 63 | |
michael@0 | 64 | nsPIDOMWindow* GetParentObject() const |
michael@0 | 65 | { |
michael@0 | 66 | return GetOwner(); |
michael@0 | 67 | } |
michael@0 | 68 | virtual JSObject* |
michael@0 | 69 | WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
michael@0 | 70 | |
michael@0 | 71 | uint16_t GetStatus(ErrorResult& aRv) |
michael@0 | 72 | { |
michael@0 | 73 | uint16_t status = 0; |
michael@0 | 74 | aRv = GetStatus(&status); |
michael@0 | 75 | return status; |
michael@0 | 76 | } |
michael@0 | 77 | void Update(ErrorResult& aRv) |
michael@0 | 78 | { |
michael@0 | 79 | aRv = Update(); |
michael@0 | 80 | } |
michael@0 | 81 | void SwapCache(ErrorResult& aRv) |
michael@0 | 82 | { |
michael@0 | 83 | aRv = SwapCache(); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | IMPL_EVENT_HANDLER(checking) |
michael@0 | 87 | IMPL_EVENT_HANDLER(error) |
michael@0 | 88 | IMPL_EVENT_HANDLER(noupdate) |
michael@0 | 89 | IMPL_EVENT_HANDLER(downloading) |
michael@0 | 90 | IMPL_EVENT_HANDLER(progress) |
michael@0 | 91 | IMPL_EVENT_HANDLER(cached) |
michael@0 | 92 | IMPL_EVENT_HANDLER(updateready) |
michael@0 | 93 | IMPL_EVENT_HANDLER(obsolete) |
michael@0 | 94 | |
michael@0 | 95 | already_AddRefed<mozilla::dom::DOMStringList> GetMozItems(ErrorResult& aRv); |
michael@0 | 96 | bool MozHasItem(const nsAString& aURI, ErrorResult& aRv) |
michael@0 | 97 | { |
michael@0 | 98 | bool hasItem = false; |
michael@0 | 99 | aRv = MozHasItem(aURI, &hasItem); |
michael@0 | 100 | return hasItem; |
michael@0 | 101 | } |
michael@0 | 102 | uint32_t GetMozLength(ErrorResult& aRv) |
michael@0 | 103 | { |
michael@0 | 104 | uint32_t length = 0; |
michael@0 | 105 | aRv = GetMozLength(&length); |
michael@0 | 106 | return length; |
michael@0 | 107 | } |
michael@0 | 108 | void MozItem(uint32_t aIndex, nsAString& aURI, ErrorResult& aRv) |
michael@0 | 109 | { |
michael@0 | 110 | aRv = MozItem(aIndex, aURI); |
michael@0 | 111 | } |
michael@0 | 112 | void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aURI, |
michael@0 | 113 | ErrorResult& aRv) |
michael@0 | 114 | { |
michael@0 | 115 | MozItem(aIndex, aURI, aRv); |
michael@0 | 116 | aFound = !aURI.IsVoid(); |
michael@0 | 117 | } |
michael@0 | 118 | uint32_t Length() |
michael@0 | 119 | { |
michael@0 | 120 | ErrorResult rv; |
michael@0 | 121 | uint32_t length = GetMozLength(rv); |
michael@0 | 122 | return rv.Failed() ? 0 : length; |
michael@0 | 123 | } |
michael@0 | 124 | void MozAdd(const nsAString& aURI, ErrorResult& aRv) |
michael@0 | 125 | { |
michael@0 | 126 | aRv = MozAdd(aURI); |
michael@0 | 127 | } |
michael@0 | 128 | void MozRemove(const nsAString& aURI, ErrorResult& aRv) |
michael@0 | 129 | { |
michael@0 | 130 | aRv = MozRemove(aURI); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | private: |
michael@0 | 134 | nsresult SendEvent(const nsAString &aEventName); |
michael@0 | 135 | |
michael@0 | 136 | nsresult UpdateAdded(nsIOfflineCacheUpdate *aUpdate); |
michael@0 | 137 | nsresult UpdateCompleted(nsIOfflineCacheUpdate *aUpdate); |
michael@0 | 138 | |
michael@0 | 139 | already_AddRefed<nsIApplicationCacheContainer> GetDocumentAppCacheContainer(); |
michael@0 | 140 | already_AddRefed<nsIApplicationCache> GetDocumentAppCache(); |
michael@0 | 141 | |
michael@0 | 142 | nsresult GetCacheKey(const nsAString &aURI, nsCString &aKey); |
michael@0 | 143 | nsresult GetCacheKey(nsIURI *aURI, nsCString &aKey); |
michael@0 | 144 | |
michael@0 | 145 | nsresult CacheKeys(); |
michael@0 | 146 | void ClearCachedKeys(); |
michael@0 | 147 | |
michael@0 | 148 | bool mInitialized; |
michael@0 | 149 | |
michael@0 | 150 | nsCOMPtr<nsIURI> mManifestURI; |
michael@0 | 151 | // AsciiSpec of mManifestURI |
michael@0 | 152 | nsCString mManifestSpec; |
michael@0 | 153 | |
michael@0 | 154 | nsCOMPtr<nsIURI> mDocumentURI; |
michael@0 | 155 | nsCOMPtr<nsIApplicationCacheService> mApplicationCacheService; |
michael@0 | 156 | nsCOMPtr<nsIApplicationCache> mAvailableApplicationCache; |
michael@0 | 157 | nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate; |
michael@0 | 158 | bool mExposeCacheUpdateStatus; |
michael@0 | 159 | uint16_t mStatus; |
michael@0 | 160 | |
michael@0 | 161 | // The set of dynamic keys for this application cache object. |
michael@0 | 162 | char **mCachedKeys; |
michael@0 | 163 | uint32_t mCachedKeysCount; |
michael@0 | 164 | |
michael@0 | 165 | nsCOMArray<nsIDOMEvent> mPendingEvents; |
michael@0 | 166 | }; |
michael@0 | 167 | |
michael@0 | 168 | #endif |