mirror of https://github.com/gorhill/uBlock.git
Firefox: ownsWeak=true for observers, +minor mods
This commit is contained in:
parent
b8c943d539
commit
9169388849
|
@ -98,7 +98,12 @@ const contentPolicy = {
|
|||
},
|
||||
// https://bugzil.la/612921
|
||||
shouldLoad: function(type, location, origin, context) {
|
||||
if (!context || !/^https?$/.test(location.scheme)) {
|
||||
// If we don't know what initiated the request, probably it's not a tab
|
||||
if ( !context ) {
|
||||
return this.ACCEPT;
|
||||
}
|
||||
|
||||
if ( location.scheme !== 'http' && location.scheme !== 'https' ) {
|
||||
return this.ACCEPT;
|
||||
}
|
||||
|
||||
|
@ -122,7 +127,11 @@ const contentPolicy = {
|
|||
/******************************************************************************/
|
||||
|
||||
const docObserver = {
|
||||
contentBaseURI: 'chrome://' + appName + '/content/',
|
||||
contentBaseURI: 'chrome://' + appName + '/content/js/',
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsIObserver,
|
||||
Ci.nsISupportsWeakReference
|
||||
]),
|
||||
initContext: function(win, sandbox) {
|
||||
let messager = getMessageManager(win);
|
||||
|
||||
|
@ -143,10 +152,7 @@ const docObserver = {
|
|||
return;
|
||||
}
|
||||
|
||||
Services.scriptloader.loadSubScript(
|
||||
docObserver.contentBaseURI + script,
|
||||
win
|
||||
);
|
||||
Services.scriptloader.loadSubScript(script, win);
|
||||
},
|
||||
win
|
||||
);
|
||||
|
@ -159,7 +165,7 @@ const docObserver = {
|
|||
return win;
|
||||
},
|
||||
register: function() {
|
||||
Services.obs.addObserver(this, 'document-element-inserted', false);
|
||||
Services.obs.addObserver(this, 'document-element-inserted', true);
|
||||
},
|
||||
unregister: function() {
|
||||
Services.obs.removeObserver(this, 'document-element-inserted');
|
||||
|
@ -171,9 +177,10 @@ const docObserver = {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!/^https?:$/.test(win.location.protocol)) {
|
||||
if (win.location.protocol === 'chrome:'
|
||||
&& win.location.host === appName) {
|
||||
let loc = win.location;
|
||||
|
||||
if (loc.protocol !== 'http:' && loc.protocol !== 'https:') {
|
||||
if (loc.protocol === 'chrome:' && loc.host === appName) {
|
||||
this.initContext(win);
|
||||
}
|
||||
|
||||
|
@ -183,15 +190,15 @@ const docObserver = {
|
|||
let lss = Services.scriptloader.loadSubScript;
|
||||
win = this.initContext(win, true);
|
||||
|
||||
lss(this.contentBaseURI + 'js/vapi-client.js', win);
|
||||
lss(this.contentBaseURI + 'js/contentscript-start.js', win);
|
||||
lss(this.contentBaseURI + 'vapi-client.js', win);
|
||||
lss(this.contentBaseURI + 'contentscript-start.js', win);
|
||||
|
||||
let docReady = function(e) {
|
||||
this.removeEventListener(e.type, docReady, true);
|
||||
lss(docObserver.contentBaseURI + 'js/contentscript-end.js', win);
|
||||
lss(docObserver.contentBaseURI + 'contentscript-end.js', win);
|
||||
};
|
||||
|
||||
doc.addEventListener('DOMContentLoaded', docReady, true);
|
||||
win.document.addEventListener('DOMContentLoaded', docReady, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -321,7 +321,6 @@ vAPI.tabs.registerListeners = function() {
|
|||
// onClosed - handled in windowWatcher.onTabClose
|
||||
// onPopup ?
|
||||
|
||||
|
||||
for (var win of this.getWindows()) {
|
||||
windowWatcher.onReady.call(win);
|
||||
}
|
||||
|
@ -561,6 +560,10 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (details.file) {
|
||||
details.file = vAPI.getURL(details.file);
|
||||
}
|
||||
|
||||
tab.linkedBrowser.messageManager.sendAsyncMessage(
|
||||
location.host + ':broadcast',
|
||||
JSON.stringify({
|
||||
|
@ -580,7 +583,7 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.tabIcons = { /*tabId: {badge: 0, img: ''}*/ };
|
||||
vAPI.tabIcons = { /*tabId: {badge: 0, img: boolean}*/ };
|
||||
vAPI.setIcon = function(tabId, iconStatus, badge) {
|
||||
// If badge is undefined, then setIcon was called from the TabSelect event
|
||||
var curWin = badge === undefined
|
||||
|
@ -718,6 +721,11 @@ vAPI.toolbarButton.register = function(doc) {
|
|||
|
||||
if (!this.styleURI) {
|
||||
this.styleURI = 'data:text/css,' + encodeURIComponent([
|
||||
'#' + this.widgetId + ' {',
|
||||
'list-style-image: url(',
|
||||
vAPI.getURL('img/browsericons/icon16-off.svg'),
|
||||
');',
|
||||
'}',
|
||||
'#' + this.widgetId + '[badge]:not([badge=""])::after {',
|
||||
'position: absolute;',
|
||||
'margin-left: -16px;',
|
||||
|
@ -856,7 +864,7 @@ vAPI.messaging.setup = function(defaultHandler) {
|
|||
this.onMessage
|
||||
);
|
||||
|
||||
this.globalMessageManager.loadFrameScript(vAPI.messaging.frameScript, true);
|
||||
this.globalMessageManager.loadFrameScript(this.frameScript, true);
|
||||
|
||||
vAPI.unload.push(function() {
|
||||
var gmm = vAPI.messaging.globalMessageManager;
|
||||
|
@ -880,10 +888,6 @@ vAPI.messaging.broadcast = function(message) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.net = {};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var httpObserver = {
|
||||
ABORT: Components.results.NS_BINDING_ABORTED,
|
||||
lastRequest: {
|
||||
|
@ -893,6 +897,23 @@ var httpObserver = {
|
|||
frameId: null,
|
||||
parentFrameId: null
|
||||
},
|
||||
QueryInterface: (function() {
|
||||
var {XPCOMUtils} = Cu['import']('resource://gre/modules/XPCOMUtils.jsm', {});
|
||||
return XPCOMUtils.generateQI([
|
||||
Ci.nsIObserver,
|
||||
Ci.nsISupportsWeakReference
|
||||
]);
|
||||
})(),
|
||||
register: function() {
|
||||
Services.obs.addObserver(httpObserver, 'http-on-opening-request', true);
|
||||
// Services.obs.addObserver(httpObserver, 'http-on-modify-request', true);
|
||||
Services.obs.addObserver(httpObserver, 'http-on-examine-response', true);
|
||||
},
|
||||
unregister: function() {
|
||||
Services.obs.removeObserver(httpObserver, 'http-on-opening-request');
|
||||
// Services.obs.removeObserver(httpObserver, 'http-on-modify-request');
|
||||
Services.obs.removeObserver(httpObserver, 'http-on-examine-response');
|
||||
},
|
||||
observe: function(httpChannel, topic) {
|
||||
// No need for QueryInterface if this check is performed?
|
||||
if (!(httpChannel instanceof Ci.nsIHttpChannel)) {
|
||||
|
@ -994,6 +1015,10 @@ var httpObserver = {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.net = {};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.net.registerListeners = function() {
|
||||
var typeMap = {
|
||||
2: 'script',
|
||||
|
@ -1022,9 +1047,7 @@ vAPI.net.registerListeners = function() {
|
|||
shouldLoadListener
|
||||
);
|
||||
|
||||
Services.obs.addObserver(httpObserver, 'http-on-opening-request', false);
|
||||
// Services.obs.addObserver(httpObserver, 'http-on-modify-request', false);
|
||||
Services.obs.addObserver(httpObserver, 'http-on-examine-response', false);
|
||||
httpObserver.register();
|
||||
|
||||
vAPI.unload.push(function() {
|
||||
vAPI.messaging.globalMessageManager.removeMessageListener(
|
||||
|
@ -1032,9 +1055,7 @@ vAPI.net.registerListeners = function() {
|
|||
shouldLoadListener
|
||||
);
|
||||
|
||||
Services.obs.removeObserver(httpObserver, 'http-on-opening-request');
|
||||
// Services.obs.removeObserver(httpObserver, 'http-on-modify-request');
|
||||
Services.obs.removeObserver(httpObserver, 'http-on-examine-response');
|
||||
httpObserver.unregister();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -427,7 +427,7 @@ safari.application.addEventListener('popover', function(e) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.tabIcons = { /*tabId: {badge: 0, img: dict}*/ };
|
||||
vAPI.tabIcons = { /*tabId: {badge: 0, img: suffix}*/ };
|
||||
vAPI.setIcon = function(tabId, iconStatus, badge) {
|
||||
var curTabId = vAPI.tabs.getTabId(
|
||||
safari.application.activeBrowserWindow.activeTab
|
||||
|
|
|
@ -22,7 +22,7 @@ cp platform/safari/Info.plist $DES/
|
|||
cp platform/safari/Settings.plist $DES/
|
||||
cp LICENSE.txt $DES/
|
||||
|
||||
echo "*** uBlock_xpi: Generating meta..."
|
||||
echo "*** uBlock.safariextension: Generating meta..."
|
||||
python tools/make-safari-meta.py $DES/
|
||||
|
||||
echo "*** uBlock.safariextension: Package done."
|
||||
|
|
Loading…
Reference in New Issue