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 {
|
export default class MainBackground {
|
||||||
messagingService: MessagingServiceAbstraction;
|
messagingService: MessagingServiceAbstraction;
|
||||||
storageService: StorageServiceAbstraction;
|
storageService: StorageServiceAbstraction;
|
||||||
|
secureStorageService: StorageServiceAbstraction;
|
||||||
i18nService: any;
|
i18nService: any;
|
||||||
platformUtilsService: PlatformUtilsServiceAbstraction;
|
platformUtilsService: PlatformUtilsServiceAbstraction;
|
||||||
utilsService: UtilsServiceAbstraction;
|
utilsService: UtilsServiceAbstraction;
|
||||||
@ -107,11 +108,11 @@ export default class MainBackground {
|
|||||||
this.utilsService = new UtilsService();
|
this.utilsService = new UtilsService();
|
||||||
this.platformUtilsService = new BrowserPlatformUtilsService();
|
this.platformUtilsService = new BrowserPlatformUtilsService();
|
||||||
this.messagingService = new BrowserMessagingService(this.platformUtilsService);
|
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.i18nService = i18nService(this.platformUtilsService);
|
||||||
this.constantsService = new ConstantsService(this.i18nService, this.platformUtilsService);
|
this.constantsService = new ConstantsService(this.i18nService, this.platformUtilsService);
|
||||||
this.cryptoService = new CryptoService(this.storageService,
|
this.cryptoService = new CryptoService(this.storageService, this.secureStorageService);
|
||||||
this.storageService);
|
|
||||||
this.tokenService = new TokenService(this.storageService);
|
this.tokenService = new TokenService(this.storageService);
|
||||||
this.appIdService = new AppIdService(this.storageService);
|
this.appIdService = new AppIdService(this.storageService);
|
||||||
this.apiService = new ApiService(this.tokenService, this.platformUtilsService,
|
this.apiService = new ApiService(this.tokenService, this.platformUtilsService,
|
||||||
|
@ -4,13 +4,21 @@ import {
|
|||||||
} from 'jslib/abstractions';
|
} from 'jslib/abstractions';
|
||||||
|
|
||||||
export default class BrowserStorageService implements StorageService {
|
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> {
|
get<T>(key: string): Promise<T> {
|
||||||
if (this.platformUtilsService.isSafari()) {
|
if (this.safariStorageApi) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const json = window.localStorage.getItem(key);
|
const json = this.safariStorageApi.getItem(key);
|
||||||
if (json) {
|
if (json) {
|
||||||
const obj = JSON.parse(json);
|
const obj = JSON.parse(json);
|
||||||
if (obj && (typeof obj[key] !== 'undefined') && obj[key] !== null) {
|
if (obj && (typeof obj[key] !== 'undefined') && obj[key] !== null) {
|
||||||
@ -22,7 +30,7 @@ export default class BrowserStorageService implements StorageService {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve) => {
|
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) {
|
if (obj && (typeof obj[key] !== 'undefined') && obj[key] !== null) {
|
||||||
resolve(obj[key] as T);
|
resolve(obj[key] as T);
|
||||||
return;
|
return;
|
||||||
@ -35,12 +43,12 @@ export default class BrowserStorageService implements StorageService {
|
|||||||
|
|
||||||
save(key: string, obj: any): Promise<any> {
|
save(key: string, obj: any): Promise<any> {
|
||||||
const keyedObj = { [key]: obj };
|
const keyedObj = { [key]: obj };
|
||||||
if (this.platformUtilsService.isSafari()) {
|
if (this.safariStorageApi) {
|
||||||
window.localStorage.setItem(key, JSON.stringify(keyedObj));
|
this.safariStorageApi.setItem(key, JSON.stringify(keyedObj));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
chrome.storage.local.set(keyedObj, () => {
|
this.chromeStorageApi.set(keyedObj, () => {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -48,12 +56,12 @@ export default class BrowserStorageService implements StorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remove(key: string): Promise<any> {
|
remove(key: string): Promise<any> {
|
||||||
if (this.platformUtilsService.isSafari()) {
|
if (this.safariStorageApi) {
|
||||||
window.localStorage.removeItem(key);
|
this.safariStorageApi.removeItem(key);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
chrome.storage.local.remove(key, () => {
|
this.chromeStorageApi.remove(key, () => {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user