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() {
|
addException() {
|
||||||
let retval = {
|
let params = {
|
||||||
exceptionAdded: false,
|
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(
|
window.browsingContext.topChromeWindow.openDialog(
|
||||||
"chrome://pippki/content/exceptionDialog.xhtml",
|
"chrome://pippki/content/exceptionDialog.xhtml",
|
||||||
"",
|
"",
|
||||||
"chrome,centerscreen,modal",
|
"chrome,centerscreen,modal",
|
||||||
retval
|
params
|
||||||
);
|
);
|
||||||
if (retval.exceptionAdded) {
|
closedCallback();
|
||||||
this.buildRichList();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_setButtonState() {
|
_setButtonState() {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
:root {
|
:root {
|
||||||
max-width: 40em;
|
max-width: 40em;
|
||||||
min-width: 35em;
|
min-width: 35em;
|
||||||
|
min-height: 24em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#warningSupplemental,
|
#warningSupplemental,
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ function updateCertStatus() {
|
|||||||
document.getElementById("viewCertButton").disabled = false;
|
document.getElementById("viewCertButton").disabled = false;
|
||||||
|
|
||||||
// Notify observers about the availability of the certificate
|
// 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) {
|
} else if (gChecking) {
|
||||||
shortDesc = "add-exception-checking-short";
|
shortDesc = "add-exception-checking-short";
|
||||||
longDesc = "add-exception-checking-long";
|
longDesc = "add-exception-checking-long";
|
||||||
@@ -325,7 +325,9 @@ function addException() {
|
|||||||
* @returns {boolean} Whether this dialog is in private browsing mode.
|
* @returns {boolean} Whether this dialog is in private browsing mode.
|
||||||
*/
|
*/
|
||||||
function inPrivateBrowsingMode() {
|
function inPrivateBrowsingMode() {
|
||||||
return PrivateBrowsingUtils.isWindowPrivate(window);
|
return window.isChromeWindow
|
||||||
|
? PrivateBrowsingUtils.isWindowPrivate(window)
|
||||||
|
: PrivateBrowsingUtils.isContentWindowPrivate(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("load", () => initExceptionDialog());
|
window.addEventListener("load", () => initExceptionDialog());
|
||||||
|
|||||||
@@ -11,80 +11,114 @@ ChromeUtils.defineESModuleGetters(this, {
|
|||||||
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
|
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
|
||||||
});
|
});
|
||||||
|
|
||||||
function test() {
|
const EXCEPTIONS_DLG_URL = "chrome://pippki/content/exceptionDialog.xhtml";
|
||||||
const EXCEPTIONS_DLG_URL = "chrome://pippki/content/exceptionDialog.xhtml";
|
const EXCEPTIONS_DLG_FEATURES = "chrome,centerscreen,modal";
|
||||||
const EXCEPTIONS_DLG_FEATURES = "chrome,centerscreen";
|
const INVALID_CERT_DOMAIN = "self-signed.example.com";
|
||||||
const INVALID_CERT_DOMAIN = "self-signed.example.com";
|
const INVALID_CERT_LOCATION = "https://" + INVALID_CERT_DOMAIN + "/";
|
||||||
const INVALID_CERT_LOCATION = "https://" + INVALID_CERT_DOMAIN + "/";
|
|
||||||
waitForExplicitFinish();
|
|
||||||
|
|
||||||
function testAddCertificate() {
|
registerCleanupFunction(() => {
|
||||||
win.removeEventListener("load", testAddCertificate);
|
let certOverrideService = Cc[
|
||||||
Services.obs.addObserver(async function onCertUI() {
|
"@mozilla.org/security/certoverride;1"
|
||||||
Services.obs.removeObserver(onCertUI, "cert-exception-ui-ready");
|
].getService(Ci.nsICertOverrideService);
|
||||||
ok(win.gCert, "The certificate information should be available now");
|
certOverrideService.clearValidityOverride(INVALID_CERT_DOMAIN, -1, {});
|
||||||
|
});
|
||||||
|
|
||||||
// Clicking on the View… button should open the certificate viewer.
|
async function onCertExceptionUI(win) {
|
||||||
let viewButton = win.document.getElementById("viewCertButton");
|
Services.obs.removeObserver(onCertExceptionUI, "cert-exception-ui-ready");
|
||||||
let tabPromise = BrowserTestUtils.waitForNewTab(
|
ok(win.gCert, "The certificate information should be available now");
|
||||||
gBrowser,
|
|
||||||
url => url.startsWith("about:certificate?cert="),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
EventUtils.synthesizeMouseAtCenter(viewButton, {}, win);
|
|
||||||
BrowserTestUtils.removeTab(await tabPromise);
|
|
||||||
|
|
||||||
if (AppConstants.platform != "macosx") {
|
// Clicking on the View… button should open the certificate viewer.
|
||||||
// Pressing enter on the View… button should open the certificate viewer.
|
let viewButton = win.document.getElementById("viewCertButton");
|
||||||
tabPromise = BrowserTestUtils.waitForNewTab(
|
let tabPromise = BrowserTestUtils.waitForNewTab(
|
||||||
gBrowser,
|
gBrowser,
|
||||||
url => url.startsWith("about:certificate?cert="),
|
url => url.startsWith("about:certificate?cert="),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
EventUtils.synthesizeKey("KEY_Enter", {}, win);
|
EventUtils.synthesizeMouseAtCenter(viewButton, {}, win);
|
||||||
BrowserTestUtils.removeTab(await tabPromise);
|
BrowserTestUtils.removeTab(await tabPromise);
|
||||||
}
|
|
||||||
|
|
||||||
let dialog = win.document.getElementById("exceptiondialog");
|
if (AppConstants.platform != "macosx") {
|
||||||
let confirmButton = dialog.getButton("extra1");
|
// Pressing enter on the View… button should open the certificate viewer.
|
||||||
confirmButton.click();
|
tabPromise = BrowserTestUtils.waitForNewTab(
|
||||||
ok(
|
gBrowser,
|
||||||
params.exceptionAdded,
|
url => url.startsWith("about:certificate?cert="),
|
||||||
"The certificate exception should have been added"
|
true
|
||||||
);
|
);
|
||||||
|
viewButton.focus();
|
||||||
registerCleanupFunction(() => {
|
EventUtils.synthesizeKey("KEY_Enter", {}, win);
|
||||||
let certOverrideService = Cc[
|
BrowserTestUtils.removeTab(await tabPromise);
|
||||||
"@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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = {
|
let params = {
|
||||||
exceptionAdded: false,
|
exceptionAdded: false,
|
||||||
location: INVALID_CERT_LOCATION,
|
location: INVALID_CERT_LOCATION,
|
||||||
prefetchCert: true,
|
prefetchCert: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let win = bWin.openDialog(
|
let bWin = BrowserWindowTracker.getTopWindow();
|
||||||
EXCEPTIONS_DLG_URL,
|
|
||||||
"",
|
// Open the add exception dialog without a sub-dialog.
|
||||||
EXCEPTIONS_DLG_FEATURES,
|
bWin.openDialog(EXCEPTIONS_DLG_URL, "", EXCEPTIONS_DLG_FEATURES, params);
|
||||||
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