Commit 1f830c96 authored by Victor Porof's avatar Victor Porof
Browse files

Bug 1561435 - Format browser/components/, a=automatic-formatting

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D36042

--HG--
extra : source : d3afcafdce650a6f36cebbc126ee93b17f13cf52
parent f9f59140
This diff is collapsed.
......@@ -6,9 +6,15 @@
var EXPORTED_SYMBOLS = ["AboutNetErrorHandler"];
const {RemotePages} = ChromeUtils.import("resource://gre/modules/remotepagemanager/RemotePageManagerParent.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(this, "BrowserUtils", "resource://gre/modules/BrowserUtils.jsm");
const { RemotePages } = ChromeUtils.import(
"resource://gre/modules/remotepagemanager/RemotePageManagerParent.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(
this,
"BrowserUtils",
"resource://gre/modules/BrowserUtils.jsm"
);
var AboutNetErrorHandler = {
_inited: false,
......@@ -52,7 +58,7 @@ var AboutNetErrorHandler = {
// Send a message to the content when a captive portal is freed
// so that error pages can refresh themselves.
this.pageListener.sendAsyncMessage("AboutNetErrorCaptivePortalFreed");
break;
break;
}
},
......@@ -60,20 +66,26 @@ var AboutNetErrorHandler = {
switch (msg.name) {
case "Browser:OpenCaptivePortalPage":
Services.obs.notifyObservers(null, "ensure-captive-portal-tab");
break;
break;
case "Browser:PrimeMitm":
this.primeMitm(msg.target.browser);
break;
break;
case "Browser:ResetEnterpriseRootsPref":
Services.prefs.clearUserPref("security.enterprise_roots.enabled");
Services.prefs.clearUserPref("security.enterprise_roots.auto-enabled");
break;
break;
case "RecordCertErrorLoad":
Services.telemetry.recordEvent("security.ui.certerror", "load", "aboutcerterror", msg.data.errorCode, {
has_sts: msg.data.has_sts.toString(),
is_frame: msg.data.is_frame.toString(),
});
break;
Services.telemetry.recordEvent(
"security.ui.certerror",
"load",
"aboutcerterror",
msg.data.errorCode,
{
has_sts: msg.data.has_sts.toString(),
is_frame: msg.data.is_frame.toString(),
}
);
break;
}
},
......@@ -88,8 +100,10 @@ var AboutNetErrorHandler = {
return;
}
let url = Services.prefs.getStringPref("security.certerrors.mitm.priming.endpoint");
let request = new XMLHttpRequest({mozAnon: true});
let url = Services.prefs.getStringPref(
"security.certerrors.mitm.priming.endpoint"
);
let request = new XMLHttpRequest({ mozAnon: true });
request.open("HEAD", url);
request.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
request.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
......@@ -100,7 +114,9 @@ var AboutNetErrorHandler = {
return;
}
let secInfo = request.channel.securityInfo.QueryInterface(Ci.nsITransportSecurityInfo);
let secInfo = request.channel.securityInfo.QueryInterface(
Ci.nsITransportSecurityInfo
);
if (secInfo.errorCodeString != "SEC_ERROR_UNKNOWN_ISSUER") {
return;
}
......@@ -110,22 +126,39 @@ var AboutNetErrorHandler = {
if (secInfo.serverCert && secInfo.serverCert.issuerName) {
// Grab the issuer of the certificate used in the exchange and store it so that our
// network-level MitM detection code has a comparison baseline.
Services.prefs.setStringPref("security.pki.mitm_canary_issuer", secInfo.serverCert.issuerName);
Services.prefs.setStringPref(
"security.pki.mitm_canary_issuer",
secInfo.serverCert.issuerName
);
// MitM issues are sometimes caused by software not registering their root certs in the
// Firefox root store. We might opt for using third party roots from the system root store.
if (Services.prefs.getBoolPref("security.certerrors.mitm.auto_enable_enterprise_roots")) {
if (!Services.prefs.getBoolPref("security.enterprise_roots.enabled")) {
if (
Services.prefs.getBoolPref(
"security.certerrors.mitm.auto_enable_enterprise_roots"
)
) {
if (
!Services.prefs.getBoolPref("security.enterprise_roots.enabled")
) {
// Loading enterprise roots happens on a background thread, so wait for import to finish.
BrowserUtils.promiseObserved("psm:enterprise-certs-imported").then(() => {
if (browser.documentURI.spec.startsWith("about:certerror")) {
browser.reload();
BrowserUtils.promiseObserved("psm:enterprise-certs-imported").then(
() => {
if (browser.documentURI.spec.startsWith("about:certerror")) {
browser.reload();
}
}
});
);
Services.prefs.setBoolPref("security.enterprise_roots.enabled", true);
Services.prefs.setBoolPref(
"security.enterprise_roots.enabled",
true
);
// Record that this pref was automatically set.
Services.prefs.setBoolPref("security.enterprise_roots.auto-enabled", true);
Services.prefs.setBoolPref(
"security.enterprise_roots.auto-enabled",
true
);
}
} else {
// Need to reload the page to make sure network code picks up the canary issuer pref.
......
......@@ -6,20 +6,22 @@
var EXPORTED_SYMBOLS = ["AboutPrivateBrowsingHandler"];
const {RemotePages} = ChromeUtils.import("resource://gre/modules/remotepagemanager/RemotePageManagerParent.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { RemotePages } = ChromeUtils.import(
"resource://gre/modules/remotepagemanager/RemotePageManagerParent.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var AboutPrivateBrowsingHandler = {
_inited: false,
_topics: [
"OpenPrivateWindow",
"SearchHandoff",
],
_topics: ["OpenPrivateWindow", "SearchHandoff"],
init() {
this.pageListener = new RemotePages("about:privatebrowsing");
for (let topic of this._topics) {
this.pageListener.addMessageListener(topic, this.receiveMessage.bind(this));
this.pageListener.addMessageListener(
topic,
this.receiveMessage.bind(this)
);
}
this._inited = true;
},
......@@ -38,12 +40,13 @@ var AboutPrivateBrowsingHandler = {
switch (aMessage.name) {
case "OpenPrivateWindow": {
let win = aMessage.target.browser.ownerGlobal;
win.OpenBrowserWindow({private: true});
win.OpenBrowserWindow({ private: true });
break;
}
case "SearchHandoff": {
let searchAlias = "";
let searchAliases = Services.search.defaultEngine.wrappedJSObject.__internalAliases;
let searchAliases =
Services.search.defaultEngine.wrappedJSObject.__internalAliases;
if (searchAliases && searchAliases.length > 0) {
searchAlias = `${searchAliases[0]} `;
}
......
......@@ -6,13 +6,13 @@
var EXPORTED_SYMBOLS = ["AboutProtectionsHandler"];
const {RemotePages} = ChromeUtils.import("resource://gre/modules/remotepagemanager/RemotePageManagerParent.jsm");
const { RemotePages } = ChromeUtils.import(
"resource://gre/modules/remotepagemanager/RemotePageManagerParent.jsm"
);
var AboutProtectionsHandler = {
_inited: false,
_topics: [
"openContentBlockingPreferences",
],
_topics: ["openContentBlockingPreferences"],
init() {
this.pageListener = new RemotePages("about:protections");
......@@ -36,7 +36,9 @@ var AboutProtectionsHandler = {
let win = aMessage.target.browser.ownerGlobal;
switch (aMessage.name) {
case "openContentBlockingPreferences":
win.openPreferences("privacy-trackingprotection", {origin: "about-protections"});
win.openPreferences("privacy-trackingprotection", {
origin: "about-protections",
});
break;
}
},
......
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const contract = "@mozilla.org/network/protocol/about;1?what=newtab";
const am = Cc[contract].getService(Ci.nsIAboutModule);
......
......@@ -2,9 +2,13 @@
* 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/. */
const {DeferredTask} = ChromeUtils.import("resource://gre/modules/DeferredTask.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const {Preferences} = ChromeUtils.import("resource://gre/modules/Preferences.jsm");
const { DeferredTask } = ChromeUtils.import(
"resource://gre/modules/DeferredTask.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
const SEARCH_TIMEOUT_MS = 100;
const SEARCH_AUTO_MIN_CRARACTERS = 3;
......@@ -22,7 +26,11 @@ const STRINGS_ADD_BY_TYPE = {
};
let gDefaultBranch = Services.prefs.getDefaultBranch("");
let gFilterPrefsTask = new DeferredTask(() => filterPrefs(), SEARCH_TIMEOUT_MS, 0);
let gFilterPrefsTask = new DeferredTask(
() => filterPrefs(),
SEARCH_TIMEOUT_MS,
0
);
/**
* Maps the name of each preference in the back-end to its PrefRow object,
......@@ -108,8 +116,10 @@ class PrefRow {
// We don't know which preferences should be read using getComplexValue,
// so we use a heuristic to determine if this is a localized preference.
// This can throw if there is no value in the localized files.
this.value = Services.prefs.getComplexValue(this.name,
Ci.nsIPrefLocalizedString).data;
this.value = Services.prefs.getComplexValue(
this.name,
Ci.nsIPrefLocalizedString
).data;
}
} catch (ex) {
this.value = "";
......@@ -125,9 +135,11 @@ class PrefRow {
}
get matchesFilter() {
return gFilterShowAll ||
(gFilterPattern && gFilterPattern.test(this.name)) ||
(gFilterString && this.name.toLowerCase().includes(gFilterString));
return (
gFilterShowAll ||
(gFilterPattern && gFilterPattern.test(this.name)) ||
(gFilterString && this.name.toLowerCase().includes(gFilterString))
);
}
/**
......@@ -145,12 +157,12 @@ class PrefRow {
let nameCell = document.createElement("th");
this._element.append(
nameCell,
this.valueCell = document.createElement("td"),
this.editCell = document.createElement("td"),
this.resetCell = document.createElement("td")
(this.valueCell = document.createElement("td")),
(this.editCell = document.createElement("td")),
(this.resetCell = document.createElement("td"))
);
this.editCell.appendChild(
this.editButton = document.createElement("button")
(this.editButton = document.createElement("button"))
);
delete this.resetButton;
......@@ -187,15 +199,19 @@ class PrefRow {
span.setAttribute("aria-hidden", "true");
let outerSpan = document.createElement("span");
let spanL10nId = this.hasUserValue
? "about-config-pref-accessible-value-custom"
: "about-config-pref-accessible-value-default";
document.l10n.setAttributes(outerSpan, spanL10nId,
{ value: "" + this.value });
? "about-config-pref-accessible-value-custom"
: "about-config-pref-accessible-value-default";
document.l10n.setAttributes(outerSpan, spanL10nId, {
value: "" + this.value,
});
outerSpan.appendChild(span);
this.valueCell.textContent = "";
this.valueCell.append(outerSpan);
if (this.type == "Boolean") {
document.l10n.setAttributes(this.editButton, "about-config-pref-toggle");
document.l10n.setAttributes(
this.editButton,
"about-config-pref-toggle"
);
this.editButton.className = "button-toggle";
} else {
document.l10n.setAttributes(this.editButton, "about-config-pref-edit");
......@@ -265,12 +281,16 @@ class PrefRow {
this.resetCell.appendChild(this.resetButton);
}
if (!this.hasDefaultValue) {
document.l10n.setAttributes(this.resetButton,
"about-config-pref-delete");
document.l10n.setAttributes(
this.resetButton,
"about-config-pref-delete"
);
this.resetButton.className = "";
} else {
document.l10n.setAttributes(this.resetButton,
"about-config-pref-reset");
document.l10n.setAttributes(
this.resetButton,
"about-config-pref-reset"
);
this.resetButton.className = "button-reset";
}
} else if (this.resetButton) {
......@@ -291,10 +311,11 @@ class PrefRow {
if (this.hidden) {
className = "hidden";
} else {
className = (this.hasUserValue ? "has-user-value " : "") +
(this.isLocked ? "locked " : "") +
(this.exists ? "" : "deleted ") +
(this.odd ? "odd " : "");
className =
(this.hasUserValue ? "has-user-value " : "") +
(this.isLocked ? "locked " : "") +
(this.exists ? "" : "deleted ") +
(this.odd ? "odd " : "");
}
if (this._lastClassName !== className) {
......@@ -357,16 +378,22 @@ if (!Preferences.get("browser.aboutConfig.showWarning")) {
// immediately to prevent flickering, but wait to filter the preferences until
// the value of the textbox has been restored from previous sessions.
document.addEventListener("DOMContentLoaded", loadPrefs, { once: true });
window.addEventListener("load", () => {
if (document.getElementById("about-config-search").value) {
filterPrefs();
}
}, { once: true });
window.addEventListener(
"load",
() => {
if (document.getElementById("about-config-search").value) {
filterPrefs();
}
},
{ once: true }
);
}
function onWarningButtonClick() {
Services.prefs.setBoolPref("browser.aboutConfig.showWarning",
document.getElementById("showWarningNextTime").checked);
Services.prefs.setBoolPref(
"browser.aboutConfig.showWarning",
document.getElementById("showWarningNextTime").checked
);
loadPrefs();
}
......@@ -378,8 +405,8 @@ function loadPrefs() {
document.body.textContent = "";
document.body.appendChild(content);
let search = gSearchInput = document.getElementById("about-config-search");
let prefs = gPrefsTable = document.getElementById("prefs");
let search = (gSearchInput = document.getElementById("about-config-search"));
let prefs = (gPrefsTable = document.getElementById("prefs"));
let showAll = document.getElementById("show-all");
search.focus();
......@@ -539,7 +566,7 @@ function filterPrefs(options = {}) {
}
if (searchName && !gExistingPrefs.has(searchName)) {
gPrefsTable.appendChild((new PrefRow(searchName)).getElement());
gPrefsTable.appendChild(new PrefRow(searchName).getElement());
}
// We only start observing preference changes after the first search is done,
......@@ -547,11 +574,17 @@ function filterPrefs(options = {}) {
if (!gPrefObserverRegistered) {
gPrefObserverRegistered = true;
Services.prefs.addObserver("", gPrefObserver);
window.addEventListener("unload", () => {
Services.prefs.removeObserver("", gPrefObserver);
}, { once: true });
window.addEventListener(
"unload",
() => {
Services.prefs.removeObserver("", gPrefObserver);
},
{ once: true }
);
}
document.body.classList.toggle("config-warning",
location.href.split(":").every(l => gFilterString.includes(l)));
document.body.classList.toggle(
"config-warning",
location.href.split(":").every(l => gFilterString.includes(l))
);
}
......@@ -6,13 +6,13 @@
* be resolved in bug 1539000.
*/
ChromeUtils.import("resource://testing-common/PromiseTestUtils.jsm", this);
PromiseTestUtils.whitelistRejectionsGlobally(/Too many characters in placeable/);
PromiseTestUtils.whitelistRejectionsGlobally(
/Too many characters in placeable/
);
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [
["test.aboutconfig.added", true],
],
set: [["test.aboutconfig.added", true]],
});
});
......@@ -25,8 +25,8 @@ add_task(async function test_accessible_value() {
]) {
let span = this.getRow(name).valueCell.querySelector("span");
let expectedL10nId = expectHasUserValue
? "about-config-pref-accessible-value-custom"
: "about-config-pref-accessible-value-default";
? "about-config-pref-accessible-value-custom"
: "about-config-pref-accessible-value-default";
Assert.equal(span.getAttribute("data-l10n-id"), expectedL10nId);
}
});
......
......@@ -6,13 +6,17 @@
* be resolved in bug 1539000.
*/
ChromeUtils.import("resource://testing-common/PromiseTestUtils.jsm", this);
PromiseTestUtils.whitelistRejectionsGlobally(/Too many characters in placeable/);
PromiseTestUtils.whitelistRejectionsGlobally(
/Too many characters in placeable/
);
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [
["test.aboutconfig.userValueLikeLocalized",
"chrome://test/locale/testing.properties"],
[
"test.aboutconfig.userValueLikeLocalized",
"chrome://test/locale/testing.properties",
],
],
});
});
......@@ -30,10 +34,12 @@ add_task(async function test_load_settings() {
Assert.equal(this.getRow(PREF_STRING_DEFAULT_EMPTY).value, "");
// Test if the modified state is displayed for the right prefs.
Assert.ok(!this.getRow(PREF_BOOLEAN_DEFAULT_TRUE)
.hasClass("has-user-value"));
Assert.ok(this.getRow(PREF_BOOLEAN_USERVALUE_TRUE)
.hasClass("has-user-value"));
Assert.ok(
!this.getRow(PREF_BOOLEAN_DEFAULT_TRUE).hasClass("has-user-value")
);
Assert.ok(
this.getRow(PREF_BOOLEAN_USERVALUE_TRUE).hasClass("has-user-value")
);
// Test to see if values are localized, sampling from different files. If
// any of these are removed or their value changes, just update the value
......@@ -42,12 +48,15 @@ add_task(async function test_load_settings() {
Assert.equal(this.getRow("intl.ellipsis").value, "\u2026");
Assert.equal(
this.getRow("gecko.handlerService.schemes.mailto.1.uriTemplate").value,
"https://mail.google.com/mail/?extsrc=mailto&url=%s");
"https://mail.google.com/mail/?extsrc=mailto&url=%s"
);
// Test to see if user created value is not empty string when it matches
// /^chrome:\/\/.+\/locale\/.+\.properties/.
Assert.equal(this.getRow("test.aboutconfig.userValueLikeLocalized").value,
"chrome://test/locale/testing.properties");
Assert.equal(
this.getRow("test.aboutconfig.userValueLikeLocalized").value,
"chrome://test/locale/testing.properties"
);
// Test to see if empty string when value matches
// /^chrome:\/\/.+\/locale\/.+\.properties/ and an exception is thrown.
......
......@@ -6,7 +6,9 @@
* be resolved in bug 1539000.
*/
ChromeUtils.import("resource://testing-common/PromiseTestUtils.jsm", this);
PromiseTestUtils.whitelistRejectionsGlobally(/Too many characters in placeable/);
PromiseTestUtils.whitelistRejectionsGlobally(
/Too many characters in placeable/
);
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
......@@ -39,19 +41,26 @@ add_task(async function test_copy() {
let row = this.getRow(name);
// Triple click at any location in the name cell should select the name.
await BrowserTestUtils.synthesizeMouseAtCenter(row.nameCell,
{ clickCount: 3 },
this.browser);
await BrowserTestUtils.synthesizeMouseAtCenter(
row.nameCell,
{ clickCount: 3 },
this.browser
);
Assert.ok(row.nameCell.contains(this.window.getSelection().anchorNode));
await SimpleTest.promiseClipboardChange(name, async () => {
await BrowserTestUtils.synthesizeKey("c", { accelKey: true },
this.browser);
await BrowserTestUtils.synthesizeKey(
"c",
{ accelKey: true },
this.browser
);
});
// Triple click at any location in the value cell should select the value.
await BrowserTestUtils.synthesizeMouseAtCenter(row.valueCell,
{ clickCount: 3 },
this.browser);
await BrowserTestUtils.synthesizeMouseAtCenter(
row.valueCell,
{ clickCount: 3 },
this.browser
);
let selection = this.window.getSelection();
Assert.ok(row.valueCell.contains(selection.anchorNode));
......@@ -59,8 +68,11 @@ add_task(async function test_copy() {
// this makes sure that an empty string can be copied.
Assert.ok(!selection.isCollapsed);
await SimpleTest.promiseClipboardChange(expectedString, async () => {
await BrowserTestUtils.synthesizeKey("c", { accelKey: true },
this.browser);
await BrowserTestUtils.synthesizeKey(
"c",
{ accelKey: true },
this.browser
);
});
}
});
......@@ -69,12 +81,13 @@ add_task(async function test_copy() {
add_task(async function test_copy_multiple() {
await AboutConfigTest.withNewTab(async function() {
// Lines are separated by a single LF character on all platforms.
let expectedString = "test.aboutconfig.copy.false\tfalse\t\n" +
"test.aboutconfig.copy.number\t10\t\n" +
"test.aboutconfig.copy.spaces.1\t \t\n" +
"test.aboutconfig.copy.spaces.2\t \t\n" +
"test.aboutconfig.copy.spaces.3\t \t\n" +
"test.aboutconfig.copy.string\t010.5";
let expectedString =
"test.aboutconfig.copy.false\tfalse\t\n" +
"test.aboutconfig.copy.number\t10\t\n" +
"test.aboutconfig.copy.spaces.1\t \t\n" +
"test.aboutconfig.copy.spaces.2\t \t\n" +
"test.aboutconfig.copy.spaces.3\t \t\n" +
"test.aboutconfig.copy.string\t010.5";
this.search("test.aboutconfig.copy.");
let startRow = this.getRow("test.aboutconfig.copy.false");
......@@ -82,18 +95,34 @@ add_task(async function test_copy_multiple() {
let { width, height } = endRow.valueCell.getBoundingClientRect();
// Drag from the top left of the first row to the bottom right of the last.
await BrowserTestUtils.synthesizeMouse(startRow.nameCell, 1, 1,
{ type: "mousedown" }, this.browser);
await BrowserTestUtils.synthesizeMouse(endRow.valueCell,
width - 1, height - 1,
{ type: "mousemove" }, this.browser);
await BrowserTestUtils.synthesizeMouse(endRow.valueCell,