This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Firefox Embedded WebExtension code.
- Loading branch information
1 parent
abf116d
commit ba96d73
Showing
14 changed files
with
590 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>uBlock</title> | ||
</head> | ||
<body> | ||
<script src="lib/punycode.js"></script> | ||
<script src="lib/publicsuffixlist.js"></script> | ||
<script src="lib/yamd5.js"></script> | ||
<script src="js/vapi-common.js"></script> | ||
<script src="js/vapi-background.js"></script> | ||
<script src="js/background.js"></script> | ||
<script src="js/async.js"></script> | ||
<script src="js/utils.js"></script> | ||
<script src="js/uritools.js"></script> | ||
<script src="js/assets.js"></script> | ||
<script src="js/dynamic-net-filtering.js"></script> | ||
<script src="js/static-net-filtering.js"></script> | ||
<script src="js/cosmetic-filtering.js"></script> | ||
<script src="js/ublock.js"></script> | ||
<script src="js/messaging.js"></script> | ||
<script src="js/profiler.js"></script> | ||
<script src="js/storage.js"></script> | ||
<script src="js/logger.js"></script> | ||
<script src="js/pagestore.js"></script> | ||
<script src="js/tab.js"></script> | ||
<script src="js/traffic.js"></script> | ||
<script src="js/contextmenu.js"></script> | ||
<script src="js/mirrors.js"></script> | ||
<script src="js/from-legacy.js"></script> | ||
<script src="js/stats.js"></script> | ||
<script src="js/start.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
/******************************************************************************* | ||
µBlock - a browser extension to block requests. | ||
Copyright (C) 2014 The µBlock 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/uBlockAdmin/uBlock | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const hostName = 'ublock'; | ||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components; | ||
const {Services} = Cu.import('resource://gre/modules/Services.jsm', null); | ||
|
||
function startup({ webExtension }) { | ||
webExtension.startup().then(api => { | ||
let { browser } = api, | ||
dataMigrator; | ||
let onMessage = function(message, sender, callback) { | ||
if ( message.what === 'getNextMigrateItem' ) { | ||
dataMigrator = dataMigrator || getDataMigrate(); | ||
dataMigrator.sendNextItemData((key, value) => { | ||
if ( key === undefined ) { | ||
dataMigrator.closeDbConn(); | ||
dataMigrator = undefined; | ||
browser.runtime.onMessage.removeListener(onMessage); | ||
} | ||
callback({ key: key, value: JSON.stringify(value) }); | ||
}); | ||
return true; | ||
} | ||
if ( message.what === 'dataMigrateDone' ) { | ||
browser.runtime.onMessage.removeListener(onMessage); | ||
} | ||
if ( typeof callback === 'function' ) { | ||
callback(); | ||
} | ||
}; | ||
browser.runtime.onMessage.addListener(onMessage); | ||
}); | ||
} | ||
|
||
function shutdown() { | ||
} | ||
|
||
function install() { | ||
} | ||
|
||
function uninstall() { | ||
} | ||
|
||
var SQLite = { | ||
|
||
open: function() { | ||
|
||
var path = Services.dirsvc.get('ProfD', Ci.nsIFile); | ||
path.append('extension-data'); | ||
path.append(hostName + '.sqlite'); | ||
if ( !path.exists() || !path.isFile() ) { | ||
return null; | ||
} | ||
this.db = Services.storage.openDatabase(path); | ||
return this.db; | ||
}, | ||
|
||
close: function() { | ||
SQLite.db.asyncClose(); | ||
}, | ||
|
||
run: function(query, values, callback) { | ||
|
||
if ( !this.db ) { | ||
if ( this.open() === null ) { | ||
callback({}); | ||
return; | ||
} | ||
} | ||
|
||
var result = {}; | ||
query = this.db.createAsyncStatement(query); | ||
|
||
if ( Array.isArray(values) && values.length ) { | ||
var i = values.length; | ||
|
||
while ( i-- ) { | ||
query.bindByIndex(i, values[i]); | ||
} | ||
} | ||
|
||
query.executeAsync({ | ||
handleResult: function(rows) { | ||
if ( !rows || typeof callback !== 'function' ) { | ||
return; | ||
} | ||
|
||
var row; | ||
|
||
while ( row = rows.getNextRow() ) { | ||
result[row.getResultByIndex(0)] = row.getResultByIndex(1); | ||
} | ||
}, | ||
handleCompletion: function(reason) { | ||
if ( typeof callback === 'function' && reason === 0 ) { | ||
callback(result); | ||
} | ||
}, | ||
handleError: function(error) { | ||
if ( typeof callback === 'function' && reason === 0 ) { | ||
callback(); | ||
} | ||
result = null; | ||
if ( error.result.toString() === '11' ) { | ||
close(); | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
var getDataMigrate = function() { | ||
|
||
var legacyData = null; | ||
var legacyDataKeys = null; | ||
|
||
var fetchLegacyData = function(cb) { | ||
var values = []; | ||
|
||
var prepareResult = function(result) { | ||
|
||
if ( result === undefined ) { | ||
cb(); | ||
return; | ||
} | ||
|
||
var key; | ||
for ( key in result ) { | ||
result[key] = JSON.parse(result[key]); | ||
} | ||
|
||
legacyData = result; | ||
legacyDataKeys = Object.keys(result); | ||
|
||
var key = legacyDataKeys.pop(); | ||
var value = legacyData[key]; | ||
cb({ key: key, value: value }); | ||
}; | ||
|
||
SQLite.run( | ||
'SELECT * FROM settings', | ||
values, | ||
prepareResult | ||
); | ||
}; | ||
|
||
var sendNextItemData = function(callback) { | ||
|
||
if(!legacyData) { | ||
fetchLegacyData( bin => { | ||
callback(bin.key, bin.value); | ||
}); | ||
return; | ||
} | ||
else { | ||
var key = legacyDataKeys.pop(); | ||
var value = legacyData[key]; | ||
callback(key,value); | ||
return; | ||
} | ||
}; | ||
|
||
var closeDbConn = function() { | ||
SQLite.close(); | ||
}; | ||
|
||
return { | ||
sendNextItemData: sendNextItemData, | ||
closeDbConn: closeDbConn | ||
}; | ||
} | ||
|
||
|
||
|
||
/******************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
content ublock ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************* | ||
µBlock - a browser extension to block requests. | ||
Copyright (C) 2014 The µBlock 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/uBlockAdmin/uBlock | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/******************************************************************************/ | ||
|
||
µBlock.migrateLegacyData = (function() { | ||
|
||
let µb = µBlock; | ||
|
||
let migrateLegacyData = function(callback) { | ||
|
||
let storeKeyValue = function(details, callback) { | ||
let bin = {}; | ||
bin[details.key] = JSON.parse(details.value); | ||
vAPI.storage.set(bin, callback); | ||
}; | ||
|
||
let migrateNextDataItem = function() { | ||
self.browser.runtime.sendMessage({ what: 'getNextMigrateItem' }, response => { | ||
if ( response.key === undefined ) { | ||
return callback(); | ||
} | ||
storeKeyValue(response, migrateNextDataItem); | ||
}); | ||
}; | ||
|
||
self.browser.storage.local.get('dataMigrateDone', bin => { | ||
if ( bin && bin.dataMigrateDone ) { | ||
self.browser.runtime.sendMessage({ what: 'dataMigrateDone' }); | ||
return callback(); | ||
} | ||
self.browser.storage.local.set({ dataMigrateDone: true }); | ||
migrateNextDataItem(); | ||
}); | ||
}; | ||
|
||
return migrateLegacyData; | ||
|
||
})(); | ||
|
||
|
||
/******************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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>{{2b10c1c8-a11f-4bad-fe9c-1c11e82cac42}}</em:id> | ||
<em:version>{version}</em:version> | ||
<em:name>{name}</em:name> | ||
<em:description>{description}</em:description> | ||
<em:homepageURL>{homepage}</em:homepageURL> | ||
<em:creator>{author}</em:creator> | ||
<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>52.0a1</em:minVersion> | ||
<em:maxVersion>56.*</em:maxVersion> | ||
</Description> | ||
</em:targetApplication> | ||
|
||
</Description> | ||
</RDF> |
Oops, something went wrong.