1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsDOMOfflineResourceList_h___
8 #define nsDOMOfflineResourceList_h___
15 #include "nsWeakReference.h"
16 #include "nsCOMArray.h"
17 #include "nsIObserver.h"
18 #include "nsIScriptContext.h"
19 #include "nsCycleCollectionParticipant.h"
20 #include "nsPIDOMWindow.h"
21 #include "mozilla/DOMEventTargetHelper.h"
22 #include "mozilla/ErrorResult.h"
23 #include "mozilla/Maybe.h"
25 namespace mozilla::dom
{
28 } // namespace mozilla::dom
30 class nsDOMOfflineResourceList final
: public mozilla::DOMEventTargetHelper
,
32 public nsSupportsWeakReference
{
33 using ErrorResult
= mozilla::ErrorResult
;
36 NS_DECL_ISUPPORTS_INHERITED
39 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMOfflineResourceList
,
40 mozilla::DOMEventTargetHelper
)
42 nsDOMOfflineResourceList(nsIURI
* aManifestURI
, nsIURI
* aDocumentURI
,
43 nsIPrincipal
* aLoadingPrincipal
,
44 nsPIDOMWindowInner
* aWindow
);
46 void FirePendingEvents();
49 nsPIDOMWindowInner
* GetParentObject() const { return GetOwner(); }
50 virtual JSObject
* WrapObject(JSContext
* aCx
,
51 JS::Handle
<JSObject
*> aGivenProto
) override
;
53 uint16_t GetStatus(ErrorResult
& aRv
);
55 void Update(ErrorResult
& aRv
);
57 void SwapCache(ErrorResult
& aRv
);
59 IMPL_EVENT_HANDLER(checking
)
60 IMPL_EVENT_HANDLER(error
)
61 IMPL_EVENT_HANDLER(noupdate
)
62 IMPL_EVENT_HANDLER(downloading
)
63 IMPL_EVENT_HANDLER(progress
)
64 IMPL_EVENT_HANDLER(cached
)
65 IMPL_EVENT_HANDLER(updateready
)
66 IMPL_EVENT_HANDLER(obsolete
)
68 already_AddRefed
<mozilla::dom::DOMStringList
> GetMozItems(ErrorResult
& aRv
);
69 bool MozHasItem(const nsAString
& aURI
, ErrorResult
& aRv
);
70 uint32_t GetMozLength(ErrorResult
& aRv
);
71 void MozItem(uint32_t aIndex
, nsAString
& aURI
, ErrorResult
& aRv
);
72 void IndexedGetter(uint32_t aIndex
, bool& aFound
, nsAString
& aURI
,
75 mozilla::IgnoredErrorResult rv
;
76 uint32_t length
= GetMozLength(rv
);
77 return rv
.Failed() ? 0 : length
;
79 void MozAdd(const nsAString
& aURI
, ErrorResult
& aRv
);
80 void MozRemove(const nsAString
& aURI
, ErrorResult
& aRv
);
83 virtual ~nsDOMOfflineResourceList();
86 void SendEvent(const nsAString
& aEventName
);
88 nsresult
GetCacheKey(const nsAString
& aURI
, nsCString
& aKey
);
89 nsresult
GetCacheKey(nsIURI
* aURI
, nsCString
& aKey
);
92 void ClearCachedKeys();