Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- onLocationChange: function(aBrowser, aWebProgress, aRequest, aLocation, aFlags) {
- if(aRequest != null) {
- // suspend early, because that becomes impossible later
- aRequest.suspend();
- // check if it is HTTPS (no HTTP, no about:, etc.)
- if(aLocation.scheme == "https") {
- var whateverIWantToDo = {
- notify: function(timer) {
- try {
- // for example I'm interested in the validation result:
- let secUI = aBrowser.securityUI;
- secUI.QueryInterface(Components.interfaces.nsISSLStatusProvider);
- let status = secUI.SSLStatus;
- // do something what you want here
- // and do not forget to resume the request at any point. otherwise that could lead to problems
- aRequest.resume();
- //....
- // the reason I suspend the request at all:
- // I do not want to completely load the page until I know if the certificate is valid
- }
- catch(err) {
- // maybe it's too early to access the SSLStatus when the event handler kicks in.
- // in this case an error will be thrown which is caught here
- // wait 10 ms and try it again, usually that works! (I know, it's a bit hacky)
- var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
- timer.initWithCallback(whateverIWantToDo, 10, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
- }
- }
- }
- whateverIWantToDo.notify();
- } else {
- // continue normally when it's not a HTTPS request, we want to intercept
- aRequest.resume();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement