nsIOfflineCacheUpdate.idl 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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. #include "nsISupports.idl"
  6. interface mozIDOMWindow;
  7. interface nsIURI;
  8. interface nsIDOMNode;
  9. interface nsIDOMDocument;
  10. interface nsIOfflineCacheUpdate;
  11. interface nsIPrincipal;
  12. interface nsIPrefBranch;
  13. interface nsIApplicationCache;
  14. interface nsIFile;
  15. interface nsIObserver;
  16. [scriptable, uuid(47360d57-8ef4-4a5d-8865-1a27a739ad1a)]
  17. interface nsIOfflineCacheUpdateObserver : nsISupports {
  18. const unsigned long STATE_ERROR = 1;
  19. const unsigned long STATE_CHECKING = 2;
  20. const unsigned long STATE_NOUPDATE = 3;
  21. const unsigned long STATE_OBSOLETE = 4;
  22. const unsigned long STATE_DOWNLOADING = 5;
  23. const unsigned long STATE_ITEMSTARTED = 6;
  24. const unsigned long STATE_ITEMCOMPLETED = 7;
  25. const unsigned long STATE_ITEMPROGRESS = 8;
  26. const unsigned long STATE_FINISHED = 10;
  27. /**
  28. * aUpdate has changed its state.
  29. *
  30. * @param aUpdate
  31. * The nsIOfflineCacheUpdate being processed.
  32. * @param event
  33. * See enumeration above
  34. */
  35. void updateStateChanged(in nsIOfflineCacheUpdate aUpdate, in uint32_t state);
  36. /**
  37. * Informs the observer about an application being available to associate.
  38. *
  39. * @param applicationCache
  40. * The application cache instance that has been created or found by the
  41. * update to associate with
  42. */
  43. void applicationCacheAvailable(in nsIApplicationCache applicationCache);
  44. };
  45. /**
  46. * An nsIOfflineCacheUpdate is used to update an application's offline
  47. * resources.
  48. *
  49. * It can be used to perform partial or complete updates.
  50. *
  51. * One update object will be updating at a time. The active object will
  52. * load its items one by one, sending itemCompleted() to any registered
  53. * observers.
  54. */
  55. [scriptable, uuid(6e3e26ea-45b2-4db7-9e4a-93b965679298)]
  56. interface nsIOfflineCacheUpdate : nsISupports {
  57. /**
  58. * Fetch the status of the running update. This will return a value
  59. * defined in nsIDOMOfflineResourceList.
  60. */
  61. readonly attribute unsigned short status;
  62. /**
  63. * TRUE if the update is being used to add specific resources.
  64. * FALSE if the complete cache update process is happening.
  65. */
  66. readonly attribute boolean partial;
  67. /**
  68. * TRUE if this is an upgrade attempt, FALSE if it is a new cache
  69. * attempt.
  70. */
  71. readonly attribute boolean isUpgrade;
  72. /**
  73. * The domain being updated, and the domain that will own any URIs added
  74. * with this update.
  75. */
  76. readonly attribute ACString updateDomain;
  77. /**
  78. * The manifest for the offline application being updated.
  79. */
  80. readonly attribute nsIURI manifestURI;
  81. /**
  82. * TRUE if the cache update completed successfully.
  83. */
  84. readonly attribute boolean succeeded;
  85. /**
  86. * Initialize the update.
  87. *
  88. * @param aManifestURI
  89. * The manifest URI to be checked.
  90. * @param aDocumentURI
  91. * The page that is requesting the update.
  92. * @param aLoadingPrincipal
  93. * The principal of the page that is requesting the update.
  94. */
  95. void init(in nsIURI aManifestURI,
  96. in nsIURI aDocumentURI,
  97. in nsIPrincipal aLoadingPrincipal,
  98. in nsIDOMDocument aDocument,
  99. [optional] in nsIFile aCustomProfileDir);
  100. /**
  101. * Initialize the update for partial processing.
  102. *
  103. * @param aManifestURI
  104. * The manifest URI of the related cache.
  105. * @param aClientID
  106. * Client ID of the cache to store resource to. This ClientID
  107. * must be ID of cache in the cache group identified by
  108. * the manifest URI passed in the first parameter.
  109. * @param aDocumentURI
  110. * The page that is requesting the update. May be null
  111. * when this information is unknown.
  112. */
  113. void initPartial(in nsIURI aManifestURI, in ACString aClientID,
  114. in nsIURI aDocumentURI, in nsIPrincipal aPrincipal);
  115. /**
  116. * Initialize the update to only check whether there is an update
  117. * to the manifest available (if it has actually changed on the server).
  118. *
  119. * @param aManifestURI
  120. * The manifest URI of the related cache.
  121. * @param aObserver
  122. * nsIObserver implementation that receives the result.
  123. * When aTopic == "offline-cache-update-available" there is an update to
  124. * to download. Update of the app cache will lead to a new version
  125. * download.
  126. * When aTopic == "offline-cache-update-unavailable" then there is no
  127. * update available (the manifest has not changed on the server).
  128. */
  129. void initForUpdateCheck(in nsIURI aManifestURI,
  130. in nsIPrincipal aLoadingPrincipal,
  131. in nsIObserver aObserver);
  132. /**
  133. * Add a dynamic URI to the offline cache as part of the update.
  134. *
  135. * @param aURI
  136. * The URI to add.
  137. */
  138. void addDynamicURI(in nsIURI aURI);
  139. /**
  140. * Add the update to the offline update queue. An offline-cache-update-added
  141. * event will be sent to the observer service.
  142. */
  143. void schedule();
  144. /**
  145. * Observe loads that are added to the update.
  146. *
  147. * @param aObserver
  148. * object that notifications will be sent to.
  149. * @param aHoldWeak
  150. * TRUE if you want the update to hold a weak reference to the
  151. * observer, FALSE for a strong reference.
  152. */
  153. void addObserver(in nsIOfflineCacheUpdateObserver aObserver,
  154. in boolean aHoldWeak);
  155. /**
  156. * Remove an observer from the update.
  157. *
  158. * @param aObserver
  159. * the observer to remove.
  160. */
  161. void removeObserver(in nsIOfflineCacheUpdateObserver aObserver);
  162. /**
  163. * Cancel the update when still in progress. This stops all running resource
  164. * downloads and discards the downloaded cache version. Throws when update
  165. * has already finished and made the new cache version active.
  166. */
  167. void cancel();
  168. /**
  169. * Return the number of bytes downloaded so far
  170. */
  171. readonly attribute uint64_t byteProgress;
  172. };
  173. [scriptable, uuid(44971e74-37e4-4140-8677-a4cf213a3f4b)]
  174. interface nsIOfflineCacheUpdateService : nsISupports {
  175. /**
  176. * Constants for the offline-app permission.
  177. *
  178. * XXX: This isn't a great place for this, but it's really the only
  179. * private offline-app-related interface
  180. */
  181. /**
  182. * Allow the domain to use offline APIs, and don't warn about excessive
  183. * usage.
  184. */
  185. const unsigned long ALLOW_NO_WARN = 3;
  186. /**
  187. * Access to the list of cache updates that have been scheduled.
  188. */
  189. readonly attribute unsigned long numUpdates;
  190. nsIOfflineCacheUpdate getUpdate(in unsigned long index);
  191. /**
  192. * Schedule a cache update for a given offline manifest. If an
  193. * existing update is scheduled or running, that update will be returned.
  194. * Otherwise a new update will be scheduled.
  195. */
  196. nsIOfflineCacheUpdate scheduleUpdate(in nsIURI aManifestURI,
  197. in nsIURI aDocumentURI,
  198. in nsIPrincipal aLoadingPrincipal,
  199. in mozIDOMWindow aWindow);
  200. /**
  201. * Schedule a cache update for a given offline manifest using app cache
  202. * bound to the given appID+inIsolatedMozBrowser flag. If an existing update
  203. * is scheduled or running, that update will be returned. Otherwise a new
  204. * update will be scheduled.
  205. */
  206. nsIOfflineCacheUpdate scheduleAppUpdate(in nsIURI aManifestURI,
  207. in nsIURI aDocumentURI,
  208. in nsIPrincipal aLoadingPrincipal,
  209. in nsIFile aProfileDir);
  210. /**
  211. * Schedule a cache update for a manifest when the document finishes
  212. * loading.
  213. */
  214. void scheduleOnDocumentStop(in nsIURI aManifestURI,
  215. in nsIURI aDocumentURI,
  216. in nsIPrincipal aLoadingPrincipal,
  217. in nsIDOMDocument aDocument);
  218. /**
  219. * Schedule a check to see if an update is available.
  220. *
  221. * This will not update or make any changes to the appcache.
  222. * It only notifies the observer to indicate whether the manifest has
  223. * changed on the server (or not): a changed manifest means that an
  224. * update is available.
  225. *
  226. * For arguments see nsIOfflineCacheUpdate.initForUpdateCheck() method
  227. * description.
  228. */
  229. void checkForUpdate(in nsIURI aManifestURI,
  230. in nsIPrincipal aLoadingPrincipal,
  231. in nsIObserver aObserver);
  232. /**
  233. * Checks whether a principal should have access to the offline
  234. * cache.
  235. * @param aPrincipal
  236. * The principal to check.
  237. * @param aPrefBranch
  238. * The pref branch to use to check the
  239. * offline-apps.allow_by_default pref. If not specified,
  240. * the pref service will be used.
  241. */
  242. boolean offlineAppAllowed(in nsIPrincipal aPrincipal,
  243. in nsIPrefBranch aPrefBranch);
  244. /**
  245. * Checks whether a document at the given URI should have access
  246. * to the offline cache.
  247. * @param aURI
  248. * The URI to check
  249. * @param aPrefBranch
  250. * The pref branch to use to check the
  251. * offline-apps.allow_by_default pref. If not specified,
  252. * the pref service will be used.
  253. */
  254. boolean offlineAppAllowedForURI(in nsIURI aURI,
  255. in nsIPrefBranch aPrefBranch);
  256. /**
  257. * Sets the "offline-app" permission for the principal.
  258. * In the single process model calls directly on permission manager.
  259. * In the multi process model dispatches to the parent process.
  260. */
  261. void allowOfflineApp(in nsIPrincipal aPrincipal);
  262. };