commit f221c755f5a0dd62eca5a220acc011c9fcfc91b5
parent 64841b5dc9c79632d3321efe74fe2fc4631a0d16
Author: Andrew McCreight <continuation@gmail.com>
Date: Mon, 15 Dec 2025 22:30:31 +0000
Bug 2005849 - Move RemoteTypePrefixMatches and mRemoteTypes to JSActorProtocol. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D276323
Diffstat:
6 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/dom/ipc/jsactor/JSActorService.cpp b/dom/ipc/jsactor/JSActorService.cpp
@@ -338,4 +338,19 @@ JSActorService::GetJSWindowActorProtocol(const nsACString& aName) {
return mWindowActorDescriptors.Get(aName);
}
+bool JSActorProtocol::RemoteTypePrefixMatches(const nsACString& aRemoteType) {
+ if (mRemoteTypes.IsEmpty()) {
+ return true;
+ }
+
+ nsDependentCSubstring remoteTypePrefix(RemoteTypePrefix(aRemoteType));
+ for (auto& remoteType : mRemoteTypes) {
+ // TODO: Maybe this should use glob-style matching instead. See bug 2006165.
+ if (StringBeginsWith(remoteTypePrefix, remoteType)) {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace mozilla::dom
diff --git a/dom/ipc/jsactor/JSActorService.h b/dom/ipc/jsactor/JSActorService.h
@@ -104,6 +104,11 @@ class JSActorProtocol : public nsISupports {
virtual const Sided& Parent() const = 0;
virtual const Sided& Child() const = 0;
bool mLoadInDevToolsLoader = false;
+
+ protected:
+ bool RemoteTypePrefixMatches(const nsACString& aRemoteType);
+
+ nsTArray<nsCString> mRemoteTypes;
};
} // namespace dom
diff --git a/dom/ipc/jsactor/JSProcessActorProtocol.cpp b/dom/ipc/jsactor/JSProcessActorProtocol.cpp
@@ -117,16 +117,6 @@ void JSProcessActorProtocol::RemoveObservers() {
}
}
-bool JSProcessActorProtocol::RemoteTypePrefixMatches(
- const nsDependentCSubstring& aRemoteType) {
- for (auto& remoteType : mRemoteTypes) {
- if (StringBeginsWith(aRemoteType, remoteType)) {
- return true;
- }
- }
- return false;
-}
-
bool JSProcessActorProtocol::Matches(const nsACString& aRemoteType,
ErrorResult& aRv) {
if (!mIncludeParent && aRemoteType.IsEmpty()) {
@@ -135,8 +125,7 @@ bool JSProcessActorProtocol::Matches(const nsACString& aRemoteType,
return false;
}
- if (!mRemoteTypes.IsEmpty() &&
- !RemoteTypePrefixMatches(RemoteTypePrefix(aRemoteType))) {
+ if (!RemoteTypePrefixMatches(aRemoteType)) {
aRv.ThrowNotSupportedError(nsPrintfCString(
"Process protocol '%s' doesn't support remote type '%s'", mName.get(),
PromiseFlatCString(aRemoteType).get()));
diff --git a/dom/ipc/jsactor/JSProcessActorProtocol.h b/dom/ipc/jsactor/JSProcessActorProtocol.h
@@ -60,11 +60,9 @@ class JSProcessActorProtocol final : public JSActorProtocol,
private:
explicit JSProcessActorProtocol(const nsACString& aName) : mName(aName) {}
- bool RemoteTypePrefixMatches(const nsDependentCSubstring& aRemoteType);
~JSProcessActorProtocol() = default;
nsCString mName;
- nsTArray<nsCString> mRemoteTypes;
bool mIncludeParent = false;
friend class JSActorProtocolUtils;
diff --git a/dom/ipc/jsactor/JSWindowActorProtocol.cpp b/dom/ipc/jsactor/JSWindowActorProtocol.cpp
@@ -309,16 +309,6 @@ extensions::MatchPatternSetCore* JSWindowActorProtocol::GetURIMatcher() {
return mURIMatcher;
}
-bool JSWindowActorProtocol::RemoteTypePrefixMatches(
- const nsDependentCSubstring& aRemoteType) {
- for (auto& remoteType : mRemoteTypes) {
- if (StringBeginsWith(aRemoteType, remoteType)) {
- return true;
- }
- }
- return false;
-}
-
bool JSWindowActorProtocol::MessageManagerGroupMatches(
BrowsingContext* aBrowsingContext) {
BrowsingContext* top = aBrowsingContext->Top();
@@ -349,8 +339,7 @@ bool JSWindowActorProtocol::Matches(BrowsingContext* aBrowsingContext,
return false;
}
- if (!mRemoteTypes.IsEmpty() &&
- !RemoteTypePrefixMatches(RemoteTypePrefix(aRemoteType))) {
+ if (!RemoteTypePrefixMatches(aRemoteType)) {
aRv.ThrowNotSupportedError(
nsPrintfCString("Window protocol '%s' doesn't match remote type '%s'",
mName.get(), PromiseFlatCString(aRemoteType).get()));
diff --git a/dom/ipc/jsactor/JSWindowActorProtocol.h b/dom/ipc/jsactor/JSWindowActorProtocol.h
@@ -78,7 +78,6 @@ class JSWindowActorProtocol final : public JSActorProtocol,
private:
explicit JSWindowActorProtocol(const nsACString& aName) : mName(aName) {}
extensions::MatchPatternSetCore* GetURIMatcher();
- bool RemoteTypePrefixMatches(const nsDependentCSubstring& aRemoteType);
bool MessageManagerGroupMatches(BrowsingContext* aBrowsingContext);
~JSWindowActorProtocol() = default;
@@ -86,7 +85,6 @@ class JSWindowActorProtocol final : public JSActorProtocol,
bool mAllFrames = false;
bool mIncludeChrome = false;
nsTArray<nsString> mMatches;
- nsTArray<nsCString> mRemoteTypes;
nsTArray<nsString> mMessageManagerGroups;
friend class JSActorProtocolUtils;