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
|
// https://bugzil.la/612921
|
||||||
shouldLoad: function(type, location, origin, context) {
|
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;
|
return this.ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +111,7 @@ const contentPolicy = {
|
||||||
? context.contentWindow || context
|
? context.contentWindow || context
|
||||||
: (context.ownerDocument || context).defaultView;
|
: (context.ownerDocument || context).defaultView;
|
||||||
|
|
||||||
if (win) {
|
if ( win ) {
|
||||||
getMessageManager(win).sendSyncMessage(this.messageName, {
|
getMessageManager(win).sendSyncMessage(this.messageName, {
|
||||||
url: location.spec,
|
url: location.spec,
|
||||||
type: type,
|
type: type,
|
||||||
|
@ -122,7 +127,11 @@ const contentPolicy = {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const docObserver = {
|
const docObserver = {
|
||||||
contentBaseURI: 'chrome://' + appName + '/content/',
|
contentBaseURI: 'chrome://' + appName + '/content/js/',
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([
|
||||||
|
Ci.nsIObserver,
|
||||||
|
Ci.nsISupportsWeakReference
|
||||||
|
]),
|
||||||
initContext: function(win, sandbox) {
|
initContext: function(win, sandbox) {
|
||||||
let messager = getMessageManager(win);
|
let messager = getMessageManager(win);
|
||||||
|
|
||||||
|
@ -143,10 +152,7 @@ const docObserver = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.scriptloader.loadSubScript(
|
Services.scriptloader.loadSubScript(script, win);
|
||||||
docObserver.contentBaseURI + script,
|
|
||||||
win
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
win
|
win
|
||||||
);
|
);
|
||||||
|
@ -159,7 +165,7 @@ const docObserver = {
|
||||||
return win;
|
return win;
|
||||||
},
|
},
|
||||||
register: function() {
|
register: function() {
|
||||||
Services.obs.addObserver(this, 'document-element-inserted', false);
|
Services.obs.addObserver(this, 'document-element-inserted', true);
|
||||||
},
|
},
|
||||||
unregister: function() {
|
unregister: function() {
|
||||||
Services.obs.removeObserver(this, 'document-element-inserted');
|
Services.obs.removeObserver(this, 'document-element-inserted');
|
||||||
|
@ -171,9 +177,10 @@ const docObserver = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!/^https?:$/.test(win.location.protocol)) {
|
let loc = win.location;
|
||||||
if (win.location.protocol === 'chrome:'
|
|
||||||
&& win.location.host === appName) {
|
if (loc.protocol !== 'http:' && loc.protocol !== 'https:') {
|
||||||
|
if (loc.protocol === 'chrome:' && loc.host === appName) {
|
||||||
this.initContext(win);
|
this.initContext(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,15 +190,15 @@ const docObserver = {
|
||||||
let lss = Services.scriptloader.loadSubScript;
|
let lss = Services.scriptloader.loadSubScript;
|
||||||
win = this.initContext(win, true);
|
win = this.initContext(win, true);
|
||||||
|
|
||||||
lss(this.contentBaseURI + 'js/vapi-client.js', win);
|
lss(this.contentBaseURI + 'vapi-client.js', win);
|
||||||
lss(this.contentBaseURI + 'js/contentscript-start.js', win);
|
lss(this.contentBaseURI + 'contentscript-start.js', win);
|
||||||
|
|
||||||
let docReady = function(e) {
|
let docReady = function(e) {
|
||||||
this.removeEventListener(e.type, docReady, true);
|
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
|
// onClosed - handled in windowWatcher.onTabClose
|
||||||
// onPopup ?
|
// onPopup ?
|
||||||
|
|
||||||
|
|
||||||
for (var win of this.getWindows()) {
|
for (var win of this.getWindows()) {
|
||||||
windowWatcher.onReady.call(win);
|
windowWatcher.onReady.call(win);
|
||||||
}
|
}
|
||||||
|
@ -561,6 +560,10 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (details.file) {
|
||||||
|
details.file = vAPI.getURL(details.file);
|
||||||
|
}
|
||||||
|
|
||||||
tab.linkedBrowser.messageManager.sendAsyncMessage(
|
tab.linkedBrowser.messageManager.sendAsyncMessage(
|
||||||
location.host + ':broadcast',
|
location.host + ':broadcast',
|
||||||
JSON.stringify({
|
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) {
|
vAPI.setIcon = function(tabId, iconStatus, badge) {
|
||||||
// If badge is undefined, then setIcon was called from the TabSelect event
|
// If badge is undefined, then setIcon was called from the TabSelect event
|
||||||
var curWin = badge === undefined
|
var curWin = badge === undefined
|
||||||
|
@ -718,6 +721,11 @@ vAPI.toolbarButton.register = function(doc) {
|
||||||
|
|
||||||
if (!this.styleURI) {
|
if (!this.styleURI) {
|
||||||
this.styleURI = 'data:text/css,' + encodeURIComponent([
|
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 {',
|
'#' + this.widgetId + '[badge]:not([badge=""])::after {',
|
||||||
'position: absolute;',
|
'position: absolute;',
|
||||||
'margin-left: -16px;',
|
'margin-left: -16px;',
|
||||||
|
@ -856,7 +864,7 @@ vAPI.messaging.setup = function(defaultHandler) {
|
||||||
this.onMessage
|
this.onMessage
|
||||||
);
|
);
|
||||||
|
|
||||||
this.globalMessageManager.loadFrameScript(vAPI.messaging.frameScript, true);
|
this.globalMessageManager.loadFrameScript(this.frameScript, true);
|
||||||
|
|
||||||
vAPI.unload.push(function() {
|
vAPI.unload.push(function() {
|
||||||
var gmm = vAPI.messaging.globalMessageManager;
|
var gmm = vAPI.messaging.globalMessageManager;
|
||||||
|
@ -880,10 +888,6 @@ vAPI.messaging.broadcast = function(message) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.net = {};
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
var httpObserver = {
|
var httpObserver = {
|
||||||
ABORT: Components.results.NS_BINDING_ABORTED,
|
ABORT: Components.results.NS_BINDING_ABORTED,
|
||||||
lastRequest: {
|
lastRequest: {
|
||||||
|
@ -893,6 +897,23 @@ var httpObserver = {
|
||||||
frameId: null,
|
frameId: null,
|
||||||
parentFrameId: 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) {
|
observe: function(httpChannel, topic) {
|
||||||
// No need for QueryInterface if this check is performed?
|
// No need for QueryInterface if this check is performed?
|
||||||
if (!(httpChannel instanceof Ci.nsIHttpChannel)) {
|
if (!(httpChannel instanceof Ci.nsIHttpChannel)) {
|
||||||
|
@ -994,14 +1015,18 @@ var httpObserver = {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.net = {};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.net.registerListeners = function() {
|
vAPI.net.registerListeners = function() {
|
||||||
var typeMap = {
|
var typeMap = {
|
||||||
2: 'script',
|
2: 'script',
|
||||||
3: 'image',
|
3: 'image',
|
||||||
4: 'stylesheet',
|
4: 'stylesheet',
|
||||||
5: 'object',
|
5: 'object',
|
||||||
6: 'main_frame',
|
6: 'main_frame',
|
||||||
7: 'sub_frame',
|
7: 'sub_frame',
|
||||||
11: 'xmlhttprequest'
|
11: 'xmlhttprequest'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1022,9 +1047,7 @@ vAPI.net.registerListeners = function() {
|
||||||
shouldLoadListener
|
shouldLoadListener
|
||||||
);
|
);
|
||||||
|
|
||||||
Services.obs.addObserver(httpObserver, 'http-on-opening-request', false);
|
httpObserver.register();
|
||||||
// Services.obs.addObserver(httpObserver, 'http-on-modify-request', false);
|
|
||||||
Services.obs.addObserver(httpObserver, 'http-on-examine-response', false);
|
|
||||||
|
|
||||||
vAPI.unload.push(function() {
|
vAPI.unload.push(function() {
|
||||||
vAPI.messaging.globalMessageManager.removeMessageListener(
|
vAPI.messaging.globalMessageManager.removeMessageListener(
|
||||||
|
@ -1032,9 +1055,7 @@ vAPI.net.registerListeners = function() {
|
||||||
shouldLoadListener
|
shouldLoadListener
|
||||||
);
|
);
|
||||||
|
|
||||||
Services.obs.removeObserver(httpObserver, 'http-on-opening-request');
|
httpObserver.unregister();
|
||||||
// Services.obs.removeObserver(httpObserver, 'http-on-modify-request');
|
|
||||||
Services.obs.removeObserver(httpObserver, 'http-on-examine-response');
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
vAPI.setIcon = function(tabId, iconStatus, badge) {
|
||||||
var curTabId = vAPI.tabs.getTabId(
|
var curTabId = vAPI.tabs.getTabId(
|
||||||
safari.application.activeBrowserWindow.activeTab
|
safari.application.activeBrowserWindow.activeTab
|
||||||
|
|
|
@ -22,7 +22,7 @@ cp platform/safari/Info.plist $DES/
|
||||||
cp platform/safari/Settings.plist $DES/
|
cp platform/safari/Settings.plist $DES/
|
||||||
cp LICENSE.txt $DES/
|
cp LICENSE.txt $DES/
|
||||||
|
|
||||||
echo "*** uBlock_xpi: Generating meta..."
|
echo "*** uBlock.safariextension: Generating meta..."
|
||||||
python tools/make-safari-meta.py $DES/
|
python tools/make-safari-meta.py $DES/
|
||||||
|
|
||||||
echo "*** uBlock.safariextension: Package done."
|
echo "*** uBlock.safariextension: Package done."
|
||||||
|
|
Loading…
Reference in New Issue