home *** CD-ROM | disk | FTP | other *** search
/ Minami 83 / MINAMI83.iso / Extra / DivXInstaller.exe / $PLUGINSDIR / GoogleToolbarFirefox.msi / xpi / components / amulet-loader.js next >
Text File  |  2006-08-07  |  5KB  |  189 lines

  1. var G_GDEBUG_LOADER = false;
  2. var Cc = Components.classes;
  3. var Ci = Components.interfaces;
  4. var PROT_appContext = this;
  5. var PROT_application;
  6. var PROT_LIB_ROOT = "amulet-jslib";
  7. var PROT_LIBS = [
  8. "google3/lang.js",
  9. "google3/thread-queue.js",
  10. "google3/eventregistrar.js",
  11. "google3/listdictionary.js",
  12. "google3/arc4.js",
  13. "firefox/lang.js",
  14. "firefox/preferences.js",
  15. "firefox/alarm.js",
  16. "firefox/base64.js",
  17. "firefox/observer.js",
  18. "firefox/filesystem.js",
  19. "firefox/protocol4.js",
  20. "firefox/debug.js",
  21. "firefox/tabbedbrowserwatcher.js",
  22. "firefox/navwatcher.js",
  23. "firefox/cryptohasher.js",
  24. "firefox/objectsafemap.js",
  25. "firefox/version-utils.js",
  26. "application.js",
  27. "browser-view.js",
  28. "content-analyzer.js",
  29. "controller.js",
  30. "enchash-decrypter.js",
  31. "firefox-commands.js",
  32. "globalstore.js",
  33. "listmanager.js",
  34. "list-warden.js",
  35. "multi-querier.js",
  36. "multi-table-querier.js",
  37. "phishing-afterload-displayer.js",
  38. "phishing-warden.js", // depends on list-warden.js
  39. "reporter.js",
  40. "sandbox.js",
  41. "tr-fetcher.js",
  42. "trtable.js",
  43. "url-canonicalizer.js",
  44. "url-crypto.js",
  45. "url-crypto-key-manager.js",
  46. "wireformat.js",
  47. "xml-fetcher.js",
  48. ];
  49. var G_GDEBUG = false;
  50. function LOADER_dump(msg) {
  51. if (G_GDEBUG_LOADER) {
  52. for (var i = 1; i < arguments.length; i++) {
  53. msg = msg.replace(/\%s/, arguments[i]);
  54. }
  55. dump("[TB BOOTSTRAP LOADER] " + msg + "\n");
  56. }
  57. }
  58. var PROTTB_loader = new function() {
  59. var CONTRACT_ID_PREFIX = "@google.com/tbsafebrowsing/";
  60. var LOADER_CONTRACT_ID = "application;1";
  61. var components = [];
  62. var componentsLookup = {};
  63. this.init = function() {
  64. LOADER_dump("initializing...");
  65. loadLibs();
  66. LOADER_dump("registering loader service...");
  67. this.registerComponent(LOADER_CONTRACT_ID,
  68. "{888f29f2-b2ec-41e8-a965-12d3780fefca}",
  69. "PROTTB_loader",
  70. ["xpcom-startup"]);
  71. };
  72. this.registerComponent =
  73. function(contractId, classId, className, categories) {
  74. var component = { contractId: contractId,
  75. classId: classId,
  76. className: className,
  77. categories: categories };
  78. components.push(component);
  79. componentsLookup[component.classId] = component;
  80. };
  81. this.registerSelf = function(compMgr, fileSpec, location, type) {
  82. LOADER_dump("registering XPCOM components... ");
  83. compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
  84. for (var i = 0, component; component = components[i]; i++) {
  85. LOADER_dump("  registering {%s} as {%s}",
  86. component.className,
  87. component.contractId);
  88. compMgr.registerFactoryLocation(Components.ID(component.classId),
  89. component.className,
  90. CONTRACT_ID_PREFIX +
  91. component.contractId,
  92. fileSpec,
  93. location,
  94. type);
  95. if (component.categories && component.categories.length) {
  96. var catMgr = Cc["@mozilla.org/categorymanager;1"]
  97. .getService(Ci.nsICategoryManager);
  98. for (var j = 0, category; category = component.categories[j]; j++) {
  99. LOADER_dump("    registering category {%s}", category);
  100. catMgr.addCategoryEntry(category,
  101. component.className,
  102. CONTRACT_ID_PREFIX + component.contractId,
  103. true,
  104. true);
  105. }
  106. }
  107. }
  108. };
  109. this.getClassObject = function(compMgr, cid, iid) {
  110. LOADER_dump("getting factory for class {%s} and interface {%s}...",
  111. cid, iid);
  112. var comp = componentsLookup[cid.toString()];
  113. if (!comp)
  114. throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  115. if (!iid.equals(Ci.nsIFactory))
  116. throw Components.results.NS_ERROR_NO_INTERFACE;
  117. return new PROT_Factory(comp);
  118. };
  119. this.canUnload = function(compMgr) {
  120. return true;
  121. };
  122. function loadLibs() {
  123. for (var i = 0, libPath; libPath = PROT_LIBS[i]; i++) {
  124. LOADER_dump("Loading library {%s}", libPath);
  125. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  126. .getService(Ci.mozIJSSubScriptLoader)
  127. .loadSubScript(getLibUrl(libPath));
  128. }
  129. };
  130. function getLibUrl(path) {
  131. var file = __LOCATION__.clone().parent.parent;
  132. var parts = path.split("/");
  133. file.append(PROT_LIB_ROOT);
  134. for (var i = 0, part; part = parts[i]; i++)
  135. file.append(part);
  136. if (!file.exists())
  137. throw new Error("Specified library {" + file.path + "} does not exist");
  138. return Cc["@mozilla.org/network/protocol;1?name=file"]
  139. .getService(Ci.nsIFileProtocolHandler)
  140. .getURLSpecFromFile(file);
  141. };
  142. this.__defineGetter__("wrappedJSObject", function() { return this; });
  143. this.appContext = PROT_appContext;
  144. this.observe = function(subject, topic, data) {
  145. if (topic != "xpcom-startup")
  146. return;
  147. function onProfileAfterChange() {
  148. if (PROT_Application.isCompatibleWithThisFirefox()) {
  149. LOADER_dump("Starting application...");
  150. PROT_application = new PROT_Application();
  151. } else
  152. LOADER_dump("Not starting application (incompatible ffox)...");
  153. };
  154. new G_ObserverServiceObserver("profile-after-change",
  155. onProfileAfterChange,
  156. true /* unregister after observing */);
  157. };
  158. this.QueryInterface = function(iid) {
  159. var Ci = Components.interfaces;
  160. if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIObserver))
  161. return this;
  162. throw Components.results.NS_ERROR_NO_INTERFACE;
  163. };
  164. }
  165. function PROT_Factory(comp) {
  166. this.comp = comp;
  167. }
  168. PROT_Factory.global = this;
  169. PROT_Factory.prototype.createInstance = function(outer, iid) {
  170. LOADER_dump("Factory creating instance for iid {%s}", iid);
  171. if (outer != null)
  172. throw Components.results.NS_ERROR_NO_AGGREGATION;
  173. var scriptObj = PROT_Factory.global[this.comp.className];
  174. if (!scriptObj)
  175. throw new Error("Could not find global object with name {%s}",
  176. this.comp.className);
  177. var retVal = (typeof scriptObj == "function") ? new scriptObj() : scriptObj;
  178. if (retVal.QueryInterface) {
  179. retVal.QueryInterface(iid);
  180. }
  181. return retVal;
  182. }
  183. PROTTB_loader.init();
  184. LOADER_dump("initialization complete");
  185. function NSGetModule() {
  186. LOADER_dump("NSGetModule called");
  187. return PROTTB_loader;
  188. }
  189.