/** * Namespace: browser.downloads * Generated from Mozilla sources. Do not manually edit! * * Permissions: "downloads" */ import { ExtensionTypes } from "./extensionTypes"; import { Events } from "./events"; export namespace Downloads { type FilenameConflictAction = "uniquify" | "overwrite" | "prompt"; type InterruptReason = | "FILE_FAILED" | "FILE_ACCESS_DENIED" | "FILE_NO_SPACE" | "FILE_NAME_TOO_LONG" | "FILE_TOO_LARGE" | "FILE_VIRUS_INFECTED" | "FILE_TRANSIENT_ERROR" | "FILE_BLOCKED" | "FILE_SECURITY_CHECK_FAILED" | "FILE_TOO_SHORT" | "NETWORK_FAILED" | "NETWORK_TIMEOUT" | "NETWORK_DISCONNECTED" | "NETWORK_SERVER_DOWN" | "NETWORK_INVALID_REQUEST" | "SERVER_FAILED" | "SERVER_NO_RANGE" | "SERVER_BAD_CONTENT" | "SERVER_UNAUTHORIZED" | "SERVER_CERT_PROBLEM" | "SERVER_FORBIDDEN" | "USER_CANCELED" | "USER_SHUTDOWN" | "CRASH"; /** *
filename
* or url
contain all of the search terms that do not begin with a dash '-' and none of the search terms that
* do begin with a dash.
* Optional.
*/
query?: string[];
/**
* Limits results to downloads that started before the given ms since the epoch.
* Optional.
*/
startedBefore?: DownloadTime;
/**
* Limits results to downloads that started after the given ms since the epoch.
* Optional.
*/
startedAfter?: DownloadTime;
/**
* Limits results to downloads that ended before the given ms since the epoch.
* Optional.
*/
endedBefore?: DownloadTime;
/**
* Limits results to downloads that ended after the given ms since the epoch.
* Optional.
*/
endedAfter?: DownloadTime;
/**
* Limits results to downloads whose totalBytes is greater than the given integer.
* Optional.
*/
totalBytesGreater?: number;
/**
* Limits results to downloads whose totalBytes is less than the given integer.
* Optional.
*/
totalBytesLess?: number;
/**
* Limits results to DownloadItems whose filename
* matches the given regular expression.
* Optional.
*/
filenameRegex?: string;
/**
* Limits results to DownloadItems whose url
* matches the given regular expression.
* Optional.
*/
urlRegex?: string;
/**
* Setting this integer limits the number of results. Otherwise, all matching DownloadItems
* will be returned.
* Optional.
*/
limit?: number;
/**
* Setting elements of this array to DownloadItem properties in order to sort the search
* results. For example, setting orderBy='startTime'
sorts the DownloadItems
* by their start time in ascending order. To specify descending order, prefix orderBy
* with a hyphen: '-startTime'.
* Optional.
*/
orderBy?: string[];
/**
* Optional.
*/
id?: number;
/**
* Absolute URL.
* Optional.
*/
url?: string;
/**
* Absolute local path.
* Optional.
*/
filename?: string;
/**
* The cookie store ID of the contextual identity.
* Optional.
*/
cookieStoreId?: string;
/**
* Indication of whether this download is thought to be safe or known to be suspicious.
* Optional.
*/
danger?: DangerType;
/**
* The file's MIME type.
* Optional.
*/
mime?: string;
/**
* Optional.
*/
startTime?: string;
/**
* Optional.
*/
endTime?: string;
/**
* Indicates whether the download is progressing, interrupted, or complete.
* Optional.
*/
state?: State;
/**
* True if the download has stopped reading data from the host, but kept the connection open.
* Optional.
*/
paused?: boolean;
/**
* Why a download was interrupted.
* Optional.
*/
error?: InterruptReason;
/**
* Number of bytes received so far from the host, without considering file compression.
* Optional.
*/
bytesReceived?: number;
/**
* Number of bytes in the whole file, without considering file compression, or -1 if unknown.
* Optional.
*/
totalBytes?: number;
/**
* Number of bytes in the whole file post-decompression, or -1 if unknown.
* Optional.
*/
fileSize?: number;
/**
* Optional.
*/
exists?: boolean;
}
/**
* What to download and how.
*/
interface DownloadOptionsType {
/**
* The URL to download.
*/
url: string;
/**
* A file path relative to the Downloads directory to contain the downloaded file.
* Optional.
*/
filename?: string;
/**
* Whether to associate the download with a private browsing session.
* Optional.
*/
incognito?: boolean;
/**
* The cookie store ID of the contextual identity; requires "cookies" permission.
* Optional.
*/
cookieStoreId?: string;
/**
* Optional.
*/
conflictAction?: FilenameConflictAction;
/**
* Use a file-chooser to allow the user to select a filename. If the option is not specified,
* the file chooser will be shown only if the Firefox "Always ask you where to save files" option is enabled (i.e.
* the pref browser.download.useDownloadDir
is set to false
).
* Optional.
*/
saveAs?: boolean;
/**
* The HTTP method to use if the URL uses the HTTP[S] protocol.
* Optional.
*/
method?: DownloadOptionsTypeMethodEnum;
/**
* Extra HTTP headers to send with the request if the URL uses the HTTP[s] protocol. Each header is represented as a
* dictionary containing the keys name
and either value
or binaryValue
,
* restricted to those allowed by XMLHttpRequest.
* Optional.
*/
headers?: DownloadOptionsTypeHeadersItemType[];
/**
* Post body.
* Optional.
*/
body?: string;
/**
* When this flag is set to true
, then the browser will allow downloads to proceed after encountering HTTP
* errors such as 404 Not Found
.
* Optional.
*/
allowHttpErrors?: boolean;
}
interface GetFileIconOptionsType {
/**
* The size of the icon. The returned icon will be square with dimensions size * size pixels.
* The default size for the icon is 32x32 pixels.
* Optional.
*/
size?: number;
}
interface OnChangedDownloadDeltaType {
/**
* The id
of the DownloadItem that changed.
*/
id: number;
/**
* Describes a change in a DownloadItem's url
.
* Optional.
*/
url?: StringDelta;
/**
* Describes a change in a DownloadItem's filename
.
* Optional.
*/
filename?: StringDelta;
/**
* Describes a change in a DownloadItem's danger
.
* Optional.
*/
danger?: StringDelta;
/**
* Describes a change in a DownloadItem's mime
.
* Optional.
*/
mime?: StringDelta;
/**
* Describes a change in a DownloadItem's startTime
.
* Optional.
*/
startTime?: StringDelta;
/**
* Describes a change in a DownloadItem's endTime
.
* Optional.
*/
endTime?: StringDelta;
/**
* Describes a change in a DownloadItem's state
.
* Optional.
*/
state?: StringDelta;
/**
* Optional.
*/
canResume?: BooleanDelta;
/**
* Describes a change in a DownloadItem's paused
.
* Optional.
*/
paused?: BooleanDelta;
/**
* Describes a change in a DownloadItem's error
.
* Optional.
*/
error?: StringDelta;
/**
* Describes a change in a DownloadItem's totalBytes
.
* Optional.
*/
totalBytes?: DoubleDelta;
/**
* Describes a change in a DownloadItem's fileSize
.
* Optional.
*/
fileSize?: DoubleDelta;
/**
* Optional.
*/
exists?: BooleanDelta;
}
/**
* The HTTP method to use if the URL uses the HTTP[S] protocol.
*/
type DownloadOptionsTypeMethodEnum = "GET" | "POST";
interface DownloadOptionsTypeHeadersItemType {
/**
* Name of the HTTP header.
*/
name: string;
/**
* Value of the HTTP header.
*/
value: string;
}
interface Static {
/**
* Download a URL. If the URL uses the HTTP[S] protocol, then the request will include all cookies currently set for its
* hostname. If both filename
and saveAs
are specified, then the Save As dialog will be displayed,
* pre-populated with the specified filename
. If the download started successfully, callback
* will be called with the new DownloadItem's downloadId
.
* If there was an error starting the download, then callback
will be called with
* downloadId=undefined
and chrome.extension.lastError
* will contain a descriptive string. The error strings are not guaranteed to remain backwards compatible between releases.
* You must not parse it.
*
* @param options What to download and how.
*/
download(options: DownloadOptionsType): Promisequery
to the empty object to get all DownloadItems. To get a specific DownloadItem,
* set only the id
field.
*
* @param query
*/
search(query: DownloadQuery): Promisecallback
is run, the download is cancelled, completed,
* interrupted or doesn't exist anymore.
*
* @param downloadId The id of the download to cancel.
*/
cancel(downloadId: number): PromisedownloadId
when a download is erased from history.
*
* @param downloadId The id
of the DownloadItem that was erased.
*/
onErased: Events.Event<(downloadId: number) => void>;
/**
* When any of a DownloadItem's properties except bytesReceived
changes,
* this event fires with the downloadId
and an object containing the properties that changed.
*
* @param downloadDelta
*/
onChanged: Events.Event<(downloadDelta: OnChangedDownloadDeltaType) => void>;
}
}