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);
};
/**
* @deprecated Please use nsIContentPrefService2 instead.
*/
[scriptable, uuid(e3f772f3-023f-4b32-b074-36cf0fd5d414)]
interface nsIContentPrefService : nsISupports
{

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

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

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

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

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

@ -96,7 +96,7 @@ DownloadLastDir.prototype = {
return PrivateBrowsingUtils.isWindowPrivate(this.window);
},
// compat shims
get file() { return this.getFile(); },
get file() this._getLastFile(),
set file(val) { this.setFile(null, val); },
cleanupPrivateFile: function () {
gDownloadLastDirFile = null;
@ -104,6 +104,11 @@ DownloadLastDir.prototype = {
// This function is now deprecated as it uses the sync nsIContentPrefService
// interface. New consumers should use the getFileAsync function.
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()) {
let loadContext = this.window
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
@ -117,6 +122,10 @@ DownloadLastDir.prototype = {
return lastDirFile;
}
}
return this._getLastFile();
},
_getLastFile: function () {
if (gDownloadLastDirFile && !gDownloadLastDirFile.exists())
gDownloadLastDirFile = null;
@ -125,12 +134,11 @@ DownloadLastDir.prototype = {
gDownloadLastDirFile = readLastDirPref();
return gDownloadLastDirFile;
}
else
return readLastDirPref();
return readLastDirPref();
},
getFileAsync: function(aURI, aCallback) {
let plainPrefFile = this.getFile();
let plainPrefFile = this._getLastFile();
if (!aURI || !isContentPrefEnabled()) {
Services.tm.mainThread.dispatch(function() aCallback(plainPrefFile),
Components.interfaces.nsIThread.DISPATCH_NORMAL);