Fine tune port connection code

Related commit:
- a223031b98
This commit is contained in:
Raymond Hill 2020-11-13 08:32:51 -05:00
parent 02b4d149e3
commit 525d7b1b3b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 19 additions and 27 deletions

View File

@ -900,23 +900,24 @@ vAPI.messaging = {
this.ports.delete(port.name);
},
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/Port
// port.sender is always present for onConnect() listeners.
onPortConnect: function(port) {
port.onDisconnect.addListener(
port => this.onPortDisconnect(port)
port.onDisconnect.addListener(port =>
this.onPortDisconnect(port)
);
port.onMessage.addListener(
(request, port) => this.onPortMessage(request, port)
port.onMessage.addListener((request, port) =>
this.onPortMessage(request, port)
);
const portDetails = { port };
const sender = port.sender;
if ( sender ) {
portDetails.frameId = sender.frameId;
const { tab, url } = sender;
if ( tab ) {
portDetails.tabId = tab.id;
}
portDetails.url = url;
portDetails.privileged = url.startsWith(this.PRIVILEGED_URL);
const { tab, url } = sender;
portDetails.frameId = sender.frameId;
portDetails.frameURL = url;
portDetails.privileged = url.startsWith(this.PRIVILEGED_URL);
if ( tab ) {
portDetails.tabId = tab.id;
portDetails.tabURL = tab.url;
}
this.ports.set(port.name, portDetails);
// https://bugzilla.mozilla.org/show_bug.cgi?id=1652925#c24
@ -944,12 +945,9 @@ vAPI.messaging = {
vAPI.webextFlavor.major < 61
) {
browser.tabs.onRemoved.addListener(tabId => {
for ( const { port } of this.ports.values() ) {
const tab = port.sender && port.sender.tab;
if ( !tab ) { continue; }
if ( tab.id === tabId ) {
this.onPortDisconnect(port);
}
for ( const { port, tabId: portTabId } of this.ports.values() ) {
if ( portTabId !== tabId ) { continue; }
this.onPortDisconnect(port);
}
});
}

View File

@ -547,15 +547,9 @@ const µb = µBlock;
const retrieveContentScriptParameters = function(sender, request) {
if ( µb.readyToFilter !== true ) { return; }
const { url: senderURL, tabId, frameId } = sender;
if (
tabId === undefined ||
frameId === undefined ||
senderURL === undefined ||
senderURL !== request.url && senderURL.startsWith('about:') === false
) {
return;
}
const { tabId, frameId } = sender;
if ( tabId === undefined || frameId === undefined ) { return; }
const pageStore = µb.pageStoreFromTabId(tabId);
if ( pageStore === null || pageStore.getNetFilteringSwitch() === false ) {
return;