2012-09-18 13:30:41 -07: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-20 20:42:25 -08:00
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
2010-02-20 20:42:25 -08:00
|
|
|
|
2014-04-22 20:19:12 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Troubleshoot.jsm");
|
|
|
|
Cu.import("resource://gre/modules/ResetProfile.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
|
|
|
|
"resource://gre/modules/PluralForm.jsm");
|
2010-02-20 20:42:25 -08:00
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
window.addEventListener("load", function onload(event) {
|
2014-05-05 07:31:26 -07:00
|
|
|
try {
|
2012-09-18 13:30:41 -07:00
|
|
|
window.removeEventListener("load", onload, false);
|
|
|
|
Troubleshoot.snapshot(function (snapshot) {
|
|
|
|
for (let prop in snapshotFormatters)
|
|
|
|
snapshotFormatters[prop](snapshot[prop]);
|
|
|
|
});
|
2012-02-23 19:34:18 -08:00
|
|
|
populateResetBox();
|
2014-03-24 06:11:21 -07:00
|
|
|
setupEventListeners();
|
2014-05-05 07:31:26 -07:00
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("stack of load error for about:support: " + e + ": " + e.stack);
|
|
|
|
}
|
2012-09-18 13:30:41 -07:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
// Each property in this object corresponds to a property in Troubleshoot.jsm's
|
|
|
|
// snapshot data. Each function is passed its property's corresponding data,
|
|
|
|
// and it's the function's job to update the page with it.
|
|
|
|
let snapshotFormatters = {
|
|
|
|
|
|
|
|
application: function application(data) {
|
|
|
|
$("application-box").textContent = data.name;
|
|
|
|
$("useragent-box").textContent = data.userAgent;
|
|
|
|
$("supportLink").href = data.supportURL;
|
|
|
|
let version = data.version;
|
|
|
|
if (data.vendor)
|
|
|
|
version += " (" + data.vendor + ")";
|
|
|
|
$("version-box").textContent = version;
|
2014-07-16 23:06:06 -07:00
|
|
|
$("multiprocess-box").textContent = data.numRemoteWindows + "/" + data.numTotalWindows;
|
2012-09-18 13:30:41 -07:00
|
|
|
},
|
|
|
|
|
2013-10-27 16:18:14 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
crashes: function crashes(data) {
|
|
|
|
let strings = stringBundle();
|
|
|
|
let daysRange = Troubleshoot.kMaxCrashAge / (24 * 60 * 60 * 1000);
|
|
|
|
$("crashes-title").textContent =
|
|
|
|
PluralForm.get(daysRange, strings.GetStringFromName("crashesTitle"))
|
|
|
|
.replace("#1", daysRange);
|
|
|
|
let reportURL;
|
|
|
|
try {
|
|
|
|
reportURL = Services.prefs.getCharPref("breakpad.reportURL");
|
|
|
|
// Ignore any non http/https urls
|
|
|
|
if (!/^https?:/i.test(reportURL))
|
|
|
|
reportURL = null;
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
if (!reportURL) {
|
|
|
|
$("crashes-noConfig").style.display = "block";
|
|
|
|
$("crashes-noConfig").classList.remove("no-copy");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("crashes-allReports").style.display = "block";
|
|
|
|
$("crashes-allReports").classList.remove("no-copy");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.pending > 0) {
|
|
|
|
$("crashes-allReportsWithPending").textContent =
|
|
|
|
PluralForm.get(data.pending, strings.GetStringFromName("pendingReports"))
|
|
|
|
.replace("#1", data.pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
let dateNow = new Date();
|
|
|
|
$.append($("crashes-tbody"), data.submitted.map(function (crash) {
|
|
|
|
let date = new Date(crash.date);
|
|
|
|
let timePassed = dateNow - date;
|
|
|
|
let formattedDate;
|
|
|
|
if (timePassed >= 24 * 60 * 60 * 1000)
|
|
|
|
{
|
|
|
|
let daysPassed = Math.round(timePassed / (24 * 60 * 60 * 1000));
|
|
|
|
let daysPassedString = strings.GetStringFromName("crashesTimeDays");
|
|
|
|
formattedDate = PluralForm.get(daysPassed, daysPassedString)
|
|
|
|
.replace("#1", daysPassed);
|
|
|
|
}
|
|
|
|
else if (timePassed >= 60 * 60 * 1000)
|
|
|
|
{
|
|
|
|
let hoursPassed = Math.round(timePassed / (60 * 60 * 1000));
|
|
|
|
let hoursPassedString = strings.GetStringFromName("crashesTimeHours");
|
|
|
|
formattedDate = PluralForm.get(hoursPassed, hoursPassedString)
|
|
|
|
.replace("#1", hoursPassed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
let minutesPassed = Math.max(Math.round(timePassed / (60 * 1000)), 1);
|
|
|
|
let minutesPassedString = strings.GetStringFromName("crashesTimeMinutes");
|
|
|
|
formattedDate = PluralForm.get(minutesPassed, minutesPassedString)
|
|
|
|
.replace("#1", minutesPassed);
|
|
|
|
}
|
|
|
|
return $.new("tr", [
|
|
|
|
$.new("td", [
|
|
|
|
$.new("a", crash.id, null, {href : reportURL + crash.id})
|
|
|
|
]),
|
|
|
|
$.new("td", formattedDate)
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
extensions: function extensions(data) {
|
|
|
|
$.append($("extensions-tbody"), data.map(function (extension) {
|
|
|
|
return $.new("tr", [
|
|
|
|
$.new("td", extension.name),
|
|
|
|
$.new("td", extension.version),
|
|
|
|
$.new("td", extension.isActive),
|
|
|
|
$.new("td", extension.id),
|
2010-04-20 15:14:15 -07:00
|
|
|
]);
|
2012-09-18 13:30:41 -07:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2014-03-20 08:19:19 -07:00
|
|
|
experiments: function experiments(data) {
|
|
|
|
$.append($("experiments-tbody"), data.map(function (experiment) {
|
|
|
|
return $.new("tr", [
|
|
|
|
$.new("td", experiment.name),
|
|
|
|
$.new("td", experiment.id),
|
|
|
|
$.new("td", experiment.description),
|
|
|
|
$.new("td", experiment.active),
|
|
|
|
$.new("td", experiment.endDate),
|
|
|
|
$.new("td", [
|
|
|
|
$.new("a", experiment.detailURL, null, {href : experiment.detailURL,})
|
|
|
|
]),
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
modifiedPreferences: function modifiedPreferences(data) {
|
|
|
|
$.append($("prefs-tbody"), sortedArrayFromObject(data).map(
|
|
|
|
function ([name, value]) {
|
|
|
|
return $.new("tr", [
|
|
|
|
$.new("td", name, "pref-name"),
|
|
|
|
// Very long preference values can cause users problems when they
|
|
|
|
// copy and paste them into some text editors. Long values generally
|
|
|
|
// aren't useful anyway, so truncate them to a reasonable length.
|
|
|
|
$.new("td", String(value).substr(0, 120), "pref-value"),
|
2014-06-10 07:49:00 -07:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
},
|
|
|
|
|
|
|
|
lockedPreferences: function lockedPreferences(data) {
|
|
|
|
$.append($("locked-prefs-tbody"), sortedArrayFromObject(data).map(
|
|
|
|
function ([name, value]) {
|
|
|
|
return $.new("tr", [
|
|
|
|
$.new("td", name, "pref-name"),
|
|
|
|
$.new("td", String(value).substr(0, 120), "pref-value"),
|
2012-09-18 13:30:41 -07:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
},
|
|
|
|
|
|
|
|
graphics: function graphics(data) {
|
|
|
|
// graphics-info-properties tbody
|
|
|
|
if ("info" in data) {
|
|
|
|
let trs = sortedArrayFromObject(data.info).map(function ([prop, val]) {
|
|
|
|
return $.new("tr", [
|
|
|
|
$.new("th", prop, "column"),
|
|
|
|
$.new("td", String(val)),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
$.append($("graphics-info-properties"), trs);
|
|
|
|
delete data.info;
|
2010-04-20 15:14:15 -07:00
|
|
|
}
|
2010-02-20 20:42:25 -08:00
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
// graphics-failures-tbody tbody
|
|
|
|
if ("failures" in data) {
|
|
|
|
$.append($("graphics-failures-tbody"), data.failures.map(function (val) {
|
|
|
|
return $.new("tr", [$.new("td", val)]);
|
|
|
|
}));
|
|
|
|
delete data.failures;
|
|
|
|
}
|
2010-02-20 20:42:25 -08:00
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
// graphics-tbody tbody
|
2012-03-12 16:04:37 -07:00
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
function localizedMsg(msgArray) {
|
|
|
|
let nameOrMsg = msgArray.shift();
|
2013-05-20 20:05:50 -07:00
|
|
|
if (msgArray.length) {
|
|
|
|
// formatStringFromName logs an NS_ASSERTION failure otherwise that says
|
|
|
|
// "use GetStringFromName". Lame.
|
|
|
|
try {
|
|
|
|
return strings.formatStringFromName(nameOrMsg, msgArray,
|
|
|
|
msgArray.length);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
// Throws if nameOrMsg is not a name in the bundle. This shouldn't
|
|
|
|
// actually happen though, since msgArray.length > 1 => nameOrMsg is a
|
|
|
|
// name in the bundle, not a message, and the remaining msgArray
|
|
|
|
// elements are parameters.
|
|
|
|
return nameOrMsg;
|
|
|
|
}
|
|
|
|
}
|
2012-09-18 13:30:41 -07:00
|
|
|
try {
|
2013-05-20 20:05:50 -07:00
|
|
|
return strings.GetStringFromName(nameOrMsg);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
// Throws if nameOrMsg is not a name in the bundle.
|
2012-09-18 13:30:41 -07:00
|
|
|
}
|
|
|
|
return nameOrMsg;
|
2011-05-03 13:07:17 -07:00
|
|
|
}
|
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
let out = Object.create(data);
|
|
|
|
let strings = stringBundle();
|
|
|
|
|
|
|
|
out.acceleratedWindows =
|
|
|
|
data.numAcceleratedWindows + "/" + data.numTotalWindows;
|
|
|
|
if (data.windowLayerManagerType)
|
|
|
|
out.acceleratedWindows += " " + data.windowLayerManagerType;
|
2013-05-21 20:36:38 -07:00
|
|
|
if (data.windowLayerManagerRemote)
|
|
|
|
out.acceleratedWindows += " (OMTC)";
|
2012-09-18 13:30:41 -07:00
|
|
|
if (data.numAcceleratedWindowsMessage)
|
|
|
|
out.acceleratedWindows +=
|
|
|
|
" " + localizedMsg(data.numAcceleratedWindowsMessage);
|
|
|
|
delete data.numAcceleratedWindows;
|
|
|
|
delete data.numTotalWindows;
|
|
|
|
delete data.windowLayerManagerType;
|
|
|
|
delete data.numAcceleratedWindowsMessage;
|
|
|
|
|
|
|
|
if ("direct2DEnabledMessage" in data) {
|
|
|
|
out.direct2DEnabled = localizedMsg(data.direct2DEnabledMessage);
|
|
|
|
delete data.direct2DEnabledMessage;
|
|
|
|
delete data.direct2DEnabled;
|
2011-05-03 13:07:17 -07:00
|
|
|
}
|
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
if ("directWriteEnabled" in data) {
|
|
|
|
out.directWriteEnabled = data.directWriteEnabled;
|
|
|
|
if ("directWriteVersion" in data)
|
|
|
|
out.directWriteEnabled += " (" + data.directWriteVersion + ")";
|
|
|
|
delete data.directWriteEnabled;
|
|
|
|
delete data.directWriteVersion;
|
2011-05-03 13:07:17 -07:00
|
|
|
}
|
2011-05-03 13:07:17 -07:00
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
if ("webglRendererMessage" in data) {
|
|
|
|
out.webglRenderer = localizedMsg(data.webglRendererMessage);
|
|
|
|
delete data.webglRendererMessage;
|
|
|
|
delete data.webglRenderer;
|
|
|
|
}
|
2011-05-10 17:30:20 -07:00
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
let localizedOut = {};
|
|
|
|
for (let prop in out) {
|
|
|
|
let val = out[prop];
|
|
|
|
if (typeof(val) == "string" && !val)
|
|
|
|
// Ignore properties that are empty strings.
|
|
|
|
continue;
|
2011-05-10 17:30:20 -07:00
|
|
|
try {
|
2012-09-18 13:30:41 -07:00
|
|
|
var localizedName = strings.GetStringFromName(prop);
|
2011-05-10 17:30:20 -07:00
|
|
|
}
|
2012-09-18 13:30:41 -07:00
|
|
|
catch (err) {
|
|
|
|
// This shouldn't happen, but if there's a reported graphics property
|
|
|
|
// that isn't in the string bundle, don't let it break the page.
|
|
|
|
localizedName = prop;
|
|
|
|
}
|
|
|
|
localizedOut[localizedName] = val;
|
2011-11-17 20:00:37 -08:00
|
|
|
}
|
2012-09-18 13:30:41 -07:00
|
|
|
let trs = sortedArrayFromObject(localizedOut).map(function ([prop, val]) {
|
|
|
|
return $.new("tr", [
|
|
|
|
$.new("th", prop, "column"),
|
|
|
|
$.new("td", val),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
$.append($("graphics-tbody"), trs);
|
|
|
|
},
|
|
|
|
|
|
|
|
javaScript: function javaScript(data) {
|
|
|
|
$("javascript-incremental-gc").textContent = data.incrementalGCEnabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
accessibility: function accessibility(data) {
|
|
|
|
$("a11y-activated").textContent = data.isActive;
|
|
|
|
$("a11y-force-disabled").textContent = data.forceDisabled || 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
libraryVersions: function libraryVersions(data) {
|
|
|
|
let strings = stringBundle();
|
|
|
|
let trs = [
|
|
|
|
$.new("tr", [
|
|
|
|
$.new("th", ""),
|
|
|
|
$.new("th", strings.GetStringFromName("minLibVersions")),
|
|
|
|
$.new("th", strings.GetStringFromName("loadedLibVersions")),
|
|
|
|
])
|
|
|
|
];
|
|
|
|
sortedArrayFromObject(data).forEach(
|
|
|
|
function ([name, val]) {
|
|
|
|
trs.push($.new("tr", [
|
|
|
|
$.new("td", name),
|
|
|
|
$.new("td", val.minVersion),
|
|
|
|
$.new("td", val.version),
|
|
|
|
]));
|
|
|
|
}
|
2011-02-07 13:11:57 -08:00
|
|
|
);
|
2012-09-18 13:30:41 -07:00
|
|
|
$.append($("libversions-tbody"), trs);
|
|
|
|
},
|
2012-09-26 16:03:00 -07:00
|
|
|
|
|
|
|
userJS: function userJS(data) {
|
|
|
|
if (!data.exists)
|
|
|
|
return;
|
|
|
|
let userJSFile = Services.dirsvc.get("PrefD", Ci.nsIFile);
|
|
|
|
userJSFile.append("user.js");
|
|
|
|
$("prefs-user-js-link").href = Services.io.newFileURI(userJSFile).spec;
|
|
|
|
$("prefs-user-js-section").style.display = "";
|
2012-10-31 16:10:46 -07:00
|
|
|
// Clear the no-copy class
|
|
|
|
$("prefs-user-js-section").className = "";
|
2012-09-26 16:03:00 -07:00
|
|
|
},
|
2014-11-06 03:40:00 -08:00
|
|
|
|
|
|
|
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
|
|
|
|
sandbox: function sandbox(data) {
|
|
|
|
const keys = ["hasSeccompBPF", "canSandboxContent", "canSandboxMedia"];
|
|
|
|
let strings = stringBundle();
|
|
|
|
let tbody = $("sandbox-tbody");
|
|
|
|
for (key of keys) {
|
|
|
|
if (key in data) {
|
|
|
|
tbody.appendChild($.new("tr", [
|
|
|
|
$.new("th", strings.GetStringFromName(key), "column"),
|
|
|
|
$.new("td", data[key])
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
#endif
|
2012-09-18 13:30:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
let $ = document.getElementById.bind(document);
|
|
|
|
|
2013-10-27 16:18:14 -07:00
|
|
|
$.new = function $_new(tag, textContentOrChildren, className, attributes) {
|
2012-09-18 13:30:41 -07:00
|
|
|
let elt = document.createElement(tag);
|
|
|
|
if (className)
|
|
|
|
elt.className = className;
|
2013-10-27 16:18:14 -07:00
|
|
|
if (attributes) {
|
|
|
|
for (let attrName in attributes)
|
|
|
|
elt.setAttribute(attrName, attributes[attrName]);
|
|
|
|
}
|
2012-09-18 13:30:41 -07:00
|
|
|
if (Array.isArray(textContentOrChildren))
|
|
|
|
this.append(elt, textContentOrChildren);
|
|
|
|
else
|
|
|
|
elt.textContent = String(textContentOrChildren);
|
|
|
|
return elt;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.append = function $_append(parent, children) {
|
|
|
|
children.forEach(function (c) parent.appendChild(c));
|
|
|
|
};
|
|
|
|
|
|
|
|
function stringBundle() {
|
|
|
|
return Services.strings.createBundle(
|
|
|
|
"chrome://global/locale/aboutSupport.properties");
|
2010-08-13 18:29:46 -07:00
|
|
|
}
|
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
function sortedArrayFromObject(obj) {
|
|
|
|
let tuples = [];
|
|
|
|
for (let prop in obj)
|
|
|
|
tuples.push([prop, obj[prop]]);
|
|
|
|
tuples.sort(function ([prop1, v1], [prop2, v2]) prop1.localeCompare(prop2));
|
|
|
|
return tuples;
|
2012-02-17 14:35:20 -08:00
|
|
|
}
|
|
|
|
|
2012-09-18 13:30:41 -07:00
|
|
|
function copyRawDataToClipboard(button) {
|
|
|
|
if (button)
|
|
|
|
button.disabled = true;
|
2012-06-27 08:47:27 -07:00
|
|
|
try {
|
2012-09-18 13:30:41 -07:00
|
|
|
Troubleshoot.snapshot(function (snapshot) {
|
|
|
|
if (button)
|
|
|
|
button.disabled = false;
|
|
|
|
let str = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
str.data = JSON.stringify(snapshot, undefined, 2);
|
|
|
|
let transferable = Cc["@mozilla.org/widget/transferable;1"].
|
|
|
|
createInstance(Ci.nsITransferable);
|
|
|
|
transferable.init(getLoadContext());
|
|
|
|
transferable.addDataFlavor("text/unicode");
|
|
|
|
transferable.setTransferData("text/unicode", str, str.data.length * 2);
|
|
|
|
Cc["@mozilla.org/widget/clipboard;1"].
|
|
|
|
getService(Ci.nsIClipboard).
|
|
|
|
setData(transferable, null, Ci.nsIClipboard.kGlobalClipboard);
|
2012-09-22 10:12:30 -07:00
|
|
|
#ifdef ANDROID
|
|
|
|
// Present a toast notification.
|
|
|
|
let message = {
|
2013-02-04 13:22:30 -08:00
|
|
|
type: "Toast:Show",
|
|
|
|
message: stringBundle().GetStringFromName("rawDataCopied"),
|
|
|
|
duration: "short"
|
2012-09-22 10:12:30 -07:00
|
|
|
};
|
2014-04-04 09:33:50 -07:00
|
|
|
Services.androidBridge.handleGeckoMessage(message);
|
2012-09-22 10:12:30 -07:00
|
|
|
#endif
|
2012-09-18 13:30:41 -07:00
|
|
|
});
|
2012-06-27 08:47:27 -07:00
|
|
|
}
|
2012-09-18 13:30:41 -07:00
|
|
|
catch (err) {
|
|
|
|
if (button)
|
|
|
|
button.disabled = false;
|
|
|
|
throw err;
|
2010-09-11 02:16:00 -07:00
|
|
|
}
|
2010-02-20 20:42:25 -08:00
|
|
|
}
|
|
|
|
|
2012-04-16 19:14:01 -07:00
|
|
|
function getLoadContext() {
|
|
|
|
return window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsILoadContext);
|
|
|
|
}
|
|
|
|
|
2010-02-20 20:42:25 -08:00
|
|
|
function copyContentsToClipboard() {
|
|
|
|
// Get the HTML and text representations for the important part of the page.
|
2012-09-18 13:30:41 -07:00
|
|
|
let contentsDiv = $("contents");
|
2010-02-20 20:42:25 -08:00
|
|
|
let dataHtml = contentsDiv.innerHTML;
|
|
|
|
let dataText = createTextForElement(contentsDiv);
|
|
|
|
|
|
|
|
// We can't use plain strings, we have to use nsSupportsString.
|
|
|
|
let supportsStringClass = Cc["@mozilla.org/supports-string;1"];
|
|
|
|
let ssHtml = supportsStringClass.createInstance(Ci.nsISupportsString);
|
|
|
|
let ssText = supportsStringClass.createInstance(Ci.nsISupportsString);
|
|
|
|
|
|
|
|
let transferable = Cc["@mozilla.org/widget/transferable;1"]
|
|
|
|
.createInstance(Ci.nsITransferable);
|
2012-04-16 19:14:01 -07:00
|
|
|
transferable.init(getLoadContext());
|
2010-02-20 20:42:25 -08:00
|
|
|
|
|
|
|
// Add the HTML flavor.
|
|
|
|
transferable.addDataFlavor("text/html");
|
|
|
|
ssHtml.data = dataHtml;
|
|
|
|
transferable.setTransferData("text/html", ssHtml, dataHtml.length * 2);
|
|
|
|
|
|
|
|
// Add the plain text flavor.
|
|
|
|
transferable.addDataFlavor("text/unicode");
|
|
|
|
ssText.data = dataText;
|
|
|
|
transferable.setTransferData("text/unicode", ssText, dataText.length * 2);
|
|
|
|
|
|
|
|
// Store the data into the clipboard.
|
|
|
|
let clipboard = Cc["@mozilla.org/widget/clipboard;1"]
|
|
|
|
.getService(Ci.nsIClipboard);
|
|
|
|
clipboard.setData(transferable, null, clipboard.kGlobalClipboard);
|
2012-09-22 10:12:30 -07:00
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
// Present a toast notification.
|
|
|
|
let message = {
|
2013-02-04 13:22:30 -08:00
|
|
|
type: "Toast:Show",
|
|
|
|
message: stringBundle().GetStringFromName("textCopied"),
|
|
|
|
duration: "short"
|
2012-09-22 10:12:30 -07:00
|
|
|
};
|
2014-04-04 09:33:50 -07:00
|
|
|
Services.androidBridge.handleGeckoMessage(message);
|
2012-09-22 10:12:30 -07:00
|
|
|
#endif
|
2010-02-20 20:42:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the plain text representation of an element. Do a little bit
|
|
|
|
// of pretty-printing to make it human-readable.
|
|
|
|
function createTextForElement(elem) {
|
2013-05-20 20:05:53 -07:00
|
|
|
let serializer = new Serializer();
|
|
|
|
let text = serializer.serialize(elem);
|
2010-02-20 20:42:25 -08:00
|
|
|
|
|
|
|
// Actual CR/LF pairs are needed for some Windows text editors.
|
|
|
|
#ifdef XP_WIN
|
|
|
|
text = text.replace(/\n/g, "\r\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2013-05-20 20:05:53 -07:00
|
|
|
function Serializer() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Serializer.prototype = {
|
|
|
|
|
|
|
|
serialize: function (rootElem) {
|
|
|
|
this._lines = [];
|
|
|
|
this._startNewLine();
|
|
|
|
this._serializeElement(rootElem);
|
|
|
|
this._startNewLine();
|
|
|
|
return this._lines.join("\n").trim() + "\n";
|
|
|
|
},
|
|
|
|
|
|
|
|
// The current line is always the line that writing will start at next. When
|
|
|
|
// an element is serialized, the current line is updated to be the line at
|
|
|
|
// which the next element should be written.
|
|
|
|
get _currentLine() {
|
|
|
|
return this._lines.length ? this._lines[this._lines.length - 1] : null;
|
|
|
|
},
|
2012-09-29 09:32:56 -07:00
|
|
|
|
2013-05-20 20:05:53 -07:00
|
|
|
set _currentLine(val) {
|
|
|
|
return this._lines[this._lines.length - 1] = val;
|
|
|
|
},
|
2010-02-20 20:42:25 -08:00
|
|
|
|
2013-05-20 20:05:53 -07:00
|
|
|
_serializeElement: function (elem) {
|
|
|
|
if (this._ignoreElement(elem))
|
|
|
|
return;
|
2010-02-20 20:42:25 -08:00
|
|
|
|
2013-05-20 20:05:53 -07:00
|
|
|
// table
|
|
|
|
if (elem.localName == "table") {
|
|
|
|
this._serializeTable(elem);
|
|
|
|
return;
|
2010-02-20 20:42:25 -08:00
|
|
|
}
|
2013-05-20 20:05:53 -07:00
|
|
|
|
|
|
|
// all other elements
|
|
|
|
|
|
|
|
let hasText = false;
|
|
|
|
for (let child of elem.childNodes) {
|
|
|
|
if (child.nodeType == Node.TEXT_NODE) {
|
|
|
|
let text = this._nodeText(child);
|
|
|
|
this._appendText(text);
|
|
|
|
hasText = hasText || !!text.trim();
|
|
|
|
}
|
|
|
|
else if (child.nodeType == Node.ELEMENT_NODE)
|
|
|
|
this._serializeElement(child);
|
2010-02-20 20:42:25 -08:00
|
|
|
}
|
|
|
|
|
2013-05-20 20:05:53 -07:00
|
|
|
// For headings, draw a "line" underneath them so they stand out.
|
|
|
|
if (/^h[0-9]+$/.test(elem.localName)) {
|
|
|
|
let headerText = (this._currentLine || "").trim();
|
|
|
|
if (headerText) {
|
|
|
|
this._startNewLine();
|
|
|
|
this._appendText("-".repeat(headerText.length));
|
|
|
|
}
|
|
|
|
}
|
2010-02-20 20:42:25 -08:00
|
|
|
|
2013-05-20 20:05:53 -07:00
|
|
|
// Add a blank line underneath block elements but only if they contain text.
|
|
|
|
if (hasText) {
|
|
|
|
let display = window.getComputedStyle(elem).getPropertyValue("display");
|
|
|
|
if (display == "block") {
|
|
|
|
this._startNewLine();
|
|
|
|
this._startNewLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_startNewLine: function (lines) {
|
|
|
|
let currLine = this._currentLine;
|
|
|
|
if (currLine) {
|
|
|
|
// The current line is not empty. Trim it.
|
|
|
|
this._currentLine = currLine.trim();
|
|
|
|
if (!this._currentLine)
|
|
|
|
// The current line became empty. Discard it.
|
|
|
|
this._lines.pop();
|
|
|
|
}
|
|
|
|
this._lines.push("");
|
|
|
|
},
|
|
|
|
|
|
|
|
_appendText: function (text, lines) {
|
|
|
|
this._currentLine += text;
|
|
|
|
},
|
|
|
|
|
|
|
|
_serializeTable: function (table) {
|
|
|
|
// Collect the table's column headings if in fact there are any. First
|
|
|
|
// check thead. If there's no thead, check the first tr.
|
|
|
|
let colHeadings = {};
|
|
|
|
let tableHeadingElem = table.querySelector("thead");
|
|
|
|
if (!tableHeadingElem)
|
|
|
|
tableHeadingElem = table.querySelector("tr");
|
|
|
|
if (tableHeadingElem) {
|
|
|
|
let tableHeadingCols = tableHeadingElem.querySelectorAll("th,td");
|
|
|
|
// If there's a contiguous run of th's in the children starting from the
|
|
|
|
// rightmost child, then consider them to be column headings.
|
|
|
|
for (let i = tableHeadingCols.length - 1; i >= 0; i--) {
|
|
|
|
if (tableHeadingCols[i].localName != "th")
|
|
|
|
break;
|
|
|
|
colHeadings[i] = this._nodeText(tableHeadingCols[i]).trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let hasColHeadings = Object.keys(colHeadings).length > 0;
|
|
|
|
if (!hasColHeadings)
|
|
|
|
tableHeadingElem = null;
|
|
|
|
|
|
|
|
let trs = table.querySelectorAll("table > tr, tbody > tr");
|
|
|
|
let startRow =
|
|
|
|
tableHeadingElem && tableHeadingElem.localName == "tr" ? 1 : 0;
|
|
|
|
|
|
|
|
if (startRow >= trs.length)
|
|
|
|
// The table's empty.
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (hasColHeadings && !this._ignoreElement(tableHeadingElem)) {
|
|
|
|
// Use column headings. Print each tr as a multi-line chunk like:
|
|
|
|
// Heading 1: Column 1 value
|
|
|
|
// Heading 2: Column 2 value
|
|
|
|
for (let i = startRow; i < trs.length; i++) {
|
|
|
|
if (this._ignoreElement(trs[i]))
|
|
|
|
continue;
|
|
|
|
let children = trs[i].querySelectorAll("td");
|
|
|
|
for (let j = 0; j < children.length; j++) {
|
|
|
|
let text = "";
|
|
|
|
if (colHeadings[j])
|
|
|
|
text += colHeadings[j] + ": ";
|
|
|
|
text += this._nodeText(children[j]).trim();
|
|
|
|
this._appendText(text);
|
|
|
|
this._startNewLine();
|
|
|
|
}
|
|
|
|
this._startNewLine();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't use column headings. Assume the table has only two columns and
|
|
|
|
// print each tr in a single line like:
|
|
|
|
// Column 1 value: Column 2 value
|
|
|
|
for (let i = startRow; i < trs.length; i++) {
|
|
|
|
if (this._ignoreElement(trs[i]))
|
|
|
|
continue;
|
|
|
|
let children = trs[i].querySelectorAll("th,td");
|
|
|
|
let rowHeading = this._nodeText(children[0]).trim();
|
|
|
|
this._appendText(rowHeading + ": " + this._nodeText(children[1]).trim());
|
|
|
|
this._startNewLine();
|
|
|
|
}
|
|
|
|
this._startNewLine();
|
|
|
|
},
|
|
|
|
|
|
|
|
_ignoreElement: function (elem) {
|
|
|
|
return elem.classList.contains("no-copy");
|
|
|
|
},
|
|
|
|
|
|
|
|
_nodeText: function (node) {
|
|
|
|
return node.textContent.replace(/\s+/g, " ");
|
|
|
|
},
|
|
|
|
};
|
2010-02-20 20:42:25 -08:00
|
|
|
|
|
|
|
function openProfileDirectory() {
|
|
|
|
// Get the profile directory.
|
2010-09-11 02:16:00 -07:00
|
|
|
let currProfD = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
2010-02-20 20:42:25 -08:00
|
|
|
let profileDir = currProfD.path;
|
|
|
|
|
|
|
|
// Show the profile directory.
|
|
|
|
let nsLocalFile = Components.Constructor("@mozilla.org/file/local;1",
|
|
|
|
"nsILocalFile", "initWithPath");
|
|
|
|
new nsLocalFile(profileDir).reveal();
|
|
|
|
}
|
2012-02-23 19:34:18 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Profile reset is only supported for the default profile if the appropriate migrator exists.
|
|
|
|
*/
|
|
|
|
function populateResetBox() {
|
2013-06-28 20:25:08 -07:00
|
|
|
if (ResetProfile.resetSupported())
|
2012-09-18 13:30:41 -07:00
|
|
|
$("reset-box").style.visibility = "visible";
|
2012-02-23 19:34:18 -08:00
|
|
|
}
|
2014-03-24 06:11:21 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up event listeners for buttons.
|
|
|
|
*/
|
|
|
|
function setupEventListeners(){
|
|
|
|
$("show-update-history-button").addEventListener("click", function (event) {
|
|
|
|
var prompter = Cc["@mozilla.org/updates/update-prompt;1"].createInstance(Ci.nsIUpdatePrompt);
|
|
|
|
prompter.showUpdateHistory(window);
|
|
|
|
});
|
|
|
|
$("reset-box-button").addEventListener("click", function (event){
|
|
|
|
ResetProfile.openConfirmationDialog(window);
|
|
|
|
});
|
|
|
|
$("copy-raw-data-to-clipboard").addEventListener("click", function (event){
|
|
|
|
copyRawDataToClipboard(this);
|
|
|
|
});
|
|
|
|
$("copy-to-clipboard").addEventListener("click", function (event){
|
|
|
|
copyContentsToClipboard();
|
|
|
|
});
|
|
|
|
$("profile-dir-button").addEventListener("click", function (event){
|
|
|
|
openProfileDirectory();
|
|
|
|
});
|
|
|
|
}
|