Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Firebug Extension

By: a guest on Apr 18th, 2012  |  syntax: JavaScript  |  size: 3.92 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. FBL.ns(function() { with (FBL) {
  2.  
  3. const Cc = Components.classes;
  4. const Ci = Components.interfaces;
  5.  
  6. const dirService = Cc["@mozilla.org/file/directory_service;1"]
  7.     .getService(Ci.nsIProperties);
  8.  
  9. // ************************************************************************************************
  10. // Module implementation
  11.  
  12. Firebug.BeepbopListenerModule = extend(Firebug.Module,
  13. {
  14.     initialize: function(owner) {
  15.         Firebug.Module.initialize.apply(this, arguments);
  16.  
  17.         // Register Beepbop listener
  18.         this.beepbopListener = new BeepbopListener();
  19.         Firebug.NetMonitor.addListener(this.beepbopListener);
  20.  
  21.         Firebug.NetMonitor.NetRequestTable.addListener(RequestTableListener);
  22.         Firebug.JSONViewerModel.addListener(JSONListener);
  23.     },
  24.  
  25.     shutdown: function() {
  26.         Firebug.Module.shutdown.apply(this, arguments);
  27.  
  28.         // Unregister Beepbop listener
  29.         Firebug.NetMonitor.removeListener(this.beepbopListener);
  30.         this.beepbopListener.outputStream.close();
  31.  
  32.         Firebug.NetMonitor.NetRequestTable.removeListener(RequestTableListener);
  33.         Firebug.JSONViewerModel.removeListener(JSONListener);
  34.     }
  35. });
  36.  
  37. // ************************************************************************************************
  38. // Net Panel Listener
  39.  
  40. function BeepbopListener(outputStream) {
  41.     // Get unique file within user profile directory.
  42.     var file = dirService.get("ProfD", Ci.nsIFile);
  43.     file.append("beepboplistener");
  44.     file.append("netMonitor.txt");
  45.     file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
  46.  
  47.     // Initialize output stream.
  48.     this.outputStream =
  49.         Cc["@mozilla.org/network/file-output-stream;1"]
  50.         .createInstance(Ci.nsIFileOutputStream);
  51.  
  52.     // write, create, truncate
  53.     this.outputStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
  54. }
  55.  
  56. BeepbopListener.prototype = {
  57.     onRequest: function(context, file) {
  58.       var pattern = /\.js$/;
  59.         if (pattern.test(file.href) && FBTrace.DBG_BEEPBOP) {
  60.           FBTrace.sysout("CANT SEE RESPONSETEXT IN ONREQUEST " + file);
  61.         }
  62.     },
  63.  
  64.     onExamineResponse: function(context, file) {
  65.         FBTrace.sysout("onexamineresponse " + file);
  66.         var pattern = /\.js$/;
  67.         if (pattern.test(file.href) && FBTrace.DBG_BEEPBOP) {
  68.           FBTrace.sysout("ONEXAMINE DOESN'T EVEN FIRE SO YOU WON'T SEE THIS");
  69.         }
  70.     },
  71.  
  72.     onResponse: function(context, file) {
  73.         var pattern = /\.js$/;
  74.         if (pattern.test(file.href) && FBTrace.DBG_BEEPBOP) {
  75.           FBTrace.sysout("CANT SEE RESPONSETEXT IN ONRESPONSE " + file);
  76.         }
  77.  
  78.         try {
  79.             var text = file.href + " (" + formatTime
  80.                 (file.endTime - file.startTime) + ")\n";
  81.             this.outputStream.write(text, text.length);
  82.         }
  83.         catch (err) {
  84.             if (FBTrace.DBG_BEEPBOP || FBTrace.DBG_ERRORS)
  85.                 FBTrace.sysout("beepbopListener.onResponse: EXCEPTION", err);
  86.         }
  87.     },
  88.  
  89.     onResponseBody: function(context, file) {
  90.       var pattern = /\.js$/;
  91.       if (pattern.test(file.href) && FBTrace.DBG_BEEPBOP) {
  92.           FBTrace.sysout("THIS IS WHAT WE WANT: " + file.responseText);
  93.       }
  94.     }
  95. };
  96.  
  97. var RequestTableListener =
  98. {
  99.     onCreateRequestEntry: function(panel, row)
  100.     {
  101.         if (FBTrace.DBG_NETLISTENER)
  102.             FBTrace.sysout("RequestTableListener.onCreateRequestEntry; " +
  103.                 panel.context.getName());
  104.     }
  105. }
  106.  
  107. var JSONListener =
  108. {
  109.     onParseJSON: function(file)
  110.     {
  111.         if (FBTrace.DBG_NETLISTENER)
  112.             FBTrace.sysout("JSONListener.onParseJSON; " + file.href, file);
  113.     }
  114. }
  115.  
  116. // ************************************************************************************************
  117. // Registration
  118.  
  119. Firebug.registerModule(Firebug.BeepbopListenerModule);
  120.  
  121. // ************************************************************************************************
  122. }});