Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6861 from AntonioMA/master

New Test Application for the PermissionSettings API
  • Loading branch information...
commit 944c91bcb4c1cd3ebf4ff788231efff6a79ae044 2 parents 811177b + e62fb82
@arcturus arcturus authored
View
23 test_apps/testpermission/index.html
@@ -0,0 +1,23 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+
+ <!-- Specific style -->
+ <link rel="stylesheet" type="text/css" href="style/lists.css"/>
+
+ <script src="js/permissiontest.js"></script>
+ <title> Testing Permissions </title>
+ </head>
+ <body>
+ <div id="full">
+ <div id="main">
+ <h1>It works!</h1>
+ <p>Or at least the app loaded. Lets see below what happens.</p>
+ </div>
+ <div id="addContent">
+ </div>
+ </div>
+
+ </body>
+</html>
View
136 test_apps/testpermission/js/permissiontest.js
@@ -0,0 +1,136 @@
+"use strict";
+
+
+//////////////////////////////////////////////////////////////////////////////
+// This exist so I don't have to keep remembering how to do it...
+//////////////////////////////////////////////////////////////////////////////
+function addText(elem,text) {
+ elem.appendChild(document.createTextNode(text));
+}
+
+function createElementAt(mainBody,type,id,optionalText,before) {
+ var elem=document.createElement(type);
+ elem.setAttribute("id",id);
+ if (!before) {
+ mainBody.appendChild(elem);
+ } else {
+ mainBody.insertBefore(elem,before);
+ }
+ if (optionalText) {
+ addText(elem,optionalText);
+ }
+ return elem;
+}
+//////////////////////////////////////////////////////////////////////////////
+// End of useful DOM manipulation...
+//////////////////////////////////////////////////////////////////////////////
+
+function testPermissions(outputElement) {
+ var _permissions = [
+ 'power', 'sms', 'contacts', 'telephony', 'browser',
+ 'mozApps', 'mobileconnection', 'mozFM', 'systemXHR', 'background',
+ 'backgroundservice', 'settings', 'alarm', 'camera', 'fmradio', 'voicemail',
+ 'wifi-manage', 'wifi', 'networkstats-manage', 'geolocation',
+ 'webapps-manage', 'permissions', 'desktop-notification',
+ 'device-storage:pictures', 'device-storage:music', 'device-storage:videos',
+ 'device-storage:apps', 'alarms', 'attention', 'content-camera',
+ 'tcp-socket', 'bluetooth', 'storage', 'time', 'networkstats-manager',
+ 'idle', 'network-events', 'embed-apps',
+ // Just don't.
+ 'deprecated-hwvideo'
+ ];
+
+ var mozPerms = navigator.mozPermissionSettings;
+ if (!mozPerms) {
+ createElementAt(outputElement,"p","","I can't access mozPermissionSettings!");
+ return;
+ }
+
+ navigator.mozApps.mgmt.getAll().onsuccess = function mozAppGotAll(evt) {
+ var apps = evt.target.result;
+
+ apps.sort(function alphabeticalSort(app, otherApp) {
+ return app.manifest.name > otherApp.manifest.name;
+ });
+
+
+ // We display permissions declared in the manifest
+ // and any other granted permission. I should see how forEach works some time.
+ // Some OTHER time
+ createElementAt(outputElement,"p","",
+ "List of application permissions below. "+
+ "Click on any permission to toggle its value.");
+ createElementAt(outputElement,"p","",
+ "NOTE: Trying to toggle a implicit permission"+
+ " should not work!");
+
+ var ulApps=createElementAt(outputElement,"ul");
+
+ for (var i=0; i<apps.length; i++) {
+ var app=apps[i];
+ var liApp=createElementAt(ulApps,"li");
+ liApp.innerHTML="<b>"+app.manifest.name+"</b>";
+ var ulPerm=createElementAt(ulApps,"ul");
+ ulPerm.hidden=true;
+
+ liApp.onclick=function () {
+ arguments[0].hidden=!arguments[0].hidden;
+ }.bind(undefined,ulPerm);
+
+ for (var j=0; j<_permissions.length; j++) {
+ var perm=_permissions[j];
+ var value = mozPerms.get(perm, app.manifestURL, app.origin, false);
+ if (value !== "unknown") {
+ var explicit =
+ mozPerms.isExplicit(perm, app.manifestURL, app.origin, false) ?
+ "/explicit" :"/implicit";
+ var printValue = value + explicit;
+ var li=createElementAt(ulPerm,"li",app.manifest.name+":"+perm,
+ perm +": "+printValue);
+ li.onclick=function() {
+ togglePermission(arguments[0], arguments[1], arguments[2]);
+ }.bind(undefined, app, perm, li);
+ }
+ }
+ }
+ };
+}
+
+function togglePermission(app,perm,item) {
+
+ var mozPerms = navigator.mozPermissionSettings;
+ var value = mozPerms.get(perm, app.manifestURL, app.origin, false);
+
+ console.log("Trying to change permission for "+app.manifest.name+
+ " perm: "+perm+" Current Value: "+value);
+
+ var newPerm="deny";
+ switch ( value ) {
+ case "deny":
+ newPerm = "prompt";
+ break;
+ case "prompt":
+ newPerm = "allow";
+ break;
+ }
+ mozPerms.set(perm, newPerm, app.manifestURL, app.origin, false);
+
+ // Nasty nasty suspicion
+ setTimeout(function () {
+ var newValue = mozPerms.get(perm, app.manifestURL, app.origin, false);
+ var explicit =
+ mozPerms.isExplicit(perm, app.manifestURL, app.origin, false) ?
+ "/explicit" :"/implicit";
+ console.log("After changing permission for "+app.manifest.name+
+ " perm: "+perm+" New Value: "+newValue+explicit);
+ item.innerHTML=perm+": "+newValue+explicit;
+ },1000);
+
+
+}
+
+window.onload=function () {
+ var outputElement=document.getElementById("addContent");
+ testPermissions(outputElement);
+}
+
View
22 test_apps/testpermission/manifest.webapp
@@ -0,0 +1,22 @@
+{
+ "name": "TestPermissions",
+ "description": "Permissions Test",
+ "launch_path": "/index.html",
+ "orientation": "portrait-primary",
+ "type": "certified",
+ "fullscreen": true,
+ "developer": {
+ "name": "amac"
+ },
+ "permissions": {
+ "webapps-manage":{},
+ "permissions": {}
+ },
+ "locales": {
+ "en-US": {
+ "name": "Permissions Test",
+ "description": "Permissions Tests"
+ }
+ },
+ "default_locale": "en-US"
+}
View
347 test_apps/testpermission/style/lists.css
@@ -0,0 +1,347 @@
+/**
+ * Table View
+ * line height = 6rem, border included
+ */
+
+ul {
+ margin: 0;
+ padding: 0;
+ overflow: hidden;
+ list-style: none;
+}
+
+ul li {
+ position: relative;
+ border-bottom: 0.1rem solid #e6e6e3;
+ color: #000;
+ -moz-box-sizing: border-box;
+ min-height: 6rem;
+}
+
+ul li.active,
+ul li:active {
+ background-color: #ddf;
+ color: #222;
+}
+
+ul li > a,
+ul li > span {
+ display: block;
+ text-decoration: none;
+ outline: 0;
+ color: #000;
+ -moz-box-sizing: border-box;
+ height: 6rem;
+ font-size: 1.9rem;
+ line-height: 6rem;
+ padding: 0 3rem;
+}
+
+ul li.disabled > a {
+ color: gray;
+ pointer-events: none;
+}
+
+/* description + value on the same line */
+ul li > a span {
+ position: absolute;
+ right: 2rem;
+ color: #505859;
+}
+
+/* text ellipsis */
+ul li > * {
+ display: block;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+/* sublines */
+ul li > small {
+ position: absolute;
+ left: 3rem;
+ right: 3rem;
+ top: 50%;
+ padding-top: 0.4rem;
+ font-size: 1.4rem;
+ color: #505859;
+ /* click/tap events should be caught by the <a> element below the <small> */
+ pointer-events: none;
+}
+
+ul li > label:not([for]) + small {
+ right: 6rem;
+}
+
+/* required for empty elements like Bluetooth */
+ul li > small:not(:empty) + a {
+ line-height: 4.4rem;
+}
+
+
+/******************************************************************************
+ * Boolean inputs
+ */
+
+ul li button,
+ul li a[role="button"] {
+ position: relative;
+ top: 1rem;
+ left: 2rem;
+ font-size: 1.7rem;
+ line-height: 1em;
+ width: calc(100% - 5rem);
+ height: calc(100% - 2rem);
+}
+
+/* custom styles for boolean inputs (see /shared/style/switches.css) */
+ul li label {
+ text-transform: none;
+}
+
+ul li > label:not([for]) {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+}
+
+ul li > label:not([for]) > span,
+ul li > label:not([for]) > input[data-type="switch"] + span {
+ left: auto;
+ right: 2rem;
+}
+
+ul li > label:not([for]) ~ a {
+ padding-right: 6rem;
+}
+
+
+/******************************************************************************
+ * Text inputs
+ */
+
+ul li p {
+ font-size: 1.9rem;
+ font-weight: 400;
+ margin: 0;
+ padding: 1rem 3rem;
+}
+
+ul li p + label:not([for]) {
+ top: 2.5rem;
+ height: calc(100% - 2.5rem);
+}
+
+ul li p + input[type="text"],
+ul li p + input[type="password"] {
+ width: calc(100% - 6rem);
+ margin: -1rem auto 1rem;
+}
+
+
+/******************************************************************************
+ * Range inputs
+ */
+
+ul li > label input[type="range"] {
+ width: 80%;
+ width: calc(100% - 6rem);
+ margin-left: 3rem;
+ margin-top: 2rem;
+}
+
+/**
+ * Polyfill until input[type=range] is natively supported by Gecko:
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=344618
+ *
+ * The JS polyfill transforms this:
+ *
+ * <label>
+ * <input type="range" value="60" />
+ * </label>
+ *
+ * into this:
+ *
+ * <label class="bug344618_polyfill">
+ * <div>
+ * <span style="width: 60%"></span>
+ * <span style="left: 60%"></span>
+ * </div>
+ * <input type="range" />
+ * </label>
+ */
+
+ul li > label.bug344618_polyfill input {
+ display: none;
+}
+
+/* slider */
+
+ul li > label.bug344618_polyfill div:before {
+ content: "";
+ position: absolute;
+ top: calc(50% - 0.1rem);
+ left: 0;
+ right: 0;
+ height: 0.1rem;
+ border-top: 0.1rem solid #7e7e7e;
+}
+
+ul li > label.bug344618_polyfill div {
+ position: relative;
+ top: calc(50% - 1.5rem);
+ left: 7.5rem;
+ right: 7.5rem;
+ height: 3rem;
+ width: calc(100% - 15rem);
+}
+
+/* fill */
+
+ul li > label.bug344618_polyfill div span:first-child {
+ position: absolute;
+ display: block;
+ top: calc(50% - 0.15rem);
+ width: 4rem;
+ height: 0.3rem;
+ background: #01c5ed;
+}
+
+/* throbber */
+
+ul li > label.bug344618_polyfill div span:last-child {
+ position: absolute;
+ top: 50%;
+ margin: -1.5rem 0 0 -1.5rem;
+ display: block;
+ width: 2.8rem;
+ height: 2.8rem;
+ border: solid 0.1rem transparent;
+ border-radius: 3rem;
+ transition: border 0.15s ease;
+ -moz-box-sizing: border-box;
+ background: url(images/range_thumb.png) no-repeat 50% 50%;
+}
+
+ul li > label.bug344618_polyfill div span:last-child:active {
+ border: solid 0.4rem #01c5ed;
+}
+
+
+/******************************************************************************
+ * Select boxes
+ */
+
+ul li select {
+ font-size: 1.9rem;
+ height: 3rem;
+ line-height: 3rem;
+ text-align: center;
+}
+
+/* half-width select boxes */
+ul li span select {
+ display: inline-block;
+ position: absolute;
+ top: 1.5rem;
+ right: 3rem;
+ width: calc(50% - 2rem);
+}
+
+/* full-width select boxes */
+ul li p + select {
+ display: block;
+ width: calc(100% - 15rem);
+ margin: -1rem 3rem 1rem 12rem;
+}
+
+
+/******************************************************************************
+ * Progress, Meter
+ */
+
+ul li progress, ul li meter {
+ display: block;
+ width: calc(100% - 6rem);
+ height: 3rem;
+ margin: 2.5rem auto;
+}
+
+
+/******************************************************************************
+ * Definition lists
+ */
+
+dl > * {
+ font-size: 1.7em;
+}
+
+dl dt {
+ padding-left: 3rem;
+ font-weight: 500;
+ border-bottom: 0.1rem solid black;
+}
+
+dl dd {
+ margin: 0;
+ padding: 1rem 3rem;
+ border-bottom: 0.1rem solid #e6e6e3; /* same as "ul li" */
+}
+
+
+/******************************************************************************
+ * Right-to-Left layout
+ */
+
+/* definition lists */
+html[dir="rtl"] dl dt {
+ padding-left: inherit;
+ padding-right: 3rem;
+}
+
+/* half-width select boxes */
+html[dir="rtl"] ul li span select {
+ left: 3rem;
+ right: inherit;
+}
+
+/* full-width select boxes */
+html[dir="rtl"] ul li p + select {
+ margin: -1rem 12rem 1rem 3rem;
+}
+
+/* boolean inputs */
+
+html[dir="rtl"] ul li button,
+html[dir="rtl"] ul li a[role="button"] {
+ left: inherit;
+ right: 2rem;
+}
+
+html[dir="rtl"] ul li > label:not([for]) > span,
+html[dir="rtl"] ul li > label:not([for]) > input[data-type="switch"] + span {
+ left: 4rem; /* XXX we use "right: 2rem" for LTR layouts... */
+ right: inherit;
+}
+
+html[dir="rtl"] ul li > label:not([for]) ~ a {
+ padding-left: 6rem;
+ padding-right: 3rem;
+}
+
+/* description + value on the same line */
+html[dir="rtl"] ul li > a span {
+ left: 2rem;
+ right: inherit;
+}
+
+/* main list items */
+html[dir="rtl"] ul li > a,
+html[dir="rtl"] ul li > span {
+ padding-left: inherit;
+ padding-right: 3rem;
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.