Simplify permission handling in widgets and services

Change-Id: I5050b0dad19f84eaf62e051978f0abc5c6a22800
diff --git a/dev/js/src/plugin/service.js b/dev/js/src/plugin/service.js
index 4029349..23271e5 100644
--- a/dev/js/src/plugin/service.js
+++ b/dev/js/src/plugin/service.js
@@ -2,18 +2,26 @@
   "use strict";
 
   return {
-    create : function (name, src, id) {
-      return Object.create(this)._init(name, src, id);
+    create : function (data) {
+      return Object.create(this)._init(data);
     },
 
     // Initialize service
-    _init : function (name, src, id) {
-      if (!name || !src || !id)
+    _init : function (data) {
+      if (!data || !data["name"] || !data["src"] || !data["id"])
         throw Error("Service not well defined");
-      this.name = name;
-      this.src = src;
-      this.id = id;
+
+      this.name = data["name"];
+      this.src = data["src"];
+      this.id = data["id"];
       this._perm = new Set();
+
+      let perm = data["permissions"];
+      if (perm && Array.isArray(perm)) {
+        perm.forEach(
+          p => this._perm.add(p)
+        );
+      };
       
       // There is no close method defined yet
       if (!this.close) {
@@ -43,7 +51,7 @@
       e.setAttribute('allowTransparency',"true");
       e.setAttribute('frameborder', 0);
       // Allow forms in Plugins
-      e.setAttribute('sandbox', this._permString());
+      e.setAttribute('sandbox', Array.from(this._perm).sort().join(" "));
       e.style.height = '0px';
       e.setAttribute('name', this.id);
       e.setAttribute('src', this.src);
@@ -52,25 +60,6 @@
       return e;
     },
 
-    allow : function (permission) {
-      if (Array.isArray(permission)) {
-        permission.forEach(
-          p => this._perm.add(p)
-        );
-      }
-      else {
-        this._perm.add(permission);
-      };
-
-      if (this._load) {
-        this._load.setAttribute('sandbox', this._permString());
-      }
-    },
-
-    _permString : function () {
-      return Array.from(this._perm).sort().join(" ");
-    },
-
     /**
      * Send a message to the embedded service.
      */