mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-17 15:37:57 +01:00
settings storage on safari. secure storage option.
This commit is contained in:
parent
c6de902901
commit
3e8db9dc36
@ -62,6 +62,7 @@ import { AutofillService as AutofillServiceAbstraction } from '../services/abstr
|
||||
export default class MainBackground {
|
||||
messagingService: MessagingServiceAbstraction;
|
||||
storageService: StorageServiceAbstraction;
|
||||
secureStorageService: StorageServiceAbstraction;
|
||||
i18nService: any;
|
||||
platformUtilsService: PlatformUtilsServiceAbstraction;
|
||||
utilsService: UtilsServiceAbstraction;
|
||||
@ -107,11 +108,11 @@ export default class MainBackground {
|
||||
this.utilsService = new UtilsService();
|
||||
this.platformUtilsService = new BrowserPlatformUtilsService();
|
||||
this.messagingService = new BrowserMessagingService(this.platformUtilsService);
|
||||
this.storageService = new BrowserStorageService(this.platformUtilsService);
|
||||
this.storageService = new BrowserStorageService(this.platformUtilsService, false);
|
||||
this.secureStorageService = new BrowserStorageService(this.platformUtilsService, true);
|
||||
this.i18nService = i18nService(this.platformUtilsService);
|
||||
this.constantsService = new ConstantsService(this.i18nService, this.platformUtilsService);
|
||||
this.cryptoService = new CryptoService(this.storageService,
|
||||
this.storageService);
|
||||
this.cryptoService = new CryptoService(this.storageService, this.secureStorageService);
|
||||
this.tokenService = new TokenService(this.storageService);
|
||||
this.appIdService = new AppIdService(this.storageService);
|
||||
this.apiService = new ApiService(this.tokenService, this.platformUtilsService,
|
||||
|
@ -4,13 +4,21 @@ import {
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
export default class BrowserStorageService implements StorageService {
|
||||
constructor(private platformUtilsService: PlatformUtilsService) {
|
||||
private safariStorageApi: any;
|
||||
private chromeStorageApi: any;
|
||||
|
||||
constructor(private platformUtilsService: PlatformUtilsService, private secure: boolean) {
|
||||
if (platformUtilsService.isSafari()) {
|
||||
this.safariStorageApi = secure ? safari.extension.secureSettings : safari.extension.settings;
|
||||
} else {
|
||||
this.chromeStorageApi = chrome.storage.local;
|
||||
}
|
||||
}
|
||||
|
||||
get<T>(key: string): Promise<T> {
|
||||
if (this.platformUtilsService.isSafari()) {
|
||||
if (this.safariStorageApi) {
|
||||
return new Promise((resolve) => {
|
||||
const json = window.localStorage.getItem(key);
|
||||
const json = this.safariStorageApi.getItem(key);
|
||||
if (json) {
|
||||
const obj = JSON.parse(json);
|
||||
if (obj && (typeof obj[key] !== 'undefined') && obj[key] !== null) {
|
||||
@ -22,7 +30,7 @@ export default class BrowserStorageService implements StorageService {
|
||||
});
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
chrome.storage.local.get(key, (obj: any) => {
|
||||
this.chromeStorageApi.get(key, (obj: any) => {
|
||||
if (obj && (typeof obj[key] !== 'undefined') && obj[key] !== null) {
|
||||
resolve(obj[key] as T);
|
||||
return;
|
||||
@ -35,12 +43,12 @@ export default class BrowserStorageService implements StorageService {
|
||||
|
||||
save(key: string, obj: any): Promise<any> {
|
||||
const keyedObj = { [key]: obj };
|
||||
if (this.platformUtilsService.isSafari()) {
|
||||
window.localStorage.setItem(key, JSON.stringify(keyedObj));
|
||||
if (this.safariStorageApi) {
|
||||
this.safariStorageApi.setItem(key, JSON.stringify(keyedObj));
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
chrome.storage.local.set(keyedObj, () => {
|
||||
this.chromeStorageApi.set(keyedObj, () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@ -48,12 +56,12 @@ export default class BrowserStorageService implements StorageService {
|
||||
}
|
||||
|
||||
remove(key: string): Promise<any> {
|
||||
if (this.platformUtilsService.isSafari()) {
|
||||
window.localStorage.removeItem(key);
|
||||
if (this.safariStorageApi) {
|
||||
this.safariStorageApi.removeItem(key);
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
chrome.storage.local.remove(key, () => {
|
||||
this.chromeStorageApi.remove(key, () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user