1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 * Handles the parsing of the ErrorPages URI and then passes them to injectValues
8 function parseQuery(queryString) {
9 if (queryString[0] === '?') {
10 queryString = queryString.substr(1);
12 const query = Object.fromEntries(new URLSearchParams(queryString).entries());
15 updateShowHSTS(query);
19 * Updates the HTML elements based on the queryMap
21 function injectValues(queryMap) {
22 const tryAgainButton = document.getElementById('errorTryAgain');
23 const continueHttpButton = document.getElementById("continueHttp");
24 const backFromHttpButton = document.getElementById('backFromHttp');
26 // Go through each element and inject the values
27 document.title = queryMap.title;
28 tryAgainButton.innerHTML = queryMap.button;
29 continueHttpButton.innerHTML = queryMap.continueHttpButton;
30 backFromHttpButton.innerHTML = queryMap.badCertGoBack;
31 document.getElementById('errorTitleText').innerHTML = queryMap.title;
32 document.getElementById('errorShortDesc').innerHTML = queryMap.description;
33 document.getElementById('advancedButton').innerHTML = queryMap.badCertAdvanced;
34 document.getElementById('badCertTechnicalInfo').innerHTML = queryMap.badCertTechInfo;
35 document.getElementById('advancedPanelBackButton').innerHTML = queryMap.badCertGoBack;
36 document.getElementById('advancedPanelAcceptButton').innerHTML = queryMap.badCertAcceptTemporary;
38 // If no image is passed in, remove the element so as not to leave an empty iframe
39 const errorImage = document.getElementById('errorImage');
40 if (!queryMap.image) {
43 errorImage.src = "resource://android/assets/" + queryMap.image;
46 if (queryMap.showContinueHttp === "true") {
47 // On the "HTTPS-Only" error page "Try again" doesn't make sense since reloading the page
48 // will just show an error page again.
49 tryAgainButton.style.display = 'none';
51 continueHttpButton.style.display = 'none';
52 backFromHttpButton.style.display = 'none';
56 let advancedVisible = false;
59 * Used to show or hide the "accept" button based on the validity of the SSL certificate
61 function updateShowSSL(queryMap) {
62 /** @type {'true' | 'false'} */
63 const showSSL = queryMap.showSSL;
64 if (typeof document.addCertException === 'undefined') {
65 document.getElementById('advancedButton').style.display='none';
67 if (showSSL === 'true') {
68 document.getElementById('advancedButton').style.display='block';
70 document.getElementById('advancedButton').style.display='none';
76 * Used to show or hide the "accept" button based for the HSTS error page
78 function updateShowHSTS(queryMap) {
79 const showHSTS = queryMap.showHSTS;
80 if (showHSTS === 'true') {
81 document.getElementById('advancedButton').style.display='block';
82 document.getElementById('advancedPanelAcceptButton').style.display='none';
87 * Used to display information about the SSL certificate in `error_pages.html`
89 function toggleAdvancedAndScroll() {
90 const advancedPanel = document.getElementById('badCertAdvancedPanel');
91 if (advancedVisible) {
92 advancedPanel.style.display='none';
94 advancedPanel.style.display='block';
96 advancedVisible = !advancedVisible;
98 const horizontalLine = document.getElementById("horizontalLine");
99 const advancedPanelAcceptButton = document.getElementById(
100 "advancedPanelAcceptButton"
102 const badCertAdvancedPanel = document.getElementById(
103 "badCertAdvancedPanel"
106 // We know that the button is being displayed
107 if (badCertAdvancedPanel.style.display === "block") {
108 horizontalLine.hidden = false;
109 advancedPanelAcceptButton.scrollIntoView({
115 horizontalLine.hidden = true;
120 * Used to bypass an SSL pages in `error_pages.html`
122 async function acceptAndContinue(temporary) {
124 await document.addCertException(temporary);
127 console.error("Unexpected error: " + error);
131 document.addEventListener('DOMContentLoaded', function () {
132 if (window.history.length == 1) {
133 document.getElementById('advancedPanelBackButton').style.display = 'none';
134 document.getElementById('backFromHttp').style.display = 'none';
136 document.getElementById('advancedPanelBackButton').addEventListener('click', () => window.history.back());
137 document.getElementById('backFromHttp').addEventListener('click', () => window.history.back());
140 document.getElementById('errorTryAgain').addEventListener('click', () => window.location.reload());
141 document.getElementById('advancedButton').addEventListener('click', toggleAdvancedAndScroll);
142 document.getElementById('advancedPanelAcceptButton').addEventListener('click', () => acceptAndContinue(true));
143 document.getElementById('continueHttp').addEventListener('click', () => document.reloadWithHttpsOnlyException());
146 parseQuery(document.documentURI);