User:Dickvl/PrefBar
From MozillaZine Knowledge Base
Jump to navigationJump to search
PrefBar is one of the extensions that stopped working in the current Minefield nightly build after the changes in XPCOM registration have landed.
Bug 568691 – Use manifests and data tables to register XPCOM components.
There have been a few extensions that have been modified and looking as them as examples I've tried to see if I could PrefBar work again as well.
This is a modification for the file goprefbar.js in the components folder. I've tested with Firefox 3.0 , 3.5 , 3.6 and 4.0 versions, so it should work there as well.
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Preferences Toolbar 4. * * The Initial Developer of the Original Code is * Manuel Reimer <manuel.reimer@gmx.de>. * Portions created by the Initial Developer are Copyright (C) 2002-2009 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Manuel Reimer <manuel.reimer@gmx.de> * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ // modified to work with Minefield 4.0b2 by dickvl@kb.mozillazine.org Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); const Cc = Components.classes; const Ci = Components.interfaces; // Gecko 1.9.0/1.9.1 compatibility - add XPCOMUtils.defineLazyServiceGetter if (!("defineLazyServiceGetter" in XPCOMUtils)) { XPCOMUtils.defineLazyServiceGetter = function XPCU_defineLazyServiceGetter(obj, prop, contract, iface) { obj.__defineGetter__(prop, function XPCU_serviceGetter() { delete obj[prop]; return obj[prop] = Cc[contract].getService(Ci[iface]); }); }; } /*********************************************************** class definition ***********************************************************/ // Raw template for "goPrefBar" object. Here, it's only prepared with a // good "Include" function (one, which logs pretty debug messages to console). // All the other parts are included from content/prefbar.js var objgoprefbar = { Include: function(asURL, aoContext) { var oLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"] .getService(Ci.mozIJSSubScriptLoader); var consoleService = Cc["@mozilla.org/consoleservice;1"] .getService(Ci.nsIConsoleService); var scriptError = Cc["@mozilla.org/scripterror;1"] .createInstance(Ci.nsIScriptError); try {oLoader.loadSubScript(asURL, aoContext); return true; } catch(e) { scriptError.init(e.message, e.fileName, null, e.lineNumber, null, 2, null); consoleService.logMessage(scriptError); return false; } } }; //class constructor function GoPrefBar() {} GoPrefBar.prototype = { classDescription: "PrefBar Global Object Component", classID: Components.ID("{830a2ec4-be0d-4592-8397-ff794b476f28}"), contractID: "@prefbar.mozdev.org/goprefbar;1", _xpcom_categories: [{ category: "app-startup", service: true }], QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupports, Ci.nsISupportsWeakReference]), // nsIObserver observe: function(subject, topic, data) { let observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); switch (topic) { case "app-startup": observerService.addObserver(this, "profile-after-change", true); break; case "profile-after-change": this.startup(); } }, startup: function() { objgoprefbar.Include("chrome://prefbar/content/prefbar.js", objgoprefbar); objgoprefbar.Init(); this.wrappedJSObject = objgoprefbar; } }; /*********************************************************** module initialization ***********************************************************/ if (XPCOMUtils.generateNSGetFactory) var NSGetFactory = XPCOMUtils.generateNSGetFactory([GoPrefBar]); else var NSGetModule = XPCOMUtils.generateNSGetModule([GoPrefBar]);
Future Minefield version may require a modified chrome.manifest as well.
See https://wiki.mozilla.org/XPCOM/Bootstrap#Registration
overlay chrome://navigator/content/navigator.xul chrome://prefbar/content/prefbarOverlay.xul overlay chrome://browser/content/browser.xul chrome://prefbar/content/prefbarOverlay.xul overlay chrome://communicator/content/pref/preferences.xul chrome://prefbar/content/preferencesOverlay.xul style chrome://global/content/customizeToolbar.xul chrome://prefbar/content/prefbarOverlay.css content prefbar jar:chrome/prefbar.jar!/content/prefbar/ locale prefbar en-US jar:chrome/prefbar.jar!/locale/en-US/prefbar/ locale prefbar de-AT jar:chrome/prefbar.jar!/locale/de-AT/prefbar/ component 830a2ec4-be0d-4592-8397-ff794b476f28 components/goprefbar.js contract @prefbar.mozdev.org/goprefbar;1 830a2ec4-be0d-4592-8397-ff794b476f28 category profile-after-change @prefbar.mozdev.org/goprefbar;1 @prefbar.mozdev.org/goprefbar;1
See also: