Skip to content

Commit

Permalink
Update Safari platform for 1.16
Browse files Browse the repository at this point in the history
- Reuse some chromium platform files
- Use new `vapi-usercss.pseudo.js` (buildscript removes useragent check, which fails for Safari)
- Add webextFlavor to vapi-common (relatively bare)
  • Loading branch information
el1t committed Apr 22, 2018
1 parent 8dbf60f commit 54f10dd
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 135 deletions.
2 changes: 1 addition & 1 deletion platform/safari/Info.plist
Expand Up @@ -66,8 +66,8 @@
<dict>
<key>Start</key>
<array>
<string>js/vapi.js</string>
<string>js/vapi-client.js</string>
<string>js/vapi-usercss.js</string>
<string>js/contentscript.js</string>
</array>
<key>End</key>
Expand Down
8 changes: 0 additions & 8 deletions platform/safari/is-webrtc-supported.html

This file was deleted.

52 changes: 0 additions & 52 deletions platform/safari/is-webrtc-supported.js

This file was deleted.

11 changes: 0 additions & 11 deletions platform/safari/options_ui.html

This file was deleted.

47 changes: 0 additions & 47 deletions platform/safari/options_ui.js

This file was deleted.

2 changes: 1 addition & 1 deletion platform/safari/vapi-background.js
Expand Up @@ -166,7 +166,7 @@ vAPI.tabs = {
/******************************************************************************/

vAPI.isBehindTheSceneTabId = function(tabId) {
return tabId.toString() === '-1';
return tabId < 0;
};

vAPI.noTabId = '-1';
Expand Down
34 changes: 32 additions & 2 deletions platform/safari/vapi-common.js
@@ -1,7 +1,7 @@
/*******************************************************************************
µBlock - a browser extension to block requests.
Copyright (C) 2014 The µBlock authors
uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2018 The uBlock Origin authors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -33,6 +33,36 @@ var vAPI = self.vAPI = self.vAPI || {};

vAPI.setTimeout = vAPI.setTimeout || self.setTimeout.bind(self);

/******************************************************************************/
vAPI.webextFlavor = {
major: 0,
soup: new Set()
};

(function() {
var ua = navigator.userAgent,
flavor = vAPI.webextFlavor,
soup = flavor.soup;
var dispatch = function() {
window.dispatchEvent(new CustomEvent('webextFlavor'));
};

soup.add('ublock');

// Whether this is a dev build.
if ( /^\d+\.\d+\.\d+\D/.test(safari.extension.displayVersion) ) {
soup.add('devbuild');
}

var match = /\bSafari\/(\d+)/.exec(ua);
if ( match !== null ) {
flavor.major = parseInt(match[1], 10) || 0;
soup.add('apple').add('safari');
}

vAPI.setTimeout(dispatch, 97);
})()

/******************************************************************************/

// http://www.w3.org/International/questions/qa-scripts#directions
Expand Down
7 changes: 6 additions & 1 deletion platform/safari/vapi-webrequest.js
Expand Up @@ -27,7 +27,12 @@

/******************************************************************************/

vAPI.net = {};
vAPI.net = {
onBeforeRequest: {},
onBeforeMaybeSpuriousCSPReport: {},
onHeadersReceived: {},
nativeCSPReportFiltering: false
};

vAPI.net.registerListeners = function() {
var µb = µBlock,
Expand Down
40 changes: 28 additions & 12 deletions tools/make-safari.sh
Expand Up @@ -21,17 +21,40 @@ cp -R src/_locales "$DES"/
cp src/*.html "$DES"/
mv $DES/img/icon_128.png "$DES"/Icon.png
cp platform/safari/*.js "$DES"/js/
cp platform/safari/*.html "$DES"/
cp -R platform/safari/img "$DES"/
cp platform/safari/Info.plist "$DES"/
cp platform/safari/Settings.plist "$DES"/
cp LICENSE.txt "$DES"/

cp platform/chromium/vapi.js "$DES"/js/
# Use some chromium scripts
echo -n '*** uBlock0.safariextension: Copying chromium files...'
chromium_files=(vapi.js is-webrtc-supported.{html,js} options_ui.{html,js})
for file in "${chromium_files[@]}"; do
file=platform/chromium/"$file"
if [[ ! -e "$file" ]]; then
>&2 echo "ERROR: $file not found."
exit 1
fi
if [[ "$file" == *.js ]]; then
cp "$file" "$DES"/js/
else
cp "$file" "$DES"/
fi
done
echo ''

# Use chrome's usercss polyfill
echo "*** uBlock0.safariextension: Concatenating content scripts..."
cat platform/chromium/vapi-usercss.js > /tmp/contentscript.js
# Detect OS for sed arguments
if [[ "$OSTYPE" == "darwin"* ]]; then
sedargs=('-i' '')
else
sedargs=('-i')
fi

# Use pseudo usercss polyfill
echo -n "*** uBlock0.safariextension: Concatenating content scripts..."
cat platform/chromium/vapi-usercss.pseudo.js > /tmp/contentscript.js
# Delete browser check from usercss
sed "${sedargs[@]}" -e '1,/Edge/{/Edge/d;}' -e '1,/ &&/ s///' /tmp/contentscript.js
echo >> /tmp/contentscript.js
grep -v "^'use strict';$" $DES/js/contentscript.js >> /tmp/contentscript.js
mv /tmp/contentscript.js $DES/js/contentscript.js
Expand All @@ -46,13 +69,6 @@ echo -n '*** uBlock0.safariextension: Generating Info.plist...'
python tools/make-safari-meta.py "$DES"/
echo ''

# Detect OS for sed arguments
if [[ "$OSTYPE" == "darwin"* ]]; then
declare -a sedargs=('-i' '')
else
declare -a sedargs=('-i')
fi

# https://github.com/el1t/uBlock-Safari/issues/15
echo -n '*** uBlock0.safariextension: Correcting ctrl to ⌘ in messages...'
for filename in "$DES"/_locales/*.json; do
Expand Down

0 comments on commit 54f10dd

Please sign in to comment.