All pastes #2014599 Raw Edit

nicdumz

public javascript v1 · immutable
#2014599 ·published 2010-12-09 10:33 UTC
rendered paste body
// adapted from Mozilla codefunction inPrivateBrowsingMode() {  // first, check to see if we should handle the private browsing mode  try {    var pb = Components.classes["@mozilla.org/privatebrowsing;1"].             getService(Components.interfaces.nsIPrivateBrowsingService);    return pb.privateBrowsingEnabled;  } catch (ex) {    Components.utils.reportError("Could not get the Private Browsing service");  }  return false;}// adapted from Mozilla codefunction getURI(doc) {  // Use fixup service instead of just ioservice's newURI since it's quite likely  // that the host will be supplied without a protocol prefix, resulting in malformed  // uri exceptions being thrown.  var fus = Components.classes["@mozilla.org/docshell/urifixup;1"]                      .getService(Components.interfaces.nsIURIFixup);  var uri = fus.createFixupURI(doc.getElementById("locationTextBox").value, 0);    if(!uri)    return null;  if(uri.scheme == "http")    uri.scheme = "https";  if (uri.port == -1)    uri.port = 443;  return uri;}// adapted from Mozilla codefunction addException(doc, gSSLStatus, gCert) {  var overrideService = Components.classes["@mozilla.org/security/certoverride;1"]                                  .getService(Components.interfaces.nsICertOverrideService);  var flags = 0;  if(gSSLStatus.isUntrusted)    flags |= overrideService.ERROR_UNTRUSTED;  if(gSSLStatus.isDomainMismatch)    flags |= overrideService.ERROR_MISMATCH;  if(gSSLStatus.isNotValidAtThisTime)    flags |= overrideService.ERROR_TIME;    var permanentCheckbox = doc.getElementById("permanent");  // XXX it would be nicer to && this value with some sslconfig.userStorePermanently  var shouldStorePermanently = !inPrivateBrowsingMode();  var uri = getURI(doc);  overrideService.rememberValidityOverride(    uri.asciiHost, uri.port,    gCert,    flags,    !shouldStorePermanently);}userContext.SSLBypass = function() {    win = window.openDialog("chrome://pippki/content/exceptionDialog.xul", "",                            "chrome,center",                            {location:content.location, prefetchCert:true});    // wait for window to load    win.addEventListener("load", function() {        dialog = win.document.documentElement;        button = dialog.getButton("extra1");        // wait for certificate retrieval        button.addEventListener("DOMAttrModified", function(e) {             if (e.attrName == "disabled" && !e.newValue) {                addException(win.document, win.gSSLStatus, win.gCert);                dialog.acceptDialog();                content.document.location.reload();            }        }, false);   }, false);}