1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5var PERMISSIONS = {origins: ['http://api.stackoverflow.com/']}; 6var YES = 'ENABLED'; 7var NO = 'DISABLED'; 8 9var $status = document.querySelector('#status'); 10chrome.permissions.onAdded.addListener(function(permissions) { 11 $status.innerText = YES; 12}); 13chrome.permissions.onRemoved.addListener(function(permissions) { 14 $status.innerText = NO; 15}); 16chrome.permissions.contains(PERMISSIONS, function(contains) { 17 $status.innerText = contains ? YES : NO; 18}); 19 20document.querySelector('button#enable').addEventListener('click', function() { 21 chrome.permissions.contains(PERMISSIONS, function(allowed) { 22 if (allowed) { 23 alert('You already have SO host permission!'); 24 } else { 25 chrome.permissions.request(PERMISSIONS, function(result) { 26 if (result) { 27 console.log('SO host permission granted!' + 28 'Open the browser action again.'); 29 } 30 }); 31 } 32 }); 33}); 34 35document.querySelector('button#disable').addEventListener('click', function() { 36 chrome.permissions.contains(PERMISSIONS, function(allowed) { 37 if (allowed) { 38 chrome.permissions.remove(PERMISSIONS, function(result) { 39 console.log('Revoked SO host permission.'); 40 }); 41 } else { 42 alert('No SO host permission found.'); 43 } 44 }); 45}); 46 47