Files
sousa-gecko/dom/ipc/jsactor/JSActorManager.h
T
Nika Layzell c51090b135 Bug 2052614 - Add a structured RemoteType representation. r=ipc-reviewers,necko-reviewers,geckoview-reviewers,extension-reviewers,media-playback-reviewers,webrtc-reviewers,places-reviewers,layout-reviewers,dom-worker-reviewers,ai-platform-reviewers,sandbox-reviewers,janerik,emilio,hiro,kershaw,bwc,asuth,mccr8,alwu,nordzilla,valentin,bobowen
Replace bare remote type strings in C++ process-selection plumbing with
a RemoteType type which stores the parsed kind, isolation URI, and
process selection attributes directly.

This preserves the existing serialized string form for IPC and JS-facing
APIs, while making native callers use explicit predicates and structured
fields instead of manually parsing remote type prefixes and suffixes.

No JS-exposed API for parsing or otherwise interpreting remote types are
currently exposed in this patch. My current expectation is that this
will likely look like a `nsIRemoteType` interface which wraps this
`RemoteType` value type, exposing helpful getters for JS callers.

Differential Revision: https://phabricator.services.mozilla.com/D310442
2026-08-31 23:49:43 +00:00

102 lines
2.8 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_JSActorManager_h
#define mozilla_dom_JSActorManager_h
#include "js/TypeDecls.h"
#include "mozilla/dom/JSActor.h"
#include "mozilla/dom/JSIPCValue.h"
#include "mozilla/dom/RemoteType.h"
#include "nsRefPtrHashtable.h"
#include "nsString.h"
namespace mozilla {
class ErrorResult;
namespace ipc {
class IProtocol;
}
namespace dom {
class JSActorProtocol;
class JSActorService;
class JSActorManager : public nsISupports {
public:
/**
* Get or create an actor by its name.
*
* Will set an error on |aRv| if the actor fails to be constructed.
*/
already_AddRefed<JSActor> GetActor(JSContext* aCx, const nsACString& aName,
ErrorResult& aRv);
/**
* Look up an existing actor by its name, returning nullptr if it doesn't
* already exist. Will not attempt to create the actor.
*/
already_AddRefed<JSActor> GetExistingActor(const nsACString& aName);
/**
* Handle receiving a raw message from the other side.
*/
void ReceiveRawMessage(const JSActorMessageMeta& aMetadata,
JSIPCValue&& aData, ipc::StructuredCloneData* aStack);
virtual const RemoteType& GetRemoteType() const = 0;
protected:
/**
* The actor is about to be destroyed so prevent it from sending any
* more messages.
*/
void JSActorWillDestroy();
/**
* Lifecycle method which will fire the `didDestroy` methods on relevant
* actors.
*/
void JSActorDidDestroy();
/**
* Return the protocol with the given name, if it is supported by the current
* actor.
*/
virtual already_AddRefed<JSActorProtocol> MatchingJSActorProtocol(
JSActorService* aActorSvc, const nsACString& aName, ErrorResult& aRv) = 0;
/**
* Initialize a JSActor instance given the constructed JS object.
* `aMaybeActor` may be `nullptr`, which should construct the default empty
* actor.
*/
virtual already_AddRefed<JSActor> InitJSActor(
JS::Handle<JSObject*> aMaybeActor, const nsACString& aName,
ErrorResult& aRv) = 0;
/**
* Return this native actor. This should be the same object which is
* implementing `JSActorManager`.
*/
virtual mozilla::ipc::IProtocol* AsNativeActor() = 0;
private:
friend class JSActorService;
/**
* Note that a particular actor name has been unregistered, and fire the
* `didDestroy` method on the actor, if it's been initialized.
*/
void JSActorUnregister(const nsACString& aName);
nsRefPtrHashtable<nsCStringHashKey, JSActor> mJSActors;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_JSActorManager_h