Skip to content

Commit a8cf063

Browse files
committed
first pass to bring Edge version up to date
1 parent 6dd6dc5 commit a8cf063

11 files changed

Lines changed: 278 additions & 29 deletions

File tree

platform/chromium/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"author": "All uBlock Origin contributors",
2+
"author": "Raymond Hill and contributors",
33
"background": {
44
"page": "background.html"
55
},

platform/chromium/vapi-background.js

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,23 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
623623
callback();
624624
}
625625
};
626-
if ( tabId ) {
627-
chrome.tabs.executeScript(toChromiumTabId(tabId), details, onScriptExecuted);
628-
} else {
629-
chrome.tabs.executeScript(details, onScriptExecuted);
626+
627+
// This may throw on some platforms due to incomplete support of API.
628+
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/executeScript#Browser_compatibility
629+
try {
630+
if ( tabId ) {
631+
chrome.tabs.executeScript(
632+
toChromiumTabId(tabId),
633+
details,
634+
onScriptExecuted
635+
);
636+
} else {
637+
chrome.tabs.executeScript(
638+
details,
639+
onScriptExecuted
640+
);
641+
}
642+
} catch(ex) {
630643
}
631644
};
632645

@@ -653,12 +666,8 @@ vAPI.setIcon = (function() {
653666
chrome.runtime.getManifest().browser_action.default_title +
654667
' ({badge})';
655668
let icons = [
656-
{
657-
path: { '16': 'img/icon_16-off.png', '32': 'img/icon_32-off.png' }
658-
},
659-
{
660-
path: { '16': 'img/icon_16.png', '32': 'img/icon_32.png' }
661-
}
669+
{ key: 'path', path: {} },
670+
{ key: 'path', path: {} }
662671
];
663672

664673
(function() {
@@ -671,6 +680,19 @@ vAPI.setIcon = (function() {
671680
});
672681
}
673682

683+
// First, copy browser icon information from the manifest -- which may
684+
// be different from one platform to another.
685+
let defaultIcons = browser.runtime.getManifest().browser_action.default_icon;
686+
for ( let key in defaultIcons ) {
687+
let path = defaultIcons[key];
688+
icons[1].path[key] = path;
689+
let pos = path.lastIndexOf('.');
690+
if ( pos !== -1 ) {
691+
path = path.slice(0, pos) + '-off' + path.slice(pos);
692+
}
693+
icons[0].path[key] = path;
694+
}
695+
674696
// As of 2018-05, benchmarks show that only Chromium benefits for sure
675697
// from using ImageData.
676698
//
@@ -718,6 +740,7 @@ vAPI.setIcon = (function() {
718740
for ( let i = 0; i < iconData.length; i++ ) {
719741
if ( iconData[i] ) {
720742
icons[i] = { imageData: iconData[i] };
743+
icons[i].key = 'imageData';
721744
}
722745
}
723746
};
@@ -731,11 +754,16 @@ vAPI.setIcon = (function() {
731754
var onTabReady = function(tab, state, badge, parts) {
732755
if ( vAPI.lastError() || !tab ) { return; }
733756

757+
// Beware: msedge modifies the icon data object passed as argument,
758+
// hence why we need to pass a copy since we are going to reuse the
759+
// icon data object.
734760
if ( browserAction.setIcon !== undefined ) {
735761
if ( parts === undefined || (parts & 0x01) !== 0 ) {
736-
browserAction.setIcon(
737-
Object.assign({ tabId: tab.id }, icons[state])
738-
);
762+
let icon = icons[state];
763+
browserAction.setIcon({
764+
tabId: tab.id,
765+
[icon.key]: Object.assign({}, icon[icon.key])
766+
});
739767
}
740768
browserAction.setBadgeText({ tabId: tab.id, text: badge });
741769
}
@@ -1017,6 +1045,9 @@ vAPI.messaging.broadcast = function(message) {
10171045
// - prevent web pages from interfering with uBO's element picker
10181046

10191047
(function() {
1048+
// https://github.com/NanoAdblocker/NanoCore/issues/40
1049+
if ( vAPI.webextFlavor.soup.has('edge') ) { return; }
1050+
10201051
vAPI.warSecret =
10211052
Math.floor(Math.random() * 982451653 + 982451653).toString(36) +
10221053
Math.floor(Math.random() * 982451653 + 982451653).toString(36);

platform/chromium/vapi.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727

2828
/******************************************************************************/
2929

30+
if ( self.browser instanceof Object ) {
31+
self.chrome = self.browser;
32+
} else {
33+
self.browser = self.chrome;
34+
}
35+
36+
/******************************************************************************/
37+
3038
// https://bugzilla.mozilla.org/show_bug.cgi?id=1408996#c9
3139
var vAPI = window.vAPI; // jshint ignore:line
3240

platform/edge/manifest.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"author": "Raymond Hill and contributors",
3+
"background": {
4+
"page": "background.html",
5+
"persistent": false
6+
},
7+
"browser_action": {
8+
"default_icon": {
9+
"20": "img/icon_16.png",
10+
"40": "img/icon_32.png"
11+
},
12+
"default_title": "uBlock Origin",
13+
"default_popup": "popup.html"
14+
},
15+
"commands": {
16+
"launch-element-zapper": {
17+
"description": "__MSG_popupTipZapper__"
18+
},
19+
"launch-element-picker": {
20+
"description": "__MSG_popupTipPicker__"
21+
},
22+
"launch-logger": {
23+
"description": "__MSG_popupTipLog__"
24+
}
25+
},
26+
"content_scripts": [
27+
{
28+
"matches": [
29+
"http://*/*",
30+
"https://*/*"
31+
],
32+
"js": [
33+
"/js/vapi.js",
34+
"/js/vapi-client.js",
35+
"/js/contentscript.js"
36+
],
37+
"run_at": "document_start",
38+
"all_frames": true
39+
},
40+
{
41+
"matches": [
42+
"http://*/*",
43+
"https://*/*"
44+
],
45+
"js": [
46+
"/js/scriptlets/subscriber.js"
47+
],
48+
"run_at": "document_idle",
49+
"all_frames": false
50+
}
51+
],
52+
"default_locale": "en",
53+
"description": "__MSG_extShortDesc__",
54+
"icons": {
55+
"16": "img/icon_16.png",
56+
"32": "img/icon_32.png",
57+
"64": "img/icon_64.png",
58+
"128": "img/icon_128.png"
59+
},
60+
"incognito": "split",
61+
"manifest_version": 2,
62+
"minimum_edge_version": "41",
63+
"name": "uBlock Origin",
64+
"optional_permissions": [
65+
"file:///*"
66+
],
67+
"options_ui": {
68+
"page": "dashboard.html",
69+
"open_in_tab": true
70+
},
71+
"permissions": [
72+
"contextMenus",
73+
"privacy",
74+
"storage",
75+
"tabs",
76+
"unlimitedStorage",
77+
"webNavigation",
78+
"webRequest",
79+
"webRequestBlocking",
80+
"<all_urls>"
81+
],
82+
"short_name": "uBlock₀",
83+
"storage": {
84+
"managed_schema": "managed_storage.json"
85+
},
86+
"version": "1.15.11.0",
87+
"web_accessible_resources": [
88+
"/web_accessible_resources/*"
89+
]
90+
}

platform/firefox/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"strict_min_version": "52.0"
66
}
77
},
8-
"author": "All uBlock Origin contributors",
8+
"author": "Raymond Hill and contributors",
99
"background": {
1010
"page": "background.html"
1111
},

src/js/cachestorage.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@
4040

4141
µBlock.cacheStorage = (function() {
4242

43-
// Firefox-specific: we use indexedDB because chrome.storage.local() has
44-
// poor performance in Firefox. See:
43+
// Firefox/Edge: we use indexedDB because browser.storage.local() has
44+
// poor performance in Firefox, and limitations on Edge. See:
4545
// https://bugzilla.mozilla.org/show_bug.cgi?id=1371255
46-
if ( vAPI.webextFlavor.soup.has('firefox') === false ) {
46+
if (
47+
vAPI.webextFlavor.soup.has('firefox') === false &&
48+
vAPI.webextFlavor.soup.has('edge') === false
49+
) {
4750
return vAPI.cacheStorage;
4851
}
4952

@@ -252,7 +255,18 @@
252255
callback(dbByteLength);
253256
});
254257
}
255-
let textEncoder = new TextEncoder();
258+
// Edge does not support TextEncoder:
259+
// https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder#Browser_compatibility
260+
let textEncoder;
261+
if ( typeof TextEncoder === 'function' ) {
262+
textEncoder = new TextEncoder();
263+
} else {
264+
textEncoder = {
265+
encode: function(s) {
266+
return { byteLength: s.length };
267+
}
268+
};
269+
}
256270
let totalByteLength = 0;
257271
visitAllFromDb(entry => {
258272
if ( entry === undefined ) {

src/js/lz4.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ let decodeValue = function(key, inputArray) {
165165

166166
return {
167167
encode: function(key, dataIn) {
168-
if ( typeof dataIn !== 'string' || dataIn.length < 4096 ) {
168+
if (
169+
typeof dataIn !== 'string' ||
170+
dataIn.length < 4096 ||
171+
typeof TextEncoder !== 'function'
172+
) {
169173
return Promise.resolve({ key, data: dataIn });
170174
}
171175
ttlManage(1);

src/js/popup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,9 @@ var renderOnce = function() {
626626
// Be prepared to fall into responsive mode if ever it is found the
627627
// viewport is not a perfect match for the popup panel.
628628

629+
// Resize handler is sort of broken on Edge, just avoid for now.
630+
if ( vAPI.webextFlavor.soup.has('edge') ) { return; }
631+
629632
let resizeTimer;
630633
let resize = function() {
631634
resizeTimer = undefined;

src/js/redirect-engine.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@
2828
/******************************************************************************/
2929
/******************************************************************************/
3030

31+
var warURLToSecretURL = function(url) {
32+
if ( vAPI.warSecret ) {
33+
url += '?secret=' + vAPI.warSecret;
34+
}
35+
return url;
36+
};
37+
3138
var warResolve = (function() {
3239
var warPairs = [];
3340

3441
var onPairsReady = function() {
35-
var reng = µBlock.redirectEngine;
36-
for ( var i = 0; i < warPairs.length; i += 2 ) {
37-
var resource = reng.resources.get(warPairs[i+0]);
42+
let reng = µBlock.redirectEngine;
43+
for ( let i = 0; i < warPairs.length; i += 2 ) {
44+
let resource = reng.resources.get(warPairs[i+0]);
3845
if ( resource === undefined ) { continue; }
3946
resource.warURL = vAPI.getURL(
4047
'/web_accessible_resources/' + warPairs[i+1]
@@ -49,22 +56,22 @@ var warResolve = (function() {
4956
}
5057

5158
var onPairsLoaded = function(details) {
52-
var marker = '>>>>>';
53-
var pos = details.content.indexOf(marker);
59+
let marker = '>>>>>';
60+
let pos = details.content.indexOf(marker);
5461
if ( pos === -1 ) { return; }
55-
var pairs = details.content.slice(pos + marker.length)
62+
let pairs = details.content.slice(pos + marker.length)
5663
.trim()
5764
.split('\n');
5865
if ( (pairs.length & 1) !== 0 ) { return; }
59-
for ( var i = 0; i < pairs.length; i++ ) {
66+
for ( let i = 0; i < pairs.length; i++ ) {
6067
pairs[i] = pairs[i].trim();
6168
}
6269
warPairs = pairs;
6370
onPairsReady();
6471
};
6572

6673
µBlock.assets.fetchText(
67-
'/web_accessible_resources/imported.txt?secret=' + vAPI.warSecret,
74+
warURLToSecretURL('/web_accessible_resources/imported.txt'),
6875
onPairsLoaded
6976
);
7077
};
@@ -105,7 +112,7 @@ RedirectEntry.prototype.toURL = function(details) {
105112
details.requestURL.startsWith('https:')
106113
)
107114
) {
108-
return this.warURL + '?secret=' + vAPI.warSecret;
115+
return warURLToSecretURL(this.warURL);
109116
}
110117
if ( this.data.startsWith('data:') === false ) {
111118
if ( this.mime.indexOf(';') === -1 ) {

tools/make-edge-meta.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import json
5+
import re
6+
import sys
7+
8+
if len(sys.argv) == 1 or not sys.argv[1]:
9+
raise SystemExit('Build dir missing.')
10+
11+
proj_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], '..')
12+
build_dir = os.path.abspath(sys.argv[1])
13+
14+
version = ''
15+
with open(os.path.join(proj_dir, 'dist', 'version')) as f:
16+
version = f.read().strip()
17+
18+
manifest_out = {}
19+
manifest_out_file = os.path.join(build_dir, 'manifest.json')
20+
with open(manifest_out_file) as f:
21+
manifest_out = json.load(f)
22+
23+
manifest_out['version'] = version
24+
25+
# Development build? If so, modify name accordingly.
26+
match = re.search('^\d+\.\d+\.\d+\.\d+$', version)
27+
if match:
28+
manifest_out['name'] += ' development build'
29+
manifest_out['short_name'] += ' dev build'
30+
manifest_out['browser_action']['default_title'] += ' dev build'
31+
32+
with open(manifest_out_file, 'w') as f:
33+
json.dump(manifest_out, f, indent=2, separators=(',', ': '), sort_keys=True)
34+
f.write('\n')

0 commit comments

Comments
 (0)