home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 9866 / 9866.xpi / modules / samfind_modlog.jsm < prev    next >
Encoding:
Text File  |  2009-11-18  |  3.0 KB  |  153 lines

  1. //-------------------------------------------------------------------------------------------
  2. // Log module.
  3. //-------------------------------------------------------------------------------------------
  4.  
  5. const Cc = Components.classes;
  6. const Ci = Components.interfaces;
  7.  
  8. const SAMFIND_MODLOG_IS_ON = false;
  9.  
  10. var EXPORTED_SYMBOLS = ["samfind_modlog"];
  11.  
  12. var samfind_modlog =
  13. {
  14.     dump : SAMFIND_MODLOG_IS_ON ?
  15.         function(s)
  16.         {
  17.             this._dump(s);
  18.         }
  19.         :
  20.         function(s)
  21.         {
  22.         },
  23.  
  24.     _dump : function(s)
  25.     {
  26.         var sidelog = samfind_modlog.getSidelog();
  27.         if (sidelog == null)
  28.         {
  29.             dump("\n[samfind]: " + s);
  30.         }
  31.         else
  32.         {
  33.             var doc = sidelog.ownerDocument;
  34.             var p = doc.createElementNS("http://www.w3.org/1999/xhtml", "p");
  35.             p.textContent = s;
  36.             sidelog.appendChild(p);
  37.         }
  38.     },
  39.  
  40.     dump_exception : SAMFIND_MODLOG_IS_ON ?
  41.         function(s, e)
  42.         {
  43.             this._dump_exception(s, e);
  44.         }
  45.         :
  46.         function(s, e)
  47.         {
  48.         },
  49.  
  50.     _dump_exception : function(s, e)
  51.     {
  52.         var sidelog = samfind_modlog.getSidelog();
  53.         if (sidelog == null)
  54.         {
  55.             dump("\n[samfind]: " + s + ": EXCEPTION: " + e.name + ", " + e.message);
  56.         }
  57.         else
  58.         {
  59.             var doc = sidelog.ownerDocument;
  60.             var p = doc.createElementNS("http://www.w3.org/1999/xhtml", "p");
  61.             p.textContent = s + ": EXCEPTION: " + e.name + ", " + e.message;
  62.             sidelog.appendChild(p);
  63.         }
  64.     },
  65.  
  66.     _start : null,
  67.  
  68.     dump_start : SAMFIND_MODLOG_IS_ON ?
  69.         function(s)
  70.         {
  71.             this._dump_start(s);
  72.         }
  73.         :
  74.         function(s)
  75.         {
  76.         },
  77.  
  78.     _dump_start : function(s)
  79.     {
  80.         if (s && s.length)
  81.         {
  82.             this._dump(s);
  83.         }    
  84.         this._start = (new Date()).getTime();
  85.     },
  86.  
  87.     dump_end : SAMFIND_MODLOG_IS_ON ?
  88.         function(s)
  89.         {
  90.             this._dump_end(s);
  91.         }
  92.         :
  93.         function(s)
  94.         {
  95.         },
  96.  
  97.     _dump_end : function(s)
  98.     {
  99.         var sidelog = samfind_modlog.getSidelog();
  100.         if (sidelog == null)
  101.         {
  102.             dump("\n[samfind]: " + s + " (time = " + ((new Date()).getTime() - this._start) + "ms)");
  103.         }
  104.         else
  105.         {
  106.             var doc = sidelog.ownerDocument;
  107.             var p = doc.createElementNS("http://www.w3.org/1999/xhtml", "p");
  108.             p.textContent = s + " (time = " + ((new Date()).getTime() - this._start) + "ms)";
  109.             sidelog.appendChild(p);
  110.         }
  111.     },
  112.  
  113.     dump_interfaces : SAMFIND_MODLOG_IS_ON ?
  114.         function(c)
  115.         {
  116.             this._dump_interfaces(c);
  117.         }
  118.         :
  119.         function(c)
  120.         {
  121.         },
  122.  
  123.     _dump_interfaces : function(c)
  124.     {
  125.         for each (var i in Components.interfaces)
  126.         {
  127.             if (c instanceof i)
  128.             {
  129.                 dump("\n" + i);
  130.             }
  131.         }
  132.     },
  133.  
  134.     getSidelog : function()
  135.     {
  136.         var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
  137.         var win = wm.getMostRecentWindow("navigator:browser");
  138.         if (win && win.document)
  139.         {
  140.             var sidebar_broadcaster = win.document.getElementById("samfind-sidelog-view");
  141.             if (sidebar_broadcaster && sidebar_broadcaster.getAttribute("checked") == "true")
  142.             {
  143.                 var sidebar = win.document.getElementById("sidebar");
  144.                 if (sidebar)
  145.                 {
  146.                     var sidelog = sidebar.contentDocument.getElementById("dumpee");
  147.                     return sidelog;
  148.                 }
  149.             }
  150.         }
  151.         return null;
  152.     }
  153. };