mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 901114 - Convert Alarm API to WebIDL. r=nsm, sr=jst
This commit is contained in:
parent
90f74aea8e
commit
4dd7733b2e
@ -18,11 +18,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
||||
|
||||
const ALARMSMANAGER_CONTRACTID = "@mozilla.org/alarmsManager;1";
|
||||
const ALARMSMANAGER_CID = Components.ID("{fea1e884-9b05-11e1-9b64-87a7016c3860}");
|
||||
const nsIDOMMozAlarmsManager = Ci.nsIDOMMozAlarmsManager;
|
||||
const nsIClassInfo = Ci.nsIClassInfo;
|
||||
|
||||
function AlarmsManager()
|
||||
{
|
||||
debug("Constructor");
|
||||
@ -32,19 +27,14 @@ AlarmsManager.prototype = {
|
||||
|
||||
__proto__: DOMRequestIpcHelper.prototype,
|
||||
|
||||
classID : ALARMSMANAGER_CID,
|
||||
contractID : "@mozilla.org/alarmsManager;1",
|
||||
|
||||
QueryInterface : XPCOMUtils.generateQI([nsIDOMMozAlarmsManager,
|
||||
Ci.nsIDOMGlobalPropertyInitializer,
|
||||
classID : Components.ID("{fea1e884-9b05-11e1-9b64-87a7016c3860}"),
|
||||
|
||||
QueryInterface : XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
|
||||
Ci.nsISupportsWeakReference,
|
||||
Ci.nsIObserver]),
|
||||
|
||||
classInfo : XPCOMUtils.generateCI({ classID: ALARMSMANAGER_CID,
|
||||
contractID: ALARMSMANAGER_CONTRACTID,
|
||||
classDescription: "AlarmsManager",
|
||||
interfaces: [nsIDOMMozAlarmsManager],
|
||||
flags: nsIClassInfo.DOM_OBJECT }),
|
||||
|
||||
add: function add(aDate, aRespectTimezone, aData) {
|
||||
debug("add()");
|
||||
|
||||
@ -155,25 +145,6 @@ AlarmsManager.prototype = {
|
||||
init: function init(aWindow) {
|
||||
debug("init()");
|
||||
|
||||
// Set navigator.mozAlarms to null.
|
||||
if (!Services.prefs.getBoolPref("dom.mozAlarms.enabled")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only pages with perm set can use the alarms.
|
||||
let principal = aWindow.document.nodePrincipal;
|
||||
let perm =
|
||||
Services.perms.testExactPermissionFromPrincipal(principal, "alarms");
|
||||
if (perm != Ci.nsIPermissionManager.ALLOW_ACTION) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// SystemPrincipal documents do not have any origin.
|
||||
// Reject them for now.
|
||||
if (!principal.URI) {
|
||||
return null;
|
||||
}
|
||||
|
||||
this._cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
|
||||
.getService(Ci.nsISyncMessageSender);
|
||||
|
||||
@ -186,6 +157,7 @@ AlarmsManager.prototype = {
|
||||
// Get the manifest URL if this is an installed app
|
||||
let appsService = Cc["@mozilla.org/AppsService;1"]
|
||||
.getService(Ci.nsIAppsService);
|
||||
let principal = aWindow.document.nodePrincipal;
|
||||
this._pageURL = principal.URI.spec;
|
||||
this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
|
||||
this._window = aWindow;
|
||||
|
@ -1,3 +1,2 @@
|
||||
component {fea1e884-9b05-11e1-9b64-87a7016c3860} AlarmsManager.js
|
||||
contract @mozilla.org/alarmsManager;1 {fea1e884-9b05-11e1-9b64-87a7016c3860}
|
||||
category JavaScript-navigator-property mozAlarms @mozilla.org/alarmsManager;1
|
||||
|
@ -8,7 +8,6 @@ TEST_DIRS += ['test']
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsIAlarmHalService.idl',
|
||||
'nsIDOMAlarmsManager.idl',
|
||||
]
|
||||
|
||||
XPIDL_MODULE = 'dom_alarm'
|
||||
|
@ -1,15 +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"
|
||||
|
||||
interface nsIDOMDOMRequest;
|
||||
|
||||
[scriptable, uuid(fea1e884-9b05-11e1-9b64-87a7016c3860)]
|
||||
interface nsIDOMMozAlarmsManager : nsISupports
|
||||
{
|
||||
nsIDOMDOMRequest getAll();
|
||||
nsIDOMDOMRequest add(in jsval date, in DOMString respectTimezone, [optional] in jsval data);
|
||||
void remove(in unsigned long id);
|
||||
};
|
@ -21,12 +21,17 @@ if (SpecialPowers.hasPermission("alarms", document)) {
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
|
||||
SpecialPowers.removePermission("alarms", document);
|
||||
|
||||
// mozAlarms is intalled on all platforms except Android for the moment.
|
||||
// mozAlarms is installed on all platforms except Android for the moment.
|
||||
if (navigator.appVersion.indexOf("Android") != -1) {
|
||||
ok(!('mozAlarms' in navigator), "navigator.mozAlarms should not exist");
|
||||
ok(!('mozAlarms' in navigator),
|
||||
"navigator.mozAlarms should not exist without permission");
|
||||
ok(!('AlarmsManager' in window),
|
||||
"Interface AlarmsManager should not exist");
|
||||
} else {
|
||||
ok('mozAlarms' in navigator, "navigator.mozAlarms should exist");
|
||||
is(navigator.mozAlarms, null, "navigator.mozAlarms should return null");
|
||||
ok(!('mozAlarms' in navigator),
|
||||
"navigator.mozAlarms should not exist without permission");
|
||||
ok(!('AlarmsManager' in window),
|
||||
"Interface AlarmsManager should not exist without permission");
|
||||
}
|
||||
SpecialPowers.addPermission("alarms", true, document);
|
||||
SimpleTest.finish();
|
||||
|
@ -18,14 +18,21 @@ SimpleTest.waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
|
||||
SpecialPowers.addPermission("alarms", true, document);
|
||||
|
||||
// mozAlarms is intalled on all platforms except Android for the moment.
|
||||
// mozAlarms is installed on all platforms except Android for the moment.
|
||||
if (navigator.appVersion.indexOf("Android") != -1) {
|
||||
ok(!('mozAlarms' in navigator), "navigator.mozAlarms should not exist");
|
||||
ok('AlarmsManager' in window, "Interface AlarmsManager should exist");
|
||||
try {
|
||||
todo('mozAlarms' in navigator,
|
||||
"mozAlarms is not allowed on Android for now. TODO Bug 863557.");
|
||||
} catch (e) {
|
||||
todo(!e, "('mozAlarms' in navigator) should not throw exceptions once " +
|
||||
"mozAlarms is installed on Android. TODO Bug 863557. " +
|
||||
"Caught exception: " + e);
|
||||
}
|
||||
} else {
|
||||
ok('mozAlarms' in navigator, "navigator.mozAlarms should exist");
|
||||
ok(navigator.mozAlarms, "navigator.mozAlarms should return an object");
|
||||
ok(navigator.mozAlarms instanceof SpecialPowers.Ci.nsIDOMMozAlarmsManager,
|
||||
"navigator.mozAlarms should be an nsIDOMMozAlarmsManager object");
|
||||
ok(navigator.mozAlarms instanceof AlarmsManager,
|
||||
"navigator.mozAlarms should be an instance of AlarmsManager");
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
|
@ -20,11 +20,11 @@ var gData = [
|
||||
{
|
||||
perm: ["alarms"],
|
||||
// AlarmsManager is not enabled on Android yet
|
||||
// exception on accessing Ci.nsIDOMMozAlarmsManager
|
||||
// exception on accessing AlarmsManager
|
||||
// See bug 863557
|
||||
skip: ["Android"],
|
||||
obj: "mozAlarms",
|
||||
idl: "nsIDOMMozAlarmsManager",
|
||||
webidl: "AlarmsManager",
|
||||
settings: [["dom.mozAlarms.enabled", true]],
|
||||
},
|
||||
]
|
||||
|
@ -111,6 +111,8 @@ var legacyMozPrefixedInterfaces =
|
||||
// IMPORTANT: Do not change the list below without review from a DOM peer!
|
||||
var interfaceNamesInGlobalScope =
|
||||
[
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "AlarmsManager", pref: "dom.mozAlarms.enabled"},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"AnalyserNode",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
17
dom/webidl/AlarmsManager.webidl
Normal file
17
dom/webidl/AlarmsManager.webidl
Normal file
@ -0,0 +1,17 @@
|
||||
/* -*- 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/.
|
||||
*
|
||||
* https://wiki.mozilla.org/WebAPI/AlarmAPI
|
||||
*/
|
||||
|
||||
[NavigatorProperty="mozAlarms",
|
||||
JSImplementation="@mozilla.org/alarmsManager;1",
|
||||
CheckPermissions="alarms",
|
||||
Pref="dom.mozAlarms.enabled"]
|
||||
interface AlarmsManager {
|
||||
DOMRequest getAll();
|
||||
DOMRequest add(any date, DOMString respectTimezone, optional any data);
|
||||
void remove(unsigned long id);
|
||||
};
|
@ -17,6 +17,7 @@ PREPROCESSED_WEBIDL_FILES = [
|
||||
WEBIDL_FILES = [
|
||||
'AbstractWorker.webidl',
|
||||
'ActivityRequestHandler.webidl',
|
||||
'AlarmsManager.webidl',
|
||||
'AnalyserNode.webidl',
|
||||
'AnimationEvent.webidl',
|
||||
'AnimationTimeline.webidl',
|
||||
|
Loading…
Reference in New Issue
Block a user