# HG changeset patch # User Ian Neal # Date 1663189995 -3600 # Node ID 0ca324fbb10640c93c41c6284ef81f855cb87bc1 # Parent f3fbbe8880b8b723aaf33264f9e18d0cb682a0fd Bug 1392929 - Port Bug 886907 - Remove old synchronous contentPrefService to SeaMonkey - comm part. r=frg a=frg diff --git a/suite/base/content/viewZoomOverlay.js b/suite/base/content/viewZoomOverlay.js --- a/suite/base/content/viewZoomOverlay.js +++ b/suite/base/content/viewZoomOverlay.js @@ -7,18 +7,16 @@ // One of the possible values for the mousewheel.* preferences. // From nsEventStateManager.cpp. const MOUSE_SCROLL_ZOOM = 3; /** * Controls the "full zoom" setting and its site-specific preferences. */ var FullZoom = FullZoom || { - contentPrefs: Services.contentPrefs.QueryInterface(Ci.nsIContentPrefService2), - // Identifies the setting in the content prefs database. name: "browser.content.full-zoom", // The global value (if any) for the setting. Asynchronously loaded from the // service when first requested, then updated by the pref change listener as // it changes. If there is no global value, then this should be undefined. globalValue: undefined, @@ -45,33 +43,33 @@ var FullZoom = FullZoom || { //**************************************************************************// // Initialization & Destruction init: function FullZoom_init() { // Listen for scrollwheel events so we can save scrollwheel-based changes. 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"); this.updateBackgroundTabs = Services.prefs.getBoolPref("browser.zoom.updateBackgroundTabs"); // Listen for changes to the browser.zoom branch so we can enable/disable // updating background tabs and per-site saving and restoring of zoom levels. Services.prefs.addObserver("browser.zoom.", this, true); }, 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); }, //**************************************************************************// // Event Handlers // nsIDOMEventListener @@ -134,40 +132,40 @@ var FullZoom = FullZoom || { } break; } }, // 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); // 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; // 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(); } }, // nsIContentPrefCallback2 handleCompletion: function(aReason) {}, @@ -201,21 +199,21 @@ var FullZoom = FullZoom || { // Image documents should always start at 1, and are not affected by prefs. if (!aIsTabSwitch && aBrowser.contentDocument.mozSyntheticDocument) { ZoomManager.setZoomForBrowser(aBrowser, this._ensureValid(1)); return; } 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) { // Check that we're still where we expect to be in case this took a // while. Null check currentURI, since the window may have been // destroyed before we were called. if (aBrowser.currentURI && aURI.equals(aBrowser.currentURI)) this.self._applyPrefToSetting(this.value, aBrowser); @@ -298,22 +296,22 @@ var FullZoom = FullZoom || { }, _applySettingToPref: function FullZoom_applySettingToPref() { if (!this.siteSpecific || window.gInPrintPreviewMode || content.document.mozSyntheticDocument) 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); }, //**************************************************************************// // Utilities _ensureValid: function FullZoom_ensureValid(aValue) { if (isNaN(aValue)) diff --git a/suite/components/dataman/content/dataman.js b/suite/components/dataman/content/dataman.js --- a/suite/components/dataman/content/dataman.js +++ b/suite/components/dataman/content/dataman.js @@ -51,17 +51,17 @@ var gDataman = { this.debug = Services.prefs.getBoolPref("data_manager.debug"); } catch (e) {} this.bundle = document.getElementById("datamanBundle"); 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"); this.timer = Cc["@mozilla.org/timer;1"] .createInstance(Ci.nsITimer); gTabs.initialize(); @@ -73,17 +73,17 @@ var gDataman = { this.loadView(window.arguments[0]) } }, shutdown: function dataman_shutdown() { 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"); gDomains.shutdown(); }, loadView: function dataman_loadView(aView) { @@ -252,21 +252,28 @@ var gDomains = { this.tree = document.getElementById("domainTree"); this.tree.view = this; this.selectfield = document.getElementById("typeSelect"); 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); let loaderInstance; function nextStep() { loaderInstance.next(); @@ -296,33 +303,35 @@ var gDomains = { else { gDomains.addDomainOrFlag(nextPermission.principal.URI.host.replace(/^\./, ""), "hasPermissions"); } } gDomains.ignoreUpdate = false; 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); gDomains.ignoreUpdate = true; gPasswords.loadList(); for (let pSignon of gPasswords.allSignons) { gDomains.addDomainOrFlag(pSignon.hostname, "hasPasswords"); } @@ -1715,52 +1724,47 @@ var gPrefs = { initialize: function prefs_initialize() { gDataman.debugMsg("Initializing prefs panel"); this.tree = document.getElementById("prefsTree"); this.tree.view = this; 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() { gDataman.debugMsg("Shutting down prefs panel"); this.tree.view.selection.clearSelection(); this.tree.view = null; this.prefs = []; }, @@ -1863,17 +1867,17 @@ var gPrefs = { } this.tree.view.selection.clearSelection(); // Loop backwards so later indexes in the list don't change. for (let i = selections.length - 1; i >= 0; i--) { 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"); // Select the entry after the first deleted one or the last of all entries. if (selections.length && this.prefs.length) this.tree.view.selection.toggleSelect(selections[0] < this.prefs.length ? selections[0] : this.prefs.length - 1); @@ -1906,44 +1910,28 @@ var gPrefs = { break; } } if (aData == "prefRemoved") domainPrefs = this.prefs.length; } 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) { if (aData == "prefSet") { this.prefs[idx] = aSubject; if (affectsLoaded) this.tree.treeBoxObject.invalidateRow(idx); } @@ -1967,50 +1955,31 @@ var gPrefs = { // Not the loaded domain but it now has a preference. else { gDomains.addDomainOrFlag(domain, "hasPreferences"); } } }, 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 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 callbacks = { + handleResult(resultDomain) { + }, + handleCompletion: () => { + gDomains.removeDomainOrFlag(domain, "hasPreferences"); + }, + }; + + 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 __proto__: gBaseTreeView, get rowCount() { return this.prefs.length; }, getCellText: function(aRow, aColumn) { diff --git a/suite/components/dataman/tests/browser_dataman_basics.js b/suite/components/dataman/tests/browser_dataman_basics.js --- a/suite/components/dataman/tests/browser_dataman_basics.js +++ b/suite/components/dataman/tests/browser_dataman_basics.js @@ -512,18 +512,18 @@ function test_permissions_add(aWin) { is(aWin.gPerms.addHost.value, "getpersonas.com", "On add, the host is set correctly"); is(aWin.gPerms.addType.value, "", "Again, no type is selected"); Services.obs.notifyObservers(window, TEST_DONE); }, 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); is(aWin.gDomains.selectedDomain.title, "drumbeat.org", "For prefs tests, correct domain is selected"); is(aWin.gTabs.activePanel, "preferencesPanel", "Preferences panel is selected"); is(aWin.gPrefs.tree.view.rowCount, 2, @@ -710,22 +710,22 @@ function test_idn(aWin) { "After deleting, correctly switched to permissions panel"); let perm = aWin.gPerms.list.children[0]; is(perm.host, "bug413909." + testDomain, "Permission has correct host"); is(perm.getAttribute("displayHost"), "bug413909." + idnDomain, "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"); is(aWin.gPrefs.tree.view.getCellText(1, aWin.gPrefs.tree.columns["prefsHostCol"]), idnDomain, "Correct domain displayed for utf8 IDN preference"); aWin.gPrefs.tree.view.selection.select(0); aWin.document.getElementById("prefsRemove").click(); diff --git a/suite/components/pref/content/pref-content.js b/suite/components/pref/content/pref-content.js --- a/suite/components/pref/content/pref-content.js +++ b/suite/components/pref/content/pref-content.js @@ -34,26 +34,25 @@ function Startup() /* defaultZoom stuff */ let defaultElement = document.getElementById("defaultZoom"); defaultElement.min = Services.prefs.getIntPref("zoom.minPercent"); defaultElement.max = Services.prefs.getIntPref("zoom.maxPercent"); - let cps2 = Services.contentPrefs.QueryInterface(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); }, handleCompletion(reason) {} }); } /** @@ -112,25 +111,25 @@ function AdjustMinZoom() } /** * Set default zoom. */ function SetDefaultZoom() { let defaultElement = document.getElementById("defaultZoom"); - let cps2 = Services.contentPrefs.QueryInterface(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); } /** * When the user toggles the layers.acceleration.disabled pref, * sync its new value to the gfx.direct2d.disabled pref too. */ function updateHardwareAcceleration(aVal) {