From ffa8b5024b74ac85770e53f5e0c3c251ba603887 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 22 Sep 2016 23:00:22 -0400 Subject: [PATCH] appId service and removed unnecessary permissions from manifest --- src/background.js | 1 + src/manifest.json | 4 -- src/popup/app/services/backgroundService.js | 3 ++ src/services/appIdService.js | 44 +++++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/services/appIdService.js diff --git a/src/background.js b/src/background.js index d815e17b..539299d2 100644 --- a/src/background.js +++ b/src/background.js @@ -8,6 +8,7 @@ var folderService = new FolderService(cryptoService, userService, apiService); var syncService = new SyncService(siteService, folderService, userService, apiService); var autofillService = new AutofillService(); var passwordGenerationService = new PasswordGenerationService(); +var appIdService = new AppIdService(); function buildContextMenu() { chrome.contextMenus.removeAll(); diff --git a/src/manifest.json b/src/manifest.json index e1554216..2bcde9e2 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -60,13 +60,9 @@ }, "permissions": [ "tabs", - "idle", - "notifications", "contextMenus", "storage", "unlimitedStorage", - "webRequest", - "webRequestBlocking", "http://*/*", "https://*/*" ], diff --git a/src/popup/app/services/backgroundService.js b/src/popup/app/services/backgroundService.js index 2be6403d..872f15bd 100644 --- a/src/popup/app/services/backgroundService.js +++ b/src/popup/app/services/backgroundService.js @@ -33,4 +33,7 @@ }) .factory('utilsService', function () { return chrome.extension.getBackgroundPage().utilsService; + }) + .factory('appIdService', function () { + return chrome.extension.getBackgroundPage().appIdService; }); diff --git a/src/services/appIdService.js b/src/services/appIdService.js new file mode 100644 index 00000000..11dd54e5 --- /dev/null +++ b/src/services/appIdService.js @@ -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); + }); + } +};