Files
firefox/mobile/android/modules/RuntimePermissions.jsm
T
brainbreaker 324cc6c216 Bug 1271570 - Ask for storage permission when accessing file:// uris; r=sebastian
This commit adds a check for not prompting the user in case
 the permissions have already been granted for accessing
 file:// uris

MozReview-Commit-ID: A62AUqqTJSb
2017-03-29 00:43:43 +05:30

61 lines
2.0 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
this.EXPORTED_SYMBOLS = ["RuntimePermissions"];
Cu.import("resource://gre/modules/Services.jsm");
// See: http://developer.android.com/reference/android/Manifest.permission.html
const CAMERA = "android.permission.CAMERA";
const WRITE_EXTERNAL_STORAGE = "android.permission.WRITE_EXTERNAL_STORAGE";
const RECORD_AUDIO = "android.permission.RECORD_AUDIO";
var RuntimePermissions = {
CAMERA: CAMERA,
RECORD_AUDIO: RECORD_AUDIO,
WRITE_EXTERNAL_STORAGE: WRITE_EXTERNAL_STORAGE,
/**
* Check whether the permissions have been granted or not. If needed prompt the user to accept the permissions.
*
* @returns A promise resolving to true if all the permissions have been granted or false if any of the
* permissions have been denied.
*/
waitForPermissions: function(permission) {
let permissions = [].concat(permission);
let msg = {
type: 'RuntimePermissions:Check',
permissions: permissions,
shouldPrompt: true
};
let window = Services.wm.getMostRecentWindow("navigator:browser");
return window.WindowEventDispatcher.sendRequestForResult(msg);
},
/**
* Check whether the specified permissions have already been granted or not.
*
* @returns A promise resolving to true if all the permissions are already granted or false if any of the
* permissions are not granted.
*/
checkPermissions: function(permission) {
let permissions = [].concat(permission);
let msg = {
type: 'RuntimePermissions:Check',
permissions: permissions,
shouldPrompt: false
};
let window = Services.wm.getMostRecentWindow("navigator:browser");
return window.WindowEventDispatcher.sendRequestForResult(msg);
}
};