mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 749551 - Alarm API (Idl and dummy Dom). r=mounir sr=jonas
This commit is contained in:
parent
b1f0381abe
commit
2500ccecd6
@ -378,6 +378,9 @@ pref("dom.sms.enabled", true);
|
||||
// Temporary permission hack for WebContacts
|
||||
pref("dom.mozContacts.enabled", true);
|
||||
|
||||
// WebAlarms
|
||||
pref("dom.mozAlarms.enabled", true);
|
||||
|
||||
// WebSettings
|
||||
pref("dom.mozSettings.enabled", true);
|
||||
|
||||
|
@ -51,7 +51,7 @@ function addPermissions(urls) {
|
||||
'indexedDB-unlimited', 'webapps-manage', 'offline-app', 'pin-app',
|
||||
'websettings-read', 'websettings-readwrite',
|
||||
'content-camera', 'webcontacts-manage', 'wifi-manage', 'desktop-notification',
|
||||
'geolocation', 'device-storage'
|
||||
'geolocation', 'device-storage', 'alarms'
|
||||
];
|
||||
urls.forEach(function(url) {
|
||||
url = url.trim();
|
||||
|
@ -163,6 +163,7 @@
|
||||
#endif
|
||||
@BINPATH@/components/dom_canvas.xpt
|
||||
@BINPATH@/components/dom_contacts.xpt
|
||||
@BINPATH@/components/dom_alarm.xpt
|
||||
@BINPATH@/components/dom_core.xpt
|
||||
@BINPATH@/components/dom_css.xpt
|
||||
@BINPATH@/components/dom_devicestorage.xpt
|
||||
@ -319,6 +320,8 @@
|
||||
@BINPATH@/components/BrowserElementParent.js
|
||||
@BINPATH@/components/ContactManager.js
|
||||
@BINPATH@/components/ContactManager.manifest
|
||||
@BINPATH@/components/AlarmsManager.js
|
||||
@BINPATH@/components/AlarmsManager.manifest
|
||||
@BINPATH@/components/FeedProcessor.manifest
|
||||
@BINPATH@/components/FeedProcessor.js
|
||||
@BINPATH@/components/BrowserFeeds.manifest
|
||||
|
@ -173,6 +173,7 @@
|
||||
#endif
|
||||
@BINPATH@/components/dom_canvas.xpt
|
||||
@BINPATH@/components/dom_contacts.xpt
|
||||
@BINPATH@/components/dom_alarm.xpt
|
||||
@BINPATH@/components/dom_core.xpt
|
||||
@BINPATH@/components/dom_css.xpt
|
||||
@BINPATH@/components/dom_devicestorage.xpt
|
||||
@ -472,6 +473,8 @@
|
||||
|
||||
@BINPATH@/components/ContactManager.js
|
||||
@BINPATH@/components/ContactManager.manifest
|
||||
@BINPATH@/components/AlarmsManager.js
|
||||
@BINPATH@/components/AlarmsManager.manifest
|
||||
#ifdef ENABLE_MARIONETTE
|
||||
@BINPATH@/chrome/marionette@JAREXT@
|
||||
@BINPATH@/chrome/marionette.manifest
|
||||
|
@ -50,6 +50,7 @@ DIRS += \
|
||||
battery \
|
||||
browser-element \
|
||||
contacts \
|
||||
alarm \
|
||||
devicestorage \
|
||||
file \
|
||||
media \
|
||||
|
75
dom/alarm/AlarmsManager.js
Normal file
75
dom/alarm/AlarmsManager.js
Normal file
@ -0,0 +1,75 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
AlarmsManager.prototype = {
|
||||
|
||||
__proto__: DOMRequestIpcHelper.prototype,
|
||||
|
||||
classID : ALARMSMANAGER_CID,
|
||||
|
||||
QueryInterface : XPCOMUtils.generateQI([nsIDOMMozAlarmsManager, Ci.nsIDOMGlobalPropertyInitializer]),
|
||||
|
||||
classInfo : XPCOMUtils.generateCI({ classID: ALARMSMANAGER_CID,
|
||||
contractID: ALARMSMANAGER_CONTRACTID,
|
||||
classDescription: "AlarmsManager",
|
||||
interfaces: [nsIDOMMozAlarmsManager],
|
||||
flags: nsIClassInfo.DOM_OBJECT }),
|
||||
|
||||
add: function add(aDate, aRespectTimezone, aData) {
|
||||
return null;
|
||||
},
|
||||
|
||||
remove: function remove(aId) {
|
||||
return;
|
||||
},
|
||||
|
||||
getAll: function getAll() {
|
||||
return null;
|
||||
},
|
||||
|
||||
// nsIDOMGlobalPropertyInitializer implementation
|
||||
init: function init(aWindow) {
|
||||
// Set navigator.mozAlarms to null.
|
||||
if (!Services.prefs.getBoolPref("dom.mozAlarms.enabled"))
|
||||
return null;
|
||||
|
||||
let principal = aWindow.document.nodePrincipal;
|
||||
let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
|
||||
|
||||
let perm = principal == secMan.getSystemPrincipal() ?
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION : Services.perms.testExactPermission(principal.URI, "alarms");
|
||||
|
||||
// Only pages with perm set can use the alarms.
|
||||
this.hasPrivileges = perm == Ci.nsIPermissionManager.ALLOW_ACTION;
|
||||
|
||||
if (!this.hasPrivileges)
|
||||
return null;
|
||||
|
||||
// Add the valid messages to be listened.
|
||||
this.initHelper(aWindow, []);
|
||||
},
|
||||
|
||||
// Called from DOMRequestIpcHelper.
|
||||
uninit: function uninit() {
|
||||
},
|
||||
}
|
||||
|
||||
const NSGetFactory = XPCOMUtils.generateNSGetFactory([AlarmsManager])
|
3
dom/alarm/AlarmsManager.manifest
Normal file
3
dom/alarm/AlarmsManager.manifest
Normal file
@ -0,0 +1,3 @@
|
||||
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
|
33
dom/alarm/Makefile.in
Normal file
33
dom/alarm/Makefile.in
Normal file
@ -0,0 +1,33 @@
|
||||
# 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/.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = dom
|
||||
XPIDL_MODULE = dom_alarm
|
||||
LIBRARY_NAME = domalarm_s
|
||||
LIBXUL_LIBRARY = 1
|
||||
|
||||
include $(topsrcdir)/dom/dom-config.mk
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
AlarmsManager.js \
|
||||
AlarmsManager.manifest \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIDOMAlarmsManager.idl \
|
||||
$(NULL)
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += test
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
15
dom/alarm/nsIDOMAlarmsManager.idl
Normal file
15
dom/alarm/nsIDOMAlarmsManager.idl
Normal file
@ -0,0 +1,15 @@
|
||||
/* 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);
|
||||
};
|
25
dom/alarm/test/Makefile.in
Normal file
25
dom/alarm/test/Makefile.in
Normal file
@ -0,0 +1,25 @@
|
||||
# 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/.
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
relativesrcdir = dom/alarm/test
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_TEST_FILES = \
|
||||
test_alarm_permitted_app.html \
|
||||
test_alarm_non_permitted_app.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
|
35
dom/alarm/test/test_alarm_non_permitted_app.html
Normal file
35
dom/alarm/test/test_alarm_non_permitted_app.html
Normal file
@ -0,0 +1,35 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test Non-Permitted Application for Alarm API</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
|
||||
SpecialPowers.removePermission("alarms", document);
|
||||
|
||||
// mozAlarms is intalled on all platforms except Android for the moment.
|
||||
if (navigator.appVersion.indexOf("Android") != -1) {
|
||||
ok(!('mozAlarms' in navigator), "navigator.mozAlarms should not exist");
|
||||
} else {
|
||||
ok('mozAlarms' in navigator, "navigator.mozAlarms should exist");
|
||||
is(navigator.mozAlarms, null, "navigator.mozAlarms should return null");
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
38
dom/alarm/test/test_alarm_permitted_app.html
Normal file
38
dom/alarm/test/test_alarm_permitted_app.html
Normal file
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test Permitted Application for Alarm API</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
"use strict";
|
||||
|
||||
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.
|
||||
if (navigator.appVersion.indexOf("Android") != -1) {
|
||||
ok(!('mozAlarms' in navigator), "navigator.mozAlarms should not exist");
|
||||
} else {
|
||||
ok('mozAlarms' in navigator, "navigator.mozAlarms should exist");
|
||||
ok(navigator.mozAlarms, "navigator.mozAlarms should return an object");
|
||||
ok(navigator.mozAlarms instanceof Components.interfaces.nsIDOMMozAlarmsManager,
|
||||
"navigator.mozAlarms should be an nsIDOMMozAlarmsManager object");
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("alarms", document);
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -12,6 +12,7 @@ DOM_SRCDIRS = \
|
||||
dom/settings \
|
||||
dom/sms/src \
|
||||
dom/contacts \
|
||||
dom/alarm \
|
||||
dom/src/events \
|
||||
dom/src/storage \
|
||||
dom/src/offline \
|
||||
|
@ -89,6 +89,7 @@ var interfaceNamesInGlobalScope =
|
||||
"WebGLExtensionLoseContext",
|
||||
"CanvasRenderingContext2D",
|
||||
"SVGPathSegLinetoVerticalRel",
|
||||
"MozAlarmsManager",
|
||||
"MozPowerManager",
|
||||
"SVGElement",
|
||||
"GeoPositionError",
|
||||
|
@ -62,6 +62,7 @@ SHARED_LIBRARY_LIBS = \
|
||||
$(DEPTH)/dom/base/$(LIB_PREFIX)jsdombase_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/dom/battery/$(LIB_PREFIX)dom_battery_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/dom/contacts/$(LIB_PREFIX)jsdomcontacts_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/dom/alarm/$(LIB_PREFIX)domalarm_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/dom/devicestorage/$(LIB_PREFIX)domdevicestorage_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/dom/file/$(LIB_PREFIX)domfile_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/dom/power/$(LIB_PREFIX)dom_power_s.$(LIB_SUFFIX) \
|
||||
|
@ -3578,6 +3578,9 @@ pref("dom.sms.whitelist", "");
|
||||
pref("dom.mozContacts.enabled", false);
|
||||
pref("dom.mozContacts.whitelist", "");
|
||||
|
||||
// WebAlarms
|
||||
pref("dom.mozAlarms.enabled", false);
|
||||
|
||||
// WebSettings
|
||||
pref("dom.mozSettings.enabled", false);
|
||||
|
||||
|
@ -35,6 +35,7 @@ MAKEFILES_dom="
|
||||
dom/interfaces/xbl/Makefile
|
||||
dom/interfaces/xpath/Makefile
|
||||
dom/interfaces/xul/Makefile
|
||||
dom/alarm/Makefile
|
||||
dom/base/Makefile
|
||||
dom/battery/Makefile
|
||||
dom/file/Makefile
|
||||
@ -709,6 +710,7 @@ if [ "$ENABLE_TESTS" ]; then
|
||||
docshell/test/Makefile
|
||||
docshell/test/chrome/Makefile
|
||||
docshell/test/navigation/Makefile
|
||||
dom/alarm/test/Makefile
|
||||
dom/battery/test/Makefile
|
||||
dom/indexedDB/test/Makefile
|
||||
dom/indexedDB/test/unit/Makefile
|
||||
|
Loading…
Reference in New Issue
Block a user