「ダウンロード状況を監視」の編集履歴(バックアップ)一覧はこちら

ダウンロード状況を監視」(2013/12/21 (土) 11:05:55) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

Firefox26からDownload.jsmを使用するようになったので試行錯誤してみた -[[Downloads.jsm - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm]] -[[DownloadList - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm/DownloadList]] -[[Download - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm/Download]] -[[DownloadSummary - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm/DownloadSummary]] *Private と Public を区別して監視 #highlight(javascript){{ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm"); var myDownloads = { PublicView : null, PrivateView : null, addView : function() { if (this.PublicView) this.PublicView.addView(); else this.PublicView = new DownloadsView(false); if (this.PrivateView) this.PrivateView.addView(); else this.PrivateView = new DownloadsView(true); }, removeView : function() { if (this.PublicView) this.PublicView.removeView(); if (this.PrivateView) this.PrivateView.removeView(); }, } // DownloadsViewクラス function DownloadsView(aPrivate) { this.isPrivate = aPrivate; this.list = null; this.summary = null; this.init(); } DownloadsView.prototype = { // View作成で自動的に登録 init : function() { let type = this.isPrivate ? Downloads.PRIVATE : Downloads.PUBLIC; Downloads.getList(type).then(aList => { this.list = aList; return this.list.addView(this); }).then(this.log("init list"), Cu.reportError); Downloads.getSummary(type).then(aSummary => { this.summary = aSummary; return this.summary.addView(this); }).then(this.log("init summary"), Cu.reportError); }, // Viewの登録と解除 addView : function() { this.list.addView(this).then(this.log("addView list"), Cu.reportError); this.summary.addView(this).then(this.log("addView summary"), Cu.reportError); }, removeView : function() { this.list.removeView(this).then(this.log("removeView list"), Cu.reportError); this.summary.removeView(this).then(this.log("removeView summary"), Cu.reportError); }, // listView用のメソッド onDownloadAdded : function(aDownload) { this.logDownload("onDownloadAdded", aDownload); }, onDownloadChanged : function(aDownload) { this.logDownload("onDownloadChanged", aDownload); }, onDownloadRemoved : function(aDownload) { this.logDownload("onDownloadRemoved", aDownload); }, // summaryView用メソッド onSummaryChanged : function() { this.logSummary(); }, // その他 logDownload : function(str, aDownload) { str += "\nSource URL : " + aDownload.source.url + "\nstopped : " + aDownload.stopped + "\nsucceeded : " + aDownload.succeeded + "\ncanceled : " + aDownload.canceled + "\nhasProgress : " + aDownload.hasProgress; this.log(str); }, logSummary : function() { let str = "onSummaryChanged" + "\nStopped :" + this.summary.allHaveStopped + "\nTotalBytes :" + this.summary.progressTotalBytes + "\nCurrentBytes:" + this.summary.progressCurrentBytes; this.log(str); }, log : function(str) { let self = this.isPrivate ? "PrivateView" : "PublicView"; str = "[" + self + "] " + str; Services.console.logStringMessage(str); }, } myDownloads.addView();}} *メモ -DownloadsCommon.jsmはFirefox本体使用に特化されてて汎用性が無いので拡張機能ではあまり使えないと思われる。でもコードの参考にはなる。
Firefox26からDownload.jsmを使用するようになったので試行錯誤してみた -[[Downloads.jsm - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm]] -[[DownloadList - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm/DownloadList]] -[[Download - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm/Download]] -[[DownloadSummary - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm/DownloadSummary]] *Private と Public を区別して監視 #highlight(javascript){{ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm"); var myDownloads = { PublicView : null, PrivateView : null, addView : function() { if (this.PublicView) this.PublicView.addView(); else this.PublicView = new DownloadsView(false); if (this.PrivateView) this.PrivateView.addView(); else this.PrivateView = new DownloadsView(true); }, removeView : function() { if (this.PublicView) this.PublicView.removeView(); if (this.PrivateView) this.PrivateView.removeView(); }, } // DownloadsViewクラス function DownloadsView(aPrivate) { this.isPrivate = aPrivate; this.list = null; this.summary = null; this.init(); } DownloadsView.prototype = { // View作成で自動的に登録 init : function() { let type = this.isPrivate ? Downloads.PRIVATE : Downloads.PUBLIC; Downloads.getList(type).then(aList => { this.list = aList; return this.list.addView(this); }).then(this.log("init list"), Cu.reportError); Downloads.getSummary(type).then(aSummary => { this.summary = aSummary; return this.summary.addView(this); }).then(this.log("init summary"), Cu.reportError); }, // Viewの登録と解除 addView : function() { this.list.addView(this).then(this.log("addView list"), Cu.reportError); this.summary.addView(this).then(this.log("addView summary"), Cu.reportError); }, removeView : function() { this.list.removeView(this).then(this.log("removeView list"), Cu.reportError); this.summary.removeView(this).then(this.log("removeView summary"), Cu.reportError); }, // listView用のメソッド onDownloadAdded : function(aDownload) { this.logDownload("onDownloadAdded", aDownload); }, onDownloadChanged : function(aDownload) { this.logDownload("onDownloadChanged", aDownload); }, onDownloadRemoved : function(aDownload) { this.logDownload("onDownloadRemoved", aDownload); }, // summaryView用メソッド onSummaryChanged : function() { this.logSummary(); }, // その他 logDownload : function(str, aDownload) { str += "\nSource URL : " + aDownload.source.url + "\nstopped : " + aDownload.stopped + "\nsucceeded : " + aDownload.succeeded + "\ncanceled : " + aDownload.canceled + "\nhasProgress : " + aDownload.hasProgress; this.log(str); }, logSummary : function() { let str = "onSummaryChanged" + "\nStopped :" + this.summary.allHaveStopped + "\nTotalBytes :" + this.summary.progressTotalBytes + "\nCurrentBytes:" + this.summary.progressCurrentBytes; this.log(str); }, log : function(str) { let self = this.isPrivate ? "PrivateView" : "PublicView"; str = "[" + self + "] " + str; Services.console.logStringMessage(str); }, } myDownloads.addView();}} *メモ -DownloadsCommon.jsmはFirefox本体使用に特化されてて汎用性が無いので拡張機能ではほぼ使えないと思われる(内部定義のオブジェクトを分析して複製するのは面倒すぎる)。でもコードの参考にはなる。

表示オプション

横に並べて表示:
変化行の前後のみ表示: