diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 46cf00d9f1a4..3d02abdf1d9b 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -738,6 +738,14 @@ Services.obs.addObserver(function(subject, topic, data) { shell.sendCustomEvent('mozmemorypressure'); }, 'memory-pressure', false); +let permissionMap = new Map([ + ['unknown', Services.perms.UNKNOWN_ACTION], + ['allow', Services.perms.ALLOW_ACTION], + ['deny', Services.perms.DENY_ACTION], + ['prompt', Services.perms.PROMPT_ACTION], +]); +let permissionMapRev = new Map(Array.from(permissionMap.entries()).reverse()); + var CustomEventManager = { init: function custevt_init() { window.addEventListener("ContentStart", (function(evt) { @@ -783,6 +791,22 @@ var CustomEventManager = { Services.obs.notifyObservers({ wrappedJSObject: shell.contentBrowser }, 'ask-children-to-execute-copypaste-command', detail.cmd); break; + case 'add-permission': + Services.perms.add(Services.io.newURI(detail.uri, null, null), + detail.permissionType, permissionMap.get(detail.permission)); + break; + case 'remove-permission': + Services.perms.remove(Services.io.newURI(detail.uri, null, null), + detail.permissionType); + break; + case 'test-permission': + let result = Services.perms.testExactPermission( + Services.io.newURI(detail.uri, null, null), detail.permissionType); + // Not equal check here because we want to prevent default only if it's not set + if (result !== permissionMapRev.get(detail.permission)) { + evt.preventDefault(); + } + break; } } }