Bug 850219 - Mark nsIContentPrefService as deprecated in favor of nsIContentPrefService2. r=mak

This commit is contained in:
Drew Willcoxon 2013-08-08 20:38:49 -07:00
Родитель 6d4b933610
Коммит 79b0077e76
4 изменённых файлов: 62 добавлений и 11 удалений

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

@ -39,6 +39,9 @@ interface nsIContentPrefCallback : nsISupports
void onResult(in nsIVariant aResult); void onResult(in nsIVariant aResult);
}; };
/**
* @deprecated Please use nsIContentPrefService2 instead.
*/
[scriptable, uuid(e3f772f3-023f-4b32-b074-36cf0fd5d414)] [scriptable, uuid(e3f772f3-023f-4b32-b074-36cf0fd5d414)]
interface nsIContentPrefService : nsISupports interface nsIContentPrefService : nsISupports
{ {

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

@ -696,7 +696,7 @@ ContentPrefService2.prototype = {
catch (err) { catch (err) {
return groupStr; return groupStr;
} }
return this._cps.grouper.group(groupURI); return this._cps._grouper.group(groupURI);
}, },
_schedule: function CPS2__schedule(fn) { _schedule: function CPS2__schedule(fn) {
@ -705,11 +705,11 @@ ContentPrefService2.prototype = {
}, },
addObserverForName: function CPS2_addObserverForName(name, observer) { addObserverForName: function CPS2_addObserverForName(name, observer) {
this._cps.addObserver(name, observer); this._cps._addObserver(name, observer);
}, },
removeObserverForName: function CPS2_removeObserverForName(name, observer) { removeObserverForName: function CPS2_removeObserverForName(name, observer) {
this._cps.removeObserver(name, observer); this._cps._removeObserver(name, observer);
}, },
extractDomain: function CPS2_extractDomain(str) { extractDomain: function CPS2_extractDomain(str) {

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

@ -231,6 +231,8 @@ ContentPrefService.prototype = {
// nsIContentPrefService // nsIContentPrefService
getPref: function ContentPrefService_getPref(aGroup, aName, aContext, aCallback) { getPref: function ContentPrefService_getPref(aGroup, aName, aContext, aCallback) {
warnDeprecated();
if (!aName) if (!aName)
throw Components.Exception("aName cannot be null or an empty string", throw Components.Exception("aName cannot be null or an empty string",
Cr.NS_ERROR_ILLEGAL_VALUE); Cr.NS_ERROR_ILLEGAL_VALUE);
@ -256,6 +258,8 @@ ContentPrefService.prototype = {
}, },
setPref: function ContentPrefService_setPref(aGroup, aName, aValue, aContext) { setPref: function ContentPrefService_setPref(aGroup, aName, aValue, aContext) {
warnDeprecated();
// If the pref is already set to the value, there's nothing more to do. // If the pref is already set to the value, there's nothing more to do.
var currentValue = this.getPref(aGroup, aName, aContext); var currentValue = this.getPref(aGroup, aName, aContext);
if (typeof currentValue != "undefined") { if (typeof currentValue != "undefined") {
@ -293,12 +297,16 @@ ContentPrefService.prototype = {
}, },
hasPref: function ContentPrefService_hasPref(aGroup, aName, aContext) { hasPref: function ContentPrefService_hasPref(aGroup, aName, aContext) {
warnDeprecated();
// XXX If consumers end up calling this method regularly, then we should // XXX If consumers end up calling this method regularly, then we should
// optimize this to query the database directly. // optimize this to query the database directly.
return (typeof this.getPref(aGroup, aName, aContext) != "undefined"); return (typeof this.getPref(aGroup, aName, aContext) != "undefined");
}, },
hasCachedPref: function ContentPrefService_hasCachedPref(aGroup, aName, aContext) { hasCachedPref: function ContentPrefService_hasCachedPref(aGroup, aName, aContext) {
warnDeprecated();
if (!aName) if (!aName)
throw Components.Exception("aName cannot be null or an empty string", throw Components.Exception("aName cannot be null or an empty string",
Cr.NS_ERROR_ILLEGAL_VALUE); Cr.NS_ERROR_ILLEGAL_VALUE);
@ -309,6 +317,8 @@ ContentPrefService.prototype = {
}, },
removePref: function ContentPrefService_removePref(aGroup, aName, aContext) { removePref: function ContentPrefService_removePref(aGroup, aName, aContext) {
warnDeprecated();
// If there's no old value, then there's nothing to remove. // If there's no old value, then there's nothing to remove.
if (!this.hasPref(aGroup, aName, aContext)) if (!this.hasPref(aGroup, aName, aContext))
return; return;
@ -344,6 +354,8 @@ ContentPrefService.prototype = {
}, },
removeGroupedPrefs: function ContentPrefService_removeGroupedPrefs(aContext) { removeGroupedPrefs: function ContentPrefService_removeGroupedPrefs(aContext) {
warnDeprecated();
// will not delete global preferences // will not delete global preferences
if (aContext && aContext.usePrivateBrowsing) { if (aContext && aContext.usePrivateBrowsing) {
// keep only global prefs // keep only global prefs
@ -367,6 +379,8 @@ ContentPrefService.prototype = {
}, },
removePrefsByName: function ContentPrefService_removePrefsByName(aName, aContext) { removePrefsByName: function ContentPrefService_removePrefsByName(aName, aContext) {
warnDeprecated();
if (!aName) if (!aName)
throw Components.Exception("aName cannot be null or an empty string", throw Components.Exception("aName cannot be null or an empty string",
Cr.NS_ERROR_ILLEGAL_VALUE); Cr.NS_ERROR_ILLEGAL_VALUE);
@ -423,6 +437,8 @@ ContentPrefService.prototype = {
}, },
getPrefs: function ContentPrefService_getPrefs(aGroup, aContext) { getPrefs: function ContentPrefService_getPrefs(aGroup, aContext) {
warnDeprecated();
var group = this._parseGroupParam(aGroup); var group = this._parseGroupParam(aGroup);
if (aContext && aContext.usePrivateBrowsing) { if (aContext && aContext.usePrivateBrowsing) {
let prefs = Cc["@mozilla.org/hash-property-bag;1"]. let prefs = Cc["@mozilla.org/hash-property-bag;1"].
@ -440,6 +456,8 @@ ContentPrefService.prototype = {
}, },
getPrefsByName: function ContentPrefService_getPrefsByName(aName, aContext) { getPrefsByName: function ContentPrefService_getPrefsByName(aName, aContext) {
warnDeprecated();
if (!aName) if (!aName)
throw Components.Exception("aName cannot be null or an empty string", throw Components.Exception("aName cannot be null or an empty string",
Cr.NS_ERROR_ILLEGAL_VALUE); Cr.NS_ERROR_ILLEGAL_VALUE);
@ -464,6 +482,11 @@ ContentPrefService.prototype = {
_genericObservers: [], _genericObservers: [],
addObserver: function ContentPrefService_addObserver(aName, aObserver) { addObserver: function ContentPrefService_addObserver(aName, aObserver) {
warnDeprecated();
this._addObserver.apply(this, arguments);
},
_addObserver: function ContentPrefService__addObserver(aName, aObserver) {
var observers; var observers;
if (aName) { if (aName) {
if (!this._observers[aName]) if (!this._observers[aName])
@ -478,6 +501,11 @@ ContentPrefService.prototype = {
}, },
removeObserver: function ContentPrefService_removeObserver(aName, aObserver) { removeObserver: function ContentPrefService_removeObserver(aName, aObserver) {
warnDeprecated();
this._removeObserver.apply(this, arguments);
},
_removeObserver: function ContentPrefService__removeObserver(aName, aObserver) {
var observers; var observers;
if (aName) { if (aName) {
if (!this._observers[aName]) if (!this._observers[aName])
@ -536,15 +564,20 @@ ContentPrefService.prototype = {
} }
}, },
_grouper: null,
get grouper() { get grouper() {
if (!this._grouper) warnDeprecated();
this._grouper = Cc["@mozilla.org/content-pref/hostname-grouper;1"].
getService(Ci.nsIContentURIGrouper);
return this._grouper; return this._grouper;
}, },
__grouper: null,
get _grouper() {
if (!this.__grouper)
this.__grouper = Cc["@mozilla.org/content-pref/hostname-grouper;1"].
getService(Ci.nsIContentURIGrouper);
return this.__grouper;
},
get DBConnection() { get DBConnection() {
warnDeprecated();
return this._dbConnection; return this._dbConnection;
}, },
@ -1205,6 +1238,13 @@ ContentPrefService.prototype = {
}, },
}; };
function warnDeprecated() {
Cu.import("resource://gre/modules/Deprecated.jsm");
Deprecated.warning("nsIContentPrefService is deprecated. Please use nsIContentPrefService2 instead.",
"https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIContentPrefService2",
Components.stack.caller);
}
function HostnameGrouper() {} function HostnameGrouper() {}

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

@ -96,7 +96,7 @@ DownloadLastDir.prototype = {
return PrivateBrowsingUtils.isWindowPrivate(this.window); return PrivateBrowsingUtils.isWindowPrivate(this.window);
}, },
// compat shims // compat shims
get file() { return this.getFile(); }, get file() this._getLastFile(),
set file(val) { this.setFile(null, val); }, set file(val) { this.setFile(null, val); },
cleanupPrivateFile: function () { cleanupPrivateFile: function () {
gDownloadLastDirFile = null; gDownloadLastDirFile = null;
@ -104,6 +104,11 @@ DownloadLastDir.prototype = {
// This function is now deprecated as it uses the sync nsIContentPrefService // This function is now deprecated as it uses the sync nsIContentPrefService
// interface. New consumers should use the getFileAsync function. // interface. New consumers should use the getFileAsync function.
getFile: function (aURI) { getFile: function (aURI) {
Components.utils.import("resource://gre/modules/Deprecated.jsm");
Deprecated.warning("DownloadLastDir.getFile is deprecated. Please use getFileAsync instead.",
"https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/DownloadLastDir.jsm",
Components.stack.caller);
if (aURI && isContentPrefEnabled()) { if (aURI && isContentPrefEnabled()) {
let loadContext = this.window let loadContext = this.window
.QueryInterface(Components.interfaces.nsIInterfaceRequestor) .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
@ -117,6 +122,10 @@ DownloadLastDir.prototype = {
return lastDirFile; return lastDirFile;
} }
} }
return this._getLastFile();
},
_getLastFile: function () {
if (gDownloadLastDirFile && !gDownloadLastDirFile.exists()) if (gDownloadLastDirFile && !gDownloadLastDirFile.exists())
gDownloadLastDirFile = null; gDownloadLastDirFile = null;
@ -125,12 +134,11 @@ DownloadLastDir.prototype = {
gDownloadLastDirFile = readLastDirPref(); gDownloadLastDirFile = readLastDirPref();
return gDownloadLastDirFile; return gDownloadLastDirFile;
} }
else return readLastDirPref();
return readLastDirPref();
}, },
getFileAsync: function(aURI, aCallback) { getFileAsync: function(aURI, aCallback) {
let plainPrefFile = this.getFile(); let plainPrefFile = this._getLastFile();
if (!aURI || !isContentPrefEnabled()) { if (!aURI || !isContentPrefEnabled()) {
Services.tm.mainThread.dispatch(function() aCallback(plainPrefFile), Services.tm.mainThread.dispatch(function() aCallback(plainPrefFile),
Components.interfaces.nsIThread.DISPATCH_NORMAL); Components.interfaces.nsIThread.DISPATCH_NORMAL);