mirror of https://github.com/gorhill/uBlock.git
drop webext-hybrid support
This commit is contained in:
parent
0503f52b1e
commit
2be7bbf6e9
|
@ -1,276 +0,0 @@
|
|||
/*******************************************************************************
|
||||
|
||||
uBlock Origin - a browser extension to block requests.
|
||||
Copyright (C) 2014-2017 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
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
|
||||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
/* exported startup, shutdown, install, uninstall */
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
const hostName = 'ublock0';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
function startup({ webExtension }, reason) {
|
||||
webExtension.startup(reason).then(api => {
|
||||
let { browser } = api,
|
||||
storageMigrator;
|
||||
let onMessage = function(message, sender, callback) {
|
||||
if ( message.what === 'webext:storageMigrateNext' ) {
|
||||
storageMigrator = storageMigrator || getStorageMigrator();
|
||||
storageMigrator.getNext((key, value) => {
|
||||
if ( key === undefined ) {
|
||||
storageMigrator.markAsDone();
|
||||
storageMigrator = undefined;
|
||||
browser.runtime.onMessage.removeListener(onMessage);
|
||||
}
|
||||
callback({ key: key, value: JSON.stringify(value) });
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if ( message.what === 'webext:storageMigrateDone' ) {
|
||||
browser.runtime.onMessage.removeListener(onMessage);
|
||||
}
|
||||
if ( typeof callback === 'function' ) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
browser.runtime.onMessage.addListener(onMessage);
|
||||
});
|
||||
}
|
||||
|
||||
function shutdown() {
|
||||
}
|
||||
|
||||
function install() {
|
||||
}
|
||||
|
||||
function uninstall() {
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var getStorageMigrator = function() {
|
||||
var db = null;
|
||||
var dbOpenError = '';
|
||||
|
||||
var close = function() {
|
||||
if ( db !== null ) {
|
||||
db.asyncClose();
|
||||
}
|
||||
db = null;
|
||||
};
|
||||
|
||||
var open = function() {
|
||||
if ( db !== null ) {
|
||||
return db;
|
||||
}
|
||||
|
||||
// Create path
|
||||
var { Services } = Components.utils.import('resource://gre/modules/Services.jsm', null),
|
||||
path = Services.dirsvc.get('ProfD', Components.interfaces.nsIFile);
|
||||
path.append('extension-data');
|
||||
path.append(hostName + '.sqlite');
|
||||
if ( !path.exists() || !path.isFile() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Open database.
|
||||
try {
|
||||
db = Services.storage.openDatabase(path);
|
||||
if ( db.connectionReady === false ) {
|
||||
db.asyncClose();
|
||||
db = null;
|
||||
}
|
||||
} catch (ex) {
|
||||
if ( dbOpenError === '' ) {
|
||||
dbOpenError = ex.name;
|
||||
if ( ex.name === 'NS_ERROR_FILE_CORRUPTED' ) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( db === null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Since database could be opened successfully, reset error flag (its
|
||||
// purpose is to avoid spamming console with error messages).
|
||||
dbOpenError = '';
|
||||
|
||||
return db;
|
||||
};
|
||||
|
||||
// Execute a query
|
||||
var runStatement = function(stmt, callback) {
|
||||
var result = {};
|
||||
|
||||
stmt.executeAsync({
|
||||
handleResult: function(rows) {
|
||||
if ( !rows || typeof callback !== 'function' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var row;
|
||||
|
||||
while ( (row = rows.getNextRow()) ) {
|
||||
// we assume that there will be two columns, since we're
|
||||
// using it only for preferences
|
||||
result[row.getResultByIndex(0)] = row.getResultByIndex(1);
|
||||
}
|
||||
},
|
||||
handleCompletion: function(reason) {
|
||||
if ( typeof callback === 'function' && reason === 0 ) {
|
||||
callback(result);
|
||||
}
|
||||
result = null;
|
||||
},
|
||||
handleError: function(error) {
|
||||
// Caller expects an answer regardless of failure.
|
||||
if ( typeof callback === 'function' ) {
|
||||
callback({});
|
||||
}
|
||||
result = null;
|
||||
// https://github.com/gorhill/uBlock/issues/1768
|
||||
// Error cases which warrant a removal of the SQL file, so far:
|
||||
// - SQLLite error 11 database disk image is malformed
|
||||
// Can't find doc on MDN about the type of error.result, so I
|
||||
// force a string comparison.
|
||||
if ( error.result.toString() === '11' ) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var bindNames = function(stmt, names) {
|
||||
if ( Array.isArray(names) === false || names.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
var params = stmt.newBindingParamsArray();
|
||||
var i = names.length, bp;
|
||||
while ( i-- ) {
|
||||
bp = params.newBindingParams();
|
||||
bp.bindByName('name', names[i]);
|
||||
params.addParams(bp);
|
||||
}
|
||||
stmt.bindParameters(params);
|
||||
};
|
||||
|
||||
var read = function(details, callback) {
|
||||
if ( typeof callback !== 'function' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var prepareResult = function(result) {
|
||||
var key;
|
||||
for ( key in result ) {
|
||||
if ( result.hasOwnProperty(key) === false ) {
|
||||
continue;
|
||||
}
|
||||
result[key] = JSON.parse(result[key]);
|
||||
}
|
||||
if ( typeof details === 'object' && details !== null ) {
|
||||
for ( key in details ) {
|
||||
if ( result.hasOwnProperty(key) === false ) {
|
||||
result[key] = details[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(result);
|
||||
};
|
||||
|
||||
if ( open() === null ) {
|
||||
prepareResult({});
|
||||
return;
|
||||
}
|
||||
|
||||
var names = [];
|
||||
if ( details !== null ) {
|
||||
if ( Array.isArray(details) ) {
|
||||
names = details;
|
||||
} else if ( typeof details === 'object' ) {
|
||||
names = Object.keys(details);
|
||||
} else {
|
||||
names = [details.toString()];
|
||||
}
|
||||
}
|
||||
|
||||
var stmt;
|
||||
if ( names.length === 0 ) {
|
||||
stmt = db.createAsyncStatement('SELECT * FROM "settings"');
|
||||
} else {
|
||||
stmt = db.createAsyncStatement('SELECT * FROM "settings" WHERE "name" = :name');
|
||||
bindNames(stmt, names);
|
||||
}
|
||||
|
||||
runStatement(stmt, prepareResult);
|
||||
};
|
||||
|
||||
let allKeys;
|
||||
|
||||
let readNext = function(key, callback) {
|
||||
if ( key === undefined ) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
read(key, bin => {
|
||||
if ( bin instanceof Object && bin.hasOwnProperty(key) ) {
|
||||
callback(key, bin[key]);
|
||||
} else {
|
||||
callback(key);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let getNext = function(callback) {
|
||||
if ( Array.isArray(allKeys) ) {
|
||||
readNext(allKeys.pop(), callback);
|
||||
return;
|
||||
}
|
||||
if ( open() === null ) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
let stmt = db.createAsyncStatement('SELECT "name",\'dummy\' FROM "settings"');
|
||||
runStatement(stmt, result => {
|
||||
allKeys = [];
|
||||
for ( let key in result ) {
|
||||
if ( result.hasOwnProperty(key) ) {
|
||||
allKeys.push(key);
|
||||
}
|
||||
}
|
||||
readNext(allKeys.pop(), callback);
|
||||
});
|
||||
};
|
||||
|
||||
let markAsDone = function() {
|
||||
close();
|
||||
};
|
||||
|
||||
return {
|
||||
getNext: getNext,
|
||||
markAsDone: markAsDone,
|
||||
};
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
|
@ -1 +0,0 @@
|
|||
content ublock0 ./
|
|
@ -1,78 +0,0 @@
|
|||
/*******************************************************************************
|
||||
|
||||
uBlock Origin - a browser extension to block requests.
|
||||
Copyright (C) 2017 Raymond Hill
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
|
||||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
// For background page
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
(function() {
|
||||
let µb = µBlock;
|
||||
let migratedKeys = new Set();
|
||||
let reCacheStorageKeys = /^(?:assetCacheRegistry|assetSourceRegistry|cache\/.+|selfie)$/;
|
||||
|
||||
let migrateAll = function(callback) {
|
||||
let migrateKeyValue = function(details, callback) {
|
||||
// https://github.com/gorhill/uBlock/issues/2653
|
||||
// Be ready to deal graciously with corrupted DB.
|
||||
if ( migratedKeys.has(details.key) ) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
migratedKeys.add(details.key);
|
||||
let bin = {};
|
||||
bin[details.key] = JSON.parse(details.value);
|
||||
if ( reCacheStorageKeys.test(details.key) ) {
|
||||
vAPI.cacheStorage.set(bin, callback);
|
||||
} else {
|
||||
vAPI.storage.set(bin, callback);
|
||||
}
|
||||
};
|
||||
|
||||
let migrateNext = function() {
|
||||
self.browser.runtime.sendMessage({ what: 'webext:storageMigrateNext' }, response => {
|
||||
if ( response.key === undefined ) {
|
||||
if ( migratedKeys.size !== 0 ) {
|
||||
self.browser.runtime.reload();
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
return;
|
||||
}
|
||||
migrateKeyValue(response, migrateNext);
|
||||
});
|
||||
};
|
||||
|
||||
self.browser.storage.local.get('legacyStorageMigrated', bin => {
|
||||
if ( bin && bin.legacyStorageMigrated ) {
|
||||
self.browser.runtime.sendMessage({ what: 'webext:storageMigrateDone' });
|
||||
return callback();
|
||||
}
|
||||
vAPI.storage.set({ legacyStorageMigrated: true });
|
||||
migrateNext();
|
||||
});
|
||||
};
|
||||
|
||||
µb.onBeforeStartQueue.push(migrateAll);
|
||||
})();
|
||||
|
||||
/******************************************************************************/
|
|
@ -1,38 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
|
||||
<Description about="urn:mozilla:install-manifest">
|
||||
<em:id>uBlock0@raymondhill.net</em:id>
|
||||
<em:version>{version}</em:version>
|
||||
<em:name>{name}</em:name>
|
||||
<em:description>{description}</em:description>
|
||||
<em:homepageURL>https://github.com/gorhill/uBlock</em:homepageURL>
|
||||
<em:creator>{author}</em:creator>
|
||||
<em:developer>Deathamns</em:developer>
|
||||
<em:developer>Alex Vallat</em:developer>
|
||||
<em:developer>Manuel Reimer</em:developer>
|
||||
<em:type>2</em:type>
|
||||
<em:bootstrap>true</em:bootstrap>
|
||||
<em:multiprocessCompatible>true</em:multiprocessCompatible>
|
||||
<em:hasEmbeddedWebExtension>true</em:hasEmbeddedWebExtension>
|
||||
{localized}
|
||||
|
||||
<!-- Firefox -->
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
<em:id>{{ec8030f7-c20a-464f-9b0e-13a3a9e97384}}</em:id>
|
||||
<em:minVersion>54.0</em:minVersion>
|
||||
<em:maxVersion>56.*</em:maxVersion>
|
||||
</Description>
|
||||
</em:targetApplication>
|
||||
|
||||
<!-- Firefox for Android -->
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
<em:id>{{aa3c5121-dab2-40e2-81ca-7ea25febc110}}</em:id>
|
||||
<em:minVersion>54.0</em:minVersion>
|
||||
<em:maxVersion>56.*</em:maxVersion>
|
||||
</Description>
|
||||
</em:targetApplication>
|
||||
|
||||
</Description>
|
||||
</RDF>
|
|
@ -1,83 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from io import open as uopen
|
||||
from collections import OrderedDict
|
||||
|
||||
if len(sys.argv) == 1 or not sys.argv[1]:
|
||||
raise SystemExit('Build dir missing.')
|
||||
|
||||
proj_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], '..')
|
||||
build_dir = os.path.abspath(sys.argv[1])
|
||||
|
||||
# Import data from chromium platform
|
||||
chromium_manifest = {}
|
||||
webext_manifest = {}
|
||||
|
||||
chromium_manifest_file = os.path.join(proj_dir, 'platform', 'chromium', 'manifest.json')
|
||||
with open(chromium_manifest_file) as f1:
|
||||
chromium_manifest = json.load(f1)
|
||||
|
||||
# WebExtension part
|
||||
webext_manifest_file = os.path.join(build_dir, 'webextension', 'manifest.json')
|
||||
with open(webext_manifest_file) as f2:
|
||||
webext_manifest = json.load(f2)
|
||||
|
||||
webext_manifest['version'] = chromium_manifest['version']
|
||||
|
||||
with open(webext_manifest_file, 'w') as f2:
|
||||
json.dump(webext_manifest, f2, indent=2, separators=(',', ': '), sort_keys=True)
|
||||
f2.write('\n')
|
||||
|
||||
# Legacy part
|
||||
descriptions = OrderedDict({})
|
||||
source_locale_dir = os.path.join(build_dir, 'webextension', '_locales')
|
||||
for alpha2 in sorted(os.listdir(source_locale_dir)):
|
||||
locale_path = os.path.join(source_locale_dir, alpha2, 'messages.json')
|
||||
with uopen(locale_path, encoding='utf-8') as f:
|
||||
strings = json.load(f, object_pairs_hook=OrderedDict)
|
||||
alpha2 = alpha2.replace('_', '-')
|
||||
descriptions[alpha2] = strings['extShortDesc']['message']
|
||||
|
||||
webext_manifest['author'] = chromium_manifest['author'];
|
||||
webext_manifest['name'] = chromium_manifest['name'] + '/webext-hybrid'
|
||||
webext_manifest['homepage'] = 'https://github.com/gorhill/uBlock'
|
||||
webext_manifest['description'] = descriptions['en']
|
||||
del descriptions['en']
|
||||
|
||||
match = re.search('^(\d+\.\d+\.\d+)(\.\d+)$', chromium_manifest['version'])
|
||||
if match:
|
||||
buildtype = int(match.group(2)[1:])
|
||||
if buildtype < 100:
|
||||
builttype = 'b' + str(buildtype)
|
||||
else:
|
||||
builttype = 'rc' + str(buildtype - 100)
|
||||
webext_manifest['version'] = match.group(1) + builttype
|
||||
|
||||
webext_manifest['localized'] = []
|
||||
t = ' '
|
||||
t3 = 3 * t
|
||||
for alpha2 in descriptions:
|
||||
if alpha2 == 'en':
|
||||
continue
|
||||
webext_manifest['localized'].append(
|
||||
'\n' + t*2 + '<em:localized><Description>\n' +
|
||||
t3 + '<em:locale>' + alpha2 + '</em:locale>\n' +
|
||||
t3 + '<em:name>' + webext_manifest['name'] + '</em:name>\n' +
|
||||
t3 + '<em:description>' + descriptions[alpha2] + '</em:description>\n' +
|
||||
t3 + '<em:creator>' + webext_manifest['author'] + '</em:creator>\n' +
|
||||
# t3 + '<translator>' + ??? + '</translator>\n' +
|
||||
t3 + '<em:homepageURL>' + webext_manifest['homepage'] + '</em:homepageURL>\n' +
|
||||
t*2 + '</Description></em:localized>'
|
||||
)
|
||||
webext_manifest['localized'] = '\n'.join(webext_manifest['localized'])
|
||||
|
||||
install_rdf = os.path.join(build_dir, 'install.rdf')
|
||||
with uopen(install_rdf, 'r+t', encoding='utf-8', newline='\n') as f:
|
||||
install_rdf = f.read()
|
||||
f.seek(0)
|
||||
f.write(install_rdf.format(**webext_manifest))
|
||||
f.truncate()
|
|
@ -1,51 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# This script assumes a linux environment
|
||||
|
||||
echo "*** uBlock0.webext-hybrid: Creating web store package"
|
||||
echo "*** uBlock0.webext-hybrid: Copying files"
|
||||
|
||||
DES=dist/build/uBlock0.webext-hybrid
|
||||
rm -rf $DES
|
||||
mkdir -p $DES/webextension
|
||||
|
||||
bash ./tools/make-assets.sh $DES/webextension
|
||||
|
||||
cp -R src/css $DES/webextension/
|
||||
cp -R src/img $DES/webextension/
|
||||
cp -R src/js $DES/webextension/
|
||||
cp -R src/lib $DES/webextension/
|
||||
cp -R src/_locales $DES/webextension/
|
||||
cp -R $DES/webextension/_locales/nb $DES/webextension/_locales/no
|
||||
cp src/*.html $DES/webextension/
|
||||
cp platform/chromium/*.js $DES/webextension/js/
|
||||
cp -R platform/chromium/img $DES/webextension/
|
||||
cp platform/chromium/*.html $DES/webextension/
|
||||
cp platform/chromium/*.json $DES/webextension/
|
||||
cp LICENSE.txt $DES/webextension/
|
||||
|
||||
cp platform/webext/manifest.json $DES/webextension/
|
||||
cp platform/webext/background.html $DES/webextension/
|
||||
cp platform/webext/options_ui.html $DES/webextension/
|
||||
cp platform/webext/polyfill.js $DES/webextension/js/
|
||||
cp platform/webext/vapi-usercss.js $DES/webextension/js/
|
||||
cp platform/webext/vapi-cachestorage.js $DES/webextension/js/
|
||||
cp platform/webext/from-legacy.js $DES/webextension/js/
|
||||
rm $DES/webextension/js/options_ui.js
|
||||
|
||||
cp platform/webext/bootstrap.js $DES/
|
||||
cp platform/webext/chrome.manifest $DES/
|
||||
cp platform/webext/install.rdf $DES/
|
||||
mv $DES/webextension/img/icon_128.png $DES/icon.png
|
||||
|
||||
echo "*** uBlock0.webext-hybrid: Generating meta..."
|
||||
python tools/make-webext-hybrid-meta.py $DES/
|
||||
|
||||
if [ "$1" = all ]; then
|
||||
echo "*** uBlock0.webext-hybrid: Creating package..."
|
||||
pushd $DES > /dev/null
|
||||
zip ../$(basename $DES).xpi -qr *
|
||||
popd > /dev/null
|
||||
fi
|
||||
|
||||
echo "*** uBlock0.webext-hybrid: Package done."
|
Loading…
Reference in New Issue