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