]> git.wh0rd.org - chrome-ext/web-power-switch.git/blobdiff - popup.js
add a permission check to display a helpful message to the user
[chrome-ext/web-power-switch.git] / popup.js
index 640aa5bb0c03ea23440fabdb54a3e2351106cec8..ee8659a379a048c2c4eb4742bd7ef5af6c7b942c 100644 (file)
--- a/popup.js
+++ b/popup.js
@@ -166,6 +166,15 @@ document.addEventListener('DOMContentLoaded', function() {
                url_base = settings['url'] || settings_defaults['url'];
                user = settings['user'] || settings_defaults['user'];
                pass = settings['pass'] || settings_defaults['pass'];
-               fetchpage('index.htm', initpopup);
+               chrome.permissions.contains({
+                       origins: [url_base + '/*']
+               }, function(granted) {
+                       if (granted)
+                               fetchpage('index.htm', initpopup);
+                       else
+                               setstatus('Missing permissions;<br>please visit the ' +
+                                         '<a href="' + chrome.extension.getURL('options.html') + '" target=_blank>settings page</a>' +
+                                         '<br>to grant access.');
+               });
        });
 });