Bug 961369 - Fallback when no file picker available in about:memory. r=njn,mfinkle

This commit is contained in:
Wes Johnston 2014-02-05 10:04:32 -08:00
Родитель 7c36268390
Коммит 98314fbfff
3 изменённых файлов: 30 добавлений и 12 удалений

Просмотреть файл

@ -25,6 +25,7 @@ const XRE_APP_DISTRIBUTION_DIR = "XREAppDist";
const XRE_UPDATE_ROOT_DIR = "UpdRootD";
const ENVVAR_UPDATE_DIR = "UPDATES_DIRECTORY";
const WEBAPPS_DIR = "webappsDir";
const DOWNLOAD_DIR = "DfltDwnld"
const SYSTEM_DIST_PATH = "/system/@ANDROID_PACKAGE_NAME@/distribution";
@ -73,6 +74,9 @@ DirectoryProvider.prototype = {
}
let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
return dm.defaultDownloadsDirectory;
} else if (prop == DOWNLOAD_DIR) {
let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
return dm.defaultDownloadsDirectory;
}
// We are retuning null to show failure instead for throwing an error. The

Просмотреть файл

@ -23,6 +23,7 @@ FilePicker.prototype = {
_filePath: null,
_promptActive: false,
_filterIndex: 0,
_addToRecentDocs: false,
init: function(aParent, aTitle, aMode) {
this._domWin = aParent;
@ -150,11 +151,11 @@ FilePicker.prototype = {
},
get addToRecentDocs() {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
return this._addToRecentDocs;
},
set addToRecentDocs(val) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
this._addToRecentDocs = val;
},
get mode() {

Просмотреть файл

@ -1844,26 +1844,39 @@ function appendSectionHeader(aP, aText)
function saveReportsToFile()
{
let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
fp.init(window, "Save Memory Reports", Ci.nsIFilePicker.modeSave);
fp.appendFilter("Zipped JSON files", "*.json.gz");
fp.appendFilters(Ci.nsIFilePicker.filterAll);
fp.filterIndex = 0;
fp.addToRecentDocs = true;
fp.defaultString = "memory-report.json.gz";
let fpFinish = function(file) {
let dumper = Cc["@mozilla.org/memory-info-dumper;1"]
.getService(Ci.nsIMemoryInfoDumper);
let finishDumping = () => {
updateMainAndFooter("Saved reports to " + file.path, HIDE_FOOTER);
}
dumper.dumpMemoryReportsToNamedFile(file.path, finishDumping, null);
}
let fpCallback = function(aResult) {
if (aResult == Ci.nsIFilePicker.returnOK ||
aResult == Ci.nsIFilePicker.returnReplace) {
let dumper = Cc["@mozilla.org/memory-info-dumper;1"]
.getService(Ci.nsIMemoryInfoDumper);
let finishDumping = () => {
updateMainAndFooter("Saved reports to " + fp.file.path, HIDE_FOOTER);
}
dumper.dumpMemoryReportsToNamedFile(fp.file.path, finishDumping, null);
fpFinish(fp.file);
}
};
try {
fp.init(window, "Save Memory Reports", Ci.nsIFilePicker.modeSave);
} catch(ex) {
// This will fail on Android, since there is no Save as file picker there.
// Just save to the default downloads dir if it does.
let file = Services.dirsvc.get("DfltDwnld", Ci.nsIFile);
file.append(fp.defaultString);
fpFinish(file);
return;
}
fp.open(fpCallback);
}