Bug 1977962 - use a subdialog for the certificate exception override dialog if available a=RyanVM DONTBUILD
Original Revision: https://phabricator.services.mozilla.com/D258326 Differential Revision: https://phabricator.services.mozilla.com/D263455
This commit is contained in:
committed by
rvandermeulen@mozilla.com
parent
ed678723ba
commit
f09f7641bb
@@ -159,18 +159,37 @@ var serverRichList = {
|
||||
},
|
||||
|
||||
addException() {
|
||||
let retval = {
|
||||
let params = {
|
||||
exceptionAdded: false,
|
||||
};
|
||||
let closedCallback = () => {
|
||||
if (params.exceptionAdded) {
|
||||
this.buildRichList();
|
||||
}
|
||||
};
|
||||
// Try to use a subdialog, if available.
|
||||
let cur = window;
|
||||
let prev = null;
|
||||
while (cur != prev) {
|
||||
if (cur.gSubDialog) {
|
||||
cur.gSubDialog.open(
|
||||
"chrome://pippki/content/exceptionDialog.xhtml",
|
||||
{ features: "chrome,centerscreen,modal", closedCallback },
|
||||
params
|
||||
);
|
||||
return;
|
||||
}
|
||||
prev = cur;
|
||||
cur = cur.parent;
|
||||
}
|
||||
// Otherwise, fall back to a dialog.
|
||||
window.browsingContext.topChromeWindow.openDialog(
|
||||
"chrome://pippki/content/exceptionDialog.xhtml",
|
||||
"",
|
||||
"chrome,centerscreen,modal",
|
||||
retval
|
||||
params
|
||||
);
|
||||
if (retval.exceptionAdded) {
|
||||
this.buildRichList();
|
||||
}
|
||||
closedCallback();
|
||||
},
|
||||
|
||||
_setButtonState() {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
:root {
|
||||
max-width: 40em;
|
||||
min-width: 35em;
|
||||
min-height: 24em;
|
||||
}
|
||||
|
||||
#warningSupplemental,
|
||||
|
||||
@@ -250,7 +250,7 @@ function updateCertStatus() {
|
||||
document.getElementById("viewCertButton").disabled = false;
|
||||
|
||||
// Notify observers about the availability of the certificate
|
||||
Services.obs.notifyObservers(null, "cert-exception-ui-ready");
|
||||
Services.obs.notifyObservers(window, "cert-exception-ui-ready");
|
||||
} else if (gChecking) {
|
||||
shortDesc = "add-exception-checking-short";
|
||||
longDesc = "add-exception-checking-long";
|
||||
@@ -325,7 +325,9 @@ function addException() {
|
||||
* @returns {boolean} Whether this dialog is in private browsing mode.
|
||||
*/
|
||||
function inPrivateBrowsingMode() {
|
||||
return PrivateBrowsingUtils.isWindowPrivate(window);
|
||||
return window.isChromeWindow
|
||||
? PrivateBrowsingUtils.isWindowPrivate(window)
|
||||
: PrivateBrowsingUtils.isContentWindowPrivate(window);
|
||||
}
|
||||
|
||||
window.addEventListener("load", () => initExceptionDialog());
|
||||
|
||||
@@ -11,80 +11,114 @@ ChromeUtils.defineESModuleGetters(this, {
|
||||
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
|
||||
});
|
||||
|
||||
function test() {
|
||||
const EXCEPTIONS_DLG_URL = "chrome://pippki/content/exceptionDialog.xhtml";
|
||||
const EXCEPTIONS_DLG_FEATURES = "chrome,centerscreen";
|
||||
const INVALID_CERT_DOMAIN = "self-signed.example.com";
|
||||
const INVALID_CERT_LOCATION = "https://" + INVALID_CERT_DOMAIN + "/";
|
||||
waitForExplicitFinish();
|
||||
const EXCEPTIONS_DLG_URL = "chrome://pippki/content/exceptionDialog.xhtml";
|
||||
const EXCEPTIONS_DLG_FEATURES = "chrome,centerscreen,modal";
|
||||
const INVALID_CERT_DOMAIN = "self-signed.example.com";
|
||||
const INVALID_CERT_LOCATION = "https://" + INVALID_CERT_DOMAIN + "/";
|
||||
|
||||
function testAddCertificate() {
|
||||
win.removeEventListener("load", testAddCertificate);
|
||||
Services.obs.addObserver(async function onCertUI() {
|
||||
Services.obs.removeObserver(onCertUI, "cert-exception-ui-ready");
|
||||
ok(win.gCert, "The certificate information should be available now");
|
||||
registerCleanupFunction(() => {
|
||||
let certOverrideService = Cc[
|
||||
"@mozilla.org/security/certoverride;1"
|
||||
].getService(Ci.nsICertOverrideService);
|
||||
certOverrideService.clearValidityOverride(INVALID_CERT_DOMAIN, -1, {});
|
||||
});
|
||||
|
||||
// Clicking on the View… button should open the certificate viewer.
|
||||
let viewButton = win.document.getElementById("viewCertButton");
|
||||
let tabPromise = BrowserTestUtils.waitForNewTab(
|
||||
gBrowser,
|
||||
url => url.startsWith("about:certificate?cert="),
|
||||
true
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(viewButton, {}, win);
|
||||
BrowserTestUtils.removeTab(await tabPromise);
|
||||
async function onCertExceptionUI(win) {
|
||||
Services.obs.removeObserver(onCertExceptionUI, "cert-exception-ui-ready");
|
||||
ok(win.gCert, "The certificate information should be available now");
|
||||
|
||||
if (AppConstants.platform != "macosx") {
|
||||
// Pressing enter on the View… button should open the certificate viewer.
|
||||
tabPromise = BrowserTestUtils.waitForNewTab(
|
||||
gBrowser,
|
||||
url => url.startsWith("about:certificate?cert="),
|
||||
true
|
||||
);
|
||||
EventUtils.synthesizeKey("KEY_Enter", {}, win);
|
||||
BrowserTestUtils.removeTab(await tabPromise);
|
||||
}
|
||||
// Clicking on the View… button should open the certificate viewer.
|
||||
let viewButton = win.document.getElementById("viewCertButton");
|
||||
let tabPromise = BrowserTestUtils.waitForNewTab(
|
||||
gBrowser,
|
||||
url => url.startsWith("about:certificate?cert="),
|
||||
true
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(viewButton, {}, win);
|
||||
BrowserTestUtils.removeTab(await tabPromise);
|
||||
|
||||
let dialog = win.document.getElementById("exceptiondialog");
|
||||
let confirmButton = dialog.getButton("extra1");
|
||||
confirmButton.click();
|
||||
ok(
|
||||
params.exceptionAdded,
|
||||
"The certificate exception should have been added"
|
||||
);
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
let certOverrideService = Cc[
|
||||
"@mozilla.org/security/certoverride;1"
|
||||
].getService(Ci.nsICertOverrideService);
|
||||
certOverrideService.clearValidityOverride(INVALID_CERT_DOMAIN, -1, {});
|
||||
});
|
||||
|
||||
BrowserTestUtils.startLoadingURIString(gBrowser, INVALID_CERT_LOCATION);
|
||||
let loaded = await BrowserTestUtils.browserLoaded(
|
||||
gBrowser,
|
||||
false,
|
||||
INVALID_CERT_LOCATION,
|
||||
true
|
||||
);
|
||||
ok(loaded, "The certificate exception should allow the page to load");
|
||||
|
||||
finish();
|
||||
}, "cert-exception-ui-ready");
|
||||
if (AppConstants.platform != "macosx") {
|
||||
// Pressing enter on the View… button should open the certificate viewer.
|
||||
tabPromise = BrowserTestUtils.waitForNewTab(
|
||||
gBrowser,
|
||||
url => url.startsWith("about:certificate?cert="),
|
||||
true
|
||||
);
|
||||
viewButton.focus();
|
||||
EventUtils.synthesizeKey("KEY_Enter", {}, win);
|
||||
BrowserTestUtils.removeTab(await tabPromise);
|
||||
}
|
||||
|
||||
let bWin = BrowserWindowTracker.getTopWindow();
|
||||
let dialog = win.document.getElementById("exceptiondialog");
|
||||
let confirmButton = dialog.getButton("extra1");
|
||||
confirmButton.click();
|
||||
}
|
||||
|
||||
add_task(async function test_with_subdialog() {
|
||||
Services.obs.addObserver(onCertExceptionUI, "cert-exception-ui-ready");
|
||||
|
||||
await BrowserTestUtils.withNewTab("about:preferences", async browser => {
|
||||
let params = {
|
||||
exceptionAdded: false,
|
||||
location: INVALID_CERT_LOCATION,
|
||||
prefetchCert: true,
|
||||
};
|
||||
await new Promise(resolve => {
|
||||
// Open the add exception dialog in the way that about:preferences does (in a sub-dialog).
|
||||
browser.contentWindow.gSubDialog.open(
|
||||
EXCEPTIONS_DLG_URL,
|
||||
{ features: EXCEPTIONS_DLG_FEATURES, closedCallback: resolve },
|
||||
params
|
||||
);
|
||||
});
|
||||
ok(
|
||||
params.exceptionAdded,
|
||||
"The certificate exception should have been added"
|
||||
);
|
||||
});
|
||||
|
||||
BrowserTestUtils.startLoadingURIString(gBrowser, INVALID_CERT_LOCATION);
|
||||
let loaded = await BrowserTestUtils.browserLoaded(
|
||||
gBrowser,
|
||||
false,
|
||||
INVALID_CERT_LOCATION,
|
||||
true
|
||||
);
|
||||
ok(loaded, "The certificate exception should allow the page to load");
|
||||
|
||||
let certOverrideService = Cc[
|
||||
"@mozilla.org/security/certoverride;1"
|
||||
].getService(Ci.nsICertOverrideService);
|
||||
certOverrideService.clearValidityOverride(INVALID_CERT_DOMAIN, -1, {});
|
||||
});
|
||||
|
||||
add_task(async function test_with_dialog() {
|
||||
Services.obs.addObserver(onCertExceptionUI, "cert-exception-ui-ready");
|
||||
|
||||
let params = {
|
||||
exceptionAdded: false,
|
||||
location: INVALID_CERT_LOCATION,
|
||||
prefetchCert: true,
|
||||
};
|
||||
|
||||
let win = bWin.openDialog(
|
||||
EXCEPTIONS_DLG_URL,
|
||||
"",
|
||||
EXCEPTIONS_DLG_FEATURES,
|
||||
params
|
||||
let bWin = BrowserWindowTracker.getTopWindow();
|
||||
|
||||
// Open the add exception dialog without a sub-dialog.
|
||||
bWin.openDialog(EXCEPTIONS_DLG_URL, "", EXCEPTIONS_DLG_FEATURES, params);
|
||||
|
||||
ok(params.exceptionAdded, "The certificate exception should have been added");
|
||||
|
||||
BrowserTestUtils.startLoadingURIString(gBrowser, INVALID_CERT_LOCATION);
|
||||
let loaded = await BrowserTestUtils.browserLoaded(
|
||||
gBrowser,
|
||||
false,
|
||||
INVALID_CERT_LOCATION,
|
||||
true
|
||||
);
|
||||
win.addEventListener("load", testAddCertificate);
|
||||
}
|
||||
ok(loaded, "The certificate exception should allow the page to load");
|
||||
|
||||
let certOverrideService = Cc[
|
||||
"@mozilla.org/security/certoverride;1"
|
||||
].getService(Ci.nsICertOverrideService);
|
||||
certOverrideService.clearValidityOverride(INVALID_CERT_DOMAIN, -1, {});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user