michael@0: /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: michael@0: interface nsIURI; michael@0: interface nsIDOMWindow; michael@0: interface nsIDOMNode; michael@0: interface nsIDOMDocument; michael@0: interface nsIOfflineCacheUpdate; michael@0: interface nsIPrincipal; michael@0: interface nsIPrefBranch; michael@0: interface nsIApplicationCache; michael@0: interface nsIFile; michael@0: interface nsIObserver; michael@0: michael@0: [scriptable, uuid(47360d57-8ef4-4a5d-8865-1a27a739ad1a)] michael@0: interface nsIOfflineCacheUpdateObserver : nsISupports { michael@0: const unsigned long STATE_ERROR = 1; michael@0: const unsigned long STATE_CHECKING = 2; michael@0: const unsigned long STATE_NOUPDATE = 3; michael@0: const unsigned long STATE_OBSOLETE = 4; michael@0: const unsigned long STATE_DOWNLOADING = 5; michael@0: const unsigned long STATE_ITEMSTARTED = 6; michael@0: const unsigned long STATE_ITEMCOMPLETED = 7; michael@0: const unsigned long STATE_ITEMPROGRESS = 8; michael@0: const unsigned long STATE_FINISHED = 10; michael@0: michael@0: /** michael@0: * aUpdate has changed its state. michael@0: * michael@0: * @param aUpdate michael@0: * The nsIOfflineCacheUpdate being processed. michael@0: * @param event michael@0: * See enumeration above michael@0: */ michael@0: void updateStateChanged(in nsIOfflineCacheUpdate aUpdate, in uint32_t state); michael@0: michael@0: /** michael@0: * Informs the observer about an application being available to associate. michael@0: * michael@0: * @param applicationCache michael@0: * The application cache instance that has been created or found by the michael@0: * update to associate with michael@0: */ michael@0: void applicationCacheAvailable(in nsIApplicationCache applicationCache); michael@0: }; michael@0: michael@0: /** michael@0: * An nsIOfflineCacheUpdate is used to update an application's offline michael@0: * resources. michael@0: * michael@0: * It can be used to perform partial or complete updates. michael@0: * michael@0: * One update object will be updating at a time. The active object will michael@0: * load its items one by one, sending itemCompleted() to any registered michael@0: * observers. michael@0: */ michael@0: [scriptable, uuid(a4503a53-6ab8-4b50-b01e-1c4f393fc980)] michael@0: interface nsIOfflineCacheUpdate : nsISupports { michael@0: /** michael@0: * Fetch the status of the running update. This will return a value michael@0: * defined in nsIDOMOfflineResourceList. michael@0: */ michael@0: readonly attribute unsigned short status; michael@0: michael@0: /** michael@0: * TRUE if the update is being used to add specific resources. michael@0: * FALSE if the complete cache update process is happening. michael@0: */ michael@0: readonly attribute boolean partial; michael@0: michael@0: /** michael@0: * TRUE if this is an upgrade attempt, FALSE if it is a new cache michael@0: * attempt. michael@0: */ michael@0: readonly attribute boolean isUpgrade; michael@0: michael@0: /** michael@0: * The domain being updated, and the domain that will own any URIs added michael@0: * with this update. michael@0: */ michael@0: readonly attribute ACString updateDomain; michael@0: michael@0: /** michael@0: * The manifest for the offline application being updated. michael@0: */ michael@0: readonly attribute nsIURI manifestURI; michael@0: michael@0: /** michael@0: * TRUE if the cache update completed successfully. michael@0: */ michael@0: readonly attribute boolean succeeded; michael@0: michael@0: /** michael@0: * Initialize the update. michael@0: * michael@0: * @param aManifestURI michael@0: * The manifest URI to be checked. michael@0: * @param aDocumentURI michael@0: * The page that is requesting the update. michael@0: */ michael@0: void init(in nsIURI aManifestURI, in nsIURI aDocumentURI, in nsIDOMDocument aDocument, michael@0: [optional] in nsIFile aCustomProfileDir, michael@0: [optional] in unsigned long aAppId, michael@0: [optional] in boolean aInBrowser); michael@0: michael@0: /** michael@0: * Initialize the update for partial processing. michael@0: * michael@0: * @param aManifestURI michael@0: * The manifest URI of the related cache. michael@0: * @param aClientID michael@0: * Client ID of the cache to store resource to. This ClientID michael@0: * must be ID of cache in the cache group identified by michael@0: * the manifest URI passed in the first parameter. michael@0: * @param aDocumentURI michael@0: * The page that is requesting the update. May be null michael@0: * when this information is unknown. michael@0: */ michael@0: void initPartial(in nsIURI aManifestURI, in ACString aClientID, in nsIURI aDocumentURI); michael@0: michael@0: /** michael@0: * Initialize the update to only check whether there is an update michael@0: * to the manifest available (if it has actually changed on the server). michael@0: * michael@0: * @param aManifestURI michael@0: * The manifest URI of the related cache. michael@0: * @param aAppID michael@0: * Local ID of an app (optional) to check the cache update for. michael@0: * @param aInBrowser michael@0: * Whether to check for a cache populated from browser element. michael@0: * @param aObserver michael@0: * nsIObserver implementation that receives the result. michael@0: * When aTopic == "offline-cache-update-available" there is an update to michael@0: * to download. Update of the app cache will lead to a new version michael@0: * download. michael@0: * When aTopic == "offline-cache-update-unavailable" then there is no michael@0: * update available (the manifest has not changed on the server). michael@0: */ michael@0: void initForUpdateCheck(in nsIURI aManifestURI, michael@0: in unsigned long aAppID, michael@0: in boolean aInBrowser, michael@0: in nsIObserver aObserver); michael@0: michael@0: /** michael@0: * Add a dynamic URI to the offline cache as part of the update. michael@0: * michael@0: * @param aURI michael@0: * The URI to add. michael@0: */ michael@0: void addDynamicURI(in nsIURI aURI); michael@0: michael@0: /** michael@0: * Add the update to the offline update queue. An offline-cache-update-added michael@0: * event will be sent to the observer service. michael@0: */ michael@0: void schedule(); michael@0: michael@0: /** michael@0: * Observe loads that are added to the update. michael@0: * michael@0: * @param aObserver michael@0: * object that notifications will be sent to. michael@0: * @param aHoldWeak michael@0: * TRUE if you want the update to hold a weak reference to the michael@0: * observer, FALSE for a strong reference. michael@0: */ michael@0: void addObserver(in nsIOfflineCacheUpdateObserver aObserver, michael@0: in boolean aHoldWeak); michael@0: michael@0: /** michael@0: * Remove an observer from the update. michael@0: * michael@0: * @param aObserver michael@0: * the observer to remove. michael@0: */ michael@0: void removeObserver(in nsIOfflineCacheUpdateObserver aObserver); michael@0: michael@0: /** michael@0: * Cancel the update when still in progress. This stops all running resource michael@0: * downloads and discards the downloaded cache version. Throws when update michael@0: * has already finished and made the new cache version active. michael@0: */ michael@0: void cancel(); michael@0: michael@0: /** michael@0: * Return the number of bytes downloaded so far michael@0: */ michael@0: readonly attribute uint64_t byteProgress; michael@0: }; michael@0: michael@0: [scriptable, uuid(0668910d-d14f-4cee-8db5-25faebc360ab)] michael@0: interface nsIOfflineCacheUpdateService : nsISupports { michael@0: /** michael@0: * Constants for the offline-app permission. michael@0: * michael@0: * XXX: This isn't a great place for this, but it's really the only michael@0: * private offline-app-related interface michael@0: */ michael@0: michael@0: /** michael@0: * Allow the domain to use offline APIs, and don't warn about excessive michael@0: * usage. michael@0: */ michael@0: const unsigned long ALLOW_NO_WARN = 3; michael@0: michael@0: /** michael@0: * Access to the list of cache updates that have been scheduled. michael@0: */ michael@0: readonly attribute unsigned long numUpdates; michael@0: nsIOfflineCacheUpdate getUpdate(in unsigned long index); michael@0: michael@0: /** michael@0: * Schedule a cache update for a given offline manifest. If an michael@0: * existing update is scheduled or running, that update will be returned. michael@0: * Otherwise a new update will be scheduled. michael@0: */ michael@0: nsIOfflineCacheUpdate scheduleUpdate(in nsIURI aManifestURI, michael@0: in nsIURI aDocumentURI, michael@0: in nsIDOMWindow aWindow); michael@0: michael@0: /** michael@0: * Schedule a cache update for a given offline manifest using app cache michael@0: * bound to the given appID+inBrowser flag. If an existing update is michael@0: * scheduled or running, that update will be returned. Otherwise a new michael@0: * update will be scheduled. michael@0: */ michael@0: nsIOfflineCacheUpdate scheduleAppUpdate(in nsIURI aManifestURI, michael@0: in nsIURI aDocumentURI, michael@0: in unsigned long aAppID, michael@0: in boolean aInBrowser, michael@0: in nsIFile aProfileDir); michael@0: michael@0: /** michael@0: * Schedule a cache update for a manifest when the document finishes michael@0: * loading. michael@0: */ michael@0: void scheduleOnDocumentStop(in nsIURI aManifestURI, michael@0: in nsIURI aDocumentURI, michael@0: in nsIDOMDocument aDocument); michael@0: michael@0: /** michael@0: * Schedule a check to see if an update is available. michael@0: * michael@0: * This will not update or make any changes to the appcache. michael@0: * It only notifies the observer to indicate whether the manifest has michael@0: * changed on the server (or not): a changed manifest means that an michael@0: * update is available. michael@0: * michael@0: * For arguments see nsIOfflineCacheUpdate.initForUpdateCheck() method michael@0: * description. michael@0: */ michael@0: void checkForUpdate(in nsIURI aManifestURI, michael@0: in unsigned long aAppID, michael@0: in boolean aInBrowser, michael@0: in nsIObserver aObserver); michael@0: michael@0: /** michael@0: * Checks whether a principal should have access to the offline michael@0: * cache. michael@0: * @param aPrincipal michael@0: * The principal to check. michael@0: * @param aPrefBranch michael@0: * The pref branch to use to check the michael@0: * offline-apps.allow_by_default pref. If not specified, michael@0: * the pref service will be used. michael@0: */ michael@0: boolean offlineAppAllowed(in nsIPrincipal aPrincipal, michael@0: in nsIPrefBranch aPrefBranch); michael@0: michael@0: /** michael@0: * Checks whether a document at the given URI should have access michael@0: * to the offline cache. michael@0: * @param aURI michael@0: * The URI to check michael@0: * @param aPrefBranch michael@0: * The pref branch to use to check the michael@0: * offline-apps.allow_by_default pref. If not specified, michael@0: * the pref service will be used. michael@0: */ michael@0: boolean offlineAppAllowedForURI(in nsIURI aURI, michael@0: in nsIPrefBranch aPrefBranch); michael@0: michael@0: /** michael@0: * Sets the "offline-app" permission for the principal. michael@0: * In the single process model calls directly on permission manager. michael@0: * In the multi process model dispatches to the parent process. michael@0: */ michael@0: void allowOfflineApp(in nsIDOMWindow aWindow, in nsIPrincipal aPrincipal); michael@0: };