home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2007 June / PCpro_2007_06.ISO / files / heftdateien / firefox / google-toolbar-win.xpi / components / bootstrap.js next >
Encoding:
Text File  |  2007-02-17  |  7.6 KB  |  159 lines

  1. // Copyright 2006 and onwards, Google
  2. // Author: Aaron Boodman
  3. // Stolen and modified by: Fritz Schneider
  4. //
  5. // We run our application in a separate context from the browser. Our
  6. // app gets its own context by virtue of the fact that it is an XPCOM
  7. // component. Glue code in the overlay will call into our component
  8. // to interact with the app.
  9. //
  10. // This file implements a loader for our component. It takes a list of
  11. // js files and dynamically loads them into this context. It then
  12. // registers to hear xpcom startup, at which point it instantiates our
  13. // application in this context. This context is exposed to overlay
  14. // code via a property of the object returned when you get the service
  15. // from contract @google.com/toolbar/application;1.
  16. //
  17. // Lots of JS and XPCOM voodoo going on here; tread lightly unless you
  18. // understand it.
  19. //
  20. // TODO: delete category entry for startup on shutdown?
  21.  
  22. const Cc = Components.classes;
  23. const Ci = Components.interfaces;
  24. const Cr = Components.results;
  25.  
  26. // Load our component JS file.
  27. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  28.   .getService(Ci.mozIJSSubScriptLoader)
  29.   .loadSubScript(getLibFile("lib/toolbar.js"));
  30.  
  31. // Load Google domain information
  32. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  33.   .getService(Ci.mozIJSSubScriptLoader)
  34.   .loadSubScript("chrome://google-toolbar/locale/domains.js");
  35.  
  36. // Now we can make our js module
  37. var GTB_module = new G_JSModule();
  38.  
  39. // Register the application.
  40. GTB_module.registerObject("{66f4ea38-ca54-4c81-b145-858a27aea21b}",
  41.                           "@google.com/toolbar/application;1",
  42.                           "GTB_Context",
  43.                           new GTB_Application(),
  44.                           ["xpcom-startup"]);
  45. var localeFeatureListService = new GTB_LocaleFeatureListService();
  46. GTB_module.registerObject("{42495560-aa41-11db-abbd-0800200c9a66}",
  47.                           "@google.com/toolbar/locale-features-list-service;1",
  48.                           "Google Toolbar Locale Features List Service",
  49.                           localeFeatureListService);
  50. GTB_module.registerObject("{71631a52-b676-4628-8831-f777932b82ec}",
  51.                           "@mozilla.org/autocomplete/search;1?name=google-search-suggest",
  52.                           "Google Search Suggest",
  53.                           new SearchSuggestAutoComplete());
  54. GTB_module.registerObject("{0706d4a9-df9a-4d57-9b5f-c2c050006db8}",
  55.                           "@google.com/toolbar/search-history;1",
  56.                           "Google Toolbar Search History",
  57.                           new GTB_SearchHistoryService());
  58. GTB_module.registerObject("{2897397f-ba06-4563-b32e-0003c360bcf6}",
  59.                           "@google.com/toolbar/search-types;1",
  60.                           "Google Toolbar Search Types",
  61.                           new GTB_SearchTypeService());
  62. GTB_module.registerObject("{2de1131b-01de-42e8-99d3-4b34654e491f}",
  63.                           "@google.com/toolbar/gaia-service;1",
  64.                           "Google Toolbar Gaia Service",
  65.                           new GTB_GaiaService());
  66. GTB_module.registerObject("{dbb5b4b6-1094-4160-8c77-5df04583f420}",
  67.                           "@google.com/toolbar/bookmarks;1",
  68.                           "Google Toolbar Server Bookmarks",
  69.                           new GTB_BookmarksService());
  70. GTB_module.registerObject("{2f2f5706-4145-437e-9959-a0f3072bd1af}",
  71.                           "@mozilla.org/autocomplete/search;1?name=bookmark-labels-suggest",
  72.                           "Google Toolbar Bookmark Label Suggest",
  73.                           new LabelAutoComplete());
  74. GTB_module.registerObject("{caf13f42-59e6-4d0e-abd0-8d0587c7e320}",
  75.                           "@mozilla.org/network/protocol;1?name=mailto",
  76.                           "Google Mail Protocol",
  77.                           new GTB_MailtoProtocolHandler());
  78. GTB_module.registerObject("{af2bee5f-bb24-53e0-f922-5288ed0180fe}",
  79.                           "@google.com/toolbar/custom-buttons-service;1",
  80.                           "Google Toolbar Custom Buttons Service",
  81.                           new GTB_CustomButtonsService());
  82. GTB_module.registerObject("{cc743e19-174c-4a61-a376-ce30f3c67112}",
  83.                           "@google.com/toolbar/cb-submithelper;1",
  84.                           "Google Toolbar Submit Helper Service",
  85.                           new GTB_CB_SubmitHelperService());
  86. GTB_module.registerObject("{80ed2c93-2340-41c3-84c9-b496c978fad1}",
  87.                           "@google.com/toolbar/pagerank-progress;1",
  88.                           "Google Toolbar PageRank Web Progress",
  89.                           new GTB_PageRankWebProgress());
  90. GTB_module.registerObject("{f1d3ee04-9baa-4f2b-96ed-23cd17f8a96f}",
  91.                           "@google.com/toolbar/search-service;1",
  92.                           "Google Toolbar Search Service",
  93.                           new GTB_SearchService());
  94. var chPrefs = new GTB_ContentPrefsService();
  95. GTB_module.registerObject("{034f1b81-d347-4485-ad25-a75ac5fa9017}",
  96.                           "@google.com/toolbar/content-prefs;1",
  97.                           "Google Toolbar Content Prefs Helper",
  98.                           chPrefs);
  99. for (var t in chPrefs.fileTypes) {
  100.   for (var i = 0; i < chPrefs.fileTypes[t].mime.length; i++) {
  101.     GTB_module.registerObject(chPrefs.fileTypes[t].uuid,
  102.                               "@mozilla.org/uriloader/content-handler;1?type=" + 
  103.                               chPrefs.fileTypes[t].mime[i],
  104.                               "Google Toolbar " + chPrefs.fileTypes[t].mime,
  105.                               new GTB_MimeTypeHandler(chPrefs.fileTypes[t].mime, 
  106.                                                       t,
  107.                                                       "{HOST}?action=updoc&formsubmitted=true&client=navclient-ff&uploadURL={URL}",
  108.                                                       localeFeatureListService));
  109.   }
  110. }
  111. GTB_module.registerObject("{251e6f99-12c3-4935-8f22-75832f87baf9}",
  112.                           "@google.com/toolbar/command-line-handler;1",
  113.                           "Google Toolbar Command Line Handler",
  114.                           new GTB_CommandLineHandler());
  115.  
  116. // Register the command line handler
  117. var catMgr = Cc["@mozilla.org/categorymanager;1"]
  118.                .getService(Ci.nsICategoryManager);
  119.  
  120. catMgr.addCategoryEntry("command-line-handler",
  121.                         "m-googletoolbar", // priority(a-z)-name
  122.                         "@google.com/toolbar/command-line-handler;1",
  123.                         true, true);
  124.  
  125. // For the "content-policy" topic, the name for the category entry must be
  126. // the contract ID of the component.
  127. // http://www.opensubscriber.com/message/mozilla-xpcom@mozilla.org/924255.html
  128. GTB_module.registerObject("{f4c526c9-d4e9-a521-0f7c-eef1e979e811}",
  129.                           "@google.com/toolbar/custom-buttons-urlchecker;1",
  130.                           "@google.com/toolbar/custom-buttons-urlchecker;1",
  131.                           new GTB_CB_UrlChecker(),
  132.                           ["content-policy"]);
  133. GTB_module.registerObject("{33f776e5-004d-4f25-a24b-e60d93251058}",
  134.                           "@google.com/toolbar/web-progress-listener;1",
  135.                           "Google Toolbar WebProgressListener",
  136.                           new GTB_WebProgress());
  137. function NSGetModule() {
  138.   return GTB_module;
  139. }
  140.  
  141. /**
  142.  * Gets a file:// URL for the given physical path relative to the libs/ 
  143.  * folder. 
  144.  */
  145. function getLibFile(path) {
  146.   var file = __LOCATION__.clone().parent.parent;
  147.   var parts = path.split("/");
  148.  
  149.   for (var i = 0, part; part = parts[i]; i++)
  150.     file.append(part);
  151.   
  152.   if (!file.exists())
  153.     throw new Error("Specified library {" + file.path + "} does not exist");
  154.  
  155.   return Cc["@mozilla.org/network/protocol;1?name=file"]
  156.     .getService(Ci.nsIFileProtocolHandler)
  157.     .getURLSpecFromFile(file);
  158. };
  159.