Skip to content

Commit

Permalink
Isolate DOM inspector layers from page context
Browse files Browse the repository at this point in the history
Related issue:
uBlockOrigin/uBlock-issues#1411

Additionally, refactored communication mechanism between content
script contexts and uBO contexts by using MessageChannel/BroadcastChannel
web APIs.
  • Loading branch information
gorhill committed Dec 3, 2023
1 parent 2c49548 commit ee83a43
Show file tree
Hide file tree
Showing 16 changed files with 586 additions and 875 deletions.
60 changes: 0 additions & 60 deletions platform/common/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,71 +967,11 @@ vAPI.messaging = {
}
},

broadcast: function(message) {
const messageWrapper = { broadcast: true, msg: message };
for ( const { port } of this.ports.values() ) {
try {
port.postMessage(messageWrapper);
} catch(ex) {
this.onPortDisconnect(port);
}
}
if ( this.defaultHandler ) {
this.defaultHandler(message, null, ( ) => { });
}
},

onFrameworkMessage: function(request, port, callback) {
const portDetails = this.ports.get(port.name) || {};
const tabId = portDetails.tabId;
const msg = request.msg;
switch ( msg.what ) {
case 'connectionAccepted':
case 'connectionRefused': {
const toPort = this.ports.get(msg.fromToken);
if ( toPort !== undefined ) {
msg.tabId = tabId;
toPort.port.postMessage(request);
} else {
msg.what = 'connectionBroken';
port.postMessage(request);
}
break;
}
case 'connectionRequested':
msg.tabId = tabId;
for ( const { port: toPort } of this.ports.values() ) {
if ( toPort === port ) { continue; }
try {
toPort.postMessage(request);
} catch (ex) {
this.onPortDisconnect(toPort);
}
}
break;
case 'connectionBroken':
case 'connectionCheck':
case 'connectionMessage': {
const toPort = this.ports.get(
port.name === msg.fromToken ? msg.toToken : msg.fromToken
);
if ( toPort !== undefined ) {
msg.tabId = tabId;
toPort.port.postMessage(request);
} else {
msg.what = 'connectionBroken';
port.postMessage(request);
}
break;
}
case 'extendClient':
vAPI.tabs.executeScript(tabId, {
file: '/js/vapi-client-extra.js',
frameId: portDetails.frameId,
}).then(( ) => {
callback();
});
break;
case 'localStorage': {
if ( portDetails.privileged !== true ) { break; }
const args = msg.args || [];
Expand Down
264 changes: 0 additions & 264 deletions platform/common/vapi-client-extra.js

This file was deleted.

Loading

0 comments on commit ee83a43

Please sign in to comment.