Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor Browser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Applications
Tor Browser
Commits
4e415a9e
Verified
Commit
4e415a9e
authored
4 years ago
by
Alex Catarineu
Committed by
Pier Angelo Vendrame
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Bug 40069: Add helpers for message passing with extensions
parent
ca1a9c3b
Loading
Loading
1 merge request
!543
Tor Browser 12.5a 102.8.0esr rebase
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
toolkit/components/extensions/ExtensionParent.jsm
+47
-0
47 additions, 0 deletions
toolkit/components/extensions/ExtensionParent.jsm
with
47 additions
and
0 deletions
toolkit/components/extensions/ExtensionParent.jsm
+
47
−
0
View file @
4e415a9e
...
...
@@ -263,6 +263,8 @@ const ProxyMessenger = {
/** @type Map<number, ParentPort> */
ports
:
new
Map
(),
_torRuntimeMessageListeners
:
[],
init
()
{
this
.
conduit
=
new
BroadcastConduit
(
ProxyMessenger
,
{
id
:
"ProxyMessenger"
,
...
...
@@ -340,6 +342,10 @@ const ProxyMessenger = {
},
async
recvRuntimeMessage
(
arg
,
{
sender
})
{
// We need to listen to some extension messages in Tor Browser
for
(
const
listener
of
this
.
_torRuntimeMessageListeners
)
{
listener
(
arg
);
}
arg
.
firstResponse
=
true
;
let
kind
=
await
this
.
normalizeArgs
(
arg
,
sender
);
let
result
=
await
this
.
conduit
.
castRuntimeMessage
(
kind
,
arg
);
...
...
@@ -2139,6 +2145,45 @@ for (let name of StartupCache.STORE_NAMES) {
StartupCache[name] = new CacheStore(name);
}
async function torSendExtensionMessage(extensionId, message) {
// This should broadcast the message to all children "
conduits
"
// listening for a "
RuntimeMessage
". Those children conduits
// will either be extension background pages or other extension
// pages listening to browser.runtime.onMessage.
const result = await ProxyMessenger.conduit.castRuntimeMessage("
messenger
", {
extensionId,
holder: new StructuredCloneHolder(message),
firstResponse: true,
sender: {
id: extensionId,
envType: "
addon_child
",
},
});
return result
? result.value
: Promise.reject({ message: ERROR_NO_RECEIVERS });
}
async function torWaitForExtensionMessage(extensionId, checker) {
return new Promise(resolve => {
const msgListener = msg => {
try {
if (msg && msg.extensionId === extensionId) {
const deserialized = msg.holder.deserialize({});
if (checker(deserialized)) {
const idx = ProxyMessenger._torRuntimeMessageListeners.indexOf(
msgListener
);
ProxyMessenger._torRuntimeMessageListeners.splice(idx, 1);
resolve(deserialized);
}
}
} catch (e) {}
};
ProxyMessenger._torRuntimeMessageListeners.push(msgListener);
});
}
var ExtensionParent = {
GlobalManager,
HiddenExtensionPage,
...
...
@@ -2151,6 +2196,8 @@ var ExtensionParent = {
watchExtensionProxyContextLoad,
watchExtensionWorkerContextLoaded,
DebugUtils,
torSendExtensionMessage,
torWaitForExtensionMessage,
};
// browserPaintedPromise and browserStartupPromise are promises that
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment