mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 14:25:49 +00:00
Bug 1915257 - refactor webchannel to use actor's principal r=nalexander,nika
Differential Revision: https://phabricator.services.mozilla.com/D227161
This commit is contained in:
parent
f4de4250a4
commit
ce8f889a6b
@ -21,11 +21,6 @@ export class WebChannelChild extends JSWindowActorChild {
|
||||
}
|
||||
|
||||
_onMessageToChrome(e) {
|
||||
// If target is window then we want the document principal, otherwise fallback to target itself.
|
||||
let principal = e.target.nodePrincipal
|
||||
? e.target.nodePrincipal
|
||||
: e.target.document.nodePrincipal;
|
||||
|
||||
if (e.detail) {
|
||||
if (typeof e.detail != "string") {
|
||||
console.error("WebChannelMessageToChrome must only send strings");
|
||||
@ -39,7 +34,6 @@ export class WebChannelChild extends JSWindowActorChild {
|
||||
this.sendAsyncMessage("WebChannelMessageToChrome", {
|
||||
contentData: e.detail,
|
||||
eventTarget,
|
||||
principal,
|
||||
});
|
||||
} else {
|
||||
console.error("WebChannel message failed. No message detail.");
|
||||
|
@ -5,7 +5,9 @@
|
||||
|
||||
import { WebChannelBroker } from "resource://gre/modules/WebChannel.sys.mjs";
|
||||
|
||||
const ERRNO_MISSING_PRINCIPAL = 1;
|
||||
// Note: ERRNO 1 deprecated and unused.
|
||||
// We used to err for cases where the child did not send a principal,
|
||||
// but now we infer it from the actor.
|
||||
const ERRNO_NO_SUCH_CHANNEL = 2;
|
||||
|
||||
export class WebChannelParent extends JSWindowActorParent {
|
||||
@ -15,7 +17,7 @@ export class WebChannelParent extends JSWindowActorParent {
|
||||
browsingContext: this.browsingContext,
|
||||
browser: this.browsingContext.top.embedderElement,
|
||||
eventTarget: msg.data.eventTarget,
|
||||
principal: msg.data.principal,
|
||||
principal: this.manager.documentPrincipal,
|
||||
};
|
||||
// data must be a string except for a few legacy origins allowed by browser-content.js.
|
||||
if (typeof data == "string") {
|
||||
@ -28,28 +30,19 @@ export class WebChannelParent extends JSWindowActorParent {
|
||||
}
|
||||
|
||||
if (data && data.id) {
|
||||
if (!msg.data.principal) {
|
||||
let validChannelFound = WebChannelBroker.tryToDeliver(
|
||||
data,
|
||||
sendingContext
|
||||
);
|
||||
|
||||
// if no valid origins send an event that there is no such valid channel
|
||||
if (!validChannelFound) {
|
||||
this._sendErrorEventToContent(
|
||||
data.id,
|
||||
sendingContext,
|
||||
ERRNO_MISSING_PRINCIPAL,
|
||||
"Message principal missing"
|
||||
ERRNO_NO_SUCH_CHANNEL,
|
||||
"No Such Channel"
|
||||
);
|
||||
} else {
|
||||
let validChannelFound = WebChannelBroker.tryToDeliver(
|
||||
data,
|
||||
sendingContext
|
||||
);
|
||||
|
||||
// if no valid origins send an event that there is no such valid channel
|
||||
if (!validChannelFound) {
|
||||
this._sendErrorEventToContent(
|
||||
data.id,
|
||||
sendingContext,
|
||||
ERRNO_NO_SUCH_CHANNEL,
|
||||
"No Such Channel"
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error("WebChannel channel id missing");
|
||||
|
Loading…
x
Reference in New Issue
Block a user