Refactoring download button logic
This commit is contained in:
parent
077f08fa6d
commit
ef658bf5f1
5 changed files with 198 additions and 132 deletions
|
@ -1,3 +1,4 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* Copyright 2012 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -13,9 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var FirefoxCom = (function FirefoxComClosure() {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
var FirefoxCom = (function FirefoxComClosure() {
|
||||
return {
|
||||
/**
|
||||
* Creates an event that the extension is listening for and will
|
||||
|
@ -69,3 +70,35 @@ var FirefoxCom = (function FirefoxComClosure() {
|
|||
}
|
||||
};
|
||||
})();
|
||||
|
||||
var DownloadManager = (function DownloadManagerClosure() {
|
||||
function DownloadManager() {}
|
||||
|
||||
DownloadManager.prototype = {
|
||||
downloadUrl: function DownloadManager_downloadUrl(url) {
|
||||
FirefoxCom.request('download', {
|
||||
originalUrl: url,
|
||||
filename: this.filename
|
||||
});
|
||||
},
|
||||
|
||||
download: function DownloadManager_download(blob, url) {
|
||||
var blobUrl = window.URL.createObjectURL(blob);
|
||||
|
||||
FirefoxCom.request('download', {
|
||||
blobUrl: blobUrl,
|
||||
originalUrl: url,
|
||||
filename: this.filename
|
||||
},
|
||||
function response(err) {
|
||||
if (err && this.onerror) {
|
||||
this.onerror(err);
|
||||
}
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return DownloadManager;
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue