Skip to content

Commit

Permalink
v7.47.3
Browse files Browse the repository at this point in the history
  • Loading branch information
cliqz-ci committed Sep 1, 2020
1 parent b041d43 commit 137b543
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v7.47.2
v7.47.3
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browser-core",
"version": "7.47.2",
"version": "7.47.3",
"description": "Cliqz features, shared across products including Cliqz browsers for Windows, Mac, Android and iOS",
"license": "MPL-2.0",
"author": {
Expand Down
17 changes: 15 additions & 2 deletions platforms/webextension/kv-store.es
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import Dexie from '@cliqz-oss/dexie';
import { chrome } from './globals';
import console from '../core/console';
import { toBase64, fromBase64 } from '../core/encoding';
import platform from './platform';

// can we write binary data directly to chrome.storage?
const binaryStorageSupported = platform.isFirefox;
let storage = {};

try {
Expand Down Expand Up @@ -40,7 +44,13 @@ try {
console.error(chrome.runtime.lastError);
reject(chrome.runtime.lastError);
} else if (res[key]) {
resolve(res[key]);
try {
// perform a base64 decode for values we encoded before write (see `set`)
const value = !binaryStorageSupported && key.endsWith('.bin') ? fromBase64(res[key]) : res[key];
resolve(value);
} catch (decodeError) {
reject(decodeError);
}
} else {
reject(new Error(`storage has no value for ${key}`));
}
Expand All @@ -49,8 +59,11 @@ try {
},
set(key, value) {
return new Promise((resolve, reject) => {
// a storage key ending with '.bin' indicates we should treat this as an ArrayBuffer.
// Only Firefox supports directly writing an ArrayBuffer to chrome.storage, so for other
// platforms we use base 64 encoding to safely storage it.
chrome.storage.local.set(
{ [key]: value },
{ [key]: !binaryStorageSupported && key.endsWith('.bin') ? toBase64(value) : value },
() => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
Expand Down

0 comments on commit 137b543

Please sign in to comment.