1 /* See license.txt for terms of usage */
  2 
  3 (function() {
  4 
  5 // ********************************************************************************************* //
  6 
  7 const Cc = Components.classes;
  8 const Ci = Components.interfaces;
  9 
 10 var prefDomain = "extensions.firebug";
 11 var config = Firebug.getModuleLoaderConfig();
 12 
 13 if (FBTrace.DBG_INITIALIZE || FBTrace.DBG_MODULES)
 14 {
 15     if (FBTrace.DBG_MODULES)
 16         config.debug = true;
 17 
 18     FBTrace.sysout("main.js; Loading Firebug modules...", config);
 19     var startLoading = new Date().getTime();
 20 }
 21 
 22 // ********************************************************************************************* //
 23 
 24 try
 25 {
 26     // xxxHonza: temporary hack for Crossfire to provide custom set of modules.
 27     var prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
 28     var value = prefService.getCharPref("extensions.firebug.defaultModuleList");
 29     if (value)
 30     {
 31         var modules = value.split(",");
 32         if (modules.length)
 33             config.modules = modules;
 34     }
 35 }
 36 catch (err)
 37 {
 38 }
 39 
 40 // ********************************************************************************************* //
 41 
 42 // Backward compatibility (some modules changed location)
 43 // http://getfirebug.com/wiki/index.php/Extension_Migration
 44 // http://code.google.com/p/fbug/issues/detail?id=5199
 45 var paths = {};
 46 paths["firebug/css/cssComputedElementPanel"] = "firebug/css/computedPanel";
 47 paths["firebug/css/cssElementPanel"] = "firebug/css/stylePanel";
 48 paths["firebug/firefox/annotations"] = "firebug/chrome/annotations";
 49 paths["firebug/firefox/privacy"] = "firebug/chrome/privacy";
 50 paths["firebug/firefox/system"] = "firebug/lib/system";
 51 paths["firebug/firefox/tabWatcher"] = "firebug/chrome/tabWatcher";
 52 paths["firebug/firefox/xpcom"] = "firebug/lib/xpcom";
 53 paths["firebug/firefox/window"] = "firebug/chrome/window";
 54 paths["firebug/firefox/firefox"] = "firebug/chrome/firefox";
 55 paths["firebug/net/httpLib"] = "firebug/lib/http";
 56 
 57 var originalLoad = require.load;
 58 require.load = function(context, fullName, url)
 59 {
 60     if (paths[fullName])
 61     {
 62         var newUrl = paths[fullName].replace("firebug/", "firebug/content/");
 63         url = "chrome://" + newUrl + ".js";
 64     }
 65 
 66     return originalLoad.apply(require, [context, fullName, url]);
 67 }
 68 
 69 // ********************************************************************************************* //
 70 
 71 // For now extensions should use 'Firebug.require' to load it's modules, so
 72 // initialize the field. It should be done now since overlays can be applied
 73 // before the core Firebug modules are (asynchronously) loaded.
 74 Firebug.require = require;
 75 
 76 // Load core Firebug modules.
 77 var modules = [
 78     "firebug/chrome/chrome",
 79     "firebug/lib/lib",
 80     "firebug/firebug",
 81     "firebug/bti/inProcess/browser"
 82 ].concat(config.modules);
 83 
 84 // ********************************************************************************************* //
 85 
 86 require(config, modules, function(ChromeFactory, FBL, Firebug, Browser)
 87 {
 88     try
 89     {
 90         // Wait till all modules (including those coming from Firebug extensions)
 91         // are loaded and thus all panels, firebug-modules, bundles, etc. are properly
 92         // registered and Firebug can start to send initialization events.
 93         if (typeof(requirejs) != "undefined")
 94         {
 95             var prevResourcesReady = requirejs.resourcesReady;
 96             requirejs.resourcesReady = function(isReady)
 97             {
 98                 if (isReady && requirejs.resourcesDone)
 99                     onModulesLoaded(ChromeFactory, FBL, Firebug, Browser);
100 
101                 if (prevResourcesReady)
102                     prevResourcesReady(isReady);
103             }
104         }
105         else
106         {
107             onModulesLoaded(ChromeFactory, FBL, Firebug, Browser);
108         }
109     }
110     catch(exc)
111     {
112         if (FBTrace)
113             FBTrace.sysout("Firebug main initialization ERROR " + exc, exc);
114 
115         window.dump("Firebug main initialization ERROR " + exc);
116 
117         if (Components)
118             Components.utils.reportError(exc);
119     }
120 });
121 
122 // ********************************************************************************************* //
123 
124 function onModulesLoaded(ChromeFactory, FBL, Firebug, Browser)
125 {
126     // Extensions are using the same loader, so make sure to not
127     // initialize Firebug twice.
128     if (Firebug.isInitialized)
129         return;
130 
131     if (FBTrace.DBG_INITIALIZE || FBTrace.DBG_MODULES)
132     {
133         var delta = (new Date().getTime()) - startLoading;
134         FBTrace.sysout("main.js; Firebug modules loaded using RequireJS in " + delta + " ms");
135     }
136 
137     // Extensions also shouldn't use the global require since it should be removed
138     // in the future (if possible). Global 'require' could collide with other
139     // extensions.
140     Firebug.connection = new Browser();  // prepare for addListener calls
141 
142     Browser.onDebug = function()
143     {
144         FBTrace.sysout.apply(FBTrace, arguments);
145     }
146 
147     Firebug.Options.initialize(prefDomain);
148 
149     function connect()
150     {
151         Firebug.connection.connect();  // start firing events
152     }
153 
154     if (FBTrace.DBG_INITIALIZE || FBTrace.DBG_MODULES)
155         FBTrace.sysout("main.js; All RequireJS modules loaded");
156 
157     if (window.FBL.legacyPatch)
158     {
159         if (FBTrace.DBG_MODULES)
160             FBTrace.sysout("firebug main.js; legacyPatch");
161 
162         window.FBL.legacyPatch(FBL, Firebug);
163     }
164 
165     if (!window.panelBarWaiter && FBTrace.DBG_ERRORS)
166         FBTrace.sysout("main; ERROR window.panelBarWaiter is not available " +
167             ", Firebug already initialized: " + Firebug.isInitialized);
168 
169     if (window.panelBarWaiter)
170         window.panelBarWaiter.waitForPanelBar(ChromeFactory, null, connect);
171 }
172 
173 // ********************************************************************************************* //
174 })();
175 
176 // ********************************************************************************************* //
177 
178