2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-02-10 04:05:31 +03:00
|
|
|
|
2015-02-09 20:50:43 +03:00
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2017-06-20 03:04:03 +03:00
|
|
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
2015-02-09 20:50:43 +03:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2017-06-20 03:04:03 +03:00
|
|
|
Cu.import("resource://gre/modules/KeyValueParser.jsm");
|
2017-01-17 18:48:17 +03:00
|
|
|
Cu.importGlobalProperties(["File"]);
|
2015-02-09 20:50:43 +03:00
|
|
|
|
2016-05-11 09:50:55 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "OS",
|
|
|
|
"resource://gre/modules/osfile.jsm");
|
2010-03-17 08:10:08 +03:00
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.EXPORTED_SYMBOLS = [
|
2010-02-10 04:05:31 +03:00
|
|
|
"CrashSubmit"
|
|
|
|
];
|
|
|
|
|
|
|
|
const STATE_START = Ci.nsIWebProgressListener.STATE_START;
|
|
|
|
const STATE_STOP = Ci.nsIWebProgressListener.STATE_STOP;
|
|
|
|
|
2010-03-17 08:10:08 +03:00
|
|
|
const SUCCESS = "success";
|
|
|
|
const FAILED = "failed";
|
|
|
|
const SUBMITTING = "submitting";
|
|
|
|
|
2016-05-11 09:50:55 +03:00
|
|
|
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
2010-02-10 04:05:31 +03:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
// TODO: this is still synchronous; need an async INI parser to make it async
|
|
|
|
function parseINIStrings(path) {
|
|
|
|
let file = new FileUtils.File(path);
|
|
|
|
let factory = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
|
2010-02-10 04:05:31 +03:00
|
|
|
getService(Ci.nsIINIParserFactory);
|
2017-06-20 03:04:03 +03:00
|
|
|
let parser = factory.createINIParser(file);
|
|
|
|
let obj = {};
|
|
|
|
let en = parser.getKeys("Strings");
|
2010-02-10 04:05:31 +03:00
|
|
|
while (en.hasMore()) {
|
2017-06-20 03:04:03 +03:00
|
|
|
let key = en.getNext();
|
2010-02-10 04:05:31 +03:00
|
|
|
obj[key] = parser.getString("Strings", key);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
// Since we're basically re-implementing (with async) part of the crashreporter
|
2010-02-10 04:05:31 +03:00
|
|
|
// client here, we'll just steal the strings we need from crashreporter.ini
|
2017-06-20 03:04:03 +03:00
|
|
|
async function getL10nStrings() {
|
2010-02-10 04:05:31 +03:00
|
|
|
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
2017-06-20 03:04:03 +03:00
|
|
|
let path = OS.Path.join(dirSvc.get("GreD", Ci.nsIFile).path,
|
|
|
|
"crashreporter.ini");
|
|
|
|
let pathExists = await OS.File.exists(path);
|
|
|
|
|
|
|
|
if (!pathExists) {
|
|
|
|
// we if we're on a mac
|
|
|
|
let parentDir = OS.Path.dirname(path);
|
|
|
|
path = OS.Path.join(parentDir, "MacOS", "crashreporter.app", "Contents",
|
|
|
|
"Resources", "crashreporter.ini");
|
|
|
|
|
|
|
|
let pathExists = await OS.File.exists(path);
|
|
|
|
|
|
|
|
if (!pathExists) {
|
2017-05-24 18:07:41 +03:00
|
|
|
// This happens on Android where everything is in an APK.
|
|
|
|
// Android users can't see the contents of the submitted files
|
|
|
|
// anyway, so just hardcode some fallback strings.
|
|
|
|
return {
|
|
|
|
"crashid": "Crash ID: %s",
|
|
|
|
"reporturl": "You can view details of this crash at %s"
|
|
|
|
};
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
|
|
|
}
|
2017-06-20 03:04:03 +03:00
|
|
|
|
2010-02-10 04:05:31 +03:00
|
|
|
let crstrings = parseINIStrings(path);
|
2016-05-11 09:50:55 +03:00
|
|
|
let strings = {
|
2017-01-17 18:48:17 +03:00
|
|
|
"crashid": crstrings.CrashID,
|
|
|
|
"reporturl": crstrings.CrashDetailsURL
|
2010-02-10 04:05:31 +03:00
|
|
|
};
|
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
path = OS.Path.join(dirSvc.get("XCurProcD", Ci.nsIFile).path,
|
|
|
|
"crashreporter-override.ini");
|
|
|
|
pathExists = await OS.File.exists(path);
|
|
|
|
|
|
|
|
if (pathExists) {
|
2010-02-10 04:05:31 +03:00
|
|
|
crstrings = parseINIStrings(path);
|
2017-06-20 03:04:03 +03:00
|
|
|
|
|
|
|
if ("CrashID" in crstrings) {
|
2017-07-25 21:15:41 +03:00
|
|
|
strings.crashid = crstrings.CrashID;
|
2017-06-20 03:04:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ("CrashDetailsURL" in crstrings) {
|
2017-07-25 21:15:41 +03:00
|
|
|
strings.reporturl = crstrings.CrashDetailsURL;
|
2017-06-20 03:04:03 +03:00
|
|
|
}
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
2017-06-20 03:04:03 +03:00
|
|
|
|
2016-05-11 09:50:55 +03:00
|
|
|
return strings;
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
|
|
|
|
2014-06-20 19:31:29 +04:00
|
|
|
function getDir(name) {
|
2017-06-20 03:04:03 +03:00
|
|
|
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
|
|
|
let uAppDataPath = dirSvc.get("UAppData", Ci.nsIFile).path;
|
|
|
|
return OS.Path.join(uAppDataPath, "Crash Reports", name);
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
async function isDirAsync(path) {
|
|
|
|
try {
|
|
|
|
let dirInfo = await OS.File.stat(path);
|
2012-12-07 01:27:49 +04:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
if (!dirInfo.isDir) {
|
|
|
|
return false;
|
2012-12-07 01:27:49 +04:00
|
|
|
}
|
2017-06-20 03:04:03 +03:00
|
|
|
} catch (ex) {
|
|
|
|
return false;
|
2012-12-07 01:27:49 +04:00
|
|
|
}
|
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
return true;
|
2012-12-07 01:27:49 +04:00
|
|
|
}
|
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
async function writeFileAsync(dirName, fileName, data) {
|
|
|
|
let dirPath = getDir(dirName);
|
|
|
|
let filePath = OS.Path.join(dirPath, fileName);
|
|
|
|
// succeeds even with existing path, permissions 700
|
|
|
|
await OS.File.makeDir(dirPath, { unixFlags: OS.Constants.libc.S_IRWXU });
|
|
|
|
await OS.File.writeAtomic(filePath, data, { encoding: "utf-8" });
|
|
|
|
}
|
2012-12-12 02:06:48 +04:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
function getPendingMinidump(id) {
|
2014-06-20 19:31:29 +04:00
|
|
|
let pendingDir = getDir("pending");
|
2012-12-12 02:06:48 +04:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
return [".dmp", ".extra", ".memory.json.gz"].map(suffix => {
|
|
|
|
return OS.Path.join(pendingDir, `${id}${suffix}`);
|
2012-12-12 02:06:48 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-02-10 04:05:31 +03:00
|
|
|
function addFormEntry(doc, form, name, value) {
|
2017-06-20 03:04:03 +03:00
|
|
|
let input = doc.createElement("input");
|
2010-02-10 04:05:31 +03:00
|
|
|
input.type = "hidden";
|
|
|
|
input.name = name;
|
|
|
|
input.value = value;
|
|
|
|
form.appendChild(input);
|
|
|
|
}
|
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
async function writeSubmittedReportAsync(crashID, viewURL) {
|
|
|
|
let strings = await getL10nStrings();
|
|
|
|
let data = strings.crashid.replace("%s", crashID);
|
|
|
|
|
|
|
|
if (viewURL) {
|
|
|
|
data += "\n" + strings.reporturl.replace("%s", viewURL);
|
|
|
|
}
|
2010-02-10 04:05:31 +03:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
await writeFileAsync("submitted", `${crashID}.txt`, data);
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// the Submitter class represents an individual submission.
|
2015-02-09 20:50:43 +03:00
|
|
|
function Submitter(id, recordSubmission, noThrottle, extraExtraKeyVals) {
|
2010-02-10 04:05:31 +03:00
|
|
|
this.id = id;
|
2014-08-22 02:43:50 +04:00
|
|
|
this.recordSubmission = recordSubmission;
|
2010-06-30 18:29:05 +04:00
|
|
|
this.noThrottle = noThrottle;
|
2012-09-08 21:20:59 +04:00
|
|
|
this.additionalDumps = [];
|
2013-02-15 03:57:50 +04:00
|
|
|
this.extraKeyVals = extraExtraKeyVals || {};
|
2017-06-20 03:04:03 +03:00
|
|
|
// mimic deferred Promise behavior
|
|
|
|
this.submitStatusPromise = new Promise((resolve, reject) => {
|
|
|
|
this.resolveSubmitStatusPromise = resolve;
|
|
|
|
this.rejectSubmitStatusPromise = reject;
|
|
|
|
});
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Submitter.prototype = {
|
2017-06-20 03:04:03 +03:00
|
|
|
submitSuccess: async function Submitter_submitSuccess(ret) {
|
|
|
|
// Write out the details file to submitted
|
|
|
|
await writeSubmittedReportAsync(ret.CrashID, ret.ViewURL);
|
2010-02-10 04:05:31 +03:00
|
|
|
|
|
|
|
try {
|
2017-06-20 03:04:03 +03:00
|
|
|
let toDelete = [this.dump, this.extra];
|
2014-08-30 09:21:25 +04:00
|
|
|
|
|
|
|
if (this.memory) {
|
2017-06-20 03:04:03 +03:00
|
|
|
toDelete.push(this.memory);
|
2014-08-30 09:21:25 +04:00
|
|
|
}
|
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
for (let dump of this.additionalDumps) {
|
|
|
|
toDelete.push(dump);
|
2012-09-08 21:20:59 +04:00
|
|
|
}
|
2017-06-20 03:04:03 +03:00
|
|
|
|
|
|
|
await Promise.all(toDelete.map(path => {
|
|
|
|
return OS.File.remove(path, { ignoreAbsent: true });
|
|
|
|
}));
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (ex) {
|
2017-06-20 03:04:03 +03:00
|
|
|
Cu.reportError(ex);
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
|
|
|
|
2010-03-17 08:10:08 +03:00
|
|
|
this.notifyStatus(SUCCESS, ret);
|
2010-02-10 04:05:31 +03:00
|
|
|
this.cleanup();
|
|
|
|
},
|
|
|
|
|
|
|
|
cleanup: function Submitter_cleanup() {
|
|
|
|
// drop some references just to be nice
|
|
|
|
this.iframe = null;
|
|
|
|
this.dump = null;
|
|
|
|
this.extra = null;
|
2014-08-30 09:21:25 +04:00
|
|
|
this.memory = null;
|
2012-09-08 21:20:59 +04:00
|
|
|
this.additionalDumps = null;
|
2010-02-10 04:05:31 +03:00
|
|
|
// remove this object from the list of active submissions
|
|
|
|
let idx = CrashSubmit._activeSubmissions.indexOf(this);
|
2017-06-20 03:04:03 +03:00
|
|
|
if (idx != -1) {
|
2010-02-10 04:05:31 +03:00
|
|
|
CrashSubmit._activeSubmissions.splice(idx, 1);
|
2017-06-20 03:04:03 +03:00
|
|
|
}
|
2010-02-10 04:05:31 +03:00
|
|
|
},
|
|
|
|
|
2016-12-31 05:47:25 +03:00
|
|
|
submitForm: function Submitter_submitForm() {
|
2017-01-17 18:48:17 +03:00
|
|
|
if (!("ServerURL" in this.extraKeyVals)) {
|
2010-02-10 04:05:31 +03:00
|
|
|
return false;
|
|
|
|
}
|
2013-02-15 03:57:50 +04:00
|
|
|
let serverURL = this.extraKeyVals.ServerURL;
|
2012-09-11 23:13:00 +04:00
|
|
|
|
2014-09-08 19:17:10 +04:00
|
|
|
// Override the submission URL from the environment
|
2012-09-11 23:13:00 +04:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
let envOverride = Cc["@mozilla.org/process/environment;1"].
|
2012-09-11 23:13:00 +04:00
|
|
|
getService(Ci.nsIEnvironment).get("MOZ_CRASHREPORTER_URL");
|
2017-01-17 18:48:17 +03:00
|
|
|
if (envOverride != "") {
|
2012-09-11 23:13:00 +04:00
|
|
|
serverURL = envOverride;
|
|
|
|
}
|
|
|
|
|
2011-07-21 04:51:55 +04:00
|
|
|
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
|
|
|
.createInstance(Ci.nsIXMLHttpRequest);
|
2012-09-11 23:13:00 +04:00
|
|
|
xhr.open("POST", serverURL, true);
|
2011-07-21 04:51:55 +04:00
|
|
|
|
|
|
|
let formData = Cc["@mozilla.org/files/formdata;1"]
|
|
|
|
.createInstance(Ci.nsIDOMFormData);
|
2013-02-15 03:57:50 +04:00
|
|
|
// add the data
|
2016-08-03 09:23:10 +03:00
|
|
|
for (let [name, value] of Object.entries(this.extraKeyVals)) {
|
2017-08-28 09:43:24 +03:00
|
|
|
if (name != "ServerURL" && name != "StackTraces") {
|
2013-02-15 03:57:50 +04:00
|
|
|
formData.append(name, value);
|
|
|
|
}
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
2010-06-30 18:29:05 +04:00
|
|
|
if (this.noThrottle) {
|
|
|
|
// tell the server not to throttle this, since it was manually submitted
|
2011-07-21 04:51:55 +04:00
|
|
|
formData.append("Throttleable", "0");
|
2010-06-30 18:29:05 +04:00
|
|
|
}
|
2012-09-08 21:20:59 +04:00
|
|
|
// add the minidumps
|
2017-02-08 12:18:32 +03:00
|
|
|
let promises = [
|
2017-06-20 03:04:03 +03:00
|
|
|
File.createFromFileName(this.dump).then(file => {
|
2017-02-08 12:18:32 +03:00
|
|
|
formData.append("upload_file_minidump", file);
|
|
|
|
})
|
2017-06-20 03:04:03 +03:00
|
|
|
];
|
2017-02-08 12:18:32 +03:00
|
|
|
|
2014-08-30 09:21:25 +04:00
|
|
|
if (this.memory) {
|
2017-06-20 03:04:03 +03:00
|
|
|
promises.push(File.createFromFileName(this.memory).then(file => {
|
2017-02-08 12:18:32 +03:00
|
|
|
formData.append("memory_report", file);
|
|
|
|
}));
|
2014-08-30 09:21:25 +04:00
|
|
|
}
|
2017-02-08 12:18:32 +03:00
|
|
|
|
2012-09-08 21:20:59 +04:00
|
|
|
if (this.additionalDumps.length > 0) {
|
|
|
|
let names = [];
|
|
|
|
for (let i of this.additionalDumps) {
|
|
|
|
names.push(i.name);
|
2017-06-20 03:04:03 +03:00
|
|
|
promises.push(File.createFromFileName(i.dump).then(file => {
|
2017-02-08 12:18:32 +03:00
|
|
|
formData.append("upload_file_minidump_" + i.name, file);
|
|
|
|
}));
|
2012-09-08 21:20:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-22 02:43:50 +04:00
|
|
|
let manager = Services.crashmanager;
|
2014-09-02 21:02:40 +04:00
|
|
|
let submissionID = manager.generateSubmissionID();
|
2014-08-22 02:43:50 +04:00
|
|
|
|
2015-02-09 20:51:17 +03:00
|
|
|
xhr.addEventListener("readystatechange", (evt) => {
|
2011-07-21 04:51:55 +04:00
|
|
|
if (xhr.readyState == 4) {
|
2014-07-09 19:14:42 +04:00
|
|
|
let ret =
|
2017-06-20 03:04:03 +03:00
|
|
|
xhr.status === 200 ? parseKeyValuePairs(xhr.responseText) : {};
|
2014-07-09 19:14:42 +04:00
|
|
|
let submitted = !!ret.CrashID;
|
2016-11-23 13:28:04 +03:00
|
|
|
let p = Promise.resolve();
|
2014-07-09 19:14:42 +04:00
|
|
|
|
2015-02-09 20:51:17 +03:00
|
|
|
if (this.recordSubmission) {
|
2014-08-22 02:43:50 +04:00
|
|
|
let result = submitted ? manager.SUBMISSION_RESULT_OK :
|
|
|
|
manager.SUBMISSION_RESULT_FAILED;
|
2016-11-23 13:28:04 +03:00
|
|
|
p = manager.addSubmissionResult(this.id, submissionID, new Date(),
|
|
|
|
result);
|
2014-08-29 08:03:02 +04:00
|
|
|
if (submitted) {
|
2015-02-09 20:51:17 +03:00
|
|
|
manager.setRemoteCrashID(this.id, ret.CrashID);
|
2014-08-29 08:03:02 +04:00
|
|
|
}
|
2014-07-09 19:14:42 +04:00
|
|
|
}
|
|
|
|
|
2016-11-23 13:28:04 +03:00
|
|
|
p.then(() => {
|
|
|
|
if (submitted) {
|
|
|
|
this.submitSuccess(ret);
|
|
|
|
} else {
|
|
|
|
this.notifyStatus(FAILED);
|
|
|
|
this.cleanup();
|
|
|
|
}
|
|
|
|
});
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
2017-01-17 13:50:25 +03:00
|
|
|
});
|
2010-02-10 04:05:31 +03:00
|
|
|
|
2017-02-08 12:18:32 +03:00
|
|
|
let p = Promise.all(promises);
|
2016-11-23 13:28:04 +03:00
|
|
|
let id = this.id;
|
|
|
|
|
2014-08-22 02:43:50 +04:00
|
|
|
if (this.recordSubmission) {
|
2017-06-12 13:00:56 +03:00
|
|
|
p = p.then(() => { return manager.ensureCrashIsPresent(id); })
|
|
|
|
.then(() => {
|
|
|
|
return manager.addSubmissionAttempt(id, submissionID, new Date());
|
|
|
|
});
|
2014-08-22 02:43:50 +04:00
|
|
|
}
|
2016-11-23 13:28:04 +03:00
|
|
|
p.then(() => { xhr.send(formData); });
|
2011-07-21 04:51:55 +04:00
|
|
|
return true;
|
2010-02-10 04:05:31 +03:00
|
|
|
},
|
|
|
|
|
2016-12-31 05:47:25 +03:00
|
|
|
notifyStatus: function Submitter_notify(status, ret) {
|
2010-03-17 08:10:08 +03:00
|
|
|
let propBag = Cc["@mozilla.org/hash-property-bag;1"].
|
|
|
|
createInstance(Ci.nsIWritablePropertyBag2);
|
|
|
|
propBag.setPropertyAsAString("minidumpID", this.id);
|
2010-06-30 18:29:05 +04:00
|
|
|
if (status == SUCCESS) {
|
|
|
|
propBag.setPropertyAsAString("serverCrashID", ret.CrashID);
|
|
|
|
}
|
2010-03-17 08:10:08 +03:00
|
|
|
|
2013-02-15 03:57:50 +04:00
|
|
|
let extraKeyValsBag = Cc["@mozilla.org/hash-property-bag;1"].
|
|
|
|
createInstance(Ci.nsIWritablePropertyBag2);
|
|
|
|
for (let key in this.extraKeyVals) {
|
|
|
|
extraKeyValsBag.setPropertyAsAString(key, this.extraKeyVals[key]);
|
|
|
|
}
|
|
|
|
propBag.setPropertyAsInterface("extra", extraKeyValsBag);
|
|
|
|
|
2010-03-17 08:10:08 +03:00
|
|
|
Services.obs.notifyObservers(propBag, "crash-report-status", status);
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case SUCCESS:
|
2017-06-20 03:04:03 +03:00
|
|
|
this.resolveSubmitStatusPromise(ret.CrashID);
|
2010-03-17 08:10:08 +03:00
|
|
|
break;
|
|
|
|
case FAILED:
|
2017-06-20 03:04:03 +03:00
|
|
|
this.rejectSubmitStatusPromise(FAILED);
|
2010-03-17 08:10:08 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// no callbacks invoked.
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
submit: async function Submitter_submit() {
|
2014-08-30 09:21:25 +04:00
|
|
|
let [dump, extra, memory] = getPendingMinidump(this.id);
|
2017-06-20 03:04:03 +03:00
|
|
|
let [dumpExists, extraExists, memoryExists] = await Promise.all([
|
|
|
|
OS.File.exists(dump),
|
|
|
|
OS.File.exists(extra),
|
|
|
|
OS.File.exists(memory)
|
|
|
|
]);
|
2014-08-30 09:21:25 +04:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
if (!dumpExists || !extraExists) {
|
2010-03-17 08:10:08 +03:00
|
|
|
this.notifyStatus(FAILED);
|
2010-02-10 20:20:37 +03:00
|
|
|
this.cleanup();
|
2017-06-20 03:04:03 +03:00
|
|
|
return this.submitStatusPromise;
|
2010-02-10 20:20:37 +03:00
|
|
|
}
|
2017-06-20 03:04:03 +03:00
|
|
|
|
2014-08-30 09:21:25 +04:00
|
|
|
this.dump = dump;
|
|
|
|
this.extra = extra;
|
2017-06-20 03:04:03 +03:00
|
|
|
this.memory = memoryExists ? memory : null;
|
2014-08-30 09:21:25 +04:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
let extraKeyVals = await parseKeyValuePairsFromFileAsync(extra);
|
2010-03-17 08:10:08 +03:00
|
|
|
|
2013-02-15 03:57:50 +04:00
|
|
|
for (let key in extraKeyVals) {
|
|
|
|
if (!(key in this.extraKeyVals)) {
|
|
|
|
this.extraKeyVals[key] = extraKeyVals[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-08 21:20:59 +04:00
|
|
|
let additionalDumps = [];
|
2017-06-20 03:04:03 +03:00
|
|
|
|
2013-02-15 03:57:50 +04:00
|
|
|
if ("additional_minidumps" in this.extraKeyVals) {
|
2017-06-20 03:04:03 +03:00
|
|
|
let dumpsExistsPromises = [];
|
2017-01-17 18:48:17 +03:00
|
|
|
let names = this.extraKeyVals.additional_minidumps.split(",");
|
2017-06-20 03:04:03 +03:00
|
|
|
|
2012-09-15 00:37:58 +04:00
|
|
|
for (let name of names) {
|
2016-11-10 01:06:32 +03:00
|
|
|
let [dump /* , extra, memory */] = getPendingMinidump(this.id + "-" + name);
|
2017-06-20 03:04:03 +03:00
|
|
|
|
|
|
|
dumpsExistsPromises.push(OS.File.exists(dump));
|
|
|
|
additionalDumps.push({name, dump});
|
|
|
|
}
|
|
|
|
|
|
|
|
let dumpsExist = await Promise.all(dumpsExistsPromises);
|
|
|
|
let allDumpsExist = dumpsExist.every(exists => exists);
|
|
|
|
|
|
|
|
if (!allDumpsExist) {
|
|
|
|
this.notifyStatus(FAILED);
|
|
|
|
this.cleanup();
|
|
|
|
return this.submitStatusPromise;
|
2012-09-08 21:20:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-17 08:10:08 +03:00
|
|
|
this.notifyStatus(SUBMITTING);
|
2012-09-08 21:20:59 +04:00
|
|
|
this.additionalDumps = additionalDumps;
|
2010-02-10 04:05:31 +03:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
if (!(await this.submitForm())) {
|
2011-07-21 04:51:55 +04:00
|
|
|
this.notifyStatus(FAILED);
|
|
|
|
this.cleanup();
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
2017-06-20 03:04:03 +03:00
|
|
|
|
|
|
|
return this.submitStatusPromise;
|
2010-02-10 04:05:31 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-24 20:14:19 +03:00
|
|
|
// ===================================
|
2010-02-10 04:05:31 +03:00
|
|
|
// External API goes here
|
2012-10-31 20:13:28 +04:00
|
|
|
this.CrashSubmit = {
|
2010-02-10 04:05:31 +03:00
|
|
|
/**
|
|
|
|
* Submit the crash report named id.dmp from the "pending" directory.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* Filename (minus .dmp extension) of the minidump to submit.
|
2011-07-21 04:52:13 +04:00
|
|
|
* @param params
|
|
|
|
* An object containing any of the following optional parameters:
|
2014-08-22 02:43:50 +04:00
|
|
|
* - recordSubmission
|
|
|
|
* If true, a submission event is recorded in CrashManager.
|
2011-07-21 04:52:13 +04:00
|
|
|
* - noThrottle
|
|
|
|
* If true, this crash report should be submitted with
|
|
|
|
* an extra parameter of "Throttleable=0" indicating that
|
|
|
|
* it should be processed right away. This should be set
|
|
|
|
* when the report is being submitted and the user expects
|
|
|
|
* to see the results immediately. Defaults to false.
|
2013-02-15 03:57:50 +04:00
|
|
|
* - extraExtraKeyVals
|
|
|
|
* An object whose key-value pairs will be merged with the data from
|
|
|
|
* the ".extra" file submitted with the report. The properties of
|
|
|
|
* this object will override properties of the same name in the
|
|
|
|
* .extra file.
|
2010-02-10 04:05:31 +03:00
|
|
|
*
|
2015-02-09 20:50:43 +03:00
|
|
|
* @return a Promise that is fulfilled with the server crash ID when the
|
|
|
|
* submission succeeds and rejected otherwise.
|
2010-02-10 04:05:31 +03:00
|
|
|
*/
|
2016-12-31 05:47:25 +03:00
|
|
|
submit: function CrashSubmit_submit(id, params) {
|
2011-07-21 04:52:13 +04:00
|
|
|
params = params || {};
|
2014-08-22 02:43:50 +04:00
|
|
|
let recordSubmission = false;
|
2011-07-21 04:52:13 +04:00
|
|
|
let noThrottle = false;
|
2013-02-15 03:57:50 +04:00
|
|
|
let extraExtraKeyVals = null;
|
2011-07-21 04:52:13 +04:00
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
if ("recordSubmission" in params) {
|
2014-08-22 02:43:50 +04:00
|
|
|
recordSubmission = params.recordSubmission;
|
2017-06-20 03:04:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ("noThrottle" in params) {
|
2011-07-21 04:52:13 +04:00
|
|
|
noThrottle = params.noThrottle;
|
2017-06-20 03:04:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ("extraExtraKeyVals" in params) {
|
2013-02-15 03:57:50 +04:00
|
|
|
extraExtraKeyVals = params.extraExtraKeyVals;
|
2017-06-20 03:04:03 +03:00
|
|
|
}
|
2011-07-21 04:52:13 +04:00
|
|
|
|
2014-08-22 02:43:50 +04:00
|
|
|
let submitter = new Submitter(id, recordSubmission,
|
2014-07-09 19:14:42 +04:00
|
|
|
noThrottle, extraExtraKeyVals);
|
2010-02-10 04:05:31 +03:00
|
|
|
CrashSubmit._activeSubmissions.push(submitter);
|
|
|
|
return submitter.submit();
|
|
|
|
},
|
|
|
|
|
2013-05-02 20:57:41 +04:00
|
|
|
/**
|
|
|
|
* Delete the minidup from the "pending" directory.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* Filename (minus .dmp extension) of the minidump to delete.
|
2017-06-20 03:04:03 +03:00
|
|
|
*
|
|
|
|
* @return a Promise that is fulfilled when the minidump is deleted and
|
|
|
|
* rejected otherwise
|
2013-05-02 20:57:41 +04:00
|
|
|
*/
|
2017-06-20 03:04:03 +03:00
|
|
|
delete: async function CrashSubmit_delete(id) {
|
|
|
|
await Promise.all(getPendingMinidump(id).map(path => {
|
|
|
|
return OS.File.remove(path, { ignoreAbsent: true });
|
|
|
|
}));
|
2013-05-02 20:57:41 +04:00
|
|
|
},
|
|
|
|
|
2016-05-11 09:50:55 +03:00
|
|
|
/**
|
|
|
|
* Add a .dmg.ignore file along side the .dmp file to indicate that the user
|
|
|
|
* shouldn't be prompted to submit this crash report again.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* Filename (minus .dmp extension) of the report to ignore
|
2012-12-07 01:27:49 +04:00
|
|
|
*
|
2017-06-20 03:04:03 +03:00
|
|
|
* @return a Promise that is fulfilled when (if) the .dmg.ignore is created
|
|
|
|
* and rejected otherwise.
|
2012-12-07 01:27:49 +04:00
|
|
|
*/
|
2017-06-20 03:04:03 +03:00
|
|
|
ignore: async function CrashSubmit_ignore(id) {
|
|
|
|
let [dump /* , extra, memory */] = getPendingMinidump(id);
|
|
|
|
let file = await OS.File.open(`${dump}.ignore`, { create: true },
|
|
|
|
{ unixFlags: OS.Constants.libc.O_CREAT });
|
|
|
|
await file.close();
|
2012-12-07 01:27:49 +04:00
|
|
|
},
|
|
|
|
|
2016-05-11 09:50:55 +03:00
|
|
|
/**
|
|
|
|
* Get the list of pending crash IDs, excluding those marked to be ignored
|
2017-06-20 03:04:03 +03:00
|
|
|
* @param minFileDate
|
2016-05-11 09:50:55 +03:00
|
|
|
* A Date object. Any files last modified before that date will be ignored
|
|
|
|
*
|
|
|
|
* @return a Promise that is fulfilled with an array of string, each
|
2017-06-20 03:04:03 +03:00
|
|
|
* being an ID as expected to be passed to submit() or ignore()
|
2016-05-11 09:50:55 +03:00
|
|
|
*/
|
2017-06-20 03:04:03 +03:00
|
|
|
pendingIDs: async function CrashSubmit_pendingIDs(minFileDate) {
|
2016-05-11 09:50:55 +03:00
|
|
|
let ids = [];
|
2017-06-20 03:04:03 +03:00
|
|
|
let dirIter = null;
|
|
|
|
let pendingDir = getDir("pending");
|
|
|
|
|
2016-05-11 09:50:55 +03:00
|
|
|
try {
|
2017-06-20 03:04:03 +03:00
|
|
|
dirIter = new OS.File.DirectoryIterator(pendingDir);
|
2016-05-11 09:50:55 +03:00
|
|
|
} catch (ex) {
|
2017-06-20 03:04:03 +03:00
|
|
|
Cu.reportError(ex);
|
|
|
|
throw ex;
|
2016-05-11 09:50:55 +03:00
|
|
|
}
|
|
|
|
|
2017-10-30 14:24:39 +03:00
|
|
|
if (!(await dirIter.exists())) {
|
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
|
2017-06-20 03:04:03 +03:00
|
|
|
try {
|
|
|
|
let entries = Object.create(null);
|
|
|
|
let ignored = Object.create(null);
|
|
|
|
|
|
|
|
// `await` in order to ensure all callbacks are called
|
|
|
|
await dirIter.forEach(entry => {
|
|
|
|
if (!entry.isDir /* is file */) {
|
|
|
|
let matches = entry.name.match(/(.+)\.dmp$/);
|
|
|
|
|
|
|
|
if (matches) {
|
|
|
|
let id = matches[1];
|
|
|
|
|
|
|
|
if (UUID_REGEX.test(id)) {
|
|
|
|
entries[id] = OS.File.stat(entry.path);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// maybe it's a .ignore file
|
|
|
|
let matchesIgnore = entry.name.match(/(.+)\.dmp.ignore$/);
|
|
|
|
|
|
|
|
if (matchesIgnore) {
|
2017-07-04 00:48:40 +03:00
|
|
|
let id = matchesIgnore[1];
|
2017-06-20 03:04:03 +03:00
|
|
|
|
|
|
|
if (UUID_REGEX.test(id)) {
|
|
|
|
ignored[id] = true;
|
|
|
|
}
|
2016-05-11 09:50:55 +03:00
|
|
|
}
|
|
|
|
}
|
2017-06-20 03:04:03 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let entry in entries) {
|
|
|
|
let entryInfo = await entries[entry];
|
|
|
|
|
2017-07-04 00:48:40 +03:00
|
|
|
if (!(entry in ignored) &&
|
2017-06-20 03:04:03 +03:00
|
|
|
entryInfo.lastAccessDate > minFileDate) {
|
|
|
|
ids.push(entry);
|
|
|
|
}
|
2016-05-11 09:50:55 +03:00
|
|
|
}
|
2017-06-20 03:04:03 +03:00
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
throw ex;
|
|
|
|
} finally {
|
|
|
|
dirIter.close();
|
2016-05-11 09:50:55 +03:00
|
|
|
}
|
2017-06-20 03:04:03 +03:00
|
|
|
|
2016-05-11 09:50:55 +03:00
|
|
|
return ids;
|
2017-05-12 15:42:39 +03:00
|
|
|
},
|
2016-05-11 09:50:55 +03:00
|
|
|
|
2012-12-12 02:06:48 +04:00
|
|
|
/**
|
|
|
|
* Prune the saved dumps.
|
2017-06-20 03:04:03 +03:00
|
|
|
*
|
|
|
|
* @return a Promise that is fulfilled when the daved dumps are deleted and
|
|
|
|
* rejected otherwise
|
2012-12-12 02:06:48 +04:00
|
|
|
*/
|
2017-06-20 03:04:03 +03:00
|
|
|
pruneSavedDumps: async function CrashSubmit_pruneSavedDumps() {
|
|
|
|
const KEEP = 10;
|
|
|
|
|
|
|
|
let dirIter = null;
|
|
|
|
let dirEntries = [];
|
|
|
|
let pendingDir = getDir("pending");
|
|
|
|
|
|
|
|
try {
|
|
|
|
dirIter = new OS.File.DirectoryIterator(pendingDir);
|
|
|
|
} catch (ex) {
|
|
|
|
if (ex instanceof OS.File.Error && ex.becauseNoSuchFile) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await dirIter.forEach(entry => {
|
|
|
|
if (!entry.isDir /* is file */) {
|
|
|
|
let matches = entry.name.match(/(.+)\.extra$/);
|
|
|
|
|
|
|
|
if (matches) {
|
|
|
|
dirEntries.push({
|
|
|
|
name: entry.name,
|
|
|
|
path: entry.path,
|
|
|
|
// dispatch promise instead of blocking iteration on `await`
|
|
|
|
infoPromise: OS.File.stat(entry.path)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
throw ex;
|
|
|
|
} finally {
|
|
|
|
dirIter.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
dirEntries.sort(async (a, b) => {
|
|
|
|
let dateA = (await a.infoPromise).lastModificationDate;
|
|
|
|
let dateB = (await b.infoPromise).lastModificationDate;
|
|
|
|
|
|
|
|
if (dateA < dateB) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dateB < dateA) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (dirEntries.length > KEEP) {
|
|
|
|
let toDelete = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < dirEntries.length - KEEP; ++i) {
|
|
|
|
let extra = dirEntries[i];
|
|
|
|
let matches = extra.leafName.match(/(.+)\.extra$/);
|
|
|
|
|
|
|
|
if (matches) {
|
|
|
|
let pathComponents = OS.Path.split(extra.path);
|
|
|
|
pathComponents[pathComponents.length - 1] = matches[1];
|
|
|
|
let path = OS.Path.join(...pathComponents);
|
|
|
|
|
|
|
|
toDelete.push(extra.path, `${path}.dmp`, `${path}.memory.json.gz`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all(toDelete.map(path => {
|
|
|
|
return OS.File.remove(path, { ignoreAbsent: true });
|
|
|
|
}));
|
|
|
|
}
|
2012-12-12 02:06:48 +04:00
|
|
|
},
|
|
|
|
|
2010-02-10 04:05:31 +03:00
|
|
|
// List of currently active submit objects
|
|
|
|
_activeSubmissions: []
|
|
|
|
};
|