Bug 889503 - Move Settings API to WebIDL. r=gwagner r=bz

--HG--
extra : rebase_source : 9f858f389b71344353658d4ed49996e0d90b8b99
This commit is contained in:
Reuben Morais 2013-07-15 18:17:46 -07:00
Родитель f7729cfa8a
Коммит ea38b25c81
12 изменённых файлов: 85 добавлений и 111 удалений

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

@ -129,7 +129,6 @@
#include "nsIXSLTProcessorPrivate.h"
#include "nsXMLHttpRequest.h"
#include "nsIDOMSettingsManager.h"
#include "nsIDOMContactManager.h"
#include "nsIDOMPermissionSettings.h"
#include "nsIDOMApplicationRegistry.h"

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

@ -6,7 +6,6 @@
XPIDL_SOURCES += [
'nsIDOMMozSettingsEvent.idl',
'nsIDOMSettingsManager.idl',
'nsISettingsService.idl',
]

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

@ -1,35 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "domstubs.idl"
#include "nsIDOMEventTarget.idl"
interface nsIDOMDOMRequest;
interface nsIVariant;
[scriptable, uuid(ef95ddd0-6308-11e1-b86c-0800200c9a66)]
interface nsIDOMSettingsLock : nsISupports
{
// Whether this lock is invalid
readonly attribute boolean closed;
// Contains a JSON object with name/value pairs to be set.
nsIDOMDOMRequest set(in nsIVariant settings);
// result contains the value of the setting.
nsIDOMDOMRequest get(in jsval name);
nsIDOMDOMRequest clear();
};
[scriptable, uuid(c40b1c70-00fb-11e2-a21f-0800200c9a66)]
interface nsIDOMSettingsManager : nsISupports
{
nsIDOMSettingsLock createLock();
void addObserver(in DOMString name, in jsval callback);
void removeObserver(in DOMString name, in jsval callback);
attribute nsIDOMEventListener onsettingchange;
};

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

