зеркало из https://github.com/mozilla/gecko-dev.git
bug 1007965
bug 1007965 * Add storageName and storagePath to DOM Download Object. r=fabrice r=bz (for WebIDL changes)
This commit is contained in:
Родитель
29d0dd7695
Коммит
48e805c683
|
@ -17,6 +17,9 @@ Cu.import("resource://gre/modules/DownloadsIPC.jsm");
|
|||
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
||||
"@mozilla.org/childprocessmessagemanager;1",
|
||||
"nsIMessageSender");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "volumeService",
|
||||
"@mozilla.org/telephony/volume-service;1",
|
||||
"nsIVolumeService");
|
||||
|
||||
function debug(aStr) {
|
||||
#ifdef MOZ_DEBUG
|
||||
|
@ -207,6 +210,8 @@ function DOMDownloadImpl() {
|
|||
this.currentBytes = 0;
|
||||
this.url = null;
|
||||
this.path = null;
|
||||
this.storageName = null;
|
||||
this.storagePath = null;
|
||||
this.contentType = null;
|
||||
|
||||
/* fields that require getters/setters */
|
||||
|
@ -308,17 +313,47 @@ DOMDownloadImpl.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
let props = ["totalBytes", "currentBytes", "url", "path", "state",
|
||||
"contentType", "startTime"];
|
||||
let props = ["totalBytes", "currentBytes", "url", "path", "storageName",
|
||||
"storagePath", "state", "contentType", "startTime"];
|
||||
let changed = false;
|
||||
let changedProps = {};
|
||||
|
||||
props.forEach((prop) => {
|
||||
if (aDownload[prop] && (aDownload[prop] != this[prop])) {
|
||||
this[prop] = aDownload[prop];
|
||||
changed = true;
|
||||
changedProps[prop] = changed = true;
|
||||
}
|
||||
});
|
||||
|
||||
// When the path changes, we should update the storage name and
|
||||
// storage path used for our downloaded file in case our download
|
||||
// was re-targetted to a different storage and/or filename.
|
||||
if (changedProps["path"]) {
|
||||
let storages = this._window.navigator.getDeviceStorages("sdcard");
|
||||
let preferredStorageName;
|
||||
// Use the first one or the default storage. Just like jsdownloads picks
|
||||
// the default / preferred download directory.
|
||||
storages.forEach((aStorage) => {
|
||||
if (aStorage.default || !preferredStorageName) {
|
||||
preferredStorageName = aStorage.storageName;
|
||||
}
|
||||
});
|
||||
// Now get the path for this storage area.
|
||||
let volume;
|
||||
if (preferredStorageName) {
|
||||
let volume = volumeService.getVolumeByName(preferredStorageName);
|
||||
if (volume) {
|
||||
// Finally, create the relative path of the file that can be used
|
||||
// later on to retrieve the file via DeviceStorage. Our path
|
||||
// needs to omit the starting '/'.
|
||||
this.storageName = preferredStorageName;
|
||||
this.storagePath =
|
||||
this.path.substring(this.path.indexOf(volume.mountPoint) +
|
||||
volume.mountPoint.length + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (aDownload.error) {
|
||||
//
|
||||
// When we get a generic error failure back from the js downloads api
|
||||
|
|
|
@ -54,10 +54,17 @@ interface DOMDownload : EventTarget {
|
|||
// The url of the resource.
|
||||
readonly attribute DOMString url;
|
||||
|
||||
// The path in local storage where the file will end up once the download
|
||||
// The full path in local storage where the file will end up once the download
|
||||
// is complete.
|
||||
readonly attribute DOMString path;
|
||||
|
||||
// The DeviceStorage volume name on which the file is being downloaded.
|
||||
readonly attribute DOMString storageName;
|
||||
|
||||
// The DeviceStorage path on the volume with 'storageName' of the file being
|
||||
// downloaded.
|
||||
readonly attribute DOMString storagePath;
|
||||
|
||||
// The state of the download.
|
||||
readonly attribute DownloadState state;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче