home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / components / sbParserError.js < prev    next >
Text File  |  2012-06-08  |  7KB  |  210 lines

  1. /**
  2. //
  3. // BEGIN SONGBIRD GPL
  4. // 
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright(c) 2005-2008 POTI, Inc.
  8. // http://songbirdnest.com
  9. // 
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the "GPL").
  12. // 
  13. // Software distributed under the License is distributed 
  14. // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
  15. // express or implied. See the GPL for the specific language 
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this 
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc., 
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. // 
  23. // END SONGBIRD GPL
  24. //
  25.  */
  26. const SONGBIRD_PARSERERRORHANDLER_CONTRACTID = "@songbirdnest.com/Songbird/ParserErrorHandler;1";
  27. const SONGBIRD_PARSERERRORHANDLER_CLASSNAME = "Songbird Parser Error Handler";
  28. const SONGBIRD_PARSERERRORHANDLER_CID = Components.ID("{213a0ebb-12b3-492f-bc4c-f472f8f24d2c}");
  29.  
  30. const MSG_ERROR_UNDEFINEDENTITY = '[JavaScript Error: "undefined entity"';
  31. const MSG_ERROR_ENTITYPROCESSING = '[JavaScript Error: "error in processing external entity reference"';
  32.  
  33. var gBusy = false;
  34.  
  35. var consoleListener = {
  36.   observe: function(msg) 
  37.   {
  38.     if (msg.message.substr(0, MSG_ERROR_UNDEFINEDENTITY.length) == MSG_ERROR_UNDEFINEDENTITY ||
  39.         msg.message.substr(0, MSG_ERROR_ENTITYPROCESSING.length) == MSG_ERROR_ENTITYPROCESSING) {
  40.       dump("parseError:" + msg.message + "\n");
  41.  
  42.       var prefs = Components.classes["@mozilla.org/preferences-service;1"].
  43.                               getService(Components.interfaces.nsIPrefBranch);
  44.       var curLocale = "en-US";
  45.       try {
  46.         curLocale = prefs.getCharPref("general.useragent.locale");
  47.       }
  48.       catch (e) { }
  49.  
  50.       if (!gBusy && curLocale != "en-US") { 
  51.       
  52.         try {                        
  53.           gBusy = true;
  54.           
  55.           var wWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  56.                                    .getService(Components.interfaces.nsIWindowWatcher);
  57.           var wMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  58.                                     .getService(Components.interfaces.nsIWindowMediator);
  59.           var mainWindow = wMediator.getMostRecentWindow("Songbird:Main");
  60.  
  61.           wWatcher.openWindow(mainWindow,
  62.                     "chrome://songbird/content/xul/parserError.xul",
  63.                     "_blank",
  64.                     "chrome,modal=yes,centerscreen,resizable=no",
  65.                     msg);
  66.         } catch (e) {
  67.         }
  68.         gBusy = false;
  69.       }
  70.     }
  71.   },
  72.   
  73.   QueryInterface : function(aIID)
  74.   {
  75.     if (!aIID.equals(Components.interfaces.nsIConsoleListener) &&
  76.         !aIID.equals(Components.interfaces.nsISupports)) 
  77.     {
  78.       throw Components.results.NS_ERROR_NO_INTERFACE;
  79.     }
  80.     return this;
  81.   }
  82. };
  83.  
  84. var gOS = null;
  85. var gConsole = null;
  86.  
  87. function ParserErrorHandler() {
  88.   try {
  89.     gConsole = Components.classes["@mozilla.org/consoleservice;1"]
  90.                         .getService(Components.interfaces.nsIConsoleService);
  91.     gOS      = Components.classes["@mozilla.org/observer-service;1"]
  92.                         .getService(Components.interfaces.nsIObserverService);
  93.     
  94.     if (gOS.addObserver) {
  95.       // We should wait until the profile has been loaded to start
  96.       gOS.addObserver(this, "profile-after-change", false);
  97.       // We need to unhook things on shutdown
  98.       gOS.addObserver(this, "xpcom-shutdown", false);
  99.     }
  100.   } catch (e) { }
  101. }
  102.  
  103. ParserErrorHandler.prototype.constructor = ParserErrorHandler;
  104.  
  105. ParserErrorHandler.prototype = {
  106.  
  107.   _init: function() {
  108.     try {
  109.       gConsole.registerListener(consoleListener);
  110.     } catch (e) { }
  111.   },
  112.   
  113.   _deinit: function() {
  114.     try {
  115.       gConsole.unregisterListener(consoleListener);
  116.     } catch (e) { }
  117.   },
  118.  
  119.   // watch for XRE startup and shutdown messages 
  120.   observe: function(subject, topic, data) {
  121.     switch (topic) {
  122.     case "profile-after-change":
  123.       gOS.removeObserver(this, "profile-after-change");
  124.       
  125.       // Preferences are initialized, ready to start the service
  126.       this._init();
  127.       break;
  128.     case "xpcom-shutdown":
  129.       gOS.removeObserver(this, "xpcom-shutdown");
  130.       this._deinit();
  131.       
  132.       // Release Services to avoid memory leaks
  133.       gOS       = null;
  134.       gConsole  = null;
  135.       break;
  136.     }
  137.   },
  138.  
  139.   /**
  140.    * See nsISupports.idl
  141.    */
  142.   QueryInterface: function(iid) {
  143.     if (!iid.equals(Components.interfaces.nsIObserver) && 
  144.         !iid.equals(Components.interfaces.nsISupports))
  145.       throw Components.results.NS_ERROR_NO_INTERFACE;
  146.     return this;
  147.   }
  148. }; // ParserErrorHandler.prototype
  149.  
  150. /**
  151.  * ----------------------------------------------------------------------------
  152.  * Registration for XPCOM
  153.  * ----------------------------------------------------------------------------
  154.  */
  155. var gModule = {
  156.   registerSelf: function(componentManager, fileSpec, location, type) {
  157.     componentManager = componentManager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  158.     for (var key in this._objects) {
  159.       var obj = this._objects[key];
  160.       componentManager.registerFactoryLocation(obj.CID, obj.className, obj.contractID,
  161.                                                fileSpec, location, type);
  162.     }
  163.     var categoryManager = Components.classes["@mozilla.org/categorymanager;1"]
  164.                                     .getService(Components.interfaces.nsICategoryManager);
  165.     categoryManager.addCategoryEntry("app-startup", this._objects.parsererrorhandler.className,
  166.                                     "service," + this._objects.parsererrorhandler.contractID, 
  167.                                     true, true, null);
  168.   },
  169.  
  170.   getClassObject: function(componentManager, cid, iid) {
  171.     if (!iid.equals(Components.interfaces.nsIFactory))
  172.       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  173.  
  174.     for (var key in this._objects) {
  175.       if (cid.equals(this._objects[key].CID))
  176.         return this._objects[key].factory;
  177.     }
  178.     
  179.     throw Components.results.NS_ERROR_NO_INTERFACE;
  180.   },
  181.  
  182.   _makeFactory: #1= function(ctor) {
  183.     function ci(outer, iid) {
  184.       if (outer != null)
  185.         throw Components.results.NS_ERROR_NO_AGGREGATION;
  186.       return (new ctor()).QueryInterface(iid);
  187.     } 
  188.     return { createInstance: ci };
  189.   },
  190.   
  191.   _objects: {
  192.     // The ParserError Component
  193.     parsererrorhandler:     { CID        : SONGBIRD_PARSERERRORHANDLER_CID,
  194.                               contractID : SONGBIRD_PARSERERRORHANDLER_CONTRACTID,
  195.                               className  : SONGBIRD_PARSERERRORHANDLER_CLASSNAME,
  196.                               factory    : #1#(ParserErrorHandler)
  197.                             },
  198.   },
  199.  
  200.   canUnload: function(componentManager) { 
  201.     return true; 
  202.   }
  203. }; // gModule
  204.  
  205. function NSGetModule(comMgr, fileSpec) {
  206.   return gModule;
  207. } // NSGetModule
  208.  
  209.  
  210.