title: How can i observe a specified Firefox event in a Firefox-Extension?
body: <p>I want to wait for Firefox-Browser-Events (<code>sessionstore-windows-restored</code>, <code>user-interaction-inactive</code>,..) in order to clear the history. My Extension is able to clear the history on shortcut for now, but i don't know how to listen for such events. I already had a lood at <a href="https://developer.mozilla.org/en/Observer_Notifications" rel="nofollow">observer notification</a>, but nothing i tried seems to work.</p>
  
  <p>My extension code so far is here:</p>
  
  <pre><code>   (function() {
  
      (window.myObj =
      {
          myObserver : function()
          {
            this.register();
          },
  
          init : function()
          {
              try {
  
                  myObserver.prototype = {
                      observe: function(subject, topic, data){
  
                          switch (topic) {
                            case 'sessionstore-windows-restored':
                              Firebug.Console.log('sessionstore-windows-restored observed');
                              myObj.clearHistory();
                              break;
                            case 'user-interaction-inactive':
                              Firebug.Console.log('user-interaction-inactive');
                              break;
                            case 'user-interaction-active':
                              Firebug.Console.log('user-interaction-active');
                              break;
                          }
  
                          Firebug.Console.log('HUI :' + subject + ','+topic+','+data);
                      },
                      register: function(){
                          var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
                          observerService.addObserver(this, "readyToClearHistory", false);
                      },
                      unregister: function(){
                          var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
                          observerService.removeObserver(this, "readyToClearHistory");
                      }
                  }
              }
              catch (e) {
                  Firebug.Console.log('MIST :' + e);
              }
  
              observer = new myObserver();
           },
           clearHistory : function(){
              var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"].getService(Components.interfaces.nsIBrowserHistory);
              var now = Date.now();
  
              // clear one hour
              globalHistory.removeVisitsByTimeframe(now - 3600, now);
  
              try {
                  var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
                  os.notifyObservers(null, "browser:purge-session-history", "");
              } 
              catch (e) {
  
                  // Clear last URL of the Open Web Location dialog
                  var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch2);
                  try {
                      prefs.clearUserPref("general.open_location.last_url");
                  } 
                  catch (e) {
                  }
              }
                } 
    }
  }
  </code></pre>
  
  <p><strong>Some example code would be nice. What do i need to solve this issue?</strong></p>