1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-14 14:15:47 +01:00

Undo certain parts from the unfortunate "service" commit, to unbreak Muttator. @Kris: Please try not to

commit unconnected things at once, as it's much harder to revert such commits :( I'll have to revert
the service -> Cc/Ci manually now, as I got lots of conflicts in reverting, and if i didn't, i wouldn't
want to undo the other parts of that commit (like VIMPERATOR_RUNTIME or the added comments)
This commit is contained in:
Martin Stubenschrott
2008-12-23 03:10:01 +01:00
parent 90d7eb0d17
commit feeccb23d2
10 changed files with 72 additions and 59 deletions

View File

@@ -1651,7 +1651,9 @@ function Completion() //{{{
context.anchored = false; context.anchored = false;
context.title = ["Firefox Preference", "Value"]; context.title = ["Firefox Preference", "Value"];
context.keys = { text: function (item) item, description: function (item) options.getPref(item) }; context.keys = { text: function (item) item, description: function (item) options.getPref(item) };
context.completions = service["pref"].getChildList("", { value: 0 }); context.completions = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch)
.getChildList("", { value: 0 });
}, },
search: function search(context, noSuggest) search: function search(context, noSuggest)

View File

@@ -1644,8 +1644,9 @@ function Events() //{{{
prefObserver: { prefObserver: {
register: function () register: function ()
{ {
this._branch = service["pref"].getBranch("") // better way to monitor all changes? const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
.QueryInterface(Ci.nsIPrefBranch2); this._branch = prefService.getBranch(""); // better way to monitor all changes?
this._branch.QueryInterface(Ci.nsIPrefBranch2);
this._branch.addObserver("", this, false); this._branch.addObserver("", this, false);
}, },

View File

@@ -67,6 +67,7 @@ function IO() //{{{
const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator" const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator"
const downloadManager = Cc["@mozilla.org/download-manager;1"].createInstance(Ci.nsIDownloadManager); const downloadManager = Cc["@mozilla.org/download-manager;1"].createInstance(Ci.nsIDownloadManager);
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var processDir = service["directory"].get("CurWorkD", Ci.nsIFile); var processDir = service["directory"].get("CurWorkD", Ci.nsIFile);
var cwd = processDir; var cwd = processDir;
@@ -777,7 +778,7 @@ lookup:
liberator.echomsg("sourcing " + filename.quote(), 2); liberator.echomsg("sourcing " + filename.quote(), 2);
let str = ioManager.readFile(file); let str = ioManager.readFile(file);
let uri = service["io"].newFileURI(file); let uri = ioService.newFileURI(file);
// handle pure javascript files specially // handle pure javascript files specially
if (/\.js$/.test(filename)) if (/\.js$/.test(filename))

View File

@@ -1053,7 +1053,8 @@ const liberator = (function () //{{{
if (typeof msg == "object") if (typeof msg == "object")
msg = util.objectToString(msg, false); msg = util.objectToString(msg, false);
service["console"].logStringMessage(config.name.toLowerCase() + ": " + msg); const consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
consoleService.logStringMessage(config.name.toLowerCase() + ": " + msg);
}, },
// open one or more URLs // open one or more URLs

View File

@@ -303,6 +303,8 @@ function Options() //{{{
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
const SAVED = "liberator.saved."; const SAVED = "liberator.saved.";
@@ -330,27 +332,27 @@ function Options() //{{{
prefContexts[prefContexts.length - 1][name] = val; prefContexts[prefContexts.length - 1][name] = val;
} }
let type = service["pref"].getPrefType(name); let type = prefService.getPrefType(name);
switch (typeof value) switch (typeof value)
{ {
case "string": case "string":
if (type == service["pref"].PREF_INVALID || type == service["pref"].PREF_STRING) if (type == prefService.PREF_INVALID || type == prefService.PREF_STRING)
service["pref"].setCharPref(name, value); prefService.setCharPref(name, value);
else if (type == service["pref"].PREF_INT) else if (type == prefService.PREF_INT)
liberator.echoerr("E521: Number required after =: " + name + "=" + value); liberator.echoerr("E521: Number required after =: " + name + "=" + value);
else else
liberator.echoerr("E474: Invalid argument: " + name + "=" + value); liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
break; break;
case "number": case "number":
if (type == service["pref"].PREF_INVALID || type == service["pref"].PREF_INT) if (type == prefService.PREF_INVALID || type == prefService.PREF_INT)
service["pref"].setIntPref(name, value); prefService.setIntPref(name, value);
else else
liberator.echoerr("E474: Invalid argument: " + name + "=" + value); liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
break; break;
case "boolean": case "boolean":
if (type == service["pref"].PREF_INVALID || type == service["pref"].PREF_BOOL) if (type == prefService.PREF_INVALID || type == prefService.PREF_BOOL)
service["pref"].setBoolPref(name, value); prefService.setBoolPref(name, value);
else if (type == service["pref"].PREF_INT) else if (type == prefService.PREF_INT)
liberator.echoerr("E521: Number required after =: " + name + "=" + value); liberator.echoerr("E521: Number required after =: " + name + "=" + value);
else else
liberator.echoerr("E474: Invalid argument: " + name + "=" + value); liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
@@ -366,22 +368,22 @@ function Options() //{{{
if (forcedDefault != null) // this argument sets defaults for non-user settable options (like extensions.history.comp_history) if (forcedDefault != null) // this argument sets defaults for non-user settable options (like extensions.history.comp_history)
defaultValue = forcedDefault; defaultValue = forcedDefault;
let branch = defaultBranch ? service["pref"].getDefaultBranch("") : service["pref"]; let branch = defaultBranch ? prefService.getDefaultBranch("") : prefService;
let type = service["pref"].getPrefType(name); let type = prefService.getPrefType(name);
try try
{ {
switch (type) switch (type)
{ {
case service["pref"].PREF_STRING: case prefService.PREF_STRING:
let value = branch.getComplexValue(name, Ci.nsISupportsString).data; let value = branch.getComplexValue(name, Ci.nsISupportsString).data;
// try in case it's a localized string (will throw an exception if not) // try in case it's a localized string (will throw an exception if not)
if (!service["pref"].prefIsLocked(name) && !service["pref"].prefHasUserValue(name) && if (!prefService.prefIsLocked(name) && !prefService.prefHasUserValue(name) &&
/^chrome:\/\/.+\/locale\/.+\.properties/.test(value)) /^chrome:\/\/.+\/locale\/.+\.properties/.test(value))
value = branch.getComplexValue(name, Ci.nsIPrefLocalizedString).data; value = branch.getComplexValue(name, Ci.nsIPrefLocalizedString).data;
return value; return value;
case service["pref"].PREF_INT: case prefService.PREF_INT:
return branch.getIntPref(name); return branch.getIntPref(name);
case service["pref"].PREF_BOOL: case prefService.PREF_BOOL:
return branch.getBoolPref(name); return branch.getBoolPref(name);
default: default:
return defaultValue; return defaultValue;
@@ -786,7 +788,7 @@ function Options() //{{{
{ {
completion.setFunctionCompleter(options.get, [function () ([o.name, o.description] for (o in options))]); completion.setFunctionCompleter(options.get, [function () ([o.name, o.description] for (o in options))]);
completion.setFunctionCompleter([options.getPref, options.safeSetPref, options.setPref, options.resetPref, options.invertPref], completion.setFunctionCompleter([options.getPref, options.safeSetPref, options.setPref, options.resetPref, options.invertPref],
[function () service["pref"].getChildList("", { value: 0 }) [function () prefService.getChildList("", { value: 0 })
.map(function (pref) [pref, ""])]); .map(function (pref) [pref, ""])]);
}); });
@@ -888,12 +890,12 @@ function Options() //{{{
if (!filter) if (!filter)
filter = ""; filter = "";
let prefArray = service["pref"].getChildList("", { value: 0 }); let prefArray = prefService.getChildList("", { value: 0 });
prefArray.sort(); prefArray.sort();
let prefs = function () { let prefs = function () {
for each (let pref in prefArray) for each (let pref in prefArray)
{ {
let userValue = service["pref"].prefHasUserValue(pref); let userValue = prefService.prefHasUserValue(pref);
if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1) if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1)
continue; continue;
@@ -988,7 +990,7 @@ function Options() //{{{
{ {
try try
{ {
return service["pref"].clearUserPref(name); return prefService.clearUserPref(name);
} }
catch (e) catch (e)
{ {
@@ -999,7 +1001,7 @@ function Options() //{{{
// this works only for booleans // this works only for booleans
invertPref: function (name) invertPref: function (name)
{ {
if (service["pref"].getPrefType(name) == service["pref"].PREF_BOOL) if (prefService.getPrefType(name) == prefService.PREF_BOOL)
this.setPref(name, !this.getPref(name)); this.setPref(name, !this.getPref(name));
else else
liberator.echoerr("E488: Trailing characters: " + name + "!"); liberator.echoerr("E488: Trailing characters: " + name + "!");

View File

@@ -1,35 +1,34 @@
/** @scope modules */ /** @scope modules */
let (cc = function (class, iface, meth) { try { return Cc[class][meth || "getService"](iface) } catch (e) {} }) let (cc = function (class, iface, meth) { try { return Components.classes[class][meth || "getService"](iface) } catch (e) {} })
{ {
// var Ci = Components.interfaces; // quick fix for muttator, will change/remove service.js anyway after the vacation
/** /**
* Cached XPCOM services and instances. * Cached XPCOM services and instances.
* *
* @singleton * @singleton
*/ */
const service = { const service = {
appStartup: cc("@mozilla.org/toolkit/app-startup;1", Ci.nsIAppStartup), appStartup: cc("@mozilla.org/toolkit/app-startup;1", Components.interfaces.nsIAppStartup),
autoCompleteSearch: cc("@mozilla.org/browser/global-history;2", Ci.nsIAutoCompleteSearch), autoCompleteSearch: cc("@mozilla.org/browser/global-history;2", Components.interfaces.nsIAutoCompleteSearch),
browserSearch: cc("@mozilla.org/browser/search-service;1", Ci.nsIBrowserSearchService), browserSearch: cc("@mozilla.org/browser/search-service;1", Components.interfaces.nsIBrowserSearchService),
cache: cc("@mozilla.org/network/cache-service;1", Ci.nsICacheService), cache: cc("@mozilla.org/network/cache-service;1", Components.interfaces.nsICacheService),
console: cc("@mozilla.org/consoleservice;1", Ci.nsIConsoleService), console: cc("@mozilla.org/consoleservice;1", Components.interfaces.nsIConsoleService),
directory: cc("@mozilla.org/file/directory_service;1", Ci.nsIProperties), directory: cc("@mozilla.org/file/directory_service;1", Components.interfaces.nsIProperties),
environment: cc("@mozilla.org/process/environment;1", Ci.nsIEnvironment), environment: cc("@mozilla.org/process/environment;1", Components.interfaces.nsIEnvironment),
extensionManager: cc("@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager), extensionManager: cc("@mozilla.org/extensions/manager;1", Components.interfaces.nsIExtensionManager),
io: cc("@mozilla.org/network/io-service;1", Ci.nsIIOService).QueryInterface(Ci.nsIIOService2), json: cc("@mozilla.org/dom/json;1", Components.interfaces.nsIJSON, "createInstance"),
json: cc("@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance"), observer: cc("@mozilla.org/observer-service;1", Components.interfaces.nsIObserverService),
observer: cc("@mozilla.org/observer-service;1", Ci.nsIObserverService), profile: cc("@mozilla.org/toolkit/profile-service;1", Components.interfaces.nsIToolkitProfileService),
profile: cc("@mozilla.org/toolkit/profile-service;1", Ci.nsIToolkitProfileService), sessionStore: cc("@mozilla.org/browser/sessionstore;1", Components.interfaces.nsISessionStore),
pref: cc("@mozilla.org/preferences-service;1", Ci.nsIPrefService) subscriptLoader: cc("@mozilla.org/moz/jssubscript-loader;1", Components.interfaces.mozIJSSubScriptLoader),
.QueryInterface(Ci.nsIPrefBranch).QueryInterface(Ci.nsIPrefBranch2), threadManager: cc("@mozilla.org/thread-manager;1", Components.interfaces.nsIThreadManager),
sessionStore: cc("@mozilla.org/browser/sessionstore;1", Ci.nsISessionStore), windowMediator: cc("@mozilla.org/appshell/window-mediator;1", Components.interfaces.nsIWindowMediator),
subscriptLoader: cc("@mozilla.org/moz/jssubscript-loader;1", Ci.mozIJSSubScriptLoader), windowWatcher: cc("@mozilla.org/embedcomp/window-watcher;1", Components.interfaces.nsIWindowWatcher),
threadManager: cc("@mozilla.org/thread-manager;1", Ci.nsIThreadManager), getFile: function () Cc["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile),
windowMediator: cc("@mozilla.org/appshell/window-mediator;1", Ci.nsIWindowMediator), getFind: function () Cc["@mozilla.org/embedcomp/rangefind;1"].createInstance(Components.interfaces.nsIFind),
windowWatcher: cc("@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher), getProcess: function () Cc["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess)
getFile: function () Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile),
getFind: function () Cc["@mozilla.org/embedcomp/rangefind;1"].createInstance(Ci.nsIFind),
getProcess: function () Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess)
}; };
}; };

View File

@@ -248,8 +248,8 @@ function Styles(name, store, serial)
const util = modules.util; const util = modules.util;
const sleep = liberator.sleep; const sleep = liberator.sleep;
const storage = modules.storage; const storage = modules.storage;
const consoleService = service["console"]; const consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
const ios = service["io"]; const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService); const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
const namespace = '@namespace html "' + XHTML + '";\n' + const namespace = '@namespace html "' + XHTML + '";\n' +
'@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' + '@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' +

View File

@@ -335,6 +335,12 @@ const util = { //{{{
return ary; return ary;
}, },
newURI: function (url)
{
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ioService.newURI(url, null, null);
},
// if color = true it uses HTML markup to color certain items // if color = true it uses HTML markup to color certain items
objectToString: function objectToString(object, color) objectToString: function objectToString(object, color)
{ {

View File

@@ -60,7 +60,6 @@ function Bookmarks() //{{{
const bookmarksService = PlacesUtils.bookmarks; const bookmarksService = PlacesUtils.bookmarks;
const taggingService = PlacesUtils.tagging; const taggingService = PlacesUtils.tagging;
const searchService = service.browserSearch; const searchService = service.browserSearch;
const ioService = service.io;
const faviconService = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService); const faviconService = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService);
const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id"); const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id");
@@ -91,7 +90,7 @@ function Bookmarks() //{{{
function loadBookmark(node) function loadBookmark(node)
{ {
let uri = ioService.newURI(node.uri, null, null); let uri = util.newURI(node.uri);
let keyword = bookmarksService.getKeywordForBookmark(node.itemId); let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
let tags = taggingService.getTagsForURI(uri, {}) || []; let tags = taggingService.getTagsForURI(uri, {}) || [];
@@ -199,7 +198,7 @@ function Bookmarks() //{{{
if (bookmark) if (bookmark)
{ {
if (property == "tags") if (property == "tags")
value = taggingService.getTagsForURI(ioService.newURI(bookmark.url, null, null), {}); value = taggingService.getTagsForURI(util.newURI(bookmark.url), {});
if (property in bookmark) if (property in bookmark)
bookmark[property] = value; bookmark[property] = value;
storage.fireEvent(name, "change", itemId); storage.fireEvent(name, "change", itemId);
@@ -220,7 +219,7 @@ function Bookmarks() //{{{
{ {
try try
{ {
return faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null)).spec; return faviconService.getFaviconImageForPage(util.newURI(uri)).spec;
} }
catch (e) catch (e)
{ {
@@ -487,7 +486,7 @@ function Bookmarks() //{{{
{ {
try try
{ {
var uri = ioService.newURI(url, null, null); var uri = util.newURI(url);
return (bookmarksService.getBookmarkedURIFor(uri) != null); return (bookmarksService.getBookmarkedURIFor(uri) != null);
} }
catch (e) catch (e)
@@ -505,7 +504,7 @@ function Bookmarks() //{{{
var i = 0; var i = 0;
try try
{ {
var uri = ioService.newURI(url, null, null); var uri = util.newURI(url);
var count = {}; var count = {};
var bmarks = bookmarksService.getBookmarkIdsForURI(uri, count); var bmarks = bookmarksService.getBookmarkIdsForURI(uri, count);

View File

@@ -427,13 +427,15 @@ const config = { //{{{
{ {
setter: function (value) setter: function (value)
{ {
service.io.offline = !value; const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService2);
gPrefService.setBoolPref("browser.offline", service.io.offline); ioService.offline = !value;
gPrefService.setBoolPref("browser.offline", ioService.offline);
return value; return value;
}, },
getter: function () getter: function ()
{ {
return service.io.offline; const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService2);
return ioService.offline;
} }
}); });