Skip to content

Commit

Permalink
Merge pull request gorhill#17 from gorhill/master
Browse files Browse the repository at this point in the history
Re-sync with uBo master
  • Loading branch information
pes10k authored Aug 22, 2020
2 parents f833032 + 3d048c9 commit 8f15500
Show file tree
Hide file tree
Showing 22 changed files with 625 additions and 288 deletions.
8 changes: 8 additions & 0 deletions assets/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
"assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat"
]
},
"ublock-badlists": {
"content": "internal",
"updateAfter": 13,
"contentURL": [
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badlists.txt",
"assets/ublock/badlists.txt"
]
},
"ublock-filters": {
"content": "filters",
"group": "default",
Expand Down
2 changes: 1 addition & 1 deletion assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@
if ( prevGetter !== undefined ) {
prevGetter();
}
return handler.getter();
return handler.getter(); // cValue
},
set(a) {
if ( prevSetter !== undefined ) {
Expand Down
6 changes: 3 additions & 3 deletions dist/firefox/updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"uBlock0@raymondhill.net": {
"updates": [
{
"version": "1.29.1.0",
"version": "1.29.3.1",
"browser_specific_settings": { "gecko": { "strict_min_version": "55" } },
"update_info_url": "https://github.com/gorhill/uBlock/releases/tag/1.29.1b0",
"update_link": "https://github.com/gorhill/uBlock/releases/download/1.29.1b0/uBlock0_1.29.1b0.firefox.signed.xpi"
"update_info_url": "https://github.com/gorhill/uBlock/releases/tag/1.29.3b1",
"update_link": "https://github.com/gorhill/uBlock/releases/download/1.29.3b1/uBlock0_1.29.3b1.firefox.signed.xpi"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion dist/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.29.1.0
1.29.3.1
100 changes: 71 additions & 29 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -1540,10 +1540,10 @@ vAPI.cloud = (( ) => {
// good thing given chrome.storage.sync.MAX_WRITE_OPERATIONS_PER_MINUTE
// and chrome.storage.sync.MAX_WRITE_OPERATIONS_PER_HOUR.

const getCoarseChunkCount = async function(dataKey) {
const getCoarseChunkCount = async function(datakey) {
const keys = {};
for ( let i = 0; i < maxChunkCountPerItem; i += 16 ) {
keys[dataKey + i.toString()] = '';
keys[datakey + i.toString()] = '';
}
let bin;
try {
Expand All @@ -1553,13 +1553,13 @@ vAPI.cloud = (( ) => {
}
let chunkCount = 0;
for ( let i = 0; i < maxChunkCountPerItem; i += 16 ) {
if ( bin[dataKey + i.toString()] === '' ) { break; }
if ( bin[datakey + i.toString()] === '' ) { break; }
chunkCount = i + 16;
}
return chunkCount;
};

const deleteChunks = function(dataKey, start) {
const deleteChunks = async function(datakey, start) {
const keys = [];

// No point in deleting more than:
Expand All @@ -1570,54 +1570,70 @@ vAPI.cloud = (( ) => {
Math.ceil(maxStorageSize / maxChunkSize)
);
for ( let i = start; i < n; i++ ) {
keys.push(dataKey + i.toString());
keys.push(datakey + i.toString());
}
if ( keys.length !== 0 ) {
webext.storage.sync.remove(keys);
}
};

const push = async function(dataKey, data) {
let bin = {
'source': options.deviceName || options.defaultDeviceName,
'tstamp': Date.now(),
'data': data,
'size': 0
const push = async function(details) {
const { datakey, data, encode } = details;
if (
data === undefined ||
typeof data === 'string' && data === ''
) {
return deleteChunks(datakey, 0);
}
const item = {
source: options.deviceName || options.defaultDeviceName,
tstamp: Date.now(),
data,
};
bin.size = JSON.stringify(bin).length;
const item = JSON.stringify(bin);
const json = JSON.stringify(item);
const encoded = encode instanceof Function
? await encode(json)
: json;

// Chunkify taking into account QUOTA_BYTES_PER_ITEM:
// https://developer.chrome.com/extensions/storage#property-sync
// "The maximum size (in bytes) of each individual item in sync
// "storage, as measured by the JSON stringification of its value
// "plus its key length."
bin = {};
let chunkCount = Math.ceil(item.length / maxChunkSize);
const bin = {};
const chunkCount = Math.ceil(encoded.length / maxChunkSize);
for ( let i = 0; i < chunkCount; i++ ) {
bin[dataKey + i.toString()] = item.substr(i * maxChunkSize, maxChunkSize);
bin[datakey + i.toString()]
= encoded.substr(i * maxChunkSize, maxChunkSize);
}
bin[dataKey + chunkCount.toString()] = ''; // Sentinel
bin[datakey + chunkCount.toString()] = ''; // Sentinel

// Remove potentially unused trailing chunks before storing the data,
// this will free storage space which could otherwise cause the push
// operation to fail.
try {
await deleteChunks(datakey, chunkCount);
} catch (reason) {
}

// Push the data to browser-provided cloud storage.
try {
await webext.storage.sync.set(bin);
} catch (reason) {
return String(reason);
}

// Remove potentially unused trailing chunks
deleteChunks(dataKey, chunkCount);
};

const pull = async function(dataKey) {
const pull = async function(details) {
const { datakey, decode } = details;

const result = await getCoarseChunkCount(dataKey);
const result = await getCoarseChunkCount(datakey);
if ( typeof result !== 'number' ) {
return result;
}
const chunkKeys = {};
for ( let i = 0; i < result; i++ ) {
chunkKeys[dataKey + i.toString()] = '';
chunkKeys[datakey + i.toString()] = '';
}

let bin;
Expand All @@ -1633,22 +1649,48 @@ vAPI.cloud = (( ) => {
// happen when the number of chunks is a multiple of
// chunkCountPerFetch. Hence why we must also test against
// undefined.
let json = [], jsonSlice;
let encoded = [];
let i = 0;
for (;;) {
jsonSlice = bin[dataKey + i.toString()];
if ( jsonSlice === '' || jsonSlice === undefined ) { break; }
json.push(jsonSlice);
const slice = bin[datakey + i.toString()];
if ( slice === '' || slice === undefined ) { break; }
encoded.push(slice);
i += 1;
}
encoded = encoded.join('');
const json = decode instanceof Function
? await decode(encoded)
: encoded;
let entry = null;
try {
entry = JSON.parse(json.join(''));
entry = JSON.parse(json);
} catch(ex) {
}
return entry;
};

const used = async function(datakey) {
if ( webext.storage.sync.getBytesInUse instanceof Function === false ) {
return;
}
const coarseCount = await getCoarseChunkCount(datakey);
if ( typeof coarseCount !== 'number' ) { return; }
const keys = [];
for ( let i = 0; i < coarseCount; i++ ) {
keys.push(`${datakey}${i}`);
}
let results;
try {
results = await Promise.all([
webext.storage.sync.getBytesInUse(keys),
webext.storage.sync.getBytesInUse(null),
]);
} catch(ex) {
}
if ( Array.isArray(results) === false ) { return; }
return { used: results[0], total: results[1], max: QUOTA_BYTES };
};

const getOptions = function(callback) {
if ( typeof callback !== 'function' ) { return; }
callback(options);
Expand All @@ -1665,7 +1707,7 @@ vAPI.cloud = (( ) => {
getOptions(callback);
};

return { push, pull, getOptions, setOptions };
return { push, pull, used, getOptions, setOptions };
})();

/******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@
"description": "used as a tooltip for error icon beside a list"
},
"1pFormatHint": {
"message": "One filter per line. A filter can be a plain hostname, or an Adblock Plus-compatible filter. Lines prefixed with <code>!</code> will be ignored.",
"message": "One filter per line. A filter can be a plain hostname, or an EasyList-compatible filter. Lines prefixed with <code>!</code> will be ignored.",
"description": "Short information about how to create custom filters"
},
"1pImport": {
Expand Down
2 changes: 1 addition & 1 deletion src/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
<script src="js/html-filtering.js"></script>
<script src="js/hnswitches.js"></script>
<script src="js/ublock.js"></script>
<script src="js/messaging.js"></script>
<script src="js/storage.js"></script>
<script src="js/logger.js"></script>
<script src="js/pagestore.js"></script>
<script src="js/tab.js"></script>
<script src="js/messaging.js"></script>
<script src="js/text-encode.js"></script>
<script src="js/contextmenu.js"></script>
<script src="js/reverselookup.js"></script>
Expand Down
15 changes: 9 additions & 6 deletions src/cloud-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
</head>
<body>
<div id="cloudToolbar">
<button id="cloudPush" type="button" data-i18n-title="cloudPush"><span class="fa-icon">cloud-upload</span></button>
<span id="cloudInfo" data-i18n="cloudNoData"></span>
<button id="cloudPull" type="button" data-i18n-title="cloudPull" disabled><span class="fa-icon">cloud-download</span></button>
<button id="cloudPullAndMerge" type="button" data-i18n-title="cloudPullAndMerge" disabled><span class="fa-icon">cloud-download</span><span class="fa-icon">plus</span></button>
<span id="cloudCog" class="fa-icon">cog</span>
<div>
<button id="cloudPush" type="button" data-i18n-title="cloudPush"><span class="fa-icon">cloud-upload</span></button>
<span id="cloudInfo" data-i18n="cloudNoData"></span>
<button id="cloudPull" type="button" data-i18n-title="cloudPull" disabled><span class="fa-icon">cloud-download</span></button>
<button id="cloudPullAndMerge" type="button" data-i18n-title="cloudPullAndMerge" disabled><span class="fa-icon">cloud-download</span><span class="fa-icon">plus</span></button>
</div>
<div id="cloudCog" class="fa-icon">cog</div>
<div id="cloudOptions">
<label data-i18n="cloudDeviceNamePrompt"></label> <input id="cloudDeviceName" type="text" value=""> <button id="cloudOptionsSubmit" class="vflex" type="button" data-i18n="genericSubmit"></button>
<label data-i18n="cloudDeviceNamePrompt">_<input id="cloudDeviceName" type="text" value=""></label>&nbsp;<button id="cloudOptionsSubmit" type="button" data-i18n="genericSubmit"></button>
</div>
</div>
<div id="cloudError"></div>
<div id="cloudCapacity"><div><div></div></div></div>
</body>
</html>
66 changes: 44 additions & 22 deletions src/css/cloud-ui.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
#cloudWidget {
background: url("../img/cloud.png") hsl(216, 100%, 93%);
border-radius: 3px;
margin: 0.5em 0;
overflow: auto;
padding: 0.5em;
min-width: max-content;
position: relative;
}
#cloudWidget.hide {
display: none;
}
#cloudToolbar > button {
font-size: 180%;
padding: 0 0.25em;
position: relative;
#cloudWidget div {
display: flex;
}
#cloudToolbar {
display: flex;
align-items: flex-start;
flex-wrap: nowrap;
justify-content: space-between;
}
#cloudToolbar > div:first-of-type {
margin: 0.5em;
}
#cloudToolbar button {
padding: 0 0.25em;
position: relative;
}
#cloudToolbar button .fa-icon {
font-size: 180%;
}
#cloudToolbar button[disabled] {
visibility: hidden;
Expand All @@ -28,56 +35,71 @@
margin-left: 0.25em;
}
#cloudPullAndMerge > span:nth-of-type(2) {
font-size: 50%;
font-size: 90%;
position: absolute;
right: 0;
top: 0;
}
#cloudInfo {
color: var(--fg-0-60);
flex-shrink: 0;
font-size: 90%;
margin: 0 1em;
overflow: hidden;
padding: 0;
white-space: pre-line;
}
#cloudCapacity {
background-color: var(--light-gray-30);
height: 4px;
}
#cloudCapacity > div {
background-color: var(--light-gray-60);
}
#cloudCapacity > div > div {
background-color: var(--violet-60);
}
#cloudError {
color: var(--fg-icon-info-lvl-4);
flex-grow: 1;
flex-shrink: 2;
font-size: small;
margin: 0.5em 0.5em 0 0;
margin: 0 0.5em 0.5em 0.5em;
}
#cloudError:empty {
display: none;
}
#cloudToolbar #cloudCog {
#cloudCog {
color: var(--fg-0-50);
cursor: pointer;
fill: var(--fg-0-50);
flex-grow: 1;
font-size: 110%;
justify-content: flex-end;
padding: 0.4em;
}
#cloudToolbar #cloudCog:hover {
#cloudCog:hover {
color: inherit;
fill: inherit;
}
#cloudToolbar #cloudOptions {
#cloudWidget #cloudOptions {
align-items: center;
background-color: var(--default-surface);
border: 1px solid var(--bg-1-border);
bottom: 0;
bottom: 2px;
display: none;
margin: 0.4em;
padding: 0.4em;
font-size: small;
padding: 0.5em;
position: absolute;
right: 0;
right: 2px;
text-align: center;
top: 0;
top: 2px;
z-index: 10;
}
#cloudToolbar #cloudOptions.show {
display: block;
#cloudWidget #cloudOptions label {
display: inline-flex;
flex-direction: column;
align-items: flex-start;
}
#cloudWidget #cloudOptions.show {
display: flex;
white-space: nowrap;
}
Loading

0 comments on commit 8f15500

Please sign in to comment.