Bug 1392929 - Port Bug 886907 - Remove old synchronous contentPrefService to SeaMonkey - comm part. r=frg

This commit is contained in:
Ian Neal 2022-09-14 22:13:15 +01:00
Родитель f29a3cea6e
Коммит f940ebc228
4 изменённых файлов: 98 добавлений и 135 удалений

Просмотреть файл

@ -12,9 +12,6 @@ const MOUSE_SCROLL_ZOOM = 3;
* Controls the "full zoom" setting and its site-specific preferences.
*/
var FullZoom = FullZoom || {
contentPrefs: Cc["@mozilla.org/content-pref/service;1"]
.getService(Ci.nsIContentPrefService2),
// Identifies the setting in the content prefs database.
name: "browser.content.full-zoom",
@ -51,10 +48,10 @@ var FullZoom = FullZoom || {
window.addEventListener("wheel", this, true);
// Fetch the initial global value.
this.contentPrefs.getGlobal(this.name, null, this);
Services.contentPrefs2.getGlobal(this.name, null, this);
// Register ourselves with the service so we know when our pref changes.
this.contentPrefs.addObserverForName(this.name, this);
Services.contentPrefs2.addObserverForName(this.name, this);
this._siteSpecificPref =
Services.prefs.getBoolPref("browser.zoom.siteSpecific");
@ -67,7 +64,7 @@ var FullZoom = FullZoom || {
destroy: function FullZoom_destroy() {
Services.prefs.removeObserver("browser.zoom.", this);
this.contentPrefs.removeObserverForName(this.name, this);
Services.contentPrefs2.removeObserverForName(this.name, this);
window.removeEventListener("wheel", this, true);
},
@ -140,7 +137,7 @@ var FullZoom = FullZoom || {
// nsIContentPrefObserver
onContentPrefSet: function FullZoom_onContentPrefSet(aGroup, aName, aValue) {
if (aGroup == this.contentPrefs.extractDomain(getBrowser().currentURI.spec))
if (aGroup == Services.contentPrefs2.extractDomain(getBrowser().currentURI.spec))
this._applyPrefToSetting(aValue);
else if (aGroup == null) {
this.globalValue = this._ensureValid(aValue);
@ -148,14 +145,14 @@ var FullZoom = FullZoom || {
// If the current page doesn't have a site-specific preference,
// then its zoom should be set to the new global preference now that
// the global preference has changed.
var zoomValue = this.contentPrefs.getCachedByDomainAndName(getBrowser().currentURI.spec, this.name, getBrowser().docShell);
var zoomValue = Services.contentPrefs2.getCachedByDomainAndName(getBrowser().currentURI.spec, this.name, getBrowser().docShell);
if (zoomValue && !zoomValue.value)
this._applyPrefToSetting();
}
},
onContentPrefRemoved: function FullZoom_onContentPrefRemoved(aGroup, aName) {
if (aGroup == this.contentPrefs.extractDomain(getBrowser().currentURI.spec))
if (aGroup == Services.contentPrefs2.extractDomain(getBrowser().currentURI.spec))
this._applyPrefToSetting();
else if (aGroup == null) {
this.globalValue = undefined;
@ -163,7 +160,7 @@ var FullZoom = FullZoom || {
// If the current page doesn't have a site-specific preference,
// then its zoom should be set to the default preference now that
// the global preference has changed.
var zoomValue = this.contentPrefs.getCachedByDomainAndName(getBrowser().currentURI.spec, this.name, getBrowser().docShell);
var zoomValue = Services.contentPrefs2.getCachedByDomainAndName(getBrowser().currentURI.spec, this.name, getBrowser().docShell);
if (zoomValue && !zoomValue.value)
this._applyPrefToSetting();
}
@ -207,11 +204,11 @@ var FullZoom = FullZoom || {
}
var loadContext = aBrowser.docShell;
var zoomValue = this.contentPrefs.getCachedByDomainAndName(aURI.spec, this.name, loadContext);
var zoomValue = Services.contentPrefs2.getCachedByDomainAndName(aURI.spec, this.name, loadContext);
if (zoomValue) {
this._applyPrefToSetting(zoomValue.value, aBrowser);
} else {
this.contentPrefs.getByDomainAndName(aURI.spec, this.name, loadContext, {
Services.contentPrefs2.getByDomainAndName(aURI.spec, this.name, loadContext, {
self: this,
value: undefined,
handleCompletion: function(aReason) {
@ -304,12 +301,12 @@ var FullZoom = FullZoom || {
return;
var zoomLevel = ZoomManager.zoom;
this.contentPrefs.set(getBrowser().currentURI.spec, this.name, zoomLevel, getBrowser().docShell);
Services.contentPrefs2.set(getBrowser().currentURI.spec, this.name, zoomLevel, getBrowser().docShell);
},
_removePref: function FullZoom_removePref() {
if (!content.document.mozSyntheticDocument)
this.contentPrefs.removeByDomainAndName(getBrowser().currentURI.spec, this.name, getBrowser().docShell);
Services.contentPrefs2.removeByDomainAndName(getBrowser().currentURI.spec, this.name, getBrowser().docShell);
},

Просмотреть файл

@ -56,7 +56,7 @@ var gDataman = {
Services.obs.addObserver(this, "cookie-changed");
Services.obs.addObserver(this, "perm-changed");
Services.obs.addObserver(this, "passwordmgr-storage-changed");
// Services.contentPrefs.addObserver(null, this);
Services.contentPrefs2.addObserverForName(null, this);
Services.obs.addObserver(this, "satchel-storage-changed");
Services.obs.addObserver(this, "dom-storage-changed");
Services.obs.addObserver(this, "dom-storage2-changed");
@ -78,7 +78,7 @@ var gDataman = {
Services.obs.removeObserver(this, "cookie-changed");
Services.obs.removeObserver(this, "perm-changed");
Services.obs.removeObserver(this, "passwordmgr-storage-changed");
// Services.contentPrefs.removeObserver(null, this);
Services.contentPrefs2.removeObserverForName(null, this);
Services.obs.removeObserver(this, "satchel-storage-changed");
Services.obs.removeObserver(this, "dom-storage-changed");
Services.obs.removeObserver(this, "dom-storage2-changed");
@ -257,11 +257,18 @@ var gDomains = {
this.searchfield = document.getElementById("domainSearch");
// global "domain"
this.domainObjects["*"] = {title: "*",
displayTitle: "*",
hasPermissions: true,
// hasPreferences: Services.contentPrefs.getPrefs(null, null).enumerator.hasMoreElements(),
hasFormData: true};
Services.contentPrefs2.hasPrefs(null, null, {
handleResult(resultPref) {
gDomains.domainObjects["*"] = {title: "*",
displayTitle: "*",
hasPermissions: true,
hasPreferences: resultPref.value,
hasFormData: true};
},
handleCompletion: () => {
},
});
this.search("");
if (!gDataman.viewToLoad.length)
this.tree.view.selection.select(0);
@ -301,23 +308,25 @@ var gDomains = {
gDomains.search(gDomains.searchfield.value);
yield setTimeout(nextStep, 0);
// Add domains for content prefs.
gDataman.debugMsg("Add content prefs to domain list: " + Date.now()/1000);
gDomains.ignoreUpdate = true;
try {
var statement = Services.contentPrefs.DBConnection.createStatement("SELECT groups.name AS host FROM groups");
while (statement.executeStep()) {
gDataman.debugMsg("Found pref: " + statement.row["host"]);
let prefHost = gDomains.getDomainFromHostWithCheck(statement.row["host"]);
gDomains.addDomainOrFlag(prefHost, "hasPreferences");
}
}
finally {
statement.reset();
}
gDomains.ignoreUpdate = false;
gDomains.search(gDomains.searchfield.value);
yield setTimeout(nextStep, 0);
let domains = [];
Services.contentPrefs2.getDomains(null, {
handleResult(resultPref) {
domains.push(resultPref.domain);
},
handleCompletion: () => {
// Add domains for content prefs.
gDataman.debugMsg("Add content prefs to domain list: " +
Date.now()/1000);
gDomains.ignoreUpdate = true;
for (let domain of domains) {
gDataman.debugMsg("Found pref: " + domain);
let prefHost = gDomains.getDomainFromHostWithCheck(domain);
gDomains.addDomainOrFlag(prefHost, "hasPreferences");
}
gDomains.ignoreUpdate = false;
gDomains.search(gDomains.searchfield.value);
},
});
// Add domains for passwords.
gDataman.debugMsg("Add passwords to domain list: " + Date.now()/1000);
@ -1720,42 +1729,37 @@ var gPrefs = {
this.removeButton = document.getElementById("prefsRemove");
this.tree.treeBoxObject.beginUpdateBatch();
// Get all groups (hosts) that match the domain.
let domain = gDomains.selectedDomain.title;
if (domain == "*") {
let enumerator = Services.contentPrefs.getPrefs(null, null).enumerator;
while (enumerator.hasMoreElements()) {
let pref = enumerator.getNext().QueryInterface(Ci.nsIProperty);
this.prefs.push({host: null, displayHost: "", name: pref.name,
value: pref.value});
}
domain = null;
}
try {
var statement = Services.contentPrefs.DBConnection.createStatement("SELECT groups.name AS host FROM groups");
while (statement.executeStep()) {
if (gDomains.hostMatchesSelected(gDomains.getDomainFromHostWithCheck(statement.row["host"]))) {
// Now, get all prefs for that host.
let enumerator = Services.contentPrefs.getPrefs(statement.row["host"], null).enumerator;
while (enumerator.hasMoreElements()) {
let pref = enumerator.getNext().QueryInterface(Ci.nsIProperty);
this.prefs.push({host: statement.row["host"],
displayHost: gLocSvc.idn.convertToDisplayIDN(statement.row["host"], {}),
name: pref.name,
value: pref.value});
let prefs = [];
Services.contentPrefs2.getBySubdomain(domain, null, {
handleResult(resultPref) {
prefs.push(resultPref);
},
handleCompletion: () => {
gPrefs.tree.treeBoxObject.beginUpdateBatch();
gPrefs.prefs = [];
for (let pref of prefs) {
if (!domain) {
gPrefs.prefs.push({host: null, displayHost: "", name: pref.name,
value: pref.value});
}
else {
let display = gLocSvc.idn.convertToDisplayIDN(pref.domain, {});
gPrefs.prefs.push({host: pref.domain, displayHost: display,
name: pref.name, value: pref.value});
}
}
}
}
finally {
statement.reset();
}
this.sort(null, false, false);
this.tree.treeBoxObject.endUpdateBatch();
gPrefs.sort(null, false, false);
gPrefs.tree.treeBoxObject.endUpdateBatch();
},
});
},
shutdown: function prefs_shutdown() {
@ -1868,7 +1872,7 @@ var gPrefs = {
let delPref = this.prefs[selections[i]];
this.prefs.splice(selections[i], 1);
this.tree.treeBoxObject.rowCountChanged(selections[i], -1);
Services.contentPrefs.removePref(delPref.host, delPref.name, null);
Services.contentPrefs2.removeByDomainAndName(delPref.host, delPref.name, null);
}
if (!this.prefs.length)
gDomains.removeDomainOrFlag(gDomains.selectedDomain.title, "hasPreferences");
@ -1911,34 +1915,18 @@ var gPrefs = {
}
else if (aData == "prefRemoved") {
// See if there are any prefs left for that domain.
if (domain == "*") {
let enumerator = Services.contentPrefs.getPrefs(null, null).enumerator;
if (enumerator.hasMoreElements())
domainPrefs++;
}
try {
let sql = "SELECT groups.name AS host FROM groups";
var statement = Services.contentPrefs.DBConnection.createStatement(sql);
while (statement.executeStep()) {
if (gDomains.hostMatchesSelected(gDomains.getDomainFromHostWithCheck(statement.row["host"]))) {
// Now, get all prefs for that host.
let enumerator = Services.contentPrefs.getPrefs(statement.row["host"], null).enumerator;
if (enumerator.hasMoreElements())
domainPrefs++;
Services.contentPrefs2.hasPrefs(domain != "*" ? domain : null, null, {
handleResult(prefResult) {
if (!prefResult.value) {
gDomains.removeDomainOrFlag(domain, "hasPreferences");
}
}
}
finally {
statement.reset();
}
if (!domainPrefs)
gDomains.removeDomainOrFlag(domain, "hasPreferences");
},
handleCompletion: () => {
},
});
}
if (aData == "prefSet")
aSubject.displayHost = gLocSvc.idn.convertToDisplayIDN(aSubject.host, {});
aSubject.displayHost = gLocSvc.idn.convertToDisplayIDN(aSubject.host, {});
// Affects loaded domain and is an existing pref.
if (idx >= 0) {
@ -1972,40 +1960,21 @@ var gPrefs = {
},
forget: function prefs_forget() {
let delPrefs = [];
try {
// Get all groups (hosts) that match the domain.
let domain = gDomains.selectedDomain.title;
if (domain == "*") {
let enumerator = Services.contentPrefs.getPrefs(null, null).enumerator;
while (enumerator.hasMoreElements()) {
let pref = enumerator.getNext().QueryInterface(Ci.nsIProperty);
delPrefs.push({host: null, name: pref.name, value: pref.value});
}
}
let callbacks = {
handleResult(resultDomain) {
},
handleCompletion: () => {
gDomains.removeDomainOrFlag(domain, "hasPreferences");
},
};
let sql = "SELECT groups.name AS host FROM groups";
var statement = Services.contentPrefs.DBConnection.createStatement(sql);
while (statement.executeStep()) {
if (gDomains.hostMatchesSelected(gDomains.getDomainFromHostWithCheck(statement.row["host"]))) {
// Now, get all prefs for that host.
let enumerator = Services.contentPrefs.getPrefs(statement.row["host"], null).enumerator;
while (enumerator.hasMoreElements()) {
let pref = enumerator.getNext().QueryInterface(Ci.nsIProperty);
delPrefs.push({host: statement.row["host"], name: pref.name, value: pref.value});
}
}
}
let domain = gDomains.selectedDomain.title;
if (domain == "*") {
Services.contentPrefs2.removeAllGlobals(null, callbacks);
}
finally {
statement.reset();
else {
Services.contentPrefs2.removeBySubdomain(domain, null, callbacks);
}
// Loop backwards so later indexes in the list don't change.
for (let i = delPrefs.length - 1; i >= 0; i--) {
Services.contentPrefs.removePref(delPrefs[i].host, delPrefs[i].name, null);
}
gDomains.removeDomainOrFlag(gDomains.selectedDomain.title, "hasPreferences");
},
// nsITreeView

Просмотреть файл

@ -517,8 +517,8 @@ function test_permissions_add(aWin) {
},
function test_prefs_panel(aWin) {
Services.contentPrefs.setPref("my.drumbeat.org", "data_manager.test", "foo", null);
Services.contentPrefs.setPref("drumbeat.org", "data_manager.test", "bar", null);
Services.contentPrefs2.setPref("my.drumbeat.org", "data_manager.test", "foo", null);
Services.contentPrefs2.setPref("drumbeat.org", "data_manager.test", "bar", null);
is(aWin.gDomains.tree.view.rowCount, kPreexistingDomains + 5,
"The domain for prefs tests has been added from the list");
aWin.gDomains.tree.view.selection.select(4);
@ -715,12 +715,12 @@ function test_idn(aWin) {
"Permission has correct display host");
// Add pref with decoded IDN name.
Services.contentPrefs.setPref(testDomain, "data_manager.test", "foo", null);
Services.contentPrefs2.setPref(testDomain, "data_manager.test", "foo", null);
aWin.gTabs.tabbox.selectedTab = aWin.document.getElementById("preferencesTab");
is(aWin.gTabs.activePanel, "preferencesPanel",
"Successfully switched to preferences panel for IDN tests");
// Add pref with encoded IDN name while panel is shown (different code path).
Services.contentPrefs.setPref(idnDomain, "data_manager.test2", "bar", null);
Services.contentPrefs2.setPref(idnDomain, "data_manager.test2", "bar", null);
is(aWin.gPrefs.tree.view.getCellText(0, aWin.gPrefs.tree.columns["prefsHostCol"]),
idnDomain,
"Correct domain displayed for punycode IDN preference");

Просмотреть файл

@ -41,17 +41,15 @@ function Startup()
defaultElement.min = Services.prefs.getIntPref("zoom.minPercent");
defaultElement.max = Services.prefs.getIntPref("zoom.maxPercent");
let cps2 = Cc["@mozilla.org/content-pref/service;1"]
.getService(Ci.nsIContentPrefService2);
var zoomValue = cps2.getCachedGlobal("browser.content.full-zoom", null);
var zoomValue = Services.contentPrefs2
.getCachedGlobal("browser.content.full-zoom", null);
if (zoomValue && zoomValue.value) {
defaultElement.value = Math.round(zoomValue.value * 100);
return;
}
defaultElement.value = 100;
cps2.getGlobal("browser.content.full-zoom", null, {
Services.contentPrefs2.getGlobal("browser.content.full-zoom", null, {
handleResult(pref) {
defaultElement.value = Math.round(pref.value * 100);
},
@ -120,16 +118,15 @@ function AdjustMinZoom()
function SetDefaultZoom()
{
let defaultElement = document.getElementById("defaultZoom");
let cps2 = Cc["@mozilla.org/content-pref/service;1"]
.getService(Ci.nsIContentPrefService2);
if (defaultElement.valueNumber == 100) {
cps2.removeGlobal("browser.content.full-zoom", null);
Services.contentPrefs2.removeGlobal("browser.content.full-zoom", null);
return;
}
let new_value = defaultElement.valueNumber / 100.;
cps2.setGlobal("browser.content.full-zoom", new_value, null);
Services.contentPrefs2.setGlobal("browser.content.full-zoom", new_value,
null);
}
/**