@ -78,7 +78,12 @@ const BrowserElementIsPreloaded = true;
Cc["@mozilla.org/contentsecuritypolicy;1"].createInstance(Ci["nsIContentSecurityPolicy"]);
/* Applications Specific Helper */
Cc["@mozilla.org/settingsManager;1"].getService(Ci["nsIDOMSettingsManager"]);
try {
// May throw if we don't have the settings permission
navigator.mozSettings;
} catch(e) {
}
try {
if (Services.prefs.getBoolPref("dom.sysmsg.enabled")) {
Cc["@mozilla.org/system-message-manager;1"].getService(Ci["nsIDOMNavigatorSystemMessages"]);

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

@ -25,7 +25,7 @@ var gData = [
{
perm: ["settings"],
obj: 'mozSettings',
idl: 'nsIDOMSettingsManager',
webidl: 'SettingsManager',
settings: [["dom.mozSettings.enabled", true]],
}
]

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

@ -23,13 +23,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
"@mozilla.org/childprocessmessagemanager;1",
"nsIMessageSender");
const nsIClassInfo = Ci.nsIClassInfo;
const SETTINGSLOCK_CONTRACTID = "@mozilla.org/settingsLock;1";
const SETTINGSLOCK_CID = Components.ID("{60c9357c-3ae0-4222-8f55-da01428470d5}");
const nsIDOMSettingsLock = Ci.nsIDOMSettingsLock;
function SettingsLock(aSettingsManager)
{
function SettingsLock(aSettingsManager) {
this._open = true;
this._isBusy = false;
this._requests = new Queue();
@ -38,7 +32,6 @@ function SettingsLock(aSettingsManager)
}
SettingsLock.prototype = {
get closed() {
return !this._open;
},
@ -217,8 +210,7 @@ SettingsLock.prototype = {
set: function set(aSettings) {
if (!this._open) {
dump("Settings lock not open!\n");
throw Components.results.NS_ERROR_ABORT;
throw "Settings lock not open";
}
if (this._settingsManager.hasWritePrivileges) {
@ -230,14 +222,13 @@ SettingsLock.prototype = {
return req;
} else {
if (DEBUG) debug("set not allowed");
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
throw "No permission to call set";
}
},
clear: function clear() {
if (!this._open) {
dump("Settings lock not open!\n");
throw Components.results.NS_ERROR_ABORT;
throw "Settings lock not open";
}
if (this._settingsManager.hasWritePrivileges) {
@ -247,28 +238,18 @@ SettingsLock.prototype = {
return req;
} else {
if (DEBUG) debug("clear not allowed");
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
throw "No permission to call clear";
}
},
classID : SETTINGSLOCK_CID,
QueryInterface : XPCOMUtils.generateQI([nsIDOMSettingsLock]),
classInfo : XPCOMUtils.generateCI({classID: SETTINGSLOCK_CID,
contractID: SETTINGSLOCK_CONTRACTID,
classDescription: "SettingsLock",
interfaces: [nsIDOMSettingsLock],
flags: nsIClassInfo.DOM_OBJECT})
classID: Components.ID("{60c9357c-3ae0-4222-8f55-da01428470d5}"),
contractID: "@mozilla.org/settingsLock;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
};
const SETTINGSMANAGER_CONTRACTID = "@mozilla.org/settingsManager;1";
const SETTINGSMANAGER_CID = Components.ID("{c40b1c70-00fb-11e2-a21f-0800200c9a66}");
const nsIDOMSettingsManager = Ci.nsIDOMSettingsManager;
let myGlobal = this;
function SettingsManager()
{
function SettingsManager() {
this._locks = new Queue();
if (!("indexedDB" in myGlobal)) {
let idbManager = Components.classes["@mozilla.org/dom/indexeddb/manager;1"].getService(Ci.nsIIndexedDatabaseManager);
@ -279,7 +260,6 @@ function SettingsManager()
}
SettingsManager.prototype = {
_onsettingchange: null,
_callbacks: null,
_wrap: function _wrap(obj) {
@ -293,19 +273,12 @@ SettingsManager.prototype = {
Services.tm.currentThread.dispatch(aCallback, Ci.nsIThread.DISPATCH_NORMAL);
},
set onsettingchange(aCallback) {
if (this.hasReadPrivileges) {
if (!this._onsettingchange) {
cpmm.sendAsyncMessage("Settings:RegisterForMessages");
}
this._onsettingchange = aCallback;
} else {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
set onsettingchange(aHandler) {
this.__DOM_IMPL__.setEventHandler("onsettingchange", aHandler);
},
get onsettingchange() {
return this._onsettingchange;
return this.__DOM_IMPL__.getEventHandler("onsettingchange");
},
createLock: function() {
@ -326,22 +299,19 @@ SettingsManager.prototype = {
switch (aMessage.name) {
case "Settings:Change:Return:OK":
if (this._onsettingchange || this._callbacks) {
if (DEBUG) debug('data:' + msg.key + ':' + msg.value + '\n');
if (DEBUG) debug('data:' + msg.key + ':' + msg.value + '\n');
if (this._onsettingchange) {
let event = new this._window.MozSettingsEvent("settingchanged", this._wrap({
settingName: msg.key,
settingValue: msg.value
}));
this._onsettingchange.handleEvent(event);
}
if (this._callbacks && this._callbacks[msg.key]) {
if (DEBUG) debug("observe callback called! " + msg.key + " " + this._callbacks[msg.key].length);
this._callbacks[msg.key].forEach(function(cb) {
cb(this._wrap({settingName: msg.key, settingValue: msg.value}));
}.bind(this));
}
let event = new this._window.MozSettingsEvent("settingchange", this._wrap({
settingName: msg.key,
settingValue: msg.value
}));
this.__DOM_IMPL__.dispatchEvent(event);
if (this._callbacks && this._callbacks[msg.key]) {
if (DEBUG) debug("observe callback called! " + msg.key + " " + this._callbacks[msg.key].length);
this._callbacks[msg.key].forEach(function(cb) {
cb(this._wrap({settingName: msg.key, settingValue: msg.value}));
}.bind(this));
} else {
if (DEBUG) debug("no observers stored!");
}
@ -390,9 +360,12 @@ SettingsManager.prototype = {
this.hasReadPrivileges = readPerm == Ci.nsIPermissionManager.ALLOW_ACTION;
this.hasWritePrivileges = writePerm == Ci.nsIPermissionManager.ALLOW_ACTION;
if (this.hasReadPrivileges) {
cpmm.sendAsyncMessage("Settings:RegisterForMessages");
}
if (!this.hasReadPrivileges && !this.hasWritePrivileges) {
Cu.reportError("NO SETTINGS PERMISSION FOR: " + aWindow.document.nodePrincipal.origin + "\n");
return null;
throw "NO SETTINGS PERMISSION FOR: " + aWindow.document.nodePrincipal.origin + "\n";
}
},
@ -406,20 +379,15 @@ SettingsManager.prototype = {
this._requests = null;
this._window = null;
this._innerWindowID = null;
this._onsettingchange = null;
this._settingsDB.close();
}
}
},
classID : SETTINGSMANAGER_CID,
QueryInterface : XPCOMUtils.generateQI([nsIDOMSettingsManager, Ci.nsIDOMGlobalPropertyInitializer]),
classInfo : XPCOMUtils.generateCI({classID: SETTINGSMANAGER_CID,
contractID: SETTINGSMANAGER_CONTRACTID,
classDescription: "SettingsManager",
interfaces: [nsIDOMSettingsManager],
flags: nsIClassInfo.DOM_OBJECT})
}
classID: Components.ID("{c40b1c70-00fb-11e2-a21f-0800200c9a66}"),
contractID: "@mozilla.org/settingsManager;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
Ci.nsIDOMGlobalPropertyInitializer]),
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SettingsManager, SettingsLock])

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

@ -1,6 +1,5 @@
component {c40b1c70-00fb-11e2-a21f-0800200c9a66} SettingsManager.js
contract @mozilla.org/settingsManager;1 {c40b1c70-00fb-11e2-a21f-0800200c9a66}
category JavaScript-navigator-property mozSettings @mozilla.org/settingsManager;1
component {60c9357c-3ae0-4222-8f55-da01428470d5} SettingsManager.js
contract @mozilla.org/settingsLock;1 {60c9357c-3ae0-4222-8f55-da01428470d5}

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

@ -64,11 +64,12 @@ let steps = [
req.onerror = onFailure("Deleting database");
},
function() {
mozSettings.addObserver("test1", function(e) {
function obs(e) {
checkBlob(e.settingValue);
mozSettings.removeObserver("test1", this);
mozSettings.removeObserver("test1", obs);
next();
});
}
mozSettings.addObserver("test1", obs);
next();
},
function() {

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

@ -0,0 +1,39 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
[JSImplementation="@mozilla.org/settingsLock;1",
Pref="dom.mozSettings.enabled"]
interface SettingsLock {
// Whether this lock is invalid
readonly attribute boolean closed;
// Contains a JSON object with name/value pairs to be set.
DOMRequest set(object settings);
// Result contains the value of the setting.
DOMRequest get(DOMString name);
DOMRequest clear();
};
dictionary SettingChange {
DOMString settingName;
DOMString settingValue;
};
callback SettingChangeCallback = void (SettingChange setting);
[JSImplementation="@mozilla.org/settingsManager;1",
NavigatorProperty="mozSettings",
Pref="dom.mozSettings.enabled"]
interface SettingsManager : EventTarget {
SettingsLock createLock();
void addObserver(DOMString name, SettingChangeCallback callback);
void removeObserver(DOMString name, SettingChangeCallback callback);
attribute EventHandler onsettingchange;
};

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

@ -227,6 +227,7 @@ webidl_files = \
Screen.webidl \
ScriptProcessorNode.webidl \
ScrollAreaEvent.webidl \
SettingsManager.webidl \
SimpleGestureEvent.webidl \
SourceBuffer.webidl \
SourceBufferList.webidl \

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

@ -4173,7 +4173,6 @@ pref("dom.mozNetworkStats.enabled", false);
// WebSettings
pref("dom.mozSettings.enabled", false);
pref("dom.navigator-property.disable.mozSettings", true);
pref("dom.mozPermissionSettings.enabled", false);
// W3C touch events

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

@ -122,7 +122,6 @@ user_pref("dom.global-constructor.disable.mozContact", false);
// Enable mozSettings
user_pref("dom.mozSettings.enabled", true);
user_pref("dom.navigator-property.disable.mozSettings", false);
// Make sure the disk cache doesn't get auto disabled
user_pref("network.http.bypass-cachelock-threshold", 200000);