sbParserError.js
Go to the documentation of this file.
1 
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 
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 
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 
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,
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 
const SONGBIRD_PARSERERRORHANDLER_CID
var gOS
sbOSDControlService prototype className
SafebrowsingApplicationMod prototype registerSelf
const MSG_ERROR_UNDEFINEDENTITY
for(let i=0;i< aHistory.count;i++)
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sidebarFactory createInstance
Definition: nsSidebar.js:351
sbOSDControlService prototype QueryInterface
function ParserErrorHandler()
getService(Ci.sbIFaceplateManager)
const CID
SafebrowsingApplicationMod prototype getClassObject
const SONGBIRD_PARSERERRORHANDLER_CLASSNAME
var gBusy
const SONGBIRD_PARSERERRORHANDLER_CONTRACTID
return null
Definition: FeedWriter.js:1143
var gConsole
var prefs
Definition: FeedWriter.js:1169
var consoleListener
var gModule
observe topic
Definition: FeedWriter.js:1326
const MSG_ERROR_ENTITYPROCESSING
function msg
observe data
Definition: FeedWriter.js:1329
sbDeviceFirmwareAutoCheckForUpdate prototype observe
function NSGetModule(comMgr, fileSpec)