nsDOMOfflineResourceList.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* -*- Mode: C++; tab-width: 8; 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. #ifndef nsDOMOfflineResourceList_h___
  6. #define nsDOMOfflineResourceList_h___
  7. #include "nscore.h"
  8. #include "nsIDOMOfflineResourceList.h"
  9. #include "nsIApplicationCache.h"
  10. #include "nsIApplicationCacheContainer.h"
  11. #include "nsIApplicationCacheService.h"
  12. #include "nsIOfflineCacheUpdate.h"
  13. #include "nsTArray.h"
  14. #include "nsString.h"
  15. #include "nsIURI.h"
  16. #include "nsCOMPtr.h"
  17. #include "nsWeakReference.h"
  18. #include "nsCOMArray.h"
  19. #include "nsIDOMEventListener.h"
  20. #include "nsIObserver.h"
  21. #include "nsIScriptContext.h"
  22. #include "nsCycleCollectionParticipant.h"
  23. #include "nsPIDOMWindow.h"
  24. #include "mozilla/DOMEventTargetHelper.h"
  25. #include "mozilla/ErrorResult.h"
  26. namespace mozilla {
  27. namespace dom {
  28. class DOMStringList;
  29. } // namespace dom
  30. } // namespace mozilla
  31. class nsDOMOfflineResourceList final : public mozilla::DOMEventTargetHelper,
  32. public nsIDOMOfflineResourceList,
  33. public nsIObserver,
  34. public nsIOfflineCacheUpdateObserver,
  35. public nsSupportsWeakReference
  36. {
  37. typedef mozilla::ErrorResult ErrorResult;
  38. public:
  39. NS_DECL_ISUPPORTS_INHERITED
  40. NS_DECL_NSIDOMOFFLINERESOURCELIST
  41. NS_DECL_NSIOBSERVER
  42. NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER
  43. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMOfflineResourceList,
  44. mozilla::DOMEventTargetHelper)
  45. nsDOMOfflineResourceList(nsIURI* aManifestURI,
  46. nsIURI* aDocumentURI,
  47. nsIPrincipal* aLoadingPrincipal,
  48. nsPIDOMWindowInner* aWindow);
  49. void FirePendingEvents();
  50. void Disconnect();
  51. nsresult Init();
  52. nsPIDOMWindowInner* GetParentObject() const
  53. {
  54. return GetOwner();
  55. }
  56. virtual JSObject*
  57. WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  58. uint16_t GetStatus(ErrorResult& aRv)
  59. {
  60. uint16_t status = 0;
  61. aRv = GetStatus(&status);
  62. return status;
  63. }
  64. void Update(ErrorResult& aRv)
  65. {
  66. aRv = Update();
  67. }
  68. void SwapCache(ErrorResult& aRv)
  69. {
  70. aRv = SwapCache();
  71. }
  72. IMPL_EVENT_HANDLER(checking)
  73. IMPL_EVENT_HANDLER(error)
  74. IMPL_EVENT_HANDLER(noupdate)
  75. IMPL_EVENT_HANDLER(downloading)
  76. IMPL_EVENT_HANDLER(progress)
  77. IMPL_EVENT_HANDLER(cached)
  78. IMPL_EVENT_HANDLER(updateready)
  79. IMPL_EVENT_HANDLER(obsolete)
  80. already_AddRefed<mozilla::dom::DOMStringList> GetMozItems(ErrorResult& aRv);
  81. bool MozHasItem(const nsAString& aURI, ErrorResult& aRv)
  82. {
  83. bool hasItem = false;
  84. aRv = MozHasItem(aURI, &hasItem);
  85. return hasItem;
  86. }
  87. uint32_t GetMozLength(ErrorResult& aRv)
  88. {
  89. uint32_t length = 0;
  90. aRv = GetMozLength(&length);
  91. return length;
  92. }
  93. void MozItem(uint32_t aIndex, nsAString& aURI, ErrorResult& aRv)
  94. {
  95. aRv = MozItem(aIndex, aURI);
  96. }
  97. void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aURI,
  98. ErrorResult& aRv)
  99. {
  100. MozItem(aIndex, aURI, aRv);
  101. aFound = !aURI.IsVoid();
  102. }
  103. uint32_t Length()
  104. {
  105. mozilla::IgnoredErrorResult rv;
  106. uint32_t length = GetMozLength(rv);
  107. return rv.Failed() ? 0 : length;
  108. }
  109. void MozAdd(const nsAString& aURI, ErrorResult& aRv)
  110. {
  111. aRv = MozAdd(aURI);
  112. }
  113. void MozRemove(const nsAString& aURI, ErrorResult& aRv)
  114. {
  115. aRv = MozRemove(aURI);
  116. }
  117. protected:
  118. virtual ~nsDOMOfflineResourceList();
  119. private:
  120. nsresult SendEvent(const nsAString &aEventName);
  121. nsresult UpdateAdded(nsIOfflineCacheUpdate *aUpdate);
  122. nsresult UpdateCompleted(nsIOfflineCacheUpdate *aUpdate);
  123. already_AddRefed<nsIApplicationCacheContainer> GetDocumentAppCacheContainer();
  124. already_AddRefed<nsIApplicationCache> GetDocumentAppCache();
  125. nsresult GetCacheKey(const nsAString &aURI, nsCString &aKey);
  126. nsresult GetCacheKey(nsIURI *aURI, nsCString &aKey);
  127. nsresult CacheKeys();
  128. void ClearCachedKeys();
  129. bool mInitialized;
  130. nsCOMPtr<nsIURI> mManifestURI;
  131. // AsciiSpec of mManifestURI
  132. nsCString mManifestSpec;
  133. nsCOMPtr<nsIURI> mDocumentURI;
  134. nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
  135. nsCOMPtr<nsIApplicationCacheService> mApplicationCacheService;
  136. nsCOMPtr<nsIApplicationCache> mAvailableApplicationCache;
  137. nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate;
  138. bool mExposeCacheUpdateStatus;
  139. uint16_t mStatus;
  140. // The set of dynamic keys for this application cache object.
  141. char **mCachedKeys;
  142. uint32_t mCachedKeysCount;
  143. nsCOMArray<nsIDOMEvent> mPendingEvents;
  144. };
  145. #endif