1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 11:13:46 +00:00

appId service and removed unnecessary permissions from manifest

This commit is contained in:
Kyle Spearrin
2016-09-22 23:00:22 -04:00
parent 6b06772f22
commit ffa8b5024b
4 changed files with 48 additions and 4 deletions

View File

@@ -0,0 +1,44 @@
function AppIdService() {
initAppIdService();
};
function initAppIdService() {
AppIdService.prototype.getAppId = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
makeAndGetAppId('appId');
};
AppIdService.prototype.getAnonymousAppId = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
makeAndGetAppId('anonymousAppId');
};
function makeAndGetAppId(key) {
chrome.storage.local.get(key, function (obj) {
if (obj && obj[key]) {
callback(obj[key]);
return;
}
var setObj = {};
setObj[key] = newGuid();
chrome.storage.local.set(setObj, function () {
callback(setObj[key]);
});
});
}
// ref: http://stackoverflow.com/a/2117523/1090359
function newGuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
};