mirror of https://github.com/gorhill/uBlock.git
Firefox: fixed content scripts?
This commit is contained in:
parent
687d226ce9
commit
a71c967613
|
@ -30,8 +30,6 @@ const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
|
||||||
const hostName = Services.io.newURI(Components.stack.filename, null, null).host;
|
const hostName = Services.io.newURI(Components.stack.filename, null, null).host;
|
||||||
let uniqueSandboxId = 1;
|
let uniqueSandboxId = 1;
|
||||||
|
|
||||||
Cu.import('resource://gre/modules/devtools/Console.jsm');
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const getMessageManager = function(win) {
|
const getMessageManager = function(win) {
|
||||||
|
@ -54,7 +52,6 @@ const contentObserver = {
|
||||||
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
||||||
contentBaseURI: 'chrome://' + hostName + '/content/js/',
|
contentBaseURI: 'chrome://' + hostName + '/content/js/',
|
||||||
cpMessageName: hostName + ':shouldLoad',
|
cpMessageName: hostName + ':shouldLoad',
|
||||||
frameSandboxes: new WeakMap(),
|
|
||||||
|
|
||||||
get componentRegistrar() {
|
get componentRegistrar() {
|
||||||
return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||||
|
@ -86,7 +83,6 @@ const contentObserver = {
|
||||||
|
|
||||||
register: function() {
|
register: function() {
|
||||||
Services.obs.addObserver(this, 'document-element-inserted', true);
|
Services.obs.addObserver(this, 'document-element-inserted', true);
|
||||||
Services.obs.addObserver(this, 'dom-window-destroyed', true);
|
|
||||||
|
|
||||||
this.componentRegistrar.registerFactory(
|
this.componentRegistrar.registerFactory(
|
||||||
this.classID,
|
this.classID,
|
||||||
|
@ -105,7 +101,6 @@ const contentObserver = {
|
||||||
|
|
||||||
unregister: function() {
|
unregister: function() {
|
||||||
Services.obs.removeObserver(this, 'document-element-inserted');
|
Services.obs.removeObserver(this, 'document-element-inserted');
|
||||||
Services.obs.removeObserver(this, 'dom-window-destroyed');
|
|
||||||
|
|
||||||
this.componentRegistrar.unregisterFactory(this.classID, this);
|
this.componentRegistrar.unregisterFactory(this.classID, this);
|
||||||
this.categoryManager.deleteCategoryEntry(
|
this.categoryManager.deleteCategoryEntry(
|
||||||
|
@ -196,10 +191,6 @@ const contentObserver = {
|
||||||
sandbox = win;
|
sandbox = win;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( win !== win.top ) {
|
|
||||||
this.frameSandboxes.set(win, sandbox);
|
|
||||||
}
|
|
||||||
|
|
||||||
sandbox._sandboxId_ = sandboxId;
|
sandbox._sandboxId_ = sandboxId;
|
||||||
sandbox.sendAsyncMessage = messager.sendAsyncMessage;
|
sandbox.sendAsyncMessage = messager.sendAsyncMessage;
|
||||||
sandbox.addMessageListener = function(callback) {
|
sandbox.addMessageListener = function(callback) {
|
||||||
|
@ -238,18 +229,7 @@ const contentObserver = {
|
||||||
return sandbox;
|
return sandbox;
|
||||||
},
|
},
|
||||||
|
|
||||||
observe: function(subject, topic) {
|
observe: function(subject) {
|
||||||
if ( topic === 'dom-window-destroyed' ) {
|
|
||||||
let sandbox = this.frameSandboxes.get(subject);
|
|
||||||
|
|
||||||
if ( sandbox ) {
|
|
||||||
sandbox.removeMessageListener();
|
|
||||||
this.frameSandboxes.delete(subject);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let win = subject.defaultView;
|
let win = subject.defaultView;
|
||||||
|
|
||||||
if ( !win ) {
|
if ( !win ) {
|
||||||
|
|
|
@ -30,8 +30,7 @@
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||||
|
const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
|
||||||
Cu.import('resource://gre/modules/Services.jsm');
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
|
@ -149,14 +149,16 @@ vAPI.messaging = {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var toggleListener = function({type, persisted}) {
|
var toggleListener = function({type, persisted}) {
|
||||||
if ( !persisted || !vAPI.messaging.connector ) {
|
if ( !vAPI.messaging.connector ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( type === 'pagehide' ) {
|
if ( type === 'pagehide' ) {
|
||||||
removeMessageListener();
|
removeMessageListener();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
if ( persisted ) {
|
||||||
addMessageListener(vAPI.messaging.connector);
|
addMessageListener(vAPI.messaging.connector);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue