- From: laszlo gombos via cvs-syncmail <cvsmail@w3.org>
- Date: Mon, 31 Oct 2011 08:03:54 +0000
- To: public-dap-commits@w3.org
Update of /sources/public/2009/dap/perms In directory hutz:/tmp/cvs-serv6243 Modified Files: FeaturePermissions.html Log Message: Add example - take 1 Index: FeaturePermissions.html =================================================================== RCS file: /sources/public/2009/dap/perms/FeaturePermissions.html,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- FeaturePermissions.html 31 Oct 2011 03:30:51 -0000 1.5 +++ FeaturePermissions.html 31 Oct 2011 08:03:52 -0000 1.6 @@ -77,6 +77,52 @@ <p> Permissions are granted and denied on a per-origin basis. </p> + <p> + The following code illustrates how to query the permission level of a feature: + </p> + <pre class="example sh_javascript_dom"> + // A feature that requires permissions + var featureID = "notifications"; + + // feature is ready to use in the app as the permission has been already granted + var useFeature = false; + + function permissionRequestCallback() { + if (permission == USER_DENIED) { + // Perform the action knowing that permission is already granted + alert("This app will not be able to use " + featureID + "."); + } else if (permission == USER_ALLOWED) { + // Feature is ready to be used as the permission is granted + useFeature = true; + } + } + + // Getting the permission level of the feature identified by 'featureID' + var permission = navigator.permissionLevel(featureID); + + if (permission == DEFAULT_DENIED) { + // Indicate to the user that allowing the feature will result in a better experience + alert("Enabling " + featureID + " will enable functionality XXX"); + + // Optionally the app can decide at any time to request a permission for the feature + navigator.requestPermission(featureID, permissionRequestCallback()); + } + + if (permission == DEFAULT_ALLOWED || permission == USER_ALLOWED) { + // Feature is ready to be used as the permission is granted + useFeature = true; + } else if (permission == DEFAULT_DENIED) { + // Proceed without using functionality that requires permission until the user responds to the permission request + } + + // Main application logic + if (useFeature) { + useFeature(); + } else { + // Limited functionality as the feature is not allowed to be used + doNotUseFeature(); + } + </pre> </section> <section id='idl-NavigatorPermissions'>
Received on Monday, 31 October 2011 08:03:58 UTC