diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index e741e0ccb922..f1218a9a8062 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -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); diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 2e9bba80cfd9..99b0c4fadbbe 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -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(); diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index 6411adae027a..42bd2f85d5ed 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -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 diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index ab86fd3a4bb2..46208503d7b3 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -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 diff --git a/dom/Makefile.in b/dom/Makefile.in index 71301c6da298..e8955b4ef4e4 100644 --- a/dom/Makefile.in +++ b/dom/Makefile.in @@ -50,6 +50,7 @@ DIRS += \ battery \ browser-element \ contacts \ + alarm \ devicestorage \ file \ media \ diff --git a/dom/alarm/AlarmsManager.js b/dom/alarm/AlarmsManager.js new file mode 100644 index 000000000000..3052fd139773 --- /dev/null +++ b/dom/alarm/AlarmsManager.js @@ -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]) diff --git a/dom/alarm/AlarmsManager.manifest b/dom/alarm/AlarmsManager.manifest new file mode 100644 index 000000000000..18cd0293fbfd --- /dev/null +++ b/dom/alarm/AlarmsManager.manifest @@ -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 diff --git a/dom/alarm/Makefile.in b/dom/alarm/Makefile.in new file mode 100644 index 000000000000..e11c90e9cb09 --- /dev/null +++ b/dom/alarm/Makefile.in @@ -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 diff --git a/dom/alarm/nsIDOMAlarmsManager.idl b/dom/alarm/nsIDOMAlarmsManager.idl new file mode 100644 index 000000000000..4ef68691d1ea --- /dev/null +++ b/dom/alarm/nsIDOMAlarmsManager.idl @@ -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); +}; diff --git a/dom/alarm/test/Makefile.in b/dom/alarm/test/Makefile.in new file mode 100644 index 000000000000..b58809903d9b --- /dev/null +++ b/dom/alarm/test/Makefile.in @@ -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) diff --git a/dom/alarm/test/test_alarm_non_permitted_app.html b/dom/alarm/test/test_alarm_non_permitted_app.html new file mode 100644 index 000000000000..1d6409e5f149 --- /dev/null +++ b/dom/alarm/test/test_alarm_non_permitted_app.html @@ -0,0 +1,35 @@ + + + + Test Non-Permitted Application for Alarm API + + + + +

+ +
+
+
+ + diff --git a/dom/alarm/test/test_alarm_permitted_app.html b/dom/alarm/test/test_alarm_permitted_app.html new file mode 100644 index 000000000000..25d7f83ca985 --- /dev/null +++ b/dom/alarm/test/test_alarm_permitted_app.html @@ -0,0 +1,38 @@ + + + + Test Permitted Application for Alarm API + + + + +

+ +
+
+
+ + diff --git a/dom/dom-config.mk b/dom/dom-config.mk index 1d4cdab4075a..f91f51a1ea04 100644 --- a/dom/dom-config.mk +++ b/dom/dom-config.mk @@ -12,6 +12,7 @@ DOM_SRCDIRS = \ dom/settings \ dom/sms/src \ dom/contacts \ + dom/alarm \ dom/src/events \ dom/src/storage \ dom/src/offline \ diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 26d7621fea51..a38bf368d80b 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -89,6 +89,7 @@ var interfaceNamesInGlobalScope = "WebGLExtensionLoseContext", "CanvasRenderingContext2D", "SVGPathSegLinetoVerticalRel", + "MozAlarmsManager", "MozPowerManager", "SVGElement", "GeoPositionError", diff --git a/layout/build/Makefile.in b/layout/build/Makefile.in index 9daa83aaee69..1cf716c8c0fb 100644 --- a/layout/build/Makefile.in +++ b/layout/build/Makefile.in @@ -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) \ diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 0c9e8a25e4bf..876c01d888a8 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -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); diff --git a/toolkit/toolkit-makefiles.sh b/toolkit/toolkit-makefiles.sh index 15bcdb761106..c623bd84a047 100644 --- a/toolkit/toolkit-makefiles.sh +++ b/toolkit/toolkit-makefiles.sh @@ -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