mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 16:47:15 +02:00
Firefox: implement toolbar button and popup
This commit is contained in:
parent
e4329b7dfe
commit
cb5d860725
@ -87,7 +87,7 @@ var messagingConnector = function(response) {
|
||||
/******************************************************************************/
|
||||
|
||||
var uniqueId = function() {
|
||||
return parseInt(Math.random() * 1e10, 10).toString(36);
|
||||
return Math.random().toString(36).slice(2);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
8
platform/firefox/bootstrap.js
vendored
8
platform/firefox/bootstrap.js
vendored
@ -39,9 +39,7 @@ function shutdown(data, reason) {
|
||||
}
|
||||
}
|
||||
|
||||
function install() {
|
||||
// https://bugzil.la/719376
|
||||
Services.strings.flushBundles();
|
||||
}
|
||||
// https://bugzil.la/719376
|
||||
function install() Services.strings.flushBundles();
|
||||
|
||||
function uninstall() {}
|
||||
function uninstall() {}
|
||||
|
@ -1,14 +1,18 @@
|
||||
/* global Services, Components, XPCOMUtils */
|
||||
/* exported EXPORTED_SYMBOLS, isTabbed */
|
||||
|
||||
'use strict';
|
||||
|
||||
var EXPORTED_SYMBOLS = ['contentPolicy', 'docObserver'];
|
||||
this.EXPORTED_SYMBOLS = ['contentPolicy', 'docObserver'];
|
||||
|
||||
Components.utils['import']('resource://gre/modules/Services.jsm');
|
||||
Components.utils['import']('resource://gre/modules/XPCOMUtils.jsm');
|
||||
|
||||
const Ci = Components.interfaces, appName = 'ublock';
|
||||
const Ci = Components.interfaces;
|
||||
var appName;
|
||||
|
||||
try { throw new Error; } catch (ex) {
|
||||
appName = ex.fileName.match(/:\/\/([^\/]+)/)[1];
|
||||
}
|
||||
|
||||
let getMessager = function(win) {
|
||||
try {
|
||||
@ -33,9 +37,10 @@ let getMessager = function(win) {
|
||||
let contentPolicy = {
|
||||
classDescription: 'ContentPolicy implementation',
|
||||
classID: Components.ID('{e6d173c8-8dbf-4189-a6fd-189e8acffd27}'),
|
||||
contractID: '@ublock/content-policy;1',
|
||||
contractID: '@' + appName + '/content-policy;1',
|
||||
ACCEPT: Ci.nsIContentPolicy.ACCEPT,
|
||||
REJECT: Ci.nsIContentPolicy.REJECT_REQUEST,
|
||||
requestMessageName: appName + ':onBeforeRequest',
|
||||
get componentRegistrar() {
|
||||
return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
},
|
||||
@ -89,7 +94,7 @@ let contentPolicy = {
|
||||
return this.ACCEPT;
|
||||
}
|
||||
|
||||
let result = getMessager(win).sendSyncMessage('ublock:onBeforeRequest', {
|
||||
let result = getMessager(win).sendSyncMessage(this.requestMessageName, {
|
||||
url: location.spec,
|
||||
type: type,
|
||||
tabId: -1,
|
||||
@ -105,7 +110,7 @@ let contentPolicy = {
|
||||
};
|
||||
|
||||
let docObserver = {
|
||||
contentBaseURI: 'chrome://ublock/content/js/',
|
||||
contentBaseURI: 'chrome://' + appName + '/content/js/',
|
||||
initContext: function(win, sandbox) {
|
||||
let messager = getMessager(win);
|
||||
|
||||
@ -115,6 +120,8 @@ let docObserver = {
|
||||
wantComponents: false,
|
||||
wantXHRConstructor: false
|
||||
});
|
||||
|
||||
win.self = win;
|
||||
}
|
||||
|
||||
win.sendAsyncMessage = messager.sendAsyncMessage;
|
||||
@ -151,17 +158,12 @@ let docObserver = {
|
||||
lss(this.contentBaseURI + 'vapi-client.js', win);
|
||||
lss(this.contentBaseURI + 'contentscript-start.js', win);
|
||||
|
||||
if (doc.readyState === 'interactive' || doc.readyState === 'complete') {
|
||||
lss(this.contentBaseURI + 'contentscript-end.js', win);
|
||||
}
|
||||
else {
|
||||
let docReady = function(e) {
|
||||
this.removeEventListener(e.type, docReady, true);
|
||||
lss(docObserver.contentBaseURI + 'contentscript-end.js', win);
|
||||
};
|
||||
let docReady = function(e) {
|
||||
this.removeEventListener(e.type, docReady, true);
|
||||
lss(docObserver.contentBaseURI + 'contentscript-end.js', win);
|
||||
};
|
||||
|
||||
doc.addEventListener('DOMContentLoaded', docReady, true);
|
||||
}
|
||||
doc.addEventListener('DOMContentLoaded', docReady, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,20 +1,27 @@
|
||||
/* globals Services, sendAsyncMessage, addMessageListener, removeMessageListener */
|
||||
|
||||
(function(frameScriptContext) {
|
||||
|
||||
'use strict';
|
||||
|
||||
let appName = 'ublock';
|
||||
let appName;
|
||||
let listeners = {};
|
||||
let frameModule = Components.utils['import']('chrome://' + appName + '/content/frameModule.js', {});
|
||||
|
||||
this.ublock_addMessageListener = function(id, fn) {
|
||||
ublock_removeMessageListener(id);
|
||||
try { throw new Error; } catch (ex) {
|
||||
appName = ex.fileName.match(/:\/\/([^\/]+)/)[1];
|
||||
}
|
||||
|
||||
Components.utils['import']('chrome://' + appName + '/content/frameModule.js', {});
|
||||
|
||||
frameScriptContext[appName + '_addMessageListener'] = function(id, fn) {
|
||||
frameScriptContext[appName + '_removeMessageListener'](id);
|
||||
listeners[id] = function(msg) {
|
||||
fn(msg.data);
|
||||
};
|
||||
addMessageListener(id, listeners[id]);
|
||||
};
|
||||
|
||||
this.ublock_removeMessageListener = function(id) {
|
||||
frameScriptContext[appName + '_removeMessageListener'] = function(id) {
|
||||
if (listeners[id]) {
|
||||
removeMessageListener(id, listeners[id]);
|
||||
}
|
||||
@ -27,3 +34,5 @@ addMessageListener(appName + ':broadcast', function(msg) {
|
||||
listeners[id](msg);
|
||||
}
|
||||
});
|
||||
|
||||
})(this);
|
@ -17,7 +17,7 @@
|
||||
<targetApplication>
|
||||
<r:Description>
|
||||
<id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</id>
|
||||
<minVersion>24.0</minVersion>
|
||||
<minVersion>29.0</minVersion>
|
||||
<maxVersion>37.0</maxVersion>
|
||||
</r:Description>
|
||||
</targetApplication>
|
||||
@ -26,7 +26,7 @@
|
||||
<targetApplication>
|
||||
<r:Description>
|
||||
<id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</id>
|
||||
<minVersion>2.21</minVersion>
|
||||
<minVersion>2.26</minVersion>
|
||||
<maxVersion>2.34</maxVersion>
|
||||
</r:Description>
|
||||
</targetApplication>
|
||||
|
@ -19,7 +19,7 @@
|
||||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
/* global Services */
|
||||
/* global Services, CustomizableUI */
|
||||
|
||||
// For background page
|
||||
|
||||
@ -34,26 +34,30 @@
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
|
||||
Cu['import']('resource://gre/modules/Services.jsm');
|
||||
Cu['import']('resource:///modules/CustomizableUI.jsm');
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
self.vAPI = self.vAPI || {};
|
||||
|
||||
vAPI.firefox = true;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.app = {
|
||||
name: 'µBlock',
|
||||
cleanName: 'ublock',
|
||||
version: '0.7.2.0'
|
||||
version: '0.7.2.0',
|
||||
cleanName: location.host
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.app.restart = function() {
|
||||
vAPI.app.restart = function() {};
|
||||
|
||||
};
|
||||
/******************************************************************************/
|
||||
|
||||
// list of things that needs to be destroyed when disabling the extension
|
||||
|
||||
vAPI.unload = [];
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
@ -76,10 +80,11 @@ var SQLite = {
|
||||
'CREATE TABLE IF NOT EXISTS settings' +
|
||||
'(name TEXT PRIMARY KEY NOT NULL, value TEXT);'
|
||||
);
|
||||
},
|
||||
close: function() {
|
||||
this.run('VACUUM');
|
||||
this.db.asyncClose();
|
||||
|
||||
vAPI.unload.push(function() {
|
||||
SQLite.run('VACUUM');
|
||||
SQLite.db.asyncClose();
|
||||
});
|
||||
},
|
||||
run: function(query, values, callback) {
|
||||
if (!this.db) {
|
||||
@ -233,10 +238,15 @@ vAPI.storage = {
|
||||
|
||||
var windowWatcher = {
|
||||
onTabClose: function(e) {
|
||||
vAPI.tabs.onClosed(vAPI.tabs.getTabId(e.target));
|
||||
var tabId = vAPI.tabs.getTabId(e.target);
|
||||
vAPI.tabs.onClosed(tabId);
|
||||
delete vAPI.tabIcons[tabId];
|
||||
},
|
||||
onTabSelect: function() {
|
||||
// vAPI.setIcon();
|
||||
onTabSelect: function(e) {
|
||||
vAPI.setIcon(
|
||||
vAPI.tabs.getTabId(e.target),
|
||||
e.target.ownerDocument.defaultView
|
||||
);
|
||||
},
|
||||
onLoad: function(e) {
|
||||
if (e) {
|
||||
@ -259,20 +269,10 @@ var windowWatcher = {
|
||||
tC.addEventListener('TabClose', windowWatcher.onTabClose);
|
||||
tC.addEventListener('TabSelect', windowWatcher.onTabSelect);
|
||||
|
||||
vAPI.toolbarButton.add(this.document);
|
||||
|
||||
// when new window is opened TabSelect doesn't run on the selected tab?
|
||||
},
|
||||
unregister: function() {
|
||||
Services.ww.unregisterNotification(this);
|
||||
|
||||
for (var win of vAPI.tabs.getWindows()) {
|
||||
win.removeEventListener('load', this.onLoad);
|
||||
win.gBrowser.removeTabsProgressListener(tabsProgressListener);
|
||||
|
||||
var tC = win.gBrowser.tabContainer;
|
||||
tC.removeEventListener('TabClose', this.onTabClose);
|
||||
tC.removeEventListener('TabSelect', this.onTabSelect);
|
||||
}
|
||||
},
|
||||
observe: function(win, topic) {
|
||||
if (topic === 'domwindowopened') {
|
||||
win.addEventListener('load', this.onLoad);
|
||||
@ -320,10 +320,35 @@ vAPI.tabs.registerListeners = function() {
|
||||
|
||||
Services.ww.registerNotification(windowWatcher);
|
||||
|
||||
// already opened windows
|
||||
for (var win of this.getWindows()) {
|
||||
windowWatcher.onLoad.call(win);
|
||||
}
|
||||
|
||||
vAPI.toolbarButton.init();
|
||||
|
||||
vAPI.unload.push(function() {
|
||||
Services.ww.unregisterNotification(windowWatcher);
|
||||
|
||||
for (var win of vAPI.tabs.getWindows()) {
|
||||
vAPI.toolbarButton.remove(win.document);
|
||||
|
||||
win.removeEventListener('load', windowWatcher.onLoad);
|
||||
win.gBrowser.removeTabsProgressListener(tabsProgressListener);
|
||||
|
||||
var tC = win.gBrowser.tabContainer;
|
||||
tC.removeEventListener('TabClose', windowWatcher.onTabClose);
|
||||
tC.removeEventListener('TabSelect', windowWatcher.onTabSelect);
|
||||
|
||||
// close extension tabs
|
||||
for (var tab of win.gBrowser.tabs) {
|
||||
var URI = tab.linkedBrowser.currentURI;
|
||||
|
||||
if (URI.scheme === 'chrome' && URI.host === vAPI.app.cleanName) {
|
||||
win.gBrowser.removeTab(tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
@ -513,21 +538,164 @@ vAPI.tabs.close = function(tabIds) {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/*vAPI.tabs.injectScript = function(tabId, details, callback) {
|
||||
vAPI.tabs.injectScript = function(tabId, details, callback) {
|
||||
|
||||
};*/
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.setIcon = function() {
|
||||
vAPI.tabIcons = { /*tabId: {badge: 0, img: dict}*/ };
|
||||
vAPI.setIcon = function(tabId, img, badge) {
|
||||
var curWin = badge === undefined ? img : Services.wm.getMostRecentWindow('navigator:browser');
|
||||
var curTabId = vAPI.tabs.getTabId(curWin.gBrowser.selectedTab);
|
||||
|
||||
// from 'TabSelect' event
|
||||
if (tabId === undefined) {
|
||||
tabId = curTabId;
|
||||
}
|
||||
else if (badge !== undefined) {
|
||||
vAPI.tabIcons[tabId] = {
|
||||
badge: badge === '>1K' ? '1k+' : badge,
|
||||
img: img && img[19] && img[19].replace(/19(-off)?\.png$/, '16$1.svg')
|
||||
};
|
||||
}
|
||||
|
||||
if (tabId !== curTabId) {
|
||||
return;
|
||||
}
|
||||
|
||||
var button = curWin.document.getElementById(vAPI.toolbarButton.widgetId);
|
||||
var icon = vAPI.tabIcons[tabId];
|
||||
button.setAttribute('badge', icon && icon.badge || '');
|
||||
button.style.listStyleImage = 'url(' + vAPI.getURL(icon && icon.img || 'img/browsericons/icon16-off.svg') + ')';
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.toolbarButton = {
|
||||
widgetId: vAPI.app.cleanName + '-button',
|
||||
panelId: vAPI.app.cleanName + '-panel'
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.toolbarButton.init = function() {
|
||||
CustomizableUI.createWidget({
|
||||
id: this.widgetId,
|
||||
type: 'view',
|
||||
viewId: this.panelId,
|
||||
defaultArea: CustomizableUI.AREA_NAVBAR,
|
||||
label: vAPI.app.name,
|
||||
tooltiptext: vAPI.app.name,
|
||||
onViewShowing: function(e) {
|
||||
e.target.firstChild.setAttribute('src', vAPI.getURL('popup.html'));
|
||||
},
|
||||
onViewHiding: function(e) {
|
||||
e.target.firstChild.setAttribute('src', 'about:blank');
|
||||
}
|
||||
});
|
||||
|
||||
var doc = Services.wm.getMostRecentWindow('navigator:browser').document;
|
||||
|
||||
var button = doc.getElementById(this.widgetId);
|
||||
button.style.listStyleImage = 'url(' + vAPI.getURL('img/icon16.svg') + ')';
|
||||
|
||||
if (!this.styleURI) {
|
||||
var css = encodeURIComponent([
|
||||
'#' + this.widgetId + '[badge]:not([badge=""])::after {',
|
||||
'position: absolute; color: #fff; background: #666;',
|
||||
'content: attr(badge); font-size: 9px; font-weight: bold;',
|
||||
'padding: 1px 2px; margin-left: -16px; margin-top: 3px }'
|
||||
].join(''));
|
||||
|
||||
this.styleURI = Services.io.newURI('data:text/css,' + css, null, null);
|
||||
}
|
||||
|
||||
var sss = Cc['@mozilla.org/content/style-sheet-service;1']
|
||||
.getService(Ci.nsIStyleSheetService);
|
||||
|
||||
sss.loadAndRegisterSheet(this.styleURI, sss.USER_SHEET);
|
||||
|
||||
vAPI.unload.push(function() {
|
||||
sss.unregisterSheet(this.styleURI, sss.USER_SHEET);
|
||||
CustomizableUI.createWidget(this.widgetId);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// it runs with windowWatcher when a window is opened
|
||||
// vAPI.tabs.registerListeners initializes it
|
||||
|
||||
vAPI.toolbarButton.add = function(doc) {
|
||||
var panel = doc.createElement('panelview');
|
||||
panel.id = this.panelId;
|
||||
|
||||
var iframe = panel.appendChild(doc.createElement('iframe'));
|
||||
iframe.setAttribute('type', 'content');
|
||||
|
||||
panel.style.cssText = iframe.style.cssText
|
||||
= 'width: 180px; height: 310px; transition: width .1s, height .1s';
|
||||
|
||||
doc.getElementById('PanelUI-multiView')
|
||||
.appendChild(panel)
|
||||
.appendChild(iframe);
|
||||
|
||||
var updateTimer = null;
|
||||
var delayedResize = function() {
|
||||
if (updateTimer) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateTimer = setTimeout(resizePopup, 20);
|
||||
};
|
||||
|
||||
var resizePopup = function() {
|
||||
var panelStyle = panel.style;
|
||||
var body = iframe.contentDocument.body;
|
||||
panelStyle.width = iframe.style.width = body.clientWidth + 'px';
|
||||
panelStyle.height = iframe.style.height = body.clientHeight + 'px';
|
||||
updateTimer = null;
|
||||
};
|
||||
|
||||
var onPopupReady = function() {
|
||||
if (!this.contentWindow
|
||||
|| this.contentWindow.location.host !== vAPI.app.cleanName) {
|
||||
return;
|
||||
}
|
||||
|
||||
var mutObs = this.contentWindow.MutationObserver;
|
||||
|
||||
(new mutObs(delayedResize)).observe(this.contentDocument, {
|
||||
childList: true,
|
||||
attributes: true,
|
||||
characterData: true,
|
||||
subtree: true
|
||||
});
|
||||
|
||||
delayedResize();
|
||||
};
|
||||
|
||||
iframe.addEventListener('load', onPopupReady, true);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.toolbarButton.remove = function(doc) {
|
||||
var panel = doc.getElementById(this.panelId);
|
||||
panel.parentNode.removeChild(panel);
|
||||
doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor).
|
||||
getInterface(Ci.nsIDOMWindowUtils).removeSheet(this.styleURI, 1);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.messaging = {
|
||||
gmm: Cc['@mozilla.org/globalmessagemanager;1'].getService(Ci.nsIMessageListenerManager),
|
||||
frameScript: 'chrome://' + vAPI.app.cleanName + '/content/frameScript.js',
|
||||
get globalMessageManager() {
|
||||
return Cc['@mozilla.org/globalmessagemanager;1']
|
||||
.getService(Ci.nsIMessageListenerManager);
|
||||
},
|
||||
frameScript: vAPI.getURL('frameScript.js'),
|
||||
listeners: {},
|
||||
defaultHandler: null,
|
||||
NOOPFUNC: function(){},
|
||||
@ -536,10 +704,6 @@ vAPI.messaging = {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.messaging.gmm.loadFrameScript(vAPI.messaging.frameScript, true);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.messaging.listen = function(listenerName, callback) {
|
||||
this.listeners[listenerName] = callback;
|
||||
};
|
||||
@ -548,6 +712,15 @@ vAPI.messaging.listen = function(listenerName, callback) {
|
||||
|
||||
vAPI.messaging.onMessage = function(request) {
|
||||
var messageManager = request.target.messageManager;
|
||||
|
||||
if (!messageManager) {
|
||||
// Message came from a popup, and its message manager is not usable.
|
||||
// So instead we broadcast to the parent window.
|
||||
messageManager = request.target
|
||||
.webNavigation.QueryInterface(Ci.nsIDocShell)
|
||||
.chromeEventHandler.ownerDocument.defaultView.messageManager;
|
||||
}
|
||||
|
||||
var listenerId = request.data.portName.split('|');
|
||||
var requestId = request.data.requestId;
|
||||
var portName = listenerId[1];
|
||||
@ -556,14 +729,18 @@ vAPI.messaging.onMessage = function(request) {
|
||||
var callback = vAPI.messaging.NOOPFUNC;
|
||||
if ( requestId !== undefined ) {
|
||||
callback = function(response) {
|
||||
messageManager.sendAsyncMessage(
|
||||
listenerId,
|
||||
JSON.stringify({
|
||||
requestId: requestId,
|
||||
portName: portName,
|
||||
msg: response !== undefined ? response : null
|
||||
})
|
||||
);
|
||||
var message = JSON.stringify({
|
||||
requestId: requestId,
|
||||
portName: portName,
|
||||
msg: response !== undefined ? response : null
|
||||
});
|
||||
|
||||
if (messageManager.sendAsyncMessage) {
|
||||
messageManager.sendAsyncMessage(listenerId, message);
|
||||
}
|
||||
else {
|
||||
messageManager.broadcastAsyncMessage(listenerId, message);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -610,16 +787,28 @@ vAPI.messaging.setup = function(defaultHandler) {
|
||||
}
|
||||
this.defaultHandler = defaultHandler;
|
||||
|
||||
this.gmm.addMessageListener(
|
||||
this.globalMessageManager.addMessageListener(
|
||||
vAPI.app.cleanName + ':background',
|
||||
this.onMessage
|
||||
);
|
||||
|
||||
this.globalMessageManager.loadFrameScript(vAPI.messaging.frameScript, true);
|
||||
|
||||
vAPI.unload.push(function() {
|
||||
var gmm = vAPI.messaging.globalMessageManager;
|
||||
|
||||
gmm.removeDelayedFrameScript(vAPI.messaging.frameScript);
|
||||
gmm.removeMessageListener(
|
||||
vAPI.app.cleanName + ':background',
|
||||
vAPI.messaging.onMessage
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.messaging.broadcast = function(message) {
|
||||
this.gmm.broadcastAsyncMessage(
|
||||
this.globalMessageManager.broadcastAsyncMessage(
|
||||
vAPI.app.cleanName + ':broadcast',
|
||||
JSON.stringify({broadcast: true, msg: message})
|
||||
);
|
||||
@ -627,20 +816,12 @@ vAPI.messaging.broadcast = function(message) {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.messaging.unload = function() {
|
||||
this.gmm.removeMessageListener(
|
||||
vAPI.app.cleanName + ':background',
|
||||
this.onMessage
|
||||
);
|
||||
this.gmm.removeDelayedFrameScript(this.frameScript);
|
||||
vAPI.net = {
|
||||
beforeRequestMessageName: vAPI.app.cleanName + ':onBeforeRequest'
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.net = {};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.net.registerListeners = function() {
|
||||
var types = {
|
||||
2: 'script',
|
||||
@ -677,20 +858,30 @@ vAPI.net.registerListeners = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
vAPI.messaging.gmm.addMessageListener(
|
||||
vAPI.app.cleanName + ':onBeforeRequest',
|
||||
vAPI.messaging.globalMessageManager.addMessageListener(
|
||||
this.beforeRequestMessageName,
|
||||
this.onBeforeRequest
|
||||
);
|
||||
|
||||
vAPI.unload.push(function() {
|
||||
vAPI.messaging.globalMessageManager.removeMessageListener(
|
||||
vAPI.net.beforeRequestMessageName,
|
||||
vAPI.net.onBeforeRequest
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.net.unregisterListeners = function() {
|
||||
vAPI.messaging.gmm.removeMessageListener(
|
||||
vAPI.app.cleanName + ':onBeforeRequest',
|
||||
this.onBeforeRequest
|
||||
);
|
||||
};
|
||||
vAPI.contextMenu = {};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.contextMenu.create = function(details, callback) {};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.contextMenu.remove = function() {};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
@ -703,30 +894,16 @@ vAPI.lastError = function() {
|
||||
// clean up when the extension is disabled
|
||||
|
||||
window.addEventListener('unload', function() {
|
||||
SQLite.close();
|
||||
windowWatcher.unregister();
|
||||
vAPI.messaging.unload();
|
||||
vAPI.net.unregisterListeners();
|
||||
for (var unload of vAPI.unload) {
|
||||
unload();
|
||||
}
|
||||
|
||||
var URI = vAPI.messaging.frameScript.replace('Script.', 'Module.');
|
||||
// frameModule needs to be cleared too
|
||||
var frameModule = {};
|
||||
Cu['import'](URI, frameModule);
|
||||
Cu['import'](vAPI.getURL('frameModule.js'), frameModule);
|
||||
frameModule.contentPolicy.unregister();
|
||||
frameModule.docObserver.unregister();
|
||||
Cu.unload(URI);
|
||||
|
||||
// close extension tabs
|
||||
var win, tab, host = vAPI.app.cleanName;
|
||||
|
||||
for (win of vAPI.tabs.getWindows()) {
|
||||
for (tab of win.gBrowser.tabs) {
|
||||
URI = tab.linkedBrowser.currentURI;
|
||||
|
||||
if (URI.scheme === 'chrome' && URI.host === host) {
|
||||
win.gBrowser.removeTab(tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
Cu.unload(vAPI.getURL('frameModule.js'));
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -19,6 +19,8 @@
|
||||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
/* global addMessageListener, removeMessageListener, sendAsyncMessage */
|
||||
|
||||
// For non background pages
|
||||
|
||||
/******************************************************************************/
|
||||
@ -74,7 +76,7 @@ var messagingConnector = function(response) {
|
||||
/******************************************************************************/
|
||||
|
||||
var uniqueId = function() {
|
||||
return parseInt(Math.random() * 1e10, 10).toString(36);
|
||||
return Math.random().toString(36).slice(2);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -69,13 +69,15 @@ vAPI.download = function(details) {
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.getURL = function(path) {
|
||||
return 'chrome://ublock/content/' + path.replace(/^\/+/, '');
|
||||
return 'chrome://' + location.host + '/content/' + path.replace(/^\/+/, '');
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.i18n = (function() {
|
||||
var stringBundle = Components.classes['@mozilla.org/intl/stringbundle;1']
|
||||
.getService(Components.interfaces.nsIStringBundleService)
|
||||
.createBundle('chrome://ublock/locale/messages.properties');
|
||||
.createBundle('chrome://' + location.host + '/locale/messages.properties');
|
||||
|
||||
return function(s) {
|
||||
try {
|
||||
|
@ -37,7 +37,7 @@
|
||||
<key>Identifier</key>
|
||||
<string>toolbarItem</string>
|
||||
<key>Image</key>
|
||||
<string>img/icon16.png</string>
|
||||
<string>img/browsericons/icon16.png</string>
|
||||
<key>Label</key>
|
||||
<string>{name}</string>
|
||||
<key>Popover</key>
|
||||
|
@ -74,7 +74,7 @@ var messagingConnector = function(response) {
|
||||
/******************************************************************************/
|
||||
|
||||
var uniqueId = function() {
|
||||
return parseInt(Math.random() * 1e10, 10).toString(36);
|
||||
return Math.random().toString(36).slice(2);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
@ -359,7 +359,7 @@ var firstMutation = function() {
|
||||
'return r;',
|
||||
'};',
|
||||
'history.replaceState = function() {',
|
||||
'var r = pR.apply(this, arguments);',
|
||||
'var r = rS.apply(this, arguments);',
|
||||
'onpopstate();',
|
||||
'return r;',
|
||||
'};'
|
||||
|
16
src/img/browsericons/icon16-off.svg
Normal file
16
src/img/browsericons/icon16-off.svg
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 603 603">
|
||||
<g transform="translate(-2.9000336,4.3318037)">
|
||||
<g transform="matrix(4.4946163,0,0,4.4784113,-1996.8254,-3025.1919)">
|
||||
<g>
|
||||
<path d="m 450.58474,716.40132 0,51.00389 35.87406,36.2877 51.05503,0 35.91927,-36.3334 0,-51.68942 -35.03824,-35.44222 -52.20713,0 z" style="fill: #7c7c7c; stroke:#ffffff; stroke-width: 2" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g transform="translate(-2.9000336,4.3318037)">
|
||||
<g transform="matrix(0.97521805,0,0,1.0217146,0,0.07624875)" style="fill:#ffffff">
|
||||
<path
|
||||
d="m 218.83305,472.64625 61.97723,0 0,-53.96657 -3.79453,-37.94524 c 3.59241,3.70669 7.58016,6.20123 11.96329,7.48364 4.38293,1.28241 9.10851,1.8797 14.17677,1.79186 9.372,-0.0176 18.03265,-2.61752 25.98195,-7.79986 7.94903,-5.18233 14.60701,-12.84164 19.97396,-22.97795 l 1.68646,0 4.63775,29.09136 50.59366,0 0,-209.12047 -61.97724,0 0,138.28934 c -5.93788,8.16005 -11.7702,14.08021 -17.49698,17.76048 -5.72704,3.68038 -12.40259,5.48981 -20.02665,5.42828 -8.81887,0.21964 -15.31875,-2.64382 -19.49965,-8.59038 -4.18109,-5.94645 -6.25402,-16.29355 -6.21879,-31.04132 l 0,-121.8464 -61.97723,0 z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 401 B After Width: | Height: | Size: 401 B |
16
src/img/browsericons/icon16.svg
Normal file
16
src/img/browsericons/icon16.svg
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 603 603">
|
||||
<g transform="translate(-2.9000336,4.3318037)">
|
||||
<g transform="matrix(4.4946163,0,0,4.4784113,-1996.8254,-3025.1919)">
|
||||
<g>
|
||||
<path d="m 450.58474,716.40132 0,51.00389 35.87406,36.2877 51.05503,0 35.91927,-36.3334 0,-51.68942 -35.03824,-35.44222 -52.20713,0 z" style="fill: #800000; stroke: #ffffff; stroke-width: 2" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g transform="translate(-2.9000336,4.3318037)">
|
||||
<g transform="matrix(0.97521805,0,0,1.0217146,0,0.07624875)" style="fill:#ffffff">
|
||||
<path
|
||||
d="m 218.83305,472.64625 61.97723,0 0,-53.96657 -3.79453,-37.94524 c 3.59241,3.70669 7.58016,6.20123 11.96329,7.48364 4.38293,1.28241 9.10851,1.8797 14.17677,1.79186 9.372,-0.0176 18.03265,-2.61752 25.98195,-7.79986 7.94903,-5.18233 14.60701,-12.84164 19.97396,-22.97795 l 1.68646,0 4.63775,29.09136 50.59366,0 0,-209.12047 -61.97724,0 0,138.28934 c -5.93788,8.16005 -11.7702,14.08021 -17.49698,17.76048 -5.72704,3.68038 -12.40259,5.48981 -20.02665,5.42828 -8.81887,0.21964 -15.31875,-2.64382 -19.49965,-8.59038 -4.18109,-5.94645 -6.25402,-16.29355 -6.21879,-31.04132 l 0,-121.8464 -61.97723,0 z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 661 B After Width: | Height: | Size: 661 B |
@ -44,14 +44,7 @@ if ( !matches || matches.length !== 2 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
uDom.onLoad(function() {
|
||||
messager.send({
|
||||
what: 'getAssetContent',
|
||||
url: matches[1]
|
||||
},
|
||||
onAssetContentReceived
|
||||
);
|
||||
});
|
||||
messager.send({ what : 'getAssetContent', url: matches[1] }, onAssetContentReceived);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user