Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. onLocationChange: function(aBrowser, aWebProgress, aRequest, aLocation, aFlags) {
  2.  
  3. if(aRequest != null) {
  4.  
  5. // suspend early, because that becomes impossible later
  6. aRequest.suspend();
  7.  
  8. // check if it is HTTPS (no HTTP, no about:, etc.)
  9. if(aLocation.scheme == "https") {
  10.  
  11. var whateverIWantToDo = {
  12. notify: function(timer) {
  13.  
  14. try {
  15. // for example I'm interested in the validation result:
  16. let secUI = aBrowser.securityUI;
  17. secUI.QueryInterface(Components.interfaces.nsISSLStatusProvider);
  18. let status = secUI.SSLStatus;
  19.  
  20. // do something what you want here
  21. // and do not forget to resume the request at any point. otherwise that could lead to problems
  22. aRequest.resume();
  23. //....
  24. // the reason I suspend the request at all:
  25. // I do not want to completely load the page until I know if the certificate is valid
  26. }
  27. catch(err) {
  28. // maybe it's too early to access the SSLStatus when the event handler kicks in.
  29. // in this case an error will be thrown which is caught here
  30. // wait 10 ms and try it again, usually that works! (I know, it's a bit hacky)
  31. var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  32. timer.initWithCallback(whateverIWantToDo, 10, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
  33. }
  34.  
  35. }
  36. }
  37.  
  38. whateverIWantToDo.notify();
  39.  
  40. } else {
  41. // continue normally when it's not a HTTPS request, we want to intercept
  42. aRequest.resume();
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement