Bug 1412893 - Change instances of using getService to Services.jsm where possible in toolkit/components/places r?mak
MozReview-Commit-ID: 4jLEf08OQUw
--- a/toolkit/components/places/ColorAnalyzer.js
+++ b/toolkit/components/places/ColorAnalyzer.js
@@ -4,27 +4,26 @@
"use strict";
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const MAXIMUM_PIXELS = Math.pow(144, 2);
function ColorAnalyzer() {
// a queue of callbacks for each job we give to the worker
this.callbacks = [];
- this.hiddenWindowDoc = Cc["@mozilla.org/appshell/appShellService;1"].
- getService(Ci.nsIAppShellService).
- hiddenDOMWindow.document;
+ this.hiddenWindowDoc = Services.appShell.hiddenDOMWindow.document;
this.worker = new ChromeWorker("resource://gre/modules/ColorAnalyzer_worker.js");
this.worker.onmessage = this.onWorkerMessage.bind(this);
this.worker.onerror = this.onWorkerError.bind(this);
}
ColorAnalyzer.prototype = {
findRepresentativeColor: function ColorAnalyzer_frc(imageURI, callback) {
--- a/toolkit/components/places/PlacesUtils.jsm
+++ b/toolkit/components/places/PlacesUtils.jsm
@@ -2019,19 +2019,17 @@ XPCOMUtils.defineLazyGetter(PlacesUtils,
tm.doTransaction(aTransaction);
}
}
});
});
XPCOMUtils.defineLazyGetter(this, "bundle", function() {
const PLACES_STRING_BUNDLE_URI = "chrome://places/locale/places.properties";
- return Cc["@mozilla.org/intl/stringbundle;1"].
- getService(Ci.nsIStringBundleService).
- createBundle(PLACES_STRING_BUNDLE_URI);
+ return Services.strings.createBundle(PLACES_STRING_BUNDLE_URI);
});
// This is just used as a reasonably-random value for copy & paste / drag operations.
XPCOMUtils.defineLazyGetter(PlacesUtils, "instanceId", () => {
return PlacesUtils.history.makeGuid();
});
/**
--- a/toolkit/components/places/nsPlacesExpiration.js
+++ b/toolkit/components/places/nsPlacesExpiration.js
@@ -415,19 +415,17 @@ function nsPlacesExpiration() {
return db;
});
XPCOMUtils.defineLazyServiceGetter(this, "_idle",
"@mozilla.org/widget/idleservice;1",
"nsIIdleService");
- this._prefBranch = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefService).
- getBranch(PREF_BRANCH);
+ this._prefBranch = Services.prefs.getBranch(PREF_BRANCH);
this._loadPrefsPromise = this._loadPrefs().then(() => {
// Observe our preferences branch for changes.
this._prefBranch.addObserver("", this, true);
// Create our expiration timer.
this._newTimer();
}, Cu.reportError);
--- a/toolkit/components/places/tests/browser/browser_bug680727.js
+++ b/toolkit/components/places/tests/browser/browser_bug680727.js
@@ -17,19 +17,17 @@ function test() {
waitForExplicitFinish();
// Tests always connect to localhost, and per bug 87717, localhost is now
// reachable in offline mode. To avoid this, disable any proxy.
proxyPrefValue = Services.prefs.getIntPref("network.proxy.type");
Services.prefs.setIntPref("network.proxy.type", 0);
// Clear network cache.
- Components.classes["@mozilla.org/netwerk/cache-storage-service;1"]
- .getService(Components.interfaces.nsICacheStorageService)
- .clear();
+ Services.cache2.clear();
// Go offline, expecting the error page.
Services.io.offline = true;
BrowserTestUtils.openNewForegroundTab(gBrowser).then(tab => {
ourTab = tab;
BrowserTestUtils.waitForContentEvent(ourTab.linkedBrowser, "DOMContentLoaded")
.then(errorListener);
--- a/toolkit/components/places/tests/browser/browser_colorAnalyzer.js
+++ b/toolkit/components/places/tests/browser/browser_colorAnalyzer.js
@@ -4,19 +4,17 @@
"use strict";
Cu.import("resource://gre/modules/Services.jsm");
const CA = Cc["@mozilla.org/places/colorAnalyzer;1"].
getService(Ci.mozIColorAnalyzer);
-const hiddenWindowDoc = Cc["@mozilla.org/appshell/appShellService;1"].
- getService(Ci.nsIAppShellService).
- hiddenDOMWindow.document;
+const hiddenWindowDoc = Services.appShell.hiddenDOMWindow.document;
const XHTML_NS = "http://www.w3.org/1999/xhtml";
/**
* Passes the given uri to findRepresentativeColor.
* If expected is null, you expect it to fail.
* If expected is a function, it will call that function.
* If expected is a color, you expect that color to be returned.
--- a/toolkit/components/places/tests/expiration/test_notifications.js
+++ b/toolkit/components/places/tests/expiration/test_notifications.js
@@ -5,34 +5,31 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* What this is aimed to test:
*
* Ensure that History (through category cache) notifies us just once.
*/
-var os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
-
var gObserver = {
notifications: 0,
observe(aSubject, aTopic, aData) {
this.notifications++;
}
};
-os.addObserver(gObserver, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
+Services.obs.addObserver(gObserver, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
function run_test() {
// Set interval to a large value so we don't expire on it.
setInterval(3600); // 1h
promiseForceExpirationStep(1);
do_timeout(2000, check_result);
do_test_pending();
}
function check_result() {
- os.removeObserver(gObserver, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
+ Services.obs.removeObserver(gObserver, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
do_check_eq(gObserver.notifications, 1);
do_test_finished();
}
--- a/toolkit/components/places/tests/unifiedcomplete/test_history_autocomplete_tags.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_history_autocomplete_tags.js
@@ -152,20 +152,18 @@ async function tagURI(url, tags) {
tagssvc.tagURI(uri(url), tags);
}
/**
* Test history autocomplete
*/
add_task(async function test_history_autocomplete_tags() {
// always search in history + bookmarks, no matter what the default is
- var prefs = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
- prefs.setIntPref("browser.urlbar.search.sources", 3);
- prefs.setIntPref("browser.urlbar.default.behavior", 0);
+ Services.prefs.setIntPref("browser.urlbar.search.sources", 3);
+ Services.prefs.setIntPref("browser.urlbar.default.behavior", 0);
await tagURI(uri1, ["foo"]);
await tagURI(uri2, ["bar"]);
await tagURI(uri3, ["cheese"]);
await tagURI(uri4, ["foo bar"]);
await tagURI(uri5, ["bar cheese"]);
await tagURI(uri6, ["foo bar cheese"]);
--- a/toolkit/components/places/tests/unit/test_adaptive_bug527311.js
+++ b/toolkit/components/places/tests/unit/test_adaptive_bug527311.js
@@ -5,27 +5,22 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const TEST_URL = "http://adapt.mozilla.org/";
const SEARCH_STRING = "adapt";
const SUGGEST_TYPES = ["history", "bookmark", "openpage"];
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-var os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
-var ps = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
-
const PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC =
"places-autocomplete-feedback-updated";
function cleanup() {
for (let type of SUGGEST_TYPES) {
- ps.clearUserPref("browser.urlbar.suggest." + type);
+ Services.prefs.clearUserPref("browser.urlbar.suggest." + type);
}
}
function AutoCompleteInput(aSearches) {
this.searches = aSearches;
}
AutoCompleteInput.prototype = {
constructor: AutoCompleteInput,
@@ -96,51 +91,51 @@ function check_results() {
});
}
function addAdaptiveFeedback(aUrl, aSearch) {
return new Promise(resolve => {
let observer = {
observe(aSubject, aTopic, aData) {
- os.removeObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC);
+ Services.obs.removeObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC);
do_timeout(0, resolve);
}
};
- os.addObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC);
+ Services.obs.addObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC);
let thing = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput,
Ci.nsIAutoCompletePopup,
Ci.nsIAutoCompleteController]),
get popup() { return thing; },
get controller() { return thing; },
popupOpen: true,
selectedIndex: 0,
getValueAt: () => aUrl,
searchString: aSearch
};
- os.notifyObservers(thing, "autocomplete-will-enter-text");
+ Services.obs.notifyObservers(thing, "autocomplete-will-enter-text");
});
}
add_task(async function test_adaptive_search_specific() {
// Add a bookmark to our url.
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
title: "test_book",
url: TEST_URL,
});
// We want to search only history.
for (let type of SUGGEST_TYPES) {
- type == "history" ? ps.setBoolPref("browser.urlbar.suggest." + type, true)
- : ps.setBoolPref("browser.urlbar.suggest." + type, false);
+ type == "history" ? Services.prefs.setBoolPref("browser.urlbar.suggest." + type, true)
+ : Services.prefs.setBoolPref("browser.urlbar.suggest." + type, false);
}
// Add an adaptive entry.
await addAdaptiveFeedback(TEST_URL, SEARCH_STRING);
await check_results();
await PlacesTestUtils.promiseAsyncUpdates();
--- a/toolkit/components/places/tests/unit/test_crash_476292.js
+++ b/toolkit/components/places/tests/unit/test_crash_476292.js
@@ -11,17 +11,15 @@
*/
function run_test() {
// First, we need to move our old database file into our test profile
// directory. This will trigger DATABASE_STATUS_UPGRADED (CREATE is not
// sufficient since there will be no entries to update frecencies for, which
// causes us to get the bookmarks service in the first place).
let dbFile = do_get_file("bug476292.sqlite");
- let profD = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).
- get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
+ let profD = Services.dirsvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
dbFile.copyTo(profD, "places.sqlite");
// Now get the bookmarks service. This will crash when the bug exists.
Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
}
--- a/toolkit/components/places/tests/unit/test_frecency.js
+++ b/toolkit/components/places/tests/unit/test_frecency.js
@@ -263,24 +263,21 @@ async function() {
}
];
add_task(async function test_frecency() {
// Disable autoFill for this test.
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
do_register_cleanup(() => Services.prefs.clearUserPref("browser.urlbar.autoFill"));
// always search in history + bookmarks, no matter what the default is
- var prefs = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
-
- prefs.setBoolPref("browser.urlbar.suggest.history", true);
- prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
- prefs.setBoolPref("browser.urlbar.suggest.openpage", false);
+ Services.prefs.setBoolPref("browser.urlbar.suggest.history", true);
+ Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", true);
+ Services.prefs.setBoolPref("browser.urlbar.suggest.openpage", false);
for (let test of tests) {
await PlacesUtils.bookmarks.eraseEverything();
await PlacesTestUtils.clearHistory();
await test();
}
for (let type of ["history", "bookmark", "openpage"]) {
- prefs.clearUserPref("browser.urlbar.suggest." + type);
+ Services.prefs.clearUserPref("browser.urlbar.suggest." + type);
}
});