Bug 1476030 - Part 1 - Expose xulStore through Services;r=Gijs
This lets us use Services.xulStore instead of requiring
Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
MozReview-Commit-ID: 2eXifCPhlGs
--- a/browser/base/content/browser-sidebar.js
+++ b/browser/base/content/browser-sidebar.js
@@ -72,17 +72,17 @@ var SidebarUI = {
uninit() {
// If this is the last browser window, persist various values that should be
// remembered for after a restart / reopening a browser window.
let enumerator = Services.wm.getEnumerator("navigator:browser");
if (!enumerator.hasMoreElements()) {
document.persist("sidebar-box", "sidebarcommand");
- let xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
+ let xulStore = Services.xulStore;
if (this._box.hasAttribute("positionend")) {
document.persist("sidebar-box", "positionend");
} else {
xulStore.removeValue(document.documentURI, "sidebar-box", "positionend");
}
if (this._box.hasAttribute("checked")) {
document.persist("sidebar-box", "checked");
} else {
--- a/browser/components/distribution.js
+++ b/browser/components/distribution.js
@@ -419,17 +419,17 @@ DistributionCustomizer.prototype = {
return this._checkCustomizationComplete();
},
_checkCustomizationComplete: function DIST__checkCustomizationComplete() {
const BROWSER_DOCURL = "chrome://browser/content/browser.xul";
if (this._newProfile) {
- let xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
+ let xulStore = Services.xulStore;
try {
var showPersonalToolbar = Services.prefs.getBoolPref("browser.showPersonalToolbar");
if (showPersonalToolbar) {
xulStore.setValue(BROWSER_DOCURL, "PersonalToolbar", "collapsed", "false");
}
} catch (e) {}
try {
--- a/browser/components/migration/tests/marionette/test_refresh_firefox.py
+++ b/browser/components/migration/tests/marionette/test_refresh_firefox.py
@@ -220,18 +220,17 @@ class TestFirefoxRefresh(MarionetteTestC
ex => resolve(ex)
);
""", script_args=(self._bookmarkURL,))
self.assertEqual(titleInBookmarks, self._bookmarkText)
def checkBookmarkToolbarVisibility(self):
toolbarVisible = self.marionette.execute_script("""
const BROWSER_DOCURL = "chrome://browser/content/browser.xul";
- let xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
- return xulStore.getValue(BROWSER_DOCURL, "PersonalToolbar", "collapsed")
+ return Services.xulStore.getValue(BROWSER_DOCURL, "PersonalToolbar", "collapsed");
""")
self.assertEqual(toolbarVisible, "false")
def checkHistory(self):
historyResult = self.runAsyncCode("""
let resolve = arguments[arguments.length - 1];
PlacesUtils.history.fetch(arguments[0]).then(pageInfo => {
if (!pageInfo) {
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -7,17 +7,17 @@ const XULNS = "http://www.mozilla.org/ke
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
(function earlyBlankFirstPaint() {
if (!Services.prefs.getBoolPref("browser.startup.blankWindow", false))
return;
- let store = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
+ let store = Services.xulStore;
let getValue = attr =>
store.getValue("chrome://browser/content/browser.xul", "main-window", attr);
let width = getValue("width");
let height = getValue("height");
// The clean profile case isn't handled yet. Return early for now.
if (!width || !height)
return;
@@ -1786,17 +1786,17 @@ BrowserGlue.prototype = {
* persisted, and user customized it or changed default bookmarks.
*
* If the user does not have a persisted value for the toolbar's
* "collapsed" attribute, try to determine whether it's customized.
*/
_maybeToggleBookmarkToolbarVisibility() {
const BROWSER_DOCURL = "chrome://browser/content/browser.xul";
const NUM_TOOLBAR_BOOKMARKS_TO_UNHIDE = 3;
- let xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
+ let xulStore = Services.xulStore;
if (!xulStore.hasValue(BROWSER_DOCURL, "PersonalToolbar", "collapsed")) {
// We consider the toolbar customized if it has more than NUM_TOOLBAR_BOOKMARKS_TO_UNHIDE
// children, or if it has a persisted currentset value.
let toolbarIsCustomized = xulStore.hasValue(BROWSER_DOCURL, "PersonalToolbar", "currentset");
let getToolbarFolderCount = () => {
let toolbarFolder = PlacesUtils.getFolderContents(PlacesUtils.bookmarks.toolbarGuid).root;
let toolbarChildCount = toolbarFolder.childCount;
@@ -1833,17 +1833,17 @@ BrowserGlue.prototype = {
Cu.reportError(ex);
}
return;
}
if (currentUIVersion >= UI_VERSION)
return;
- let xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
+ let xulStore = Services.xulStore;
if (currentUIVersion < 36) {
xulStore.removeValue("chrome://passwordmgr/content/passwordManager.xul",
"passwordCol",
"hidden");
}
if (currentUIVersion < 37) {
--- a/browser/components/places/content/treeView.js
+++ b/browser/components/places/content/treeView.js
@@ -43,24 +43,16 @@ function PlacesTreeView(aFlatList, aOnOp
this._controller = aController;
}
PlacesTreeView.prototype = {
get wrappedJSObject() {
return this;
},
- __xulStore: null,
- get _xulStore() {
- if (!this.__xulStore) {
- this.__xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
- }
- return this.__xulStore;
- },
-
QueryInterface: ChromeUtils.generateQI([
Ci.nsITreeView,
Ci.nsINavHistoryResultObserver,
Ci.nsISupportsWeakReference
]),
/**
* This is called once both the result and the tree are set.
@@ -352,17 +344,17 @@ PlacesTreeView.prototype = {
// Recursively do containers.
if (!this._flatList &&
curChild instanceof Ci.nsINavHistoryContainerResultNode &&
!this._controller.hasCachedLivemarkInfo(curChild)) {
let uri = curChild.uri;
let isopen = false;
if (uri) {
- let val = this._xulStore.getValue(document.documentURI, uri, "open");
+ let val = Services.xulStore.getValue(document.documentURI, uri, "open");
isopen = (val == "true");
}
if (isopen != curChild.containerOpen)
aToOpen.push(curChild);
else if (curChild.containerOpen && curChild.childCount > 0)
rowsInserted += this._buildVisibleSection(curChild, row + 1, aToOpen);
}
@@ -1601,19 +1593,19 @@ PlacesTreeView.prototype = {
// Persist containers open status, but never persist livemarks.
if (!this._controller.hasCachedLivemarkInfo(node)) {
let uri = node.uri;
if (uri) {
let docURI = document.documentURI;
if (node.containerOpen) {
- this._xulStore.removeValue(docURI, uri, "open");
+ Services.xulStore.removeValue(docURI, uri, "open");
} else {
- this._xulStore.setValue(docURI, uri, "open", "true");
+ Services.xulStore.setValue(docURI, uri, "open", "true");
}
}
}
node.containerOpen = !node.containerOpen;
},
cycleHeader: function PTV_cycleHeader(aColumn) {
--- a/browser/components/tests/browser/browser_default_bookmark_toolbar_visibility.js
+++ b/browser/components/tests/browser/browser_default_bookmark_toolbar_visibility.js
@@ -4,15 +4,15 @@
/**
* Test _maybeToggleBookmarkToolbarVisibility() code running for new profiles.
* Ensure that the bookmarks toolbar is hidden in a default configuration.
* If new default bookmarks are added to the toolbar then the threshold of > 3
* in NUM_TOOLBAR_BOOKMARKS_TO_UNHIDE may need to be adjusted there.
*/
add_task(async function test_default_bookmark_toolbar_visibility() {
const BROWSER_DOCURL = "chrome://browser/content/browser.xul";
- let xulStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
+ let xulStore = Services.xulStore;
is(xulStore.getValue(BROWSER_DOCURL, "PersonalToolbar", "collapsed"), "",
"Check that @collapsed isn't persisted");
ok(document.getElementById("PersonalToolbar").collapsed,
"The bookmarks toolbar should be collapsed by default");
});
--- a/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js
+++ b/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js
@@ -1,14 +1,15 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/◦
*/
"use strict";
+ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/osfile.jsm");
var XULStore = null;
var browserURI = "chrome://browser/content/browser.xul";
var aboutURI = "about:config";
function run_test() {
do_get_profile();
@@ -54,17 +55,17 @@ function getAttributes(uri, id) {
function checkArrays(a, b) {
a.sort();
b.sort();
Assert.equal(a.toString(), b.toString());
}
add_task(async function setup() {
// Set a value that a future test depends on manually
- XULStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
+ XULStore = Services.xulStore;
XULStore.setValue(browserURI, "main-window", "width", "994");
});
add_task(async function testTruncation() {
let dos = Array(8192).join("~");
// Long id names should trigger an exception
Assert.throws(() => XULStore.setValue(browserURI, dos, "foo", "foo"), /NS_ERROR_ILLEGAL_VALUE/);
--- a/toolkit/modules/Services.jsm
+++ b/toolkit/modules/Services.jsm
@@ -92,16 +92,17 @@ var initTable = {
clipboard: ["@mozilla.org/widget/clipboard;1", "nsIClipboard"],
DOMRequest: ["@mozilla.org/dom/dom-request-service;1", "nsIDOMRequestService"],
focus: ["@mozilla.org/focus-manager;1", "nsIFocusManager"],
uriFixup: ["@mozilla.org/docshell/urifixup;1", "nsIURIFixup"],
blocklist: ["@mozilla.org/extensions/blocklist;1"],
netUtils: ["@mozilla.org/network/util;1", "nsINetUtil"],
loadContextInfo: ["@mozilla.org/load-context-info-factory;1", "nsILoadContextInfoFactory"],
qms: ["@mozilla.org/dom/quota-manager-service;1", "nsIQuotaManagerService"],
+ xulStore: ["@mozilla.org/xul/xulstore;1", "nsIXULStore"],
};
if (AppConstants.platform == "android") {
initTable.androidBridge = ["@mozilla.org/android/bridge;1", "nsIAndroidBridge"];
}
if (AppConstants.MOZ_GECKO_PROFILER) {
initTable.profiler = ["@mozilla.org/tools/profiler;1", "nsIProfiler"];
}