Skip to content
This repository has been archived by the owner on Oct 11, 2020. It is now read-only.

Commit

Permalink
Use services.jsm's getters
Browse files Browse the repository at this point in the history
  • Loading branch information
hultmann committed Feb 22, 2012
1 parent 716ca47 commit 42fdef8
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 53 deletions.
5 changes: 2 additions & 3 deletions src/components/protocol.js
Expand Up @@ -37,6 +37,7 @@
"use strict";

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");


function AboutMultifox() {}
Expand All @@ -51,9 +52,7 @@ AboutMultifox.prototype = {
return Components.interfaces.nsIAboutModule.ALLOW_SCRIPT;
},
newChannel: function(aURI) {
var channel = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newChannel("${PATH_CONTENT}/about-multifox.html", null, null);
var channel = Services.io.newChannel("${PATH_CONTENT}/about-multifox.html", null, null);
channel.originalURI = aURI;
return channel;
}
Expand Down
5 changes: 2 additions & 3 deletions src/content/about-multifox.js
Expand Up @@ -48,9 +48,8 @@ window.addEventListener("DOMContentLoaded", function() {

// load badges document into file:// iframe
function loadBadges() {
var uri = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService)
.newURI("${PATH_CONTENT}/about-badges.html", "UTF-8", null);
Components.utils.import("resource://gre/modules/Services.jsm");
var uri = Services.io.newURI("${PATH_CONTENT}/about-badges.html", "UTF-8", null);

var fileUrl = Cc["@mozilla.org/chrome/chrome-registry;1"]
.getService(Ci.nsIChromeRegistry)
Expand Down
4 changes: 1 addition & 3 deletions src/content/overlays.js
Expand Up @@ -45,9 +45,7 @@ var AboutOverlay = {

var Cc = Components.classes;
var Ci = Components.interfaces;
var browserWin = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator)
.getMostRecentWindow("navigator:browser");
var browserWin = Services.wm.getMostRecentWindow("navigator:browser");
if (browserWin) {
browserWin.openUILinkIn("about:multifox", "tab", false, null, null);
win.onunload = function() {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/main.cookies.js
Expand Up @@ -43,7 +43,7 @@ var Cookies = {

start: function() {
this._service = Cc["@mozilla.org/cookieService;1"].getService().QueryInterface(Ci.nsICookieService);
this._prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
this._prefs = Services.prefs;
this._prefListener.behavior = this._prefs.getIntPref(PREF_COOKIE_BEHAVIOR);
this._prefs.addObserver(PREF_COOKIE_BEHAVIOR, this._prefListener, false);
},
Expand Down
5 changes: 2 additions & 3 deletions src/modules/main.icon.js
Expand Up @@ -44,7 +44,7 @@ function setWelcomeMode(enable) {

m_welcomeMode = enable; // TODO check tabs with login attr

var winEnum = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator).getEnumerator("navigator:browser");
var winEnum = Services.wm.getEnumerator("navigator:browser");
while (winEnum.hasMoreElements()) {
var win = winEnum.getNext();
var tab = win.getBrowser().selectedTab;
Expand Down Expand Up @@ -403,7 +403,6 @@ function showMenuPopup(evt) {

function loadSubScript(path) {
var ns = {};
var sub = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
sub.loadSubScript(path, ns);
Services.scriptloader.loadSubScript(path, ns);
return ns;
}
4 changes: 2 additions & 2 deletions src/modules/main.js
Expand Up @@ -67,7 +67,7 @@ function MultifoxRunner() {
StringEncoding.init();
DocStartScriptInjection.start();
var obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
var obs = Services.obs;
obs.addObserver(SubmitObserver, "earlyformsubmit", false);
obs.addObserver(LoginDB.onCookieRejected, "cookie-rejected", false);
obs.addObserver(LoginDB.onCookieChanged, "cookie-changed", false);
Expand All @@ -87,7 +87,7 @@ MultifoxRunner.prototype = {
Cookies.stop();
LoginDB.shutdown();
var obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
var obs = Services.obs;
obs.removeObserver(SubmitObserver, "earlyformsubmit");
obs.removeObserver(LoginDB.onCookieRejected, "cookie-rejected");
obs.removeObserver(LoginDB.onCookieChanged, "cookie-changed");
Expand Down
6 changes: 2 additions & 4 deletions src/modules/main.script-injection.js
Expand Up @@ -41,13 +41,11 @@ var DocStartScriptInjection = {
this._loader = new ScriptSourceLoader();
this._sentByChrome = "multifox-chrome_event-" + Math.random().toString(36).substr(2);
this._sentByContent = "multifox-content_event-" + Math.random().toString(36).substr(2);
var obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
obs.addObserver(this, "document-element-inserted", false);
Services.obs.addObserver(this, "document-element-inserted", false);
},

stop: function() {
var obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
obs.removeObserver(this, "document-element-inserted");
Services.obs.removeObserver(this, "document-element-inserted");
delete this._loader;
},

Expand Down
14 changes: 6 additions & 8 deletions src/modules/main.utils-storage.js
Expand Up @@ -37,10 +37,9 @@

function copyCookieToNewHost(cookie, newHost) {
var expiryTime = cookie.isSession ? 4611686018427388 : cookie.expiry; // Math.pow(2, 62)=4611686018427388000
var mgr = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
mgr.add(newHost, cookie.path,
cookie.name, cookie.value,
cookie.isSecure, cookie.isHttpOnly, cookie.isSession, expiryTime);
Services.cookies.add(newHost, cookie.path,
cookie.name, cookie.value,
cookie.isSecure, cookie.isHttpOnly, cookie.isSession, expiryTime);
}


Expand Down Expand Up @@ -114,14 +113,13 @@ var CookieUtils = {

function getAllCookiesFromHost(h) {
var rv = [];
var mgr = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
var COOKIE = Ci.nsICookie2;

var _qty = 0;
var _t = new Date().getTime();

// TODO use mgr.getCookiesFromHost when it works properly
var all = mgr.enumerator;
// TODO use nsICookieManager2.getCookiesFromHost when it works properly
var all = Services.cookies.enumerator;
while (all.hasMoreElements()) {
var cookie = all.getNext().QueryInterface(COOKIE);
_qty++;
Expand All @@ -139,7 +137,7 @@ function removeCookies(all) {
var tlds = [];
var realHost;

var mgr = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
var mgr = Services.cookies;
var cookie;
for (var idx = all.length - 1; idx > -1; idx--) {
cookie = all[idx];
Expand Down
2 changes: 1 addition & 1 deletion src/modules/main.window.js
Expand Up @@ -162,7 +162,7 @@ var TabContainerEvents = {
// first run?
function onStart() {
var prefName = "extensions.${EXT_ID}.currentVersion";
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
var prefs = Services.prefs;
var ver = prefs.prefHasUserValue(prefName) ? prefs.getCharPref(prefName) : "";
if (ver === "${EXT_VERSION}") {
return;
Expand Down
31 changes: 10 additions & 21 deletions src/modules/new-window.js
Expand Up @@ -43,6 +43,7 @@ var Ci = Components.interfaces;
var Cu = Components.utils;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");

var m_docObserver = null;

Expand All @@ -59,12 +60,10 @@ function init() {


function DocObserver() {
var obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
obs.addObserver(this, "chrome-document-global-created", false);
Services.obs.addObserver(this, "chrome-document-global-created", false);

// workaround for top windows until chrome-document-global-created works again in Fx4
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher);
ww.registerNotification(this);
Services.ww.registerNotification(this);
}


Expand All @@ -81,8 +80,7 @@ DocObserver.prototype = {
if (win.document.location.href === "chrome://mozapps/content/extensions/about.xul") {
console.log("OK overlay via", topic, "/", win.document.location.href);
var ns = {};
var subscript = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
subscript.loadSubScript("${PATH_CONTENT}/overlays.js", ns);
Services.scriptloader.loadSubScript("${PATH_CONTENT}/overlays.js", ns);
ns.AboutOverlay.add(win);
}
return;
Expand All @@ -94,8 +92,7 @@ DocObserver.prototype = {
case "chrome://mozapps/content/extensions/about.xul":
console.log("OK overlay via", topic, "/", win.document.location.href);
var ns = {};
var subscript = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
subscript.loadSubScript("${PATH_CONTENT}/overlays.js", ns);
Services.scriptloader.loadSubScript("${PATH_CONTENT}/overlays.js", ns);
ns.AboutOverlay.add(win);
break;

Expand Down Expand Up @@ -165,9 +162,7 @@ var console = {
var len = arguments.length;
var msg = len > 1 ? Array.prototype.slice.call(arguments, 0, len).join(" ")
: arguments[0];
Cc["@mozilla.org/consoleservice;1"]
.getService(Ci.nsIConsoleService)
.logStringMessage(p + msg);
Services.console.logStringMessage(p + msg);
},

warn: function(msg) {
Expand All @@ -178,7 +173,7 @@ var console = {
0, 0, // line, col
Ci.nsIScriptError.warningFlag,
"component javascript");
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logMessage(message);
Services.console.logMessage(message);
this.trace(msg);
},

Expand Down Expand Up @@ -229,9 +224,7 @@ var util = {
},

_getTextCore: function(filename, name, args, startAt) {
var bundle = Cc["@mozilla.org/intl/stringbundle;1"]
.getService(Ci.nsIStringBundleService)
.createBundle("${PATH_LOCALE}/" + filename);
var bundle = Services.strings.createBundle("${PATH_LOCALE}/" + filename);

if (args.length === startAt) {
return bundle.GetStringFromName(name);
Expand All @@ -256,18 +249,14 @@ var util = {
}
this._observers = [onRequest, onResponse];

var obs = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);

var obs = Services.obs;
obs.addObserver(this._observers[0], "http-on-modify-request", false);
obs.addObserver(this._observers[1], "http-on-examine-response", false);
},

disable: function() {
console.log("networkListeners disable");
var obs = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);

var obs = Services.obs;
obs.removeObserver(this._observers[0], "http-on-modify-request");
obs.removeObserver(this._observers[1], "http-on-examine-response");
this._observers = null;
Expand Down
6 changes: 2 additions & 4 deletions src/modules/popup.js
Expand Up @@ -76,8 +76,7 @@ function appendContent(container, panel) {
}

var ns = {};
var subscript = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
subscript.loadSubScript("${PATH_MODULE}/error.js", ns);
Services.scriptloader.loadSubScript("${PATH_MODULE}/error.js", ns);
return ns.appendErrorToPanel(container, panel);
}

Expand Down Expand Up @@ -252,8 +251,7 @@ function loadTab(newTab, tab, encUser, encTld) {


function openNewTab(url, win) {
var io = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var uri = io.newURI(url, null, null);
var uri = Services.io.newURI(url, null, null);
var where = Ci.nsIBrowserDOMWindow.OPEN_NEWTAB;
var win2 = win.browserDOMWindow.openURI(uri, null, where, 0); // TODO open tab at the right
}

0 comments on commit 42fdef8

Please sign in to comment.