Skip to content

Commit a9e2da8

Browse files
committed
Fix #88, catch up to 1.14.24
Use vAPI.getURL to filter details.file in vAPI.tabs.injectScript. Also moved some scripts around.
1 parent 37cf0d0 commit a9e2da8

File tree

7 files changed

+324
-263
lines changed

7 files changed

+324
-263
lines changed

platform/safari/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<string>Chris Aljoudi/Raymond Hill</string>
77
<key>Builder Version</key>
88
<string>534.57.2</string>
9+
<key>DeveloperIdentifier</key>
10+
<string>3NU33NW2M3</string>
911
<key>CFBundleDisplayName</key>
1012
<string>{name}</string>
1113
<key>CFBundleIdentifier</key>

platform/safari/vapi-background.js

Lines changed: 1 addition & 262 deletions
Large diffs are not rendered by default.

platform/safari/vapi-cachestorage.js

Lines changed: 191 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

platform/safari/vapi-client.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,8 @@ self.addEventListener('contextmenu', onContextMenu, true);
643643
})(this);
644644

645645
/******************************************************************************/
646+
647+
vAPI.shutdown.add(function() {
648+
vAPI.messaging.shutdown();
649+
window.vAPI = undefined;
650+
});

platform/safari/vapi-common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ vAPI.getURL = function(path) {
8585
if ( path.match(/^assets\/thirdparties\/.*\/[^\/.]*$/) ) {
8686
path += '.txt';
8787
}
88+
if ( path[0] === '/' ) {
89+
path = path.slice(1);
90+
}
8891
return safari.extension.baseURI + path;
8992
};
9093

platform/safari/vapi-webrequest.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*******************************************************************************
2+
3+
uBlock - a browser extension to block requests.
4+
Copyright (C) 2018 The uBlock authors
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see {http://www.gnu.org/licenses/}.
18+
19+
Home: https://github.com/gorhill/uBlock
20+
*/
21+
22+
/* global self, safari, SafariBrowserTab, µBlock */
23+
24+
// For background page
25+
26+
'use strict';
27+
28+
/******************************************************************************/
29+
30+
vAPI.net = {};
31+
32+
vAPI.net.registerListeners = function() {
33+
var µb = µBlock,
34+
µburi = µb.URI;
35+
36+
// Until Safari has more specific events, those are instead handled
37+
// in the onBeforeRequestAdapter; clean them up so they're garbage-collected
38+
vAPI.net.onBeforeSendHeaders = null;
39+
40+
var onBeforeRequest = vAPI.net.onBeforeRequest,
41+
onBeforeRequestClient = onBeforeRequest.callback,
42+
onHeadersReceivedClient = vAPI.net.onHeadersReceived.callback;
43+
44+
// https://github.com/el1t/uBlock-Safari/issues/32
45+
// Ignore directives
46+
var shouldBlockResponseHeader = {
47+
script: /script-src/,
48+
worker: /child-src/
49+
};
50+
51+
var onBeforeRequestAdapter = function(e) {
52+
if ( e.name !== 'canLoad' ) {
53+
return;
54+
}
55+
e.stopPropagation && e.stopPropagation();
56+
switch ( e.message.type ) {
57+
case 'main_frame':
58+
vAPI.tabs.onNavigation({
59+
url: e.message.url,
60+
frameId: 0,
61+
tabId: vAPI.tabs.getTabId(e.target).toString()
62+
});
63+
e.message.hostname = µburi.hostnameFromURI(e.message.url);
64+
e.message.tabId = vAPI.tabs.getTabId(e.target);
65+
e.message.responseHeaders = [];
66+
onBeforeRequestClient(e.message);
67+
var blockVerdict = onHeadersReceivedClient(e.message);
68+
blockVerdict = blockVerdict && blockVerdict.responseHeaders && blockVerdict.responseHeaders[0] &&
69+
shouldBlockResponseHeader.script.test(blockVerdict.responseHeaders[0].value);
70+
e.message = {
71+
shouldBlock: blockVerdict === true
72+
};
73+
return;
74+
case 'popup':
75+
var openerTabId = vAPI.tabs.getTabId(e.target).toString();
76+
var shouldBlock = !!vAPI.tabs.onPopupUpdated('preempt', openerTabId, e.message.url);
77+
if ( !shouldBlock ) {
78+
vAPI.tabs.popupCandidate = openerTabId;
79+
}
80+
e.message = {
81+
shouldBlock: shouldBlock
82+
};
83+
break;
84+
case 'popstate':
85+
// No return value/message
86+
vAPI.tabs.onUpdated(vAPI.tabs.getTabId(e.target), {
87+
url: e.message.url
88+
}, {
89+
url: e.message.url
90+
});
91+
break;
92+
case 'worker':
93+
e.message.type = 'sub_frame';
94+
e.message.hostname = µburi.hostnameFromURI(e.message.url);
95+
e.message.tabId = vAPI.tabs.getTabId(e.target);
96+
e.message.responseHeaders = [];
97+
var blockVerdict = onHeadersReceivedClient(e.message);
98+
blockVerdict = blockVerdict && blockVerdict.responseHeaders && blockVerdict.responseHeaders[0] &&
99+
shouldBlockResponseHeader.worker.test(blockVerdict.responseHeaders[0].value);
100+
e.message = {
101+
shouldBlock: blockVerdict === true
102+
}
103+
return;
104+
default:
105+
e.message.hostname = µburi.hostnameFromURI(e.message.url);
106+
e.message.tabId = vAPI.tabs.getTabId(e.target);
107+
var blockVerdict = onBeforeRequestClient(e.message) || {};
108+
blockVerdict.shouldBlock = blockVerdict.cancel === true || blockVerdict.redirectUrl !== undefined;
109+
e.message = blockVerdict;
110+
return;
111+
}
112+
};
113+
safari.application.addEventListener('message', onBeforeRequestAdapter, true);
114+
};

tools/make-safari.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ cp platform/safari/Info.plist "$DES"/
2727
cp platform/safari/Settings.plist "$DES"/
2828
cp LICENSE.txt "$DES"/
2929

30+
cp platform/chromium/vapi.js "$DES"/js/
31+
3032
# Use chrome's usercss polyfill
31-
cp platform/chromium/vapi-usercss.js "$DES"/js/
33+
echo "*** uBlock0.safariextension: Concatenating content scripts..."
34+
cat platform/chromium/vapi-usercss.js > /tmp/contentscript.js
35+
echo >> /tmp/contentscript.js
36+
grep -v "^'use strict';$" $DES/js/contentscript.js >> /tmp/contentscript.js
37+
mv /tmp/contentscript.js $DES/js/contentscript.js
38+
echo ''
3239

3340
# https://github.com/el1t/uBlock-Safari/issues/4
3441
echo -n '*** uBlock0.safariextension: Adding extensions to extensionless assets...'

0 commit comments

Comments
 (0)