docshell/resources/content/netError.xhtml

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 <?xml version="1.0" encoding="UTF-8"?>
michael@0 2
michael@0 3 <!DOCTYPE html [
michael@0 4 <!ENTITY % htmlDTD
michael@0 5 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
michael@0 6 "DTD/xhtml1-strict.dtd">
michael@0 7 %htmlDTD;
michael@0 8 <!ENTITY % netErrorDTD
michael@0 9 SYSTEM "chrome://global/locale/netError.dtd">
michael@0 10 %netErrorDTD;
michael@0 11 <!ENTITY % globalDTD
michael@0 12 SYSTEM "chrome://global/locale/global.dtd">
michael@0 13 %globalDTD;
michael@0 14 ]>
michael@0 15
michael@0 16 <!-- This Source Code Form is subject to the terms of the Mozilla Public
michael@0 17 - License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 18 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
michael@0 19
michael@0 20 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 21 <head>
michael@0 22 <title>&loadError.label;</title>
michael@0 23 <link rel="stylesheet" href="chrome://global/skin/netError.css" type="text/css" media="all" />
michael@0 24 <!-- If the location of the favicon is changed here, the FAVICON_ERRORPAGE_URL symbol in
michael@0 25 toolkit/components/places/src/nsFaviconService.h should be updated. -->
michael@0 26 <link rel="icon" type="image/png" id="favicon" href="chrome://global/skin/icons/warning-16.png"/>
michael@0 27
michael@0 28 <script type="application/javascript"><![CDATA[
michael@0 29 // Error url MUST be formatted like this:
michael@0 30 // moz-neterror:page?e=error&u=url&d=desc
michael@0 31 //
michael@0 32 // or optionally, to specify an alternate CSS class to allow for
michael@0 33 // custom styling and favicon:
michael@0 34 //
michael@0 35 // moz-neterror:page?e=error&u=url&s=classname&d=desc
michael@0 36
michael@0 37 // Note that this file uses document.documentURI to get
michael@0 38 // the URL (with the format from above). This is because
michael@0 39 // document.location.href gets the current URI off the docshell,
michael@0 40 // which is the URL displayed in the location bar, i.e.
michael@0 41 // the URI that the user attempted to load.
michael@0 42
michael@0 43 function getErrorCode()
michael@0 44 {
michael@0 45 var url = document.documentURI;
michael@0 46 var error = url.search(/e\=/);
michael@0 47 var duffUrl = url.search(/\&u\=/);
michael@0 48 return decodeURIComponent(url.slice(error + 2, duffUrl));
michael@0 49 }
michael@0 50
michael@0 51 function getCSSClass()
michael@0 52 {
michael@0 53 var url = document.documentURI;
michael@0 54 var matches = url.match(/s\=([^&]+)\&/);
michael@0 55 // s is optional, if no match just return nothing
michael@0 56 if (!matches || matches.length < 2)
michael@0 57 return "";
michael@0 58
michael@0 59 // parenthetical match is the second entry
michael@0 60 return decodeURIComponent(matches[1]);
michael@0 61 }
michael@0 62
michael@0 63 function getDescription()
michael@0 64 {
michael@0 65 var url = document.documentURI;
michael@0 66 var desc = url.search(/d\=/);
michael@0 67
michael@0 68 // desc == -1 if not found; if so, return an empty string
michael@0 69 // instead of what would turn out to be portions of the URI
michael@0 70 if (desc == -1)
michael@0 71 return "";
michael@0 72
michael@0 73 return decodeURIComponent(url.slice(desc + 2));
michael@0 74 }
michael@0 75
michael@0 76 function retryThis(buttonEl)
michael@0 77 {
michael@0 78 // Note: The application may wish to handle switching off "offline mode"
michael@0 79 // before this event handler runs, but using a capturing event handler.
michael@0 80
michael@0 81 // Session history has the URL of the page that failed
michael@0 82 // to load, not the one of the error page. So, just call
michael@0 83 // reload(), which will also repost POST data correctly.
michael@0 84 try {
michael@0 85 location.reload();
michael@0 86 } catch (e) {
michael@0 87 // We probably tried to reload a URI that caused an exception to
michael@0 88 // occur; e.g. a nonexistent file.
michael@0 89 }
michael@0 90
michael@0 91 buttonEl.disabled = true;
michael@0 92 }
michael@0 93
michael@0 94 function initPage()
michael@0 95 {
michael@0 96 var err = getErrorCode();
michael@0 97
michael@0 98 // if it's an unknown error or there's no title or description
michael@0 99 // defined, get the generic message
michael@0 100 var errTitle = document.getElementById("et_" + err);
michael@0 101 var errDesc = document.getElementById("ed_" + err);
michael@0 102 if (!errTitle || !errDesc)
michael@0 103 {
michael@0 104 errTitle = document.getElementById("et_generic");
michael@0 105 errDesc = document.getElementById("ed_generic");
michael@0 106 }
michael@0 107
michael@0 108 var title = document.getElementById("errorTitleText");
michael@0 109 if (title)
michael@0 110 {
michael@0 111 title.parentNode.replaceChild(errTitle, title);
michael@0 112 // change id to the replaced child's id so styling works
michael@0 113 errTitle.id = "errorTitleText";
michael@0 114 }
michael@0 115
michael@0 116 var sd = document.getElementById("errorShortDescText");
michael@0 117 if (sd)
michael@0 118 sd.textContent = getDescription();
michael@0 119
michael@0 120 var ld = document.getElementById("errorLongDesc");
michael@0 121 if (ld)
michael@0 122 {
michael@0 123 ld.parentNode.replaceChild(errDesc, ld);
michael@0 124 // change id to the replaced child's id so styling works
michael@0 125 errDesc.id = "errorLongDesc";
michael@0 126 }
michael@0 127
michael@0 128 // remove undisplayed errors to avoid bug 39098
michael@0 129 var errContainer = document.getElementById("errorContainer");
michael@0 130 errContainer.parentNode.removeChild(errContainer);
michael@0 131
michael@0 132 var className = getCSSClass();
michael@0 133 if (className && className != "expertBadCert") {
michael@0 134 // Associate a CSS class with the root of the page, if one was passed in,
michael@0 135 // to allow custom styling.
michael@0 136 // Not "expertBadCert" though, don't want to deal with the favicon
michael@0 137 document.documentElement.className = className;
michael@0 138
michael@0 139 // Also, if they specified a CSS class, they must supply their own
michael@0 140 // favicon. In order to trigger the browser to repaint though, we
michael@0 141 // need to remove/add the link element.
michael@0 142 var favicon = document.getElementById("favicon");
michael@0 143 var faviconParent = favicon.parentNode;
michael@0 144 faviconParent.removeChild(favicon);
michael@0 145 favicon.setAttribute("href", "chrome://global/skin/icons/" + className + "_favicon.png");
michael@0 146 faviconParent.appendChild(favicon);
michael@0 147 }
michael@0 148 if (className == "expertBadCert") {
michael@0 149 showSecuritySection();
michael@0 150 }
michael@0 151
michael@0 152 if (err == "remoteXUL") {
michael@0 153 // Remove the "Try again" button for remote XUL errors given that
michael@0 154 // it is useless.
michael@0 155 document.getElementById("errorTryAgain").style.display = "none";
michael@0 156 }
michael@0 157
michael@0 158 if (err == "cspFrameAncestorBlocked") {
michael@0 159 // Remove the "Try again" button for CSP frame ancestors violation, since it's
michael@0 160 // almost certainly useless. (Bug 553180)
michael@0 161 document.getElementById("errorTryAgain").style.display = "none";
michael@0 162 }
michael@0 163
michael@0 164 if (err == "nssBadCert") {
michael@0 165 // Remove the "Try again" button for security exceptions, since it's
michael@0 166 // almost certainly useless.
michael@0 167 document.getElementById("errorTryAgain").style.display = "none";
michael@0 168 document.getElementById("errorPageContainer").setAttribute("class", "certerror");
michael@0 169 addDomainErrorLink();
michael@0 170 }
michael@0 171 else {
michael@0 172 // Remove the override block for non-certificate errors. CSS-hiding
michael@0 173 // isn't good enough here, because of bug 39098
michael@0 174 var secOverride = document.getElementById("securityOverrideDiv");
michael@0 175 secOverride.parentNode.removeChild(secOverride);
michael@0 176 }
michael@0 177 }
michael@0 178
michael@0 179 function showSecuritySection() {
michael@0 180 // Swap link out, content in
michael@0 181 document.getElementById('securityOverrideContent').style.display = '';
michael@0 182 document.getElementById('securityOverrideLink').style.display = 'none';
michael@0 183 }
michael@0 184
michael@0 185 /* In the case of SSL error pages about domain mismatch, see if
michael@0 186 we can hyperlink the user to the correct site. We don't want
michael@0 187 to do this generically since it allows MitM attacks to redirect
michael@0 188 users to a site under attacker control, but in certain cases
michael@0 189 it is safe (and helpful!) to do so. Bug 402210
michael@0 190 */
michael@0 191 function addDomainErrorLink() {
michael@0 192 // Rather than textContent, we need to treat description as HTML
michael@0 193 var sd = document.getElementById("errorShortDescText");
michael@0 194 if (sd) {
michael@0 195 var desc = getDescription();
michael@0 196
michael@0 197 // sanitize description text - see bug 441169
michael@0 198
michael@0 199 // First, find the index of the <a> tag we care about, being careful not to
michael@0 200 // use an over-greedy regex
michael@0 201 var re = /<a id="cert_domain_link" title="([^"]+)">/;
michael@0 202 var result = re.exec(desc);
michael@0 203 if(!result)
michael@0 204 return;
michael@0 205
michael@0 206 // Remove sd's existing children
michael@0 207 sd.textContent = "";
michael@0 208
michael@0 209 // Everything up to the link should be text content
michael@0 210 sd.appendChild(document.createTextNode(desc.slice(0, result.index)));
michael@0 211
michael@0 212 // Now create the link itself
michael@0 213 var anchorEl = document.createElement("a");
michael@0 214 anchorEl.setAttribute("id", "cert_domain_link");
michael@0 215 anchorEl.setAttribute("title", result[1]);
michael@0 216 anchorEl.appendChild(document.createTextNode(result[1]));
michael@0 217 sd.appendChild(anchorEl);
michael@0 218
michael@0 219 // Finally, append text for anything after the closing </a>
michael@0 220 sd.appendChild(document.createTextNode(desc.slice(desc.indexOf("</a>") + "</a>".length)));
michael@0 221 }
michael@0 222
michael@0 223 var link = document.getElementById('cert_domain_link');
michael@0 224 if (!link)
michael@0 225 return;
michael@0 226
michael@0 227 var okHost = link.getAttribute("title");
michael@0 228 var thisHost = document.location.hostname;
michael@0 229 var proto = document.location.protocol;
michael@0 230
michael@0 231 // If okHost is a wildcard domain ("*.example.com") let's
michael@0 232 // use "www" instead. "*.example.com" isn't going to
michael@0 233 // get anyone anywhere useful. bug 432491
michael@0 234 okHost = okHost.replace(/^\*\./, "www.");
michael@0 235
michael@0 236 /* case #1:
michael@0 237 * example.com uses an invalid security certificate.
michael@0 238 *
michael@0 239 * The certificate is only valid for www.example.com
michael@0 240 *
michael@0 241 * Make sure to include the "." ahead of thisHost so that
michael@0 242 * a MitM attack on paypal.com doesn't hyperlink to "notpaypal.com"
michael@0 243 *
michael@0 244 * We'd normally just use a RegExp here except that we lack a
michael@0 245 * library function to escape them properly (bug 248062), and
michael@0 246 * domain names are famous for having '.' characters in them,
michael@0 247 * which would allow spurious and possibly hostile matches.
michael@0 248 */
michael@0 249 if (endsWith(okHost, "." + thisHost))
michael@0 250 link.href = proto + okHost;
michael@0 251
michael@0 252 /* case #2:
michael@0 253 * browser.garage.maemo.org uses an invalid security certificate.
michael@0 254 *
michael@0 255 * The certificate is only valid for garage.maemo.org
michael@0 256 */
michael@0 257 if (endsWith(thisHost, "." + okHost))
michael@0 258 link.href = proto + okHost;
michael@0 259 }
michael@0 260
michael@0 261 function endsWith(haystack, needle) {
michael@0 262 return haystack.slice(-needle.length) == needle;
michael@0 263 }
michael@0 264
michael@0 265 ]]></script>
michael@0 266 </head>
michael@0 267
michael@0 268 <body dir="&locale.dir;">
michael@0 269
michael@0 270 <!-- ERROR ITEM CONTAINER (removed during loading to avoid bug 39098) -->
michael@0 271 <div id="errorContainer">
michael@0 272 <div id="errorTitlesContainer">
michael@0 273 <h1 id="et_generic">&generic.title;</h1>
michael@0 274 <h1 id="et_dnsNotFound">&dnsNotFound.title;</h1>
michael@0 275 <h1 id="et_fileNotFound">&fileNotFound.title;</h1>
michael@0 276 <h1 id="et_malformedURI">&malformedURI.title;</h1>
michael@0 277 <h1 id="et_unknownProtocolFound">&unknownProtocolFound.title;</h1>
michael@0 278 <h1 id="et_connectionFailure">&connectionFailure.title;</h1>
michael@0 279 <h1 id="et_netTimeout">&netTimeout.title;</h1>
michael@0 280 <h1 id="et_redirectLoop">&redirectLoop.title;</h1>
michael@0 281 <h1 id="et_unknownSocketType">&unknownSocketType.title;</h1>
michael@0 282 <h1 id="et_netReset">&netReset.title;</h1>
michael@0 283 <h1 id="et_notCached">&notCached.title;</h1>
michael@0 284 <h1 id="et_netOffline">&netOffline.title;</h1>
michael@0 285 <h1 id="et_netInterrupt">&netInterrupt.title;</h1>
michael@0 286 <h1 id="et_deniedPortAccess">&deniedPortAccess.title;</h1>
michael@0 287 <h1 id="et_proxyResolveFailure">&proxyResolveFailure.title;</h1>
michael@0 288 <h1 id="et_proxyConnectFailure">&proxyConnectFailure.title;</h1>
michael@0 289 <h1 id="et_contentEncodingError">&contentEncodingError.title;</h1>
michael@0 290 <h1 id="et_unsafeContentType">&unsafeContentType.title;</h1>
michael@0 291 <h1 id="et_nssFailure2">&nssFailure2.title;</h1>
michael@0 292 <h1 id="et_nssBadCert">&nssBadCert.title;</h1>
michael@0 293 <h1 id="et_malwareBlocked">&malwareBlocked.title;</h1>
michael@0 294 <h1 id="et_cspFrameAncestorBlocked">&cspFrameAncestorBlocked.title;</h1>
michael@0 295 <h1 id="et_remoteXUL">&remoteXUL.title;</h1>
michael@0 296 <h1 id="et_corruptedContentError">&corruptedContentError.title;</h1>
michael@0 297 </div>
michael@0 298 <div id="errorDescriptionsContainer">
michael@0 299 <div id="ed_generic">&generic.longDesc;</div>
michael@0 300 <div id="ed_dnsNotFound">&dnsNotFound.longDesc;</div>
michael@0 301 <div id="ed_fileNotFound">&fileNotFound.longDesc;</div>
michael@0 302 <div id="ed_malformedURI">&malformedURI.longDesc;</div>
michael@0 303 <div id="ed_unknownProtocolFound">&unknownProtocolFound.longDesc;</div>
michael@0 304 <div id="ed_connectionFailure">&connectionFailure.longDesc;</div>
michael@0 305 <div id="ed_netTimeout">&netTimeout.longDesc;</div>
michael@0 306 <div id="ed_redirectLoop">&redirectLoop.longDesc;</div>
michael@0 307 <div id="ed_unknownSocketType">&unknownSocketType.longDesc;</div>
michael@0 308 <div id="ed_netReset">&netReset.longDesc;</div>
michael@0 309 <div id="ed_notCached">&notCached.longDesc;</div>
michael@0 310 <div id="ed_netOffline">&netOffline.longDesc2;</div>
michael@0 311 <div id="ed_netInterrupt">&netInterrupt.longDesc;</div>
michael@0 312 <div id="ed_deniedPortAccess">&deniedPortAccess.longDesc;</div>
michael@0 313 <div id="ed_proxyResolveFailure">&proxyResolveFailure.longDesc;</div>
michael@0 314 <div id="ed_proxyConnectFailure">&proxyConnectFailure.longDesc;</div>
michael@0 315 <div id="ed_contentEncodingError">&contentEncodingError.longDesc;</div>
michael@0 316 <div id="ed_unsafeContentType">&unsafeContentType.longDesc;</div>
michael@0 317 <div id="ed_nssFailure2">&nssFailure2.longDesc;</div>
michael@0 318 <div id="ed_nssBadCert">&nssBadCert.longDesc2;</div>
michael@0 319 <div id="ed_malwareBlocked">&malwareBlocked.longDesc;</div>
michael@0 320 <div id="ed_cspFrameAncestorBlocked">&cspFrameAncestorBlocked.longDesc;</div>
michael@0 321 <div id="ed_remoteXUL">&remoteXUL.longDesc;</div>
michael@0 322 <div id="ed_corruptedContentError">&corruptedContentError.longDesc;</div>
michael@0 323 </div>
michael@0 324 </div>
michael@0 325
michael@0 326 <!-- PAGE CONTAINER (for styling purposes only) -->
michael@0 327 <div id="errorPageContainer">
michael@0 328
michael@0 329 <!-- Error Title -->
michael@0 330 <div id="errorTitle">
michael@0 331 <h1 id="errorTitleText" />
michael@0 332 </div>
michael@0 333
michael@0 334 <!-- LONG CONTENT (the section most likely to require scrolling) -->
michael@0 335 <div id="errorLongContent">
michael@0 336
michael@0 337 <!-- Short Description -->
michael@0 338 <div id="errorShortDesc">
michael@0 339 <p id="errorShortDescText" />
michael@0 340 </div>
michael@0 341
michael@0 342 <!-- Long Description (Note: See netError.dtd for used XHTML tags) -->
michael@0 343 <div id="errorLongDesc" />
michael@0 344
michael@0 345 <!-- Override section - For ssl errors only. Removed on init for other
michael@0 346 error types. -->
michael@0 347 <div id="securityOverrideDiv">
michael@0 348 <a id="securityOverrideLink" href="javascript:showSecuritySection();" >&securityOverride.linkText;</a>
michael@0 349 <div id="securityOverrideContent" style="display: none;">&securityOverride.warningContent;</div>
michael@0 350 </div>
michael@0 351 </div>
michael@0 352
michael@0 353 <!-- Retry Button -->
michael@0 354 <button id="errorTryAgain" autocomplete="off" onclick="retryThis(this);">&retry.label;</button>
michael@0 355 <script>
michael@0 356 // Only do autofocus if we're the toplevel frame; otherwise we
michael@0 357 // don't want to call attention to ourselves! The key part is
michael@0 358 // that autofocus happens on insertion into the tree, so we
michael@0 359 // can remove the button, add @autofocus, and reinsert the
michael@0 360 // button.
michael@0 361 if (window.top == window) {
michael@0 362 var button = document.getElementById("errorTryAgain");
michael@0 363 var nextSibling = button.nextSibling;
michael@0 364 var parent = button.parentNode;
michael@0 365 parent.removeChild(button);
michael@0 366 button.setAttribute("autofocus", "true");
michael@0 367 parent.insertBefore(button, nextSibling);
michael@0 368 }
michael@0 369 </script>
michael@0 370
michael@0 371 </div>
michael@0 372
michael@0 373 <!--
michael@0 374 - Note: It is important to run the script this way, instead of using
michael@0 375 - an onload handler. This is because error pages are loaded as
michael@0 376 - LOAD_BACKGROUND, which means that onload handlers will not be executed.
michael@0 377 -->
michael@0 378 <script type="application/javascript">initPage();</script>
michael@0 379
michael@0 380 </body>
michael@0 381 </html>

mercurial