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
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Applications
Tor Browser
Commits
e5081b09
Verified
Commit
e5081b09
authored
Aug 2, 2020
by
Alex Catarineu
Committed by
Pier Angelo Vendrame
8 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Bug 40069: Add helpers for message passing with extensions
parent
79a58f77
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1293
Bug 43306: Rebased stable onto 128.5.0esr
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
toolkit/components/extensions/ExtensionParent.sys.mjs
+46
-0
46 additions, 0 deletions
toolkit/components/extensions/ExtensionParent.sys.mjs
with
46 additions
and
0 deletions
toolkit/components/extensions/ExtensionParent.sys.mjs
+
46
−
0
View file @
e5081b09
...
...
@@ -252,6 +252,8 @@ const ProxyMessenger = {
/** @type {Map<number, Promise>} */
portPromises
:
new
Map
(),
_torRuntimeMessageListeners
:
[],
init
()
{
this
.
conduit
=
new
lazy
.
BroadcastConduit
(
ProxyMessenger
,
{
id
:
"
ProxyMessenger
"
,
...
...
@@ -352,6 +354,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
);
...
...
@@ -2331,6 +2337,44 @@ var StartupCache = {
Services
.
obs
.
addObserver
(
StartupCache
,
"
startupcache-invalidate
"
);
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
(
"
torSendExtensionMessage
"
,
null
,
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
);
});
}
export
var
ExtensionParent
=
{
GlobalManager
,
HiddenExtensionPage
,
...
...
@@ -2343,6 +2387,8 @@ export 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