From 83088feef3ce714a77d53194de1afb519d7944ea Mon Sep 17 00:00:00 2001 From: Jan Odvarko Date: Thu, 4 Oct 2012 13:07:25 +0200 Subject: [PATCH] Initial commit. Basic structure for bootstrapped Firebug extension --- .gitignore | 32 +++++ ant.properties | 3 + bootstrap.js | 148 ++++++++++++++++++++++++ build.xml | 44 +++++++ chrome.manifest | 3 + chrome/content/lessModule.js | 66 +++++++++++ chrome/content/main.js | 44 +++++++ chrome/locale/en-US/fireless.properties | 4 + chrome/skin/classic/fireless.css | 11 ++ defaults/preferences/prefs.js | 1 + install.rdf | 26 +++++ license.txt | 30 +++++ 12 files changed, 412 insertions(+) create mode 100644 .gitignore create mode 100644 ant.properties create mode 100644 bootstrap.js create mode 100644 build.xml create mode 100644 chrome.manifest create mode 100644 chrome/content/lessModule.js create mode 100644 chrome/content/main.js create mode 100644 chrome/locale/en-US/fireless.properties create mode 100644 chrome/skin/classic/fireless.css create mode 100644 defaults/preferences/prefs.js create mode 100644 install.rdf create mode 100644 license.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf93e53 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ + +# Junk that could exist anywhere: +.DS_Store +*.swp +*.tmp +.*.gz +*.patch + +# Temporary files created by Eclipse +.tmp* + +# Editor junk +*.project +/.pydevproject +/.settings/ +/.settings.xml +/.settings.xml.old +/.idea/ + +# Build Files +/extension/build/ +/extension/release/ +/tests/FBTest/release/ +*.graphml +/extension/bz-locale/ + +# Files from NPM +/extension/node_modules/ + +# Extensions +/extension/firebug@software.joehewitt.com + diff --git a/ant.properties b/ant.properties new file mode 100644 index 0000000..e99725b --- /dev/null +++ b/ant.properties @@ -0,0 +1,3 @@ +# DO NOT MERGE INTO TRUNK +RELEASE=.1 +VERSION=0.5 diff --git a/bootstrap.js b/bootstrap.js new file mode 100644 index 0000000..88f429a --- /dev/null +++ b/bootstrap.js @@ -0,0 +1,148 @@ +/* See license.txt for terms of usage */ + +// ********************************************************************************************* // +// XPCOM + +var {classes: Cc, interfaces: Ci, utils: Cu} = Components; + +// ********************************************************************************************* // +// Constants + +// Extension installation path. Set within startup callback. +var installPath; + +// ********************************************************************************************* // +// Firefox Bootstrap API + +function install(data, reason) {} +function uninstall(data, reason) {} + +function startup(data, reason) +{ + // Remember so, we can use later within firebugStartup callback. + installPath = data.installPath; + + // Firebug extension start-up callback. Since extension load order isn't guaranteed + // the code needs to be ready for two alternatives: + // 1) Firebug is already loaded - good, let's just execute firebugStartup() callback + // that will ensure proper Firebug related initialization for this extension. + // 2) Firebug is not loaded yet - as soon as Firebug is loaded it'll execute this + // method automatially. + firebugStartup(); +} + +function shutdown(data, reason) +{ + firebugShutdown(); +} + +function isFirebugLoaded() +{ + try + { + // Import Firebug modules into this scope. It fails if Firebug isn't loaded yet. + Cu.import("resource://firebug/loader.js"); + Cu.import("resource://firebug/prefLoader.js"); + + return true; + } + catch (e) + { + } + + return true; +} + +// ********************************************************************************************* // +// Firebug Bootstrap API + +/** + * Executed by Firebug framework when Firebug is started. Since the order of Firebug + * and its bootstrapped extensions is not guaranteed this function is executed twice. + * 1) When Firebug is loaded + * 2) When this extension is loaded + */ +function firebugStartup() +{ + // If Firebu isn't loade just bail out, Firebug will execute this method + // as soon as it loads. + if (!isFirebugLoaded()) + return; + + FirebugLoader.registerBootstrapScope(this); + + // Load default preferences + PrefLoader.loadDefaultPrefs(installPath, "prefs.js"); +} + +/** + * Executed by Firefox when this extension shutdowns. + */ +function firebugShutdown() +{ + try + { + FirebugLoader.unregisterBootstrapScope(this); + } + catch (e) + { + Cu.reportError(e); + } +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +/** + * Executed by Firebug framework for every browser window. Use this function to append + * any new elements into the browser window (browser.xul). Don't forget to remove + * these elements in topWindowUnload. + * + * @param {Window} win The browser window + */ +function topWindowLoad(win) +{ + // TODO: overlay global browser window +} + +/** + * Executed by Firebug framework when this extension + * @param {Object} win + */ +function topWindowUnload(win) +{ + // TODO: remove global browser window overlays +} + +/** + * Entire Firebug UI is running inside an iframe (firebugFrame.xul). This function + * is executed by Firebug framework when the frame is loaded. This happens when + * the user requires Firebug for the first time (doesn't have to happen during the + * Firefox session at all) + * + * @param {Window} win The Firebug window + */ +function firebugFrameLoad(Firebug) +{ + // Register trace listener the customizes trace logs coming from this extension + // * fireless; is unique prefix of all messages that should be customized. + // * DBG_FIRELESS is a class name with style defined in the specified stylesheet. + Firebug.registerTracePrefix("fireless;", "DBG_FIRELESS", true, + "chrome://fireless/skin/fireless.css"); + + // The registration process will automatically look for 'main' module and load it. + // The is the same what happens in a XUL overlay applied on: + // chrome://firebug/content/firebugOverlay.xul + var config = {id: "fireless@getfirebug.com"}; + Firebug.registerExtension("fireless", config); +} + +function firebugFrameUnload(Firebug) +{ + if (!Firebug.isInitialized) + return; + + Firebug.unregisterExtension("fireless"); + Firebug.unregisterTracePrefix("fireless;"); +} + +// ********************************************************************************************* // diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..3f9b8c9 --- /dev/null +++ b/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/chrome.manifest b/chrome.manifest new file mode 100644 index 0000000..f5d1ebe --- /dev/null +++ b/chrome.manifest @@ -0,0 +1,3 @@ +content fireless chrome/content/ +skin fireless classic/1.0 chrome/skin/classic/ +locale fireless en-US chrome/locale/en-US/ diff --git a/chrome/content/lessModule.js b/chrome/content/lessModule.js new file mode 100644 index 0000000..d348d02 --- /dev/null +++ b/chrome/content/lessModule.js @@ -0,0 +1,66 @@ +/* See license.txt for terms of usage */ + +define([ + "firebug/lib/object", + "firebug/lib/trace", + "firebug/css/stylePanel", +], +function(Obj, FBTrace, CSSStylePanel) { + +// ********************************************************************************************* // +// Custom Module Implementation + +Firebug.LessModule = Obj.extend(Firebug.Module, +{ + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // Initialization + + initialize: function(owner) + { + Firebug.Module.initialize.apply(this, arguments); + + // TODO: Module initialization (there is one module instance per browser window) + + if (FBTrace.DBG_FIRELESS) + FBTrace.sysout("fireless; LessModule.initialize"); + }, + + shutdown: function() + { + Firebug.Module.shutdown.apply(this, arguments); + + if (FBTrace.DBG_FIRELESS) + FBTrace.sysout("fireless; LessModule.shutdown"); + }, + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // CSSStylePanel Patch + + onCreatePanel: function(context, panel, panelType) + { + // Monkey patch the Style side panel. + if (panel instanceof CSSStylePanel) + { + this.styleGetSourceLink = panel.getSourceLink; + panel.getSourceLink = this.getSourceLink; + } + }, + + getSourceLink: function(target, rule) + { + if (FBTrace.DBG_FIRELESS) + FBTrace.sysout("fireless; LessModule.getSourceLink"); + + Firebug.LessModule.styleGetSourceLink.apply(this, arguments); + } +}); + +// ********************************************************************************************* // +// Registration + +Firebug.registerModule(Firebug.LessModule); + +return Firebug.LessModule; + +// ********************************************************************************************* // +}); diff --git a/chrome/content/main.js b/chrome/content/main.js new file mode 100644 index 0000000..c2bd375 --- /dev/null +++ b/chrome/content/main.js @@ -0,0 +1,44 @@ +/* See license.txt for terms of usage */ + +define([ + "firebug/lib/trace", + "fireless/lessModule", +], +function(FBTrace, LessModule) { + +// ********************************************************************************************* // +// The application/extension object + +var theExtension = +{ + initialize: function() + { + if (FBTrace.DBG_FIRELESS) + FBTrace.sysout("fireless; FireLess extension initialize"); + + // Registration of Firebug panels and modules is made within appropriate files, + // but it could be also done here. + + // TODO: Extension initialization + }, + + shutdown: function() + { + if (FBTrace.DBG_FIRELESS) + FBTrace.sysout("fireless; FireLess extension shutdown"); + + // Unregister all registered Firebug components + Firebug.unregisterModule(Firebug.LessModule); + Firebug.unregisterStylesheet("chrome://fireless/skin/fireless.css"); + Firebug.unregisterStringBundle("chrome://fireless/locale/fireless.properties"); + + // TODO: Extension shutdown + } +} + +// ********************************************************************************************* // + +return theExtension; + +// ********************************************************************************************* // +}); diff --git a/chrome/locale/en-US/fireless.properties b/chrome/locale/en-US/fireless.properties new file mode 100644 index 0000000..6317883 --- /dev/null +++ b/chrome/locale/en-US/fireless.properties @@ -0,0 +1,4 @@ +# All UI should be here +# Example: +# fireless.label.cssError=CSS Error + diff --git a/chrome/skin/classic/fireless.css b/chrome/skin/classic/fireless.css new file mode 100644 index 0000000..8650a32 --- /dev/null +++ b/chrome/skin/classic/fireless.css @@ -0,0 +1,11 @@ +/* See license.txt for terms of usage */ + +/*************************************************************************************************/ + +/* Firebug Tracing Console customization. All messages from this example use this color. + This helps to distinguish logs from those coming from Firebug + Rule syntax: .DBG_ + See: http://getfirebug.com/wiki/index.php/FBTrace for more details */ +.DBG_FIRELESS { + color: rgb(101, 0, 114); +} diff --git a/defaults/preferences/prefs.js b/defaults/preferences/prefs.js new file mode 100644 index 0000000..e376b92 --- /dev/null +++ b/defaults/preferences/prefs.js @@ -0,0 +1 @@ +pref("extensions.firebug.DBG_FIRELESS", true); diff --git a/install.rdf b/install.rdf new file mode 100644 index 0000000..f099938 --- /dev/null +++ b/install.rdf @@ -0,0 +1,26 @@ + + + + fireless@getfirebug.com + 0.5 + 2 + true + + + + + {ec8030f7-c20a-464f-9b0e-13a3a9e97384} + 10.0 + 20.* + + + + + FireLess + Support for LESS CSS in Firebug + Jan Odvarko + http://getfirebug.com + + diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..ba43b75 --- /dev/null +++ b/license.txt @@ -0,0 +1,30 @@ +Software License Agreement (BSD License) + +Copyright (c) 2007, Parakey Inc. +All rights reserved. + +Redistribution and use of this software in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of Parakey Inc. nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of Parakey Inc. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.