BlockingObserver: Don't block when browserId is 0
This commit is contained in:
parent
6ebb15778b
commit
5099da355c
1 changed files with 18 additions and 0 deletions
|
@ -52,6 +52,9 @@ class BlockingObserver {
|
|||
|
||||
register(browser) {
|
||||
let id = Zotero.platformMajorVersion > 102 ? browser.browserId : browser.browsingContext.top.id;
|
||||
if (id === 0) {
|
||||
throw new Error('BlockingObserver: Browser is not initialized');
|
||||
}
|
||||
this._ids.add(id);
|
||||
if (!this._observerAdded) {
|
||||
Services.obs.addObserver(this, 'http-on-modify-request');
|
||||
|
@ -62,6 +65,9 @@ class BlockingObserver {
|
|||
|
||||
unregister(browser) {
|
||||
let id = Zotero.platformMajorVersion > 102 ? browser.browserId : browser.browsingContext.top.id;
|
||||
if (id === 0) {
|
||||
throw new Error('BlockingObserver: Browser is not initialized');
|
||||
}
|
||||
this._ids.delete(id);
|
||||
if (this._observerAdded && !this._ids.size) {
|
||||
Services.obs.removeObserver(this, 'http-on-modify-request');
|
||||
|
@ -69,10 +75,22 @@ class BlockingObserver {
|
|||
this._observerAdded = false;
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
if (this._observerAdded) {
|
||||
this._ids.clear();
|
||||
Services.obs.removeObserver(this, 'http-on-modify-request');
|
||||
Zotero.debug('BlockingObserver: Removed observer');
|
||||
this._observerAdded = false;
|
||||
}
|
||||
}
|
||||
|
||||
observe(subject) {
|
||||
let channel = subject.QueryInterface(Ci.nsIHttpChannel);
|
||||
let id = Zotero.platformMajorVersion > 102 ? channel.browserId : channel.topBrowsingContextId;
|
||||
if (id === 0) {
|
||||
return;
|
||||
}
|
||||
if (this._ids.has(id) && this.shouldBlock(channel.URI)) {
|
||||
channel.cancel(Cr.NS_BINDING_ABORTED);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue