User:Dickvl/PrefBar: Difference between revisions
From MozillaZine Knowledge Base
Jump to navigationJump to search
(PrefBar broken in Minefield - modified goprefbar.js included) |
(No difference)
|
Revision as of 00:33, 4 July 2010
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@mozillazine.org Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); // 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] = Components.classes[contract].getService(Components.interfaces[iface]); }); }; } const Cc = Components.classes; const Ci = Components.interfaces; /*********************************************************** 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 = Components.classes["@mozilla.org/moz/jssubscript-loader;1"] .getService(Components.interfaces.mozIJSSubScriptLoader); var consoleService = Components.classes["@mozilla.org/consoleservice;1"] .getService(Components.interfaces.nsIConsoleService); var scriptError = Components.classes["@mozilla.org/scripterror;1"] .createInstance(Components.interfaces.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 and definition 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([Components.interfaces.nsIObserver, Components.interfaces.nsISupports, Components.interfaces.nsISupportsWeakReference]), _config: null, // 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. If that is necessary then I will see if I can come up a modified chrome.manifest as well.