Skip to content

Commit 8f15500

Browse files
authored
Merge pull request gorhill#17 from gorhill/master
Re-sync with uBo master
2 parents f833032 + 3d048c9 commit 8f15500

22 files changed

Lines changed: 625 additions & 288 deletions

assets/assets.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
"assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat"
1717
]
1818
},
19+
"ublock-badlists": {
20+
"content": "internal",
21+
"updateAfter": 13,
22+
"contentURL": [
23+
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badlists.txt",
24+
"assets/ublock/badlists.txt"
25+
]
26+
},
1927
"ublock-filters": {
2028
"content": "filters",
2129
"group": "default",

assets/resources/scriptlets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@
643643
if ( prevGetter !== undefined ) {
644644
prevGetter();
645645
}
646-
return handler.getter();
646+
return handler.getter(); // cValue
647647
},
648648
set(a) {
649649
if ( prevSetter !== undefined ) {

dist/firefox/updates.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"uBlock0@raymondhill.net": {
44
"updates": [
55
{
6-
"version": "1.29.1.0",
6+
"version": "1.29.3.1",
77
"browser_specific_settings": { "gecko": { "strict_min_version": "55" } },
8-
"update_info_url": "https://github.com/gorhill/uBlock/releases/tag/1.29.1b0",
9-
"update_link": "https://github.com/gorhill/uBlock/releases/download/1.29.1b0/uBlock0_1.29.1b0.firefox.signed.xpi"
8+
"update_info_url": "https://github.com/gorhill/uBlock/releases/tag/1.29.3b1",
9+
"update_link": "https://github.com/gorhill/uBlock/releases/download/1.29.3b1/uBlock0_1.29.3b1.firefox.signed.xpi"
1010
}
1111
]
1212
}

dist/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.29.1.0
1+
1.29.3.1

platform/chromium/vapi-background.js

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,10 +1540,10 @@ vAPI.cloud = (( ) => {
15401540
// good thing given chrome.storage.sync.MAX_WRITE_OPERATIONS_PER_MINUTE
15411541
// and chrome.storage.sync.MAX_WRITE_OPERATIONS_PER_HOUR.
15421542

1543-
const getCoarseChunkCount = async function(dataKey) {
1543+
const getCoarseChunkCount = async function(datakey) {
15441544
const keys = {};
15451545
for ( let i = 0; i < maxChunkCountPerItem; i += 16 ) {
1546-
keys[dataKey + i.toString()] = '';
1546+
keys[datakey + i.toString()] = '';
15471547
}
15481548
let bin;
15491549
try {
@@ -1553,13 +1553,13 @@ vAPI.cloud = (( ) => {
15531553
}
15541554
let chunkCount = 0;
15551555
for ( let i = 0; i < maxChunkCountPerItem; i += 16 ) {
1556-
if ( bin[dataKey + i.toString()] === '' ) { break; }
1556+
if ( bin[datakey + i.toString()] === '' ) { break; }
15571557
chunkCount = i + 16;
15581558
}
15591559
return chunkCount;
15601560
};
15611561

1562-
const deleteChunks = function(dataKey, start) {
1562+
const deleteChunks = async function(datakey, start) {
15631563
const keys = [];
15641564

15651565
// No point in deleting more than:
@@ -1570,54 +1570,70 @@ vAPI.cloud = (( ) => {
15701570
Math.ceil(maxStorageSize / maxChunkSize)
15711571
);
15721572
for ( let i = start; i < n; i++ ) {
1573-
keys.push(dataKey + i.toString());
1573+
keys.push(datakey + i.toString());
15741574
}
15751575
if ( keys.length !== 0 ) {
15761576
webext.storage.sync.remove(keys);
15771577
}
15781578
};
15791579

1580-
const push = async function(dataKey, data) {
1581-
let bin = {
1582-
'source': options.deviceName || options.defaultDeviceName,
1583-
'tstamp': Date.now(),
1584-
'data': data,
1585-
'size': 0
1580+
const push = async function(details) {
1581+
const { datakey, data, encode } = details;
1582+
if (
1583+
data === undefined ||
1584+
typeof data === 'string' && data === ''
1585+
) {
1586+
return deleteChunks(datakey, 0);
1587+
}
1588+
const item = {
1589+
source: options.deviceName || options.defaultDeviceName,
1590+
tstamp: Date.now(),
1591+
data,
15861592
};
1587-
bin.size = JSON.stringify(bin).length;
1588-
const item = JSON.stringify(bin);
1593+
const json = JSON.stringify(item);
1594+
const encoded = encode instanceof Function
1595+
? await encode(json)
1596+
: json;
15891597

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

1611+
// Remove potentially unused trailing chunks before storing the data,
1612+
// this will free storage space which could otherwise cause the push
1613+
// operation to fail.
1614+
try {
1615+
await deleteChunks(datakey, chunkCount);
1616+
} catch (reason) {
1617+
}
1618+
1619+
// Push the data to browser-provided cloud storage.
16021620
try {
16031621
await webext.storage.sync.set(bin);
16041622
} catch (reason) {
16051623
return String(reason);
16061624
}
1607-
1608-
// Remove potentially unused trailing chunks
1609-
deleteChunks(dataKey, chunkCount);
16101625
};
16111626

1612-
const pull = async function(dataKey) {
1627+
const pull = async function(details) {
1628+
const { datakey, decode } = details;
16131629

1614-
const result = await getCoarseChunkCount(dataKey);
1630+
const result = await getCoarseChunkCount(datakey);
16151631
if ( typeof result !== 'number' ) {
16161632
return result;
16171633
}
16181634
const chunkKeys = {};
16191635
for ( let i = 0; i < result; i++ ) {
1620-
chunkKeys[dataKey + i.toString()] = '';
1636+
chunkKeys[datakey + i.toString()] = '';
16211637
}
16221638

16231639
let bin;
@@ -1633,22 +1649,48 @@ vAPI.cloud = (( ) => {
16331649
// happen when the number of chunks is a multiple of
16341650
// chunkCountPerFetch. Hence why we must also test against
16351651
// undefined.
1636-
let json = [], jsonSlice;
1652+
let encoded = [];
16371653
let i = 0;
16381654
for (;;) {
1639-
jsonSlice = bin[dataKey + i.toString()];
1640-
if ( jsonSlice === '' || jsonSlice === undefined ) { break; }
1641-
json.push(jsonSlice);
1655+
const slice = bin[datakey + i.toString()];
1656+
if ( slice === '' || slice === undefined ) { break; }
1657+
encoded.push(slice);
16421658
i += 1;
16431659
}
1660+
encoded = encoded.join('');
1661+
const json = decode instanceof Function
1662+
? await decode(encoded)
1663+
: encoded;
16441664
let entry = null;
16451665
try {
1646-
entry = JSON.parse(json.join(''));
1666+
entry = JSON.parse(json);
16471667
} catch(ex) {
16481668
}
16491669
return entry;
16501670
};
16511671

1672+
const used = async function(datakey) {
1673+
if ( webext.storage.sync.getBytesInUse instanceof Function === false ) {
1674+
return;
1675+
}
1676+
const coarseCount = await getCoarseChunkCount(datakey);
1677+
if ( typeof coarseCount !== 'number' ) { return; }
1678+
const keys = [];
1679+
for ( let i = 0; i < coarseCount; i++ ) {
1680+
keys.push(`${datakey}${i}`);
1681+
}
1682+
let results;
1683+
try {
1684+
results = await Promise.all([
1685+
webext.storage.sync.getBytesInUse(keys),
1686+
webext.storage.sync.getBytesInUse(null),
1687+
]);
1688+
} catch(ex) {
1689+
}
1690+
if ( Array.isArray(results) === false ) { return; }
1691+
return { used: results[0], total: results[1], max: QUOTA_BYTES };
1692+
};
1693+
16521694
const getOptions = function(callback) {
16531695
if ( typeof callback !== 'function' ) { return; }
16541696
callback(options);
@@ -1665,7 +1707,7 @@ vAPI.cloud = (( ) => {
16651707
getOptions(callback);
16661708
};
16671709

1668-
return { push, pull, getOptions, setOptions };
1710+
return { push, pull, used, getOptions, setOptions };
16691711
})();
16701712

16711713
/******************************************************************************/

src/_locales/en/messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@
484484
"description": "used as a tooltip for error icon beside a list"
485485
},
486486
"1pFormatHint": {
487-
"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.",
487+
"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.",
488488
"description": "Short information about how to create custom filters"
489489
},
490490
"1pImport": {

src/background.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
<script src="js/html-filtering.js"></script>
3636
<script src="js/hnswitches.js"></script>
3737
<script src="js/ublock.js"></script>
38-
<script src="js/messaging.js"></script>
3938
<script src="js/storage.js"></script>
4039
<script src="js/logger.js"></script>
4140
<script src="js/pagestore.js"></script>
4241
<script src="js/tab.js"></script>
42+
<script src="js/messaging.js"></script>
4343
<script src="js/text-encode.js"></script>
4444
<script src="js/contextmenu.js"></script>
4545
<script src="js/reverselookup.js"></script>

src/cloud-ui.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
</head>
77
<body>
88
<div id="cloudToolbar">
9-
<button id="cloudPush" type="button" data-i18n-title="cloudPush"><span class="fa-icon">cloud-upload</span></button>
10-
<span id="cloudInfo" data-i18n="cloudNoData"></span>
11-
<button id="cloudPull" type="button" data-i18n-title="cloudPull" disabled><span class="fa-icon">cloud-download</span></button>
12-
<button id="cloudPullAndMerge" type="button" data-i18n-title="cloudPullAndMerge" disabled><span class="fa-icon">cloud-download</span><span class="fa-icon">plus</span></button>
13-
<span id="cloudCog" class="fa-icon">cog</span>
9+
<div>
10+
<button id="cloudPush" type="button" data-i18n-title="cloudPush"><span class="fa-icon">cloud-upload</span></button>
11+
<span id="cloudInfo" data-i18n="cloudNoData"></span>
12+
<button id="cloudPull" type="button" data-i18n-title="cloudPull" disabled><span class="fa-icon">cloud-download</span></button>
13+
<button id="cloudPullAndMerge" type="button" data-i18n-title="cloudPullAndMerge" disabled><span class="fa-icon">cloud-download</span><span class="fa-icon">plus</span></button>
14+
</div>
15+
<div id="cloudCog" class="fa-icon">cog</div>
1416
<div id="cloudOptions">
15-
<label data-i18n="cloudDeviceNamePrompt"></label> <input id="cloudDeviceName" type="text" value=""> <button id="cloudOptionsSubmit" class="vflex" type="button" data-i18n="genericSubmit"></button>
17+
<label data-i18n="cloudDeviceNamePrompt">_<input id="cloudDeviceName" type="text" value=""></label>&nbsp;<button id="cloudOptionsSubmit" type="button" data-i18n="genericSubmit"></button>
1618
</div>
1719
</div>
1820
<div id="cloudError"></div>
21+
<div id="cloudCapacity"><div><div></div></div></div>
1922
</body>
2023
</html>

src/css/cloud-ui.css

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
#cloudWidget {
22
background: url("../img/cloud.png") hsl(216, 100%, 93%);
3-
border-radius: 3px;
43
margin: 0.5em 0;
5-
overflow: auto;
6-
padding: 0.5em;
4+
min-width: max-content;
75
position: relative;
86
}
97
#cloudWidget.hide {
108
display: none;
119
}
12-
#cloudToolbar > button {
13-
font-size: 180%;
14-
padding: 0 0.25em;
15-
position: relative;
10+
#cloudWidget div {
11+
display: flex;
1612
}
1713
#cloudToolbar {
18-
display: flex;
14+
align-items: flex-start;
1915
flex-wrap: nowrap;
16+
justify-content: space-between;
17+
}
18+
#cloudToolbar > div:first-of-type {
19+
margin: 0.5em;
20+
}
21+
#cloudToolbar button {
22+
padding: 0 0.25em;
23+
position: relative;
24+
}
25+
#cloudToolbar button .fa-icon {
26+
font-size: 180%;
2027
}
2128
#cloudToolbar button[disabled] {
2229
visibility: hidden;
@@ -28,56 +35,71 @@
2835
margin-left: 0.25em;
2936
}
3037
#cloudPullAndMerge > span:nth-of-type(2) {
31-
font-size: 50%;
38+
font-size: 90%;
3239
position: absolute;
3340
right: 0;
3441
top: 0;
3542
}
3643
#cloudInfo {
37-
color: var(--fg-0-60);
3844
flex-shrink: 0;
3945
font-size: 90%;
4046
margin: 0 1em;
4147
overflow: hidden;
4248
padding: 0;
4349
white-space: pre-line;
4450
}
51+
#cloudCapacity {
52+
background-color: var(--light-gray-30);
53+
height: 4px;
54+
}
55+
#cloudCapacity > div {
56+
background-color: var(--light-gray-60);
57+
}
58+
#cloudCapacity > div > div {
59+
background-color: var(--violet-60);
60+
}
4561
#cloudError {
4662
color: var(--fg-icon-info-lvl-4);
4763
flex-grow: 1;
4864
flex-shrink: 2;
4965
font-size: small;
50-
margin: 0.5em 0.5em 0 0;
66+
margin: 0 0.5em 0.5em 0.5em;
5167
}
5268
#cloudError:empty {
5369
display: none;
5470
}
55-
#cloudToolbar #cloudCog {
71+
#cloudCog {
5672
color: var(--fg-0-50);
5773
cursor: pointer;
5874
fill: var(--fg-0-50);
59-
flex-grow: 1;
6075
font-size: 110%;
6176
justify-content: flex-end;
6277
padding: 0.4em;
6378
}
64-
#cloudToolbar #cloudCog:hover {
79+
#cloudCog:hover {
6580
color: inherit;
6681
fill: inherit;
6782
}
68-
#cloudToolbar #cloudOptions {
83+
#cloudWidget #cloudOptions {
84+
align-items: center;
6985
background-color: var(--default-surface);
7086
border: 1px solid var(--bg-1-border);
71-
bottom: 0;
87+
bottom: 2px;
7288
display: none;
73-
margin: 0.4em;
74-
padding: 0.4em;
89+
font-size: small;
90+
padding: 0.5em;
7591
position: absolute;
76-
right: 0;
92+
right: 2px;
7793
text-align: center;
78-
top: 0;
94+
top: 2px;
7995
z-index: 10;
8096
}
81-
#cloudToolbar #cloudOptions.show {
82-
display: block;
97+
#cloudWidget #cloudOptions label {
98+
display: inline-flex;
99+
flex-direction: column;
100+
align-items: flex-start;
101+
}
102+
#cloudWidget #cloudOptions.show {
103+
display: flex;
104+
white-space: nowrap;
83105
}

0 commit comments

Comments
 (0)