1 /* See license.txt for terms of usage */ 2 3 // ********************************************************************************************* // 4 // Constants 5 6 const Cc = Components.classes; 7 const Ci = Components.interfaces; 8 const Cu = Components.utils; 9 10 // List of firebug modules that must be loaded at startup and unloaded on shutdown. 11 // !important every new module loaded with Cu.import must be added here 12 var FIREBUG_MODULES = [ 13 "resource://firebug/debuggerHalter.js", 14 "resource://firebug/fbtrace.js", 15 "resource://firebug/firebug-http-observer.js", 16 "resource://firebug/firebug-service.js", 17 "resource://firebug/firebug-trace-service.js", 18 "resource://firebug/gcli.js", 19 "resource://firebug/loader.js", 20 "resource://firebug/locale.js", 21 "resource://firebug/mini-require.js", 22 "resource://firebug/observer-service.js", 23 "resource://firebug/prefLoader.js", 24 "resource://firebug/require-debug.js", 25 "resource://firebug/require.js", 26 "resource://firebug/storageService.js" 27 ]; 28 29 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 30 Cu.import("resource://gre/modules/Services.jsm"); 31 32 // ********************************************************************************************* // 33 // Bootstrap API 34 35 function install(params, reason) 36 { 37 } 38 39 function uninstall(params, reason) 40 { 41 } 42 43 function startup(params, reason) 44 { 45 // Register the resource:// mappings 46 var res = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler); 47 var resourceURI = Services.io.newURI(__SCRIPT_URI_SPEC__ + "/../modules/", null, null); 48 res.setSubstitution("firebug", resourceURI); 49 res.setSubstitution("moduleloader", resourceURI); 50 51 // Add our chrome registration. not needed for 10+ 52 Components.manager.addBootstrappedManifestLocation(params.installPath); 53 54 Cu.import("resource://firebug/prefLoader.js"); 55 56 // Register default preferences 57 PrefLoader.loadDefaultPrefs(params.installPath, "firebug.js"); 58 PrefLoader.loadDefaultPrefs(params.installPath, "cookies.js"); 59 PrefLoader.loadDefaultPrefs(params.installPath, "tracingConsole.js"); 60 61 // Load the overlay manager 62 Cu.import("resource://firebug/loader.js"); 63 64 //register extensions 65 FirebugLoader.startup(); 66 67 // Load Firebug into all existing browser windows. 68 var enumerator = Services.wm.getEnumerator("navigator:browser"); 69 while (enumerator.hasMoreElements()) 70 FirebugLoader.loadIntoWindow(enumerator.getNext(), reason); 71 72 // Listen for new windows, Firebug must be loaded into them too. 73 Services.obs.addObserver(windowWatcher, "chrome-document-global-created", false); 74 75 // GCLI commands 76 Cu.import("resource://firebug/gcli.js"); 77 FirebugGCLICommands.startup(); 78 } 79 80 function shutdown(params, reason) 81 { 82 // Don't need to clean anything up if the application is shutting down 83 if (reason == APP_SHUTDOWN) 84 return; 85 86 // Remove "new window" listener. 87 Services.obs.removeObserver(windowWatcher, "chrome-document-global-created"); 88 89 // remove from all windows 90 try 91 { 92 FirebugLoader.shutdown(); 93 } 94 catch(e) 95 { 96 Cu.reportError(e); 97 } 98 99 // Unregister all GCLI commands 100 FirebugGCLICommands.shutdown(); 101 102 // xxxHonza: I think this shouldn't be here (perhaps in firebug-service.js) 103 // Shutdown Firebug's JSD debugger service. 104 var fbs = Cu.import("resource://firebug/firebug-service.js", {}).fbs; 105 fbs.disableDebugger(); 106 fbs.shutdown(); 107 108 // remove default preferences 109 PrefLoader.clearDefaultPrefs(); 110 111 // Unload all Firebug modules added with Cu.import 112 FIREBUG_MODULES.forEach(Cu.unload, Cu); 113 114 // Remove our chrome registration. not needed for 10+ 115 Components.manager.removeBootstrappedManifestLocation(params.installPath); 116 117 // Clear our resource registration 118 var res = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler); 119 res.setSubstitution("firebug", null); 120 res.setSubstitution("moduleloader", null); 121 } 122 123 // ********************************************************************************************* // 124 // Window Listener 125 126 var windowWatcher = 127 { 128 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), 129 observe: function windowWatcher(win, topic, data) 130 { 131 // https://bugzil.la/795961 ? 132 win.addEventListener("load", function onLoad(evt) 133 { 134 // load listener not necessary once https://bugzil.la/800677 is fixed 135 var win = evt.currentTarget; 136 win.removeEventListener("load", onLoad, false); 137 if (win.document.documentElement.getAttribute("windowtype") == "navigator:browser") 138 FirebugLoader.loadIntoWindow(win); 139 }, false); 140 } 141 }; 142 143 // ********************************************************************************************* // 144