diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index 0c9542782e8c..d27780d4decd 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -26,7 +26,6 @@ #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentParent.h" #include "mozilla/dom/IdleDeadline.h" -#include "mozilla/dom/InProcessChild.h" #include "mozilla/dom/JSActorService.h" #include "mozilla/dom/MediaControlUtils.h" #include "mozilla/dom/MediaControlService.h" @@ -1304,10 +1303,7 @@ void ChromeUtils::GenerateMediaControlKey(const GlobalObject& aGlobal, } /* static */ -nsIDOMProcessChild* ChromeUtils::GetDomProcessChild(const GlobalObject&) { - if (XRE_IsParentProcess()) { - return InProcessChild::Singleton(); - } +nsIContentChild* ChromeUtils::GetContentChild(const GlobalObject&) { return ContentChild::GetSingleton(); } diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h index 97092451ddb1..94a3044f5078 100644 --- a/dom/base/ChromeUtils.h +++ b/dom/base/ChromeUtils.h @@ -12,7 +12,7 @@ #include "mozilla/dom/ChromeUtilsBinding.h" #include "mozilla/ErrorResult.h" #include "nsDOMNavigationTiming.h" // for DOMHighResTimeStamp -#include "nsIDOMProcessChild.h" +#include "nsIContentChild.h" namespace mozilla { @@ -218,7 +218,7 @@ class ChromeUtils { static void GenerateMediaControlKey(const GlobalObject& aGlobal, MediaControlKey aKey); - static nsIDOMProcessChild* GetDomProcessChild(const GlobalObject&); + static nsIContentChild* GetContentChild(const GlobalObject&); // This function would only be used for testing. static void GetCurrentActiveMediaMetadata(const GlobalObject& aGlobal, diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 4e6e62c0b3d7..d858181b369d 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -1875,8 +1875,8 @@ addExternalIface('nsITreeSelection', nativeType='nsITreeSelection', notflattened=True) addExternalIface('nsISupports', nativeType='nsISupports') addExternalIface('nsIDocShell', nativeType='nsIDocShell', notflattened=True) -addExternalIface('nsIDOMProcessChild', nativeType='nsIDOMProcessChild', notflattened=True) -addExternalIface('nsIDOMProcessParent', nativeType='nsIDOMProcessParent', notflattened=True) +addExternalIface('nsIContentChild', nativeType='nsIContentChild', notflattened=True) +addExternalIface('nsIContentParent', nativeType='nsIContentParent', notflattened=True) addExternalIface('nsIReferrerInfo', nativeType='nsIReferrerInfo', notflattened=True) addExternalIface('nsISecureBrowserUI', nativeType='nsISecureBrowserUI', notflattened=True) addExternalIface('nsIWebProgress', nativeType='nsIWebProgress', notflattened=True) diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl index 1ff8ada3fd78..c0be3514627e 100644 --- a/dom/chrome-webidl/ChromeUtils.webidl +++ b/dom/chrome-webidl/ChromeUtils.webidl @@ -4,7 +4,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ -interface nsIDOMProcessChild; +interface nsIContentChild; /** * An optimized QueryInterface method, generated by generateQI. @@ -477,10 +477,10 @@ partial namespace ChromeUtils { void generateMediaControlKey(MediaControlKey aKey); /** - * nsIDOMProcessChild for the current process. + * ContentChild of the current process. */ [ChromeOnly] - readonly attribute nsIDOMProcessChild? domProcessChild; + readonly attribute nsIContentChild? contentChild; // This is used to get the media metadata from the current main controller in // testing. diff --git a/dom/chrome-webidl/JSProcessActor.webidl b/dom/chrome-webidl/JSProcessActor.webidl index eea710b4d6fc..c70cd62208de 100644 --- a/dom/chrome-webidl/JSProcessActor.webidl +++ b/dom/chrome-webidl/JSProcessActor.webidl @@ -20,7 +20,7 @@ interface JSProcessActorParent { [ChromeOnly] constructor(); - readonly attribute nsIDOMProcessParent manager; + readonly attribute nsIContentParent manager; }; JSProcessActorParent includes JSActor; @@ -29,7 +29,7 @@ interface JSProcessActorChild { [ChromeOnly] constructor(); - readonly attribute nsIDOMProcessChild manager; + readonly attribute nsIContentChild manager; }; JSProcessActorChild includes JSActor; diff --git a/dom/chrome-webidl/WindowGlobalActors.webidl b/dom/chrome-webidl/WindowGlobalActors.webidl index c754974a044f..85d2f36b5fbb 100644 --- a/dom/chrome-webidl/WindowGlobalActors.webidl +++ b/dom/chrome-webidl/WindowGlobalActors.webidl @@ -8,7 +8,7 @@ interface URI; interface nsIDocShell; interface RemoteTab; interface nsITransportSecurityInfo; -interface nsIDOMProcessParent; +interface nsIContentParent; [Exposed=Window, ChromeOnly] interface WindowContext { @@ -62,10 +62,9 @@ interface WindowGlobalParent : WindowContext { // String containing serialized content blocking log. readonly attribute DOMString contentBlockingLog; - // DOM Process which this window was loaded in. Will be either InProcessParent - // for windows loaded in the parent process, or ContentParent for windows - // loaded in the content process. - readonly attribute nsIDOMProcessParent? domProcess; + // ContentParent of the process this window is loaded in. + // Will be `null` for windows loaded in the parent process. + readonly attribute nsIContentParent? contentParent; static WindowGlobalParent? getByInnerWindowId(unsigned long long innerWindowId); diff --git a/dom/docs/Fission.rst b/dom/docs/Fission.rst index 532c69332cb5..673d0ee31167 100644 --- a/dom/docs/Fission.rst +++ b/dom/docs/Fission.rst @@ -583,11 +583,11 @@ Get a JSProcessActor let parentActor = this.browser .browsingContext .currentWindowGlobal - .domProcess + .contentParent .getActor("TestProcess"); // get child side actor - let childActor = ChromeUtils.domProcessChild + let childActor = ChromeUtils.contentChild .getActor("TestProcess"); And more diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index a3846b8189fa..ae85a9db8084 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -50,7 +50,6 @@ #include "mozilla/dom/DocGroup.h" #include "mozilla/dom/ExternalHelperAppChild.h" #include "mozilla/dom/GetFilesHelper.h" -#include "mozilla/dom/InProcessChild.h" #include "mozilla/dom/IPCBlobInputStreamChild.h" #include "mozilla/dom/IPCBlobUtils.h" #include "mozilla/dom/JSActorService.h" @@ -79,6 +78,7 @@ #include "mozilla/ipc/FileDescriptorSetChild.h" #include "mozilla/ipc/FileDescriptorUtils.h" #include "mozilla/ipc/GeckoChildProcessHost.h" +#include "mozilla/ipc/InProcessChild.h" #include "mozilla/ipc/LibrarySandboxPreload.h" #include "mozilla/ipc/ProcessChild.h" #include "mozilla/ipc/PChildToParentStreamChild.h" @@ -612,8 +612,8 @@ ContentChild::~ContentChild() { #endif NS_INTERFACE_MAP_BEGIN(ContentChild) - NS_INTERFACE_MAP_ENTRY(nsIDOMProcessChild) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMProcessChild) + NS_INTERFACE_MAP_ENTRY(nsIContentChild) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentChild) NS_INTERFACE_MAP_END mozilla::ipc::IPCResult ContentChild::RecvSetXPCOMProcessAttributes( @@ -4195,24 +4195,58 @@ NS_IMETHODIMP ContentChild::GetActor(const nsACString& aName, IPCResult ContentChild::RecvRawMessage(const JSActorMessageMeta& aMeta, const ClonedMessageData& aData, const ClonedMessageData& aStack) { - RefPtr actor; - GetActor(aMeta.actorName(), getter_AddRefs(actor)); - if (actor) { - StructuredCloneData data; - data.BorrowFromClonedMessageDataForChild(aData); - StructuredCloneData stack; - stack.BorrowFromClonedMessageDataForChild(aStack); - actor->ReceiveRawMessage(aMeta, std::move(data), std::move(stack)); - } + StructuredCloneData data; + data.BorrowFromClonedMessageDataForChild(aData); + StructuredCloneData stack; + stack.BorrowFromClonedMessageDataForChild(aStack); + ReceiveRawMessage(aMeta, std::move(data), std::move(stack)); return IPC_OK(); } -NS_IMETHODIMP ContentChild::GetCanSend(bool* aCanSend) { - *aCanSend = CanSend(); - return NS_OK; +void ContentChild::ReceiveRawMessage(const JSActorMessageMeta& aMeta, + StructuredCloneData&& aData, + StructuredCloneData&& aStack) { + RefPtr actor = + GetActor(aMeta.actorName(), IgnoreErrors()); + if (actor) { + actor->ReceiveRawMessage(aMeta, std::move(aData), std::move(aStack)); + } } -NS_IMETHODIMP_(ContentChild*) ContentChild::AsContentChild() { return this; } +already_AddRefed ContentChild::GetActor( + const nsACString& aName, ErrorResult& aRv) { + if (!CanSend()) { + aRv.ThrowInvalidStateError( + "Cannot get JSProcessActor, process is shutting down"); + return nullptr; + } + + // Check if this actor has already been created, and return it if it has. + if (mProcessActors.Contains(aName)) { + return mProcessActors.Get(aName); + } + + // Otherwise, we want to create a new instance of this actor. + JS::RootedObject obj(RootingCx()); + ConstructActor(aName, &obj, aRv); + if (aRv.Failed()) { + return nullptr; + } + + // Unwrap our actor to a JSProcessActorChild object. + RefPtr actor; + if (NS_FAILED(UNWRAP_OBJECT(JSProcessActorChild, &obj, actor))) { + aRv.ThrowTypeMismatchError( + "Constructed actor does not inherit from JSProcessActorChild"); + return nullptr; + } + + MOZ_RELEASE_ASSERT(!actor->Manager(), + "mManager was already initialized once!"); + actor->Init(aName, this); + mProcessActors.Put(aName, RefPtr{actor}); + return actor.forget(); +} IPCResult ContentChild::RecvFlushFOGData(FlushFOGDataResolver&& aResolver) { #ifdef MOZ_GLEAN diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index 863318ac5679..7d7d4f6e93eb 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -21,7 +21,7 @@ #include "mozilla/ipc/InputStreamUtils.h" #include "mozilla/ipc/Shmem.h" #include "nsHashKeys.h" -#include "nsIDOMProcessChild.h" +#include "nsIContentChild.h" #include "nsIObserver.h" #include "nsTHashtable.h" #include "nsStringFwd.h" @@ -42,6 +42,7 @@ struct LookAndFeelInt; class nsDocShellLoadState; class nsFrameLoader; class nsIOpenWindowInfo; +class JSProcessActorChild; namespace mozilla { class RemoteSpellcheckEngineChild; @@ -73,7 +74,7 @@ class GetFilesHelperChild; class TabContext; class ContentChild final : public PContentChild, - public nsIDOMProcessChild, + public nsIContentChild, public mozilla::ipc::IShmemAllocator, public mozilla::ipc::ChildToParentStreamActorManager, public ProcessActor { @@ -84,7 +85,7 @@ class ContentChild final : public PContentChild, friend class PContentChild; public: - NS_DECL_NSIDOMPROCESSCHILD + NS_DECL_NSICONTENTCHILD ContentChild(); virtual ~ContentChild(); @@ -678,6 +679,10 @@ class ContentChild final : public PContentChild, PFileDescriptorSetChild* SendPFileDescriptorSetConstructor( const FileDescriptor& aFD) override; + // Get a JS actor object by name. + already_AddRefed GetActor( + const nsACString& aName, ErrorResult& aRv); + private: static void ForceKillTimerCallback(nsITimer* aTimer, void* aClosure); void StartForceKillTimer(); @@ -777,6 +782,10 @@ class ContentChild final : public PContentChild, const ClonedMessageData& aData, const ClonedMessageData& aStack); + void ReceiveRawMessage(const JSActorMessageMeta& aMeta, + ipc::StructuredCloneData&& aData, + ipc::StructuredCloneData&& aStack); + JSActor::Type GetSide() override { return JSActor::Type::Child; } mozilla::ipc::IPCResult RecvHistoryCommitLength( @@ -883,7 +892,7 @@ class ContentChild final : public PContentChild, }; inline nsISupports* ToSupports(mozilla::dom::ContentChild* aContentChild) { - return static_cast(aContentChild); + return static_cast(aContentChild); } } // namespace dom diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 8090b15b9d2e..1b6b35c12ce6 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -3184,13 +3184,13 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(ContentParent) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContentParent) NS_INTERFACE_MAP_ENTRY_CONCRETE(ContentParent) - NS_INTERFACE_MAP_ENTRY(nsIDOMProcessParent) + NS_INTERFACE_MAP_ENTRY(nsIContentParent) NS_INTERFACE_MAP_ENTRY(nsIObserver) NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCallback) NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionErrorCallback) NS_INTERFACE_MAP_ENTRY(nsIAsyncShutdownBlocker) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMProcessParent) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentParent) NS_INTERFACE_MAP_END // Async shutdown blocker @@ -6819,18 +6819,60 @@ NS_IMETHODIMP ContentParent::GetChildID(uint64_t* aOut) { IPCResult ContentParent::RecvRawMessage(const JSActorMessageMeta& aMeta, const ClonedMessageData& aData, const ClonedMessageData& aStack) { - RefPtr actor; - GetActor(aMeta.actorName(), getter_AddRefs(actor)); - if (actor) { - StructuredCloneData data; - data.BorrowFromClonedMessageDataForParent(aData); - StructuredCloneData stack; - stack.BorrowFromClonedMessageDataForParent(aStack); - actor->ReceiveRawMessage(aMeta, std::move(data), std::move(stack)); - } + StructuredCloneData data; + data.BorrowFromClonedMessageDataForParent(aData); + StructuredCloneData stack; + stack.BorrowFromClonedMessageDataForParent(aStack); + ReceiveRawMessage(aMeta, std::move(data), std::move(stack)); return IPC_OK(); } +void ContentParent::ReceiveRawMessage(const JSActorMessageMeta& aMeta, + StructuredCloneData&& aData, + StructuredCloneData&& aStack) { + RefPtr actor = + GetActor(aMeta.actorName(), IgnoreErrors()); + if (actor) { + actor->ReceiveRawMessage(aMeta, std::move(aData), std::move(aStack)); + } +} + +already_AddRefed ContentParent::GetActor( + const nsACString& aName, ErrorResult& aRv) { + if (!CanSend()) { + aRv.ThrowInvalidStateError(nsPrintfCString( + "Cannot get actor '%s': content parent is ready to communicate.", + PromiseFlatCString(aName).get())); + return nullptr; + } + + // Check if this actor has already been created, and return it if it has. + if (mProcessActors.Contains(aName)) { + return do_AddRef(mProcessActors.GetWeak(aName)); + } + + // Otherwise, we want to create a new instance of this actor. + JS::RootedObject obj(RootingCx()); + ConstructActor(aName, &obj, aRv); + if (aRv.Failed()) { + return nullptr; + } + + // Unwrap our actor to a JSProcessActorParent object. + RefPtr actor; + if (NS_FAILED(UNWRAP_OBJECT(JSProcessActorParent, &obj, actor))) { + aRv.ThrowTypeMismatchError( + "Constructed actor does not inherit from JSProcessActorParent"); + return nullptr; + } + + MOZ_RELEASE_ASSERT(!actor->Manager(), + "mManager was already initialized once!"); + actor->Init(aName, this); + mProcessActors.Put(aName, RefPtr{actor}); + return actor.forget(); +} + NS_IMETHODIMP ContentParent::GetActor(const nsACString& aName, JSProcessActorParent** retval) { if (!CanSend()) { @@ -6874,13 +6916,6 @@ IPCResult ContentParent::RecvFOGData(ByteBuf&& buf) { return IPC_OK(); } -NS_IMETHODIMP ContentParent::GetCanSend(bool* aCanSend) { - *aCanSend = CanSend(); - return NS_OK; -} - -NS_IMETHODIMP_(ContentParent*) ContentParent::AsContentParent() { return this; } - } // namespace dom } // namespace mozilla diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 51710457a61c..274e8ebac66a 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -36,7 +36,7 @@ #include "nsFrameMessageManager.h" #include "nsHashKeys.h" #include "nsIAsyncShutdown.h" -#include "nsIDOMProcessParent.h" +#include "nsIContentParent.h" #include "nsIInterfaceRequestor.h" #include "nsIObserver.h" #include "nsIRemoteTab.h" @@ -128,7 +128,7 @@ struct CancelContentJSOptions; class ContentParent final : public PContentParent, - public nsIDOMProcessParent, + public nsIContentParent, public nsIObserver, public nsIDOMGeoPositionCallback, public nsIDOMGeoPositionErrorCallback, @@ -357,7 +357,7 @@ class ContentParent final NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ContentParent, nsIObserver) NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_NSIDOMPROCESSPARENT + NS_DECL_NSICONTENTPARENT NS_DECL_NSIOBSERVER NS_DECL_NSIDOMGEOPOSITIONCALLBACK NS_DECL_NSIDOMGEOPOSITIONERRORCALLBACK @@ -1358,6 +1358,13 @@ class ContentParent final nsTArray& aContentParents, uint32_t aMaxContentParents, bool aPreferUsed); + // Get a JS actor object by name. + already_AddRefed GetActor(const nsACString& aName, + ErrorResult& aRv); + void ReceiveRawMessage(const JSActorMessageMeta& aMeta, + StructuredCloneData&& aData, + StructuredCloneData&& aStack); + void AddToPool(nsTArray&); void RemoveFromPool(nsTArray&); void AssertNotInPool(); @@ -1540,7 +1547,7 @@ bool IsWebRemoteType(const nsAString& aContentProcessType); bool IsWebCoopCoepRemoteType(const nsAString& aContentProcessType); inline nsISupports* ToSupports(mozilla::dom::ContentParent* aContentParent) { - return static_cast(aContentParent); + return static_cast(aContentParent); } } // namespace dom diff --git a/dom/ipc/JSProcessActorChild.cpp b/dom/ipc/JSProcessActorChild.cpp index 7d6aa85b9503..3b4f28f3725d 100644 --- a/dom/ipc/JSProcessActorChild.cpp +++ b/dom/ipc/JSProcessActorChild.cpp @@ -6,7 +6,7 @@ #include "mozilla/dom/JSProcessActorBinding.h" #include "mozilla/dom/JSProcessActorChild.h" -#include "mozilla/dom/InProcessChild.h" +#include "mozilla/ipc/InProcessChild.h" namespace mozilla { namespace dom { @@ -27,44 +27,14 @@ JSObject* JSProcessActorChild::WrapObject(JSContext* aCx, return JSProcessActorChild_Binding::Wrap(aCx, this, aGivenProto); } -namespace { - -class AsyncMessageToProcessParent : public Runnable { - public: - AsyncMessageToProcessParent(const JSActorMessageMeta& aMetadata, - ipc::StructuredCloneData&& aData, - ipc::StructuredCloneData&& aStack) - : mozilla::Runnable("InProcessParent::HandleAsyncMessage"), - mMetadata(aMetadata), - mData(std::move(aData)), - mStack(std::move(aStack)) {} - - NS_IMETHOD Run() override { - MOZ_ASSERT(NS_IsMainThread(), "Should be called on the main thread."); - if (auto* parent = InProcessParent::Singleton()) { - RefPtr actor; - parent->GetActor(mMetadata.actorName(), getter_AddRefs(actor)); - if (actor) { - actor->ReceiveRawMessage(mMetadata, std::move(mData), - std::move(mStack)); - } - } - return NS_OK; - } - - private: - JSActorMessageMeta mMetadata; - ipc::StructuredCloneData mData; - ipc::StructuredCloneData mStack; -}; - -} // namespace - void JSProcessActorChild::SendRawMessage(const JSActorMessageMeta& aMeta, ipc::StructuredCloneData&& aData, ipc::StructuredCloneData&& aStack, ErrorResult& aRv) { - if (NS_WARN_IF(!mCanSend || !mManager || !mManager->GetCanSend())) { + // We only ever have JSProcessActorChild in a multi-process scenario. + MOZ_ASSERT(XRE_IsContentProcess()); + + if (NS_WARN_IF(!mCanSend || !mManager || !mManager->CanSend())) { aRv.ThrowInvalidStateError("JSProcessActorChild cannot send at the moment"); return; } @@ -78,29 +48,17 @@ void JSProcessActorChild::SendRawMessage(const JSActorMessageMeta& aMeta, return; } - // If the parent side is in the same process, we have a PInProcess manager, - // and can dispatch the message directly to the event loop. - ContentChild* contentChild = mManager->AsContentChild(); - if (!contentChild) { - MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess()); - NS_DispatchToMainThread(MakeAndAddRef( - aMeta, std::move(aData), std::move(aStack))); - return; - } - ClonedMessageData msgData; ClonedMessageData stackData; - if (NS_WARN_IF( - !aData.BuildClonedMessageDataForChild(contentChild, msgData)) || - NS_WARN_IF( - !aStack.BuildClonedMessageDataForChild(contentChild, stackData))) { + if (NS_WARN_IF(!aData.BuildClonedMessageDataForChild(mManager, msgData)) || + NS_WARN_IF(!aStack.BuildClonedMessageDataForChild(mManager, stackData))) { aRv.ThrowDataCloneError(nsPrintfCString( "JSProcessActorChild serialization error: cannot clone, in actor '%s'", PromiseFlatCString(aMeta.actorName()).get())); return; } - if (NS_WARN_IF(!contentChild->SendRawMessage(aMeta, msgData, stackData))) { + if (NS_WARN_IF(!mManager->SendRawMessage(aMeta, msgData, stackData))) { aRv.ThrowOperationError( nsPrintfCString("JSProcessActorChild send error in actor '%s'", PromiseFlatCString(aMeta.actorName()).get())); @@ -109,7 +67,7 @@ void JSProcessActorChild::SendRawMessage(const JSActorMessageMeta& aMeta, } void JSProcessActorChild::Init(const nsACString& aName, - nsIDOMProcessChild* aManager) { + ContentChild* aManager) { MOZ_ASSERT(!mManager, "Cannot Init() a JSProcessActorChild twice!"); SetName(aName); mManager = aManager; diff --git a/dom/ipc/JSProcessActorChild.h b/dom/ipc/JSProcessActorChild.h index 186930d294b5..ec74ec233ead 100644 --- a/dom/ipc/JSProcessActorChild.h +++ b/dom/ipc/JSProcessActorChild.h @@ -7,8 +7,8 @@ #ifndef mozilla_dom_JSProcessActorChild_h #define mozilla_dom_JSProcessActorChild_h +#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/JSActor.h" -#include "nsIDOMProcessChild.h" namespace mozilla { namespace dom { @@ -32,9 +32,9 @@ class JSProcessActorChild final : public JSActor { return MakeAndAddRef(); } - nsIDOMProcessChild* Manager() const { return mManager; } + ContentChild* Manager() const { return mManager; } - void Init(const nsACString& aName, nsIDOMProcessChild* aManager); + void Init(const nsACString& aName, ContentChild* aManager); void AfterDestroy(); protected: @@ -50,7 +50,7 @@ class JSProcessActorChild final : public JSActor { ~JSProcessActorChild() { MOZ_ASSERT(!mManager); } bool mCanSend = true; - nsCOMPtr mManager; + RefPtr mManager; }; } // namespace dom diff --git a/dom/ipc/JSProcessActorParent.cpp b/dom/ipc/JSProcessActorParent.cpp index 1e9634135689..17528b250629 100644 --- a/dom/ipc/JSProcessActorParent.cpp +++ b/dom/ipc/JSProcessActorParent.cpp @@ -27,7 +27,7 @@ JSObject* JSProcessActorParent::WrapObject(JSContext* aCx, } void JSProcessActorParent::Init(const nsACString& aName, - nsIDOMProcessParent* aManager) { + ContentParent* aManager) { MOZ_ASSERT(!mManager, "Cannot Init() a JSProcessActorParent twice!"); SetName(aName); mManager = aManager; @@ -37,44 +37,11 @@ void JSProcessActorParent::Init(const nsACString& aName, JSProcessActorParent::~JSProcessActorParent() { MOZ_ASSERT(!mManager); } -namespace { - -class AsyncMessageToProcessChild : public Runnable { - public: - AsyncMessageToProcessChild(const JSActorMessageMeta& aMetadata, - ipc::StructuredCloneData&& aData, - ipc::StructuredCloneData&& aStack) - : mozilla::Runnable("InProcessChild::HandleAsyncMessage"), - mMetadata(aMetadata), - mData(std::move(aData)), - mStack(std::move(aStack)) {} - - NS_IMETHOD Run() override { - MOZ_ASSERT(NS_IsMainThread(), "Should be called on the main thread."); - if (auto* child = InProcessChild::Singleton()) { - RefPtr actor; - child->GetActor(mMetadata.actorName(), getter_AddRefs(actor)); - if (actor) { - actor->ReceiveRawMessage(mMetadata, std::move(mData), - std::move(mStack)); - } - } - return NS_OK; - } - - private: - JSActorMessageMeta mMetadata; - ipc::StructuredCloneData mData; - ipc::StructuredCloneData mStack; -}; - -} // namespace - void JSProcessActorParent::SendRawMessage(const JSActorMessageMeta& aMeta, ipc::StructuredCloneData&& aData, ipc::StructuredCloneData&& aStack, ErrorResult& aRv) { - if (NS_WARN_IF(!mCanSend || !mManager || !mManager->GetCanSend())) { + if (NS_WARN_IF(!mCanSend || !mManager || !mManager->CanSend())) { aRv.ThrowInvalidStateError( nsPrintfCString("Actor '%s' cannot send message '%s' during shutdown.", PromiseFlatCString(aMeta.actorName()).get(), @@ -91,22 +58,12 @@ void JSProcessActorParent::SendRawMessage(const JSActorMessageMeta& aMeta, return; } - // If the parent side is in the same process, we have a PInProcess manager, - // and can dispatch the message directly to the event loop. - ContentParent* contentParent = mManager->AsContentParent(); - if (!contentParent) { - NS_DispatchToMainThread(MakeAndAddRef( - aMeta, std::move(aData), std::move(aStack))); - return; - } - // Cross-process case - send data over ContentParent to other side. ClonedMessageData msgData; ClonedMessageData stackData; - if (NS_WARN_IF( - !aData.BuildClonedMessageDataForParent(contentParent, msgData)) || + if (NS_WARN_IF(!aData.BuildClonedMessageDataForParent(mManager, msgData)) || NS_WARN_IF( - !aStack.BuildClonedMessageDataForParent(contentParent, stackData))) { + !aStack.BuildClonedMessageDataForParent(mManager, stackData))) { aRv.ThrowDataCloneError( nsPrintfCString("Actor '%s' cannot send message '%s': cannot clone.", PromiseFlatCString(aMeta.actorName()).get(), @@ -114,7 +71,7 @@ void JSProcessActorParent::SendRawMessage(const JSActorMessageMeta& aMeta, return; } - if (NS_WARN_IF(!contentParent->SendRawMessage(aMeta, msgData, stackData))) { + if (NS_WARN_IF(!mManager->SendRawMessage(aMeta, msgData, stackData))) { aRv.Throw(NS_ERROR_UNEXPECTED); return; } diff --git a/dom/ipc/JSProcessActorParent.h b/dom/ipc/JSProcessActorParent.h index cfcdc0343a14..33a01dd6ef9f 100644 --- a/dom/ipc/JSProcessActorParent.h +++ b/dom/ipc/JSProcessActorParent.h @@ -15,7 +15,6 @@ #include "mozilla/dom/JSActor.h" #include "mozilla/extensions/WebExtensionContentScript.h" #include "nsCycleCollectionParticipant.h" -#include "nsIDOMProcessParent.h" #include "nsWrapperCache.h" namespace mozilla { @@ -39,9 +38,9 @@ class JSProcessActorParent final : public JSActor { return MakeAndAddRef(); } - nsIDOMProcessParent* Manager() const { return mManager; } + ContentParent* Manager() const { return mManager; } - void Init(const nsACString& aName, nsIDOMProcessParent* aManager); + void Init(const nsACString& aName, ContentParent* aManager); void AfterDestroy(); protected: @@ -57,7 +56,7 @@ class JSProcessActorParent final : public JSActor { ~JSProcessActorParent(); bool mCanSend = true; - nsCOMPtr mManager; + RefPtr mManager; }; } // namespace dom diff --git a/dom/ipc/JSProcessActorProtocol.cpp b/dom/ipc/JSProcessActorProtocol.cpp index a90dd054c459..cae0e0d0f509 100644 --- a/dom/ipc/JSProcessActorProtocol.cpp +++ b/dom/ipc/JSProcessActorProtocol.cpp @@ -78,18 +78,16 @@ NS_IMETHODIMP JSProcessActorProtocol::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { MOZ_ASSERT(nsContentUtils::IsSafeToRunScript()); + MOZ_ASSERT(!XRE_IsParentProcess()); - nsCOMPtr manager; - if (XRE_IsParentProcess()) { - manager = InProcessChild::Singleton(); - } else { - manager = ContentChild::GetSingleton(); - } + ErrorResult error; + RefPtr actor = + ContentChild::GetSingleton()->GetActor(mName, error); + + // Don't raise an error if creation of our actor was vetoed. + if (NS_WARN_IF(error.Failed())) { + nsresult rv = error.StealNSResult(); - RefPtr actor; - nsresult rv = manager->GetActor(mName, getter_AddRefs(actor)); - if (NS_WARN_IF(NS_FAILED(rv))) { - // Don't raise an error if creation of our actor was vetoed. if (rv == NS_ERROR_NOT_AVAILABLE) { return NS_OK; } @@ -107,6 +105,12 @@ NS_IMETHODIMP JSProcessActorProtocol::Observe(nsISupports* aSubject, } void JSProcessActorProtocol::AddObservers() { + // Ignore adding observers for parent processes, but this will + // need to change with bug 1633379. + if (XRE_IsParentProcess()) { + return; + } + nsCOMPtr os = services::GetObserverService(); for (auto& topic : mChild.mObservers) { // This makes the observer service hold an owning reference to the diff --git a/dom/ipc/JSWindowActorChild.h b/dom/ipc/JSWindowActorChild.h index 289fd61bb40b..bed53415ad67 100644 --- a/dom/ipc/JSWindowActorChild.h +++ b/dom/ipc/JSWindowActorChild.h @@ -15,7 +15,7 @@ #include "mozilla/dom/JSActor.h" #include "nsCycleCollectionParticipant.h" #include "nsWrapperCache.h" -#include "nsIDOMProcessChild.h" +#include "nsIContentChild.h" namespace mozilla { namespace dom { diff --git a/dom/ipc/PropertyBagUtils.cpp b/dom/ipc/PropertyBagUtils.cpp index eaed6beb5978..bf224d92ad90 100644 --- a/dom/ipc/PropertyBagUtils.cpp +++ b/dom/ipc/PropertyBagUtils.cpp @@ -16,7 +16,6 @@ #include "nsVariant.h" using namespace IPC; -using namespace mozilla::dom; namespace mozilla { namespace ipc { diff --git a/dom/ipc/WindowGlobalChild.cpp b/dom/ipc/WindowGlobalChild.cpp index 1bd23184c3e3..3c438b0db3ee 100644 --- a/dom/ipc/WindowGlobalChild.cpp +++ b/dom/ipc/WindowGlobalChild.cpp @@ -20,8 +20,8 @@ #include "mozilla/dom/WindowGlobalActorsBinding.h" #include "mozilla/dom/WindowGlobalParent.h" #include "mozilla/dom/WindowContext.h" -#include "mozilla/dom/InProcessChild.h" -#include "mozilla/dom/InProcessParent.h" +#include "mozilla/ipc/InProcessChild.h" +#include "mozilla/ipc/InProcessParent.h" #include "nsContentUtils.h" #include "nsDocShell.h" #include "nsFocusManager.h" diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index 4da750763e39..d04822874fcd 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -10,7 +10,7 @@ #include "mozilla/AsyncEventDispatcher.h" #include "mozilla/ClearOnShutdown.h" -#include "mozilla/dom/InProcessParent.h" +#include "mozilla/ipc/InProcessParent.h" #include "mozilla/dom/BrowserBridgeParent.h" #include "mozilla/dom/CanonicalBrowsingContext.h" #include "mozilla/dom/ClientInfo.h" @@ -213,13 +213,6 @@ already_AddRefed WindowGlobalParent::GetBrowserParent() { return do_AddRef(static_cast(Manager())); } -ContentParent* WindowGlobalParent::GetContentParent() { - if (IsInProcess() || !CanSend()) { - return nullptr; - } - return static_cast(Manager()->Manager()); -} - already_AddRefed WindowGlobalParent::GetRootFrameLoader() { dom::BrowsingContext* top = BrowsingContext()->Top(); @@ -830,11 +823,13 @@ nsIGlobalObject* WindowGlobalParent::GetParentObject() { return xpc::NativeGlobal(xpc::PrivilegedJunkScope()); } -nsIDOMProcessParent* WindowGlobalParent::GetDomProcess() { - if (RefPtr browserParent = GetBrowserParent()) { - return browserParent->Manager(); +nsIContentParent* WindowGlobalParent::GetContentParent() { + RefPtr browserParent = GetBrowserParent(); + if (!browserParent) { + return nullptr; } - return InProcessParent::Singleton(); + + return browserParent->Manager(); } void WindowGlobalParent::DidBecomeCurrentWindowGlobal(bool aCurrent) { diff --git a/dom/ipc/WindowGlobalParent.h b/dom/ipc/WindowGlobalParent.h index 12c2d92d4e7f..380d5df21288 100644 --- a/dom/ipc/WindowGlobalParent.h +++ b/dom/ipc/WindowGlobalParent.h @@ -20,7 +20,7 @@ #include "nsRefPtrHashtable.h" #include "nsWrapperCache.h" #include "nsISupports.h" -#include "nsIDOMProcessParent.h" +#include "nsIContentParent.h" #include "mozilla/dom/WindowGlobalActor.h" #include "mozilla/dom/CanonicalBrowsingContext.h" #include "mozilla/net/CookieJarSettings.h" @@ -93,8 +93,6 @@ class WindowGlobalParent final : public WindowContext, // |nullptr| if the actor has been torn down, or is in-process. already_AddRefed GetBrowserParent(); - ContentParent* GetContentParent(); - void ReceiveRawMessage(const JSActorMessageMeta& aMeta, ipc::StructuredCloneData&& aData, ipc::StructuredCloneData&& aStack); @@ -175,7 +173,7 @@ class WindowGlobalParent final : public WindowContext, ContentBlockingLog* GetContentBlockingLog() { return &mContentBlockingLog; } - nsIDOMProcessParent* GetDomProcess(); + nsIContentParent* GetContentParent(); nsICookieJarSettings* CookieJarSettings() { return mCookieJarSettings; } diff --git a/dom/ipc/moz.build b/dom/ipc/moz.build index 4395c178532e..9f36416b14da 100644 --- a/dom/ipc/moz.build +++ b/dom/ipc/moz.build @@ -8,8 +8,8 @@ with Files("**"): BUG_COMPONENT = ("Core", "DOM: Content Processes") XPIDL_SOURCES += [ - 'nsIDOMProcessChild.idl', - 'nsIDOMProcessParent.idl', + 'nsIContentChild.idl', + 'nsIContentParent.idl', 'nsIHangReport.idl', ] @@ -48,8 +48,6 @@ EXPORTS.mozilla.dom += [ 'DocShellMessageUtils.h', 'EffectsInfo.h', 'FilePickerParent.h', - 'InProcessChild.h', - 'InProcessParent.h', 'JSActor.h', 'JSActorService.h', 'JSProcessActorChild.h', @@ -107,7 +105,6 @@ UNIFIED_SOURCES += [ 'CSPMessageUtils.cpp', 'DocShellMessageUtils.cpp', 'FilePickerParent.cpp', - 'InProcessImpl.cpp', 'JSActor.cpp', 'JSActorService.cpp', 'JSProcessActorChild.cpp', @@ -161,7 +158,6 @@ IPDL_SOURCES += [ 'PContentPermissionRequest.ipdl', 'PCycleCollectWithLogs.ipdl', 'PFilePicker.ipdl', - 'PInProcess.ipdl', 'PLoginReputation.ipdl', 'PPluginWidget.ipdl', 'PProcessHangMonitor.ipdl', diff --git a/dom/ipc/nsIContentChild.idl b/dom/ipc/nsIContentChild.idl new file mode 100644 index 000000000000..82a1bbc9990d --- /dev/null +++ b/dom/ipc/nsIContentChild.idl @@ -0,0 +1,11 @@ +#include "nsISupports.idl" + +webidl JSProcessActorChild; + +[scriptable, builtinclass, uuid(b0c6e5f3-02f1-4f11-a0af-336fc231f3bf)] +interface nsIContentChild: nsISupports { + // Internal ID of the process. + readonly attribute unsigned long long childID; + + JSProcessActorChild getActor(in ACString name); +}; diff --git a/dom/ipc/nsIContentParent.idl b/dom/ipc/nsIContentParent.idl new file mode 100644 index 000000000000..fb8fd0ff9524 --- /dev/null +++ b/dom/ipc/nsIContentParent.idl @@ -0,0 +1,11 @@ +#include "nsISupports.idl" + +webidl JSProcessActorParent; + +[scriptable, builtinclass, uuid(81fc08b9-c901-471f-ab0d-876362eba770)] +interface nsIContentParent: nsISupports { + // Internal ID of the process. + readonly attribute unsigned long long childID; + + JSProcessActorParent getActor(in ACString name); +}; diff --git a/dom/ipc/nsIDOMProcessChild.idl b/dom/ipc/nsIDOMProcessChild.idl deleted file mode 100644 index 91e060868efd..000000000000 --- a/dom/ipc/nsIDOMProcessChild.idl +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* 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/. */ - -#include "nsISupports.idl" - -%{C++ -namespace mozilla { -namespace dom { -class ContentChild; -} // namespace dom -} // namespace mozilla -%} -[ptr] native ContentChildPtr(mozilla::dom::ContentChild); - -webidl JSProcessActorChild; - -/** - * Child actor interface for a process which can host DOM content. - * - * Implemented by either `InProcessChild` for the parent process, or - * `ContentChild` for a content process. - */ -[scriptable, builtinclass, uuid(b0c6e5f3-02f1-4f11-a0af-336fc231f3bf)] -interface nsIDOMProcessChild: nsISupports { - /** - * Internal child process ID. `0` is reserved for the parent process. - */ - [infallible] readonly attribute unsigned long long childID; - - /** - * Lookup a JSProcessActorChild managed by this interface by name. - */ - JSProcessActorChild getActor(in ACString name); - - /** Can the actor still send messages? */ - [infallible] readonly attribute boolean canSend; - - [notxpcom, nostdcall] ContentChildPtr AsContentChild(); -}; diff --git a/dom/ipc/nsIDOMProcessParent.idl b/dom/ipc/nsIDOMProcessParent.idl deleted file mode 100644 index c105ec46d09a..000000000000 --- a/dom/ipc/nsIDOMProcessParent.idl +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* 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/. */ - -#include "nsISupports.idl" - -%{C++ -namespace mozilla { -namespace dom { -class ContentParent; -} // namespace dom -} // namespace mozilla -%} -[ptr] native ContentParentPtr(mozilla::dom::ContentParent); - -webidl JSProcessActorParent; - -/** - * Parent actor interface for a process which can host DOM content. - * - * Implemented by either `InProcessParent` for the parent process, or - * `ContentParent` for a content process. - */ -[scriptable, builtinclass, uuid(81fc08b9-c901-471f-ab0d-876362eba770)] -interface nsIDOMProcessParent: nsISupports { - /** - * Internal child process ID. `0` is reserved for the parent process. - */ - [infallible] readonly attribute unsigned long long childID; - - /** - * Lookup a JSProcessActorParent managed by this interface by name. - */ - JSProcessActorParent getActor(in ACString name); - - /** Can the actor still send messages? */ - [infallible] readonly attribute boolean canSend; - - [notxpcom, nostdcall] ContentParentPtr AsContentParent(); -}; diff --git a/dom/ipc/tests/JSProcessActor/browser_getActor.js b/dom/ipc/tests/JSProcessActor/browser_getActor.js index e972eaaac9a7..2a555acbc9f0 100644 --- a/dom/ipc/tests/JSProcessActor/browser_getActor.js +++ b/dom/ipc/tests/JSProcessActor/browser_getActor.js @@ -4,7 +4,7 @@ declTest("getActor on both sides", { async test(browser) { - let parent = browser.browsingContext.currentWindowGlobal.domProcess; + let parent = browser.browsingContext.currentWindowGlobal.contentParent; ok(parent, "WindowGlobalParent should have value."); let actorParent = parent.getActor("TestProcessActor"); is( @@ -15,7 +15,7 @@ declTest("getActor on both sides", { is( actorParent.manager, parent, - "manager should match WindowGlobalParent.domProcess" + "manager should match WindowGlobalParent.contentParent" ); ok( @@ -24,7 +24,7 @@ declTest("getActor on both sides", { ); await SpecialPowers.spawn(browser, [], async function() { - let child = ChromeUtils.domProcessChild; + let child = ChromeUtils.contentChild; ok(child, "WindowGlobalChild should have value."); let actorChild = child.getActor("TestProcessActor"); is( @@ -35,7 +35,7 @@ declTest("getActor on both sides", { is( actorChild.manager, child, - "manager should match ChromeUtils.domProcessChild." + "manager should match ChromeUtils.contentChild." ); ok( diff --git a/dom/ipc/tests/JSProcessActor/browser_observer_notification.js b/dom/ipc/tests/JSProcessActor/browser_observer_notification.js index dfe92ad24079..a8b819eb412d 100644 --- a/dom/ipc/tests/JSProcessActor/browser_observer_notification.js +++ b/dom/ipc/tests/JSProcessActor/browser_observer_notification.js @@ -9,7 +9,7 @@ declTest("test observer triggering actor creation", { const TOPIC = "test-js-content-actor-child-observer"; Services.obs.notifyObservers(content.window, TOPIC, "dataString"); - let child = ChromeUtils.domProcessChild; + let child = ChromeUtils.contentChild; let actorChild = child.getActor("TestProcessActor"); ok(actorChild, "JSProcessActorChild should have value."); ok( @@ -29,7 +29,7 @@ declTest("test observers with null data", { const TOPIC = "test-js-content-actor-child-observer"; Services.obs.notifyObservers(content.window, TOPIC); - let child = ChromeUtils.domProcessChild; + let child = ChromeUtils.contentChild; let actorChild = child.getActor("TestProcessActor"); ok(actorChild, "JSProcessActorChild should have value."); let { subject, topic, data } = actorChild.lastObserved; diff --git a/dom/ipc/tests/JSProcessActor/browser_sendAsyncMessage.js b/dom/ipc/tests/JSProcessActor/browser_sendAsyncMessage.js index f81d4ddbeed4..2906f9d81ae6 100644 --- a/dom/ipc/tests/JSProcessActor/browser_sendAsyncMessage.js +++ b/dom/ipc/tests/JSProcessActor/browser_sendAsyncMessage.js @@ -4,12 +4,12 @@ declTest("asyncMessage testing", { async test(browser) { - let parent = browser.browsingContext.currentWindowGlobal.domProcess; + let parent = browser.browsingContext.currentWindowGlobal.contentParent; let actorParent = parent.getActor("TestProcessActor"); ok(actorParent, "JSProcessActorParent should have value."); await ContentTask.spawn(browser, {}, async function() { - let child = ChromeUtils.domProcessChild; + let child = ChromeUtils.contentChild; let actorChild = child.getActor("TestProcessActor"); ok(actorChild, "JSProcessActorChild should have value."); @@ -32,7 +32,7 @@ declTest("asyncMessage without both sides", { // If we don't create a parent actor, make sure the parent actor // gets created by having sent the message. await ContentTask.spawn(browser, {}, async function() { - let child = ChromeUtils.domProcessChild; + let child = ChromeUtils.contentChild; let actorChild = child.getActor("TestProcessActor"); ok(actorChild, "JSProcessActorChild should have value."); diff --git a/dom/ipc/tests/JSProcessActor/browser_sendQuery.js b/dom/ipc/tests/JSProcessActor/browser_sendQuery.js index 69fe881367c4..99b7209f494d 100644 --- a/dom/ipc/tests/JSProcessActor/browser_sendQuery.js +++ b/dom/ipc/tests/JSProcessActor/browser_sendQuery.js @@ -23,7 +23,7 @@ function maybeAsyncStack(offset, column) { declTest("sendQuery Error", { async test(browser) { - let parent = browser.browsingContext.currentWindowGlobal.domProcess; + let parent = browser.browsingContext.currentWindowGlobal.contentParent; let actorParent = parent.getActor("TestProcessActor"); let asyncStack = maybeAsyncStack(2, 8); @@ -44,7 +44,7 @@ declTest("sendQuery Error", { declTest("sendQuery Exception", { async test(browser) { - let parent = browser.browsingContext.currentWindowGlobal.domProcess; + let parent = browser.browsingContext.currentWindowGlobal.contentParent; let actorParent = parent.getActor("TestProcessActor"); let asyncStack = maybeAsyncStack(2, 8); @@ -72,7 +72,7 @@ declTest("sendQuery Exception", { declTest("sendQuery testing", { async test(browser) { - let parent = browser.browsingContext.currentWindowGlobal.domProcess; + let parent = browser.browsingContext.currentWindowGlobal.contentParent; let actorParent = parent.getActor("TestProcessActor"); ok(actorParent, "JSWindowActorParent should have value."); diff --git a/dom/ipc/tests/JSWindowActor/browser_process_childid.js b/dom/ipc/tests/JSWindowActor/browser_process_childid.js index 95e1a0c422a3..076419ba0bb5 100644 --- a/dom/ipc/tests/JSWindowActor/browser_process_childid.js +++ b/dom/ipc/tests/JSWindowActor/browser_process_childid.js @@ -8,18 +8,18 @@ declTest("test childid", { async test(browser) { let parent = browser.browsingContext.currentWindowGlobal; ok( - parent.domProcess.childID, - "parent domProcess.childID should have a value." + parent.contentParent.childID, + "parent contentParent.childID should have a value." ); await SpecialPowers.spawn( browser, - [parent.domProcess.childID], + [parent.contentParent.childID], async function(parentChildID) { ok( - ChromeUtils.domProcessChild.childID, + ChromeUtils.contentChild.childID, "child process.childID should have a value." ); - let childID = ChromeUtils.domProcessChild.childID; + let childID = ChromeUtils.contentChild.childID; is(parentChildID, childID); } ); diff --git a/ipc/glue/IPDLParamTraits.h b/ipc/glue/IPDLParamTraits.h index f258bdcaf688..90d0baf37921 100644 --- a/ipc/glue/IPDLParamTraits.h +++ b/ipc/glue/IPDLParamTraits.h @@ -10,8 +10,6 @@ #include "chrome/common/ipc_message_utils.h" #include "mozilla/UniquePtr.h" #include "mozilla/Variant.h" -#include "mozilla/Tuple.h" -#include "nsTArray.h" #include diff --git a/dom/ipc/InProcessChild.h b/ipc/glue/InProcessChild.h similarity index 68% rename from dom/ipc/InProcessChild.h rename to ipc/glue/InProcessChild.h index 26d695148a50..f0f3645a75d8 100644 --- a/dom/ipc/InProcessChild.h +++ b/ipc/glue/InProcessChild.h @@ -4,19 +4,20 @@ * 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_InProcessChild_h -#define mozilla_dom_InProcessChild_h +#ifndef mozilla_ipc_InProcessChild_h +#define mozilla_ipc_InProcessChild_h -#include "mozilla/dom/PInProcessChild.h" -#include "mozilla/dom/JSProcessActorChild.h" -#include "mozilla/dom/ProcessActor.h" +#include "mozilla/ipc/PInProcessChild.h" #include "mozilla/StaticPtr.h" -#include "nsIDOMProcessChild.h" namespace mozilla { namespace dom { class PWindowGlobalParent; class PWindowGlobalChild; +} // namespace dom + +namespace ipc { + class InProcessParent; /** @@ -27,15 +28,12 @@ class InProcessParent; * for async actors which want to communicate uniformly between Content->Chrome * and Chrome->Chrome situations. */ -class InProcessChild final : public nsIDOMProcessChild, - public PInProcessChild, - public ProcessActor { +class InProcessChild final : public PInProcessChild { public: friend class InProcessParent; friend class PInProcessChild; - NS_DECL_ISUPPORTS - NS_DECL_NSIDOMPROCESSCHILD + NS_INLINE_DECL_REFCOUNTING(InProcessChild, final) // Get the singleton instance of this actor. static InProcessChild* Singleton(); @@ -45,9 +43,6 @@ class InProcessChild final : public nsIDOMProcessChild, // |nullptr|. static IProtocol* ParentActorFor(IProtocol* aActor); - const nsAString& GetRemoteType() const override { return VoidString(); } - JSActor::Type GetSide() override { return JSActor::Type::Child; } - private: // NOTE: PInProcess lifecycle management is declared as staic methods and // state on InProcessParent, and implemented in InProcessImpl.cpp. @@ -55,11 +50,9 @@ class InProcessChild final : public nsIDOMProcessChild, ~InProcessChild() = default; static StaticRefPtr sSingleton; - - nsRefPtrHashtable mProcessActors; }; -} // namespace dom +} // namespace ipc } // namespace mozilla -#endif // defined(mozilla_dom_InProcessChild_h) +#endif // defined(mozilla_ipc_InProcessChild_h) diff --git a/dom/ipc/InProcessImpl.cpp b/ipc/glue/InProcessImpl.cpp similarity index 61% rename from dom/ipc/InProcessImpl.cpp rename to ipc/glue/InProcessImpl.cpp index b34ba95c1447..db5b8d3adceb 100644 --- a/dom/ipc/InProcessImpl.cpp +++ b/ipc/glue/InProcessImpl.cpp @@ -4,19 +4,16 @@ * 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/. */ -#include "mozilla/dom/InProcessParent.h" -#include "mozilla/dom/InProcessChild.h" -#include "mozilla/dom/JSProcessActorBinding.h" +#include "mozilla/ipc/InProcessParent.h" +#include "mozilla/ipc/InProcessChild.h" #include "nsIObserverService.h" #include "mozilla/Services.h" -using namespace mozilla::ipc; - // This file contains the implementation of core InProcess lifecycle management // facilities. namespace mozilla { -namespace dom { +namespace ipc { StaticRefPtr InProcessParent::sSingleton; StaticRefPtr InProcessChild::sSingleton; @@ -118,118 +115,6 @@ void InProcessChild::ActorDestroy(ActorDestroyReason aWhy) { InProcessParent::Shutdown(); } -///////////////////////// -// nsIDOMProcessParent // -///////////////////////// - -NS_IMETHODIMP -InProcessParent::GetChildID(uint64_t* aChildID) { - *aChildID = 0; - return NS_OK; -} - -NS_IMETHODIMP -InProcessParent::GetActor(const nsACString& aName, - JSProcessActorParent** aActor) { - if (!CanSend()) { - return NS_ERROR_DOM_INVALID_STATE_ERR; - } - - // Check if this actor has already been created, and return it if it has. - if (mProcessActors.Contains(aName)) { - RefPtr actor(mProcessActors.Get(aName)); - actor.forget(aActor); - return NS_OK; - } - - // Otherwise, we want to create a new instance of this actor. - JS::RootedObject obj(RootingCx()); - ErrorResult result; - ConstructActor(aName, &obj, result); - if (result.Failed()) { - return result.StealNSResult(); - } - - // Unwrap our actor to a JSProcessActorParent object. - RefPtr actor; - nsresult rv = UNWRAP_OBJECT(JSProcessActorParent, &obj, actor); - if (NS_FAILED(rv)) { - return rv; - } - - MOZ_RELEASE_ASSERT(!actor->Manager(), - "mManager was already initialized once!"); - actor->Init(aName, this); - mProcessActors.Put(aName, RefPtr{actor}); - actor.forget(aActor); - return NS_OK; -} - -NS_IMETHODIMP -InProcessParent::GetCanSend(bool* aCanSend) { - *aCanSend = CanSend(); - return NS_OK; -} - -NS_IMETHODIMP_(ContentParent*) -InProcessParent::AsContentParent() { return nullptr; } - -//////////////////////// -// nsIDOMProcessChild // -//////////////////////// - -NS_IMETHODIMP -InProcessChild::GetChildID(uint64_t* aChildID) { - *aChildID = 0; - return NS_OK; -} - -NS_IMETHODIMP -InProcessChild::GetActor(const nsACString& aName, - JSProcessActorChild** aActor) { - if (!CanSend()) { - return NS_ERROR_DOM_INVALID_STATE_ERR; - } - - // Check if this actor has already been created, and return it if it has. - if (mProcessActors.Contains(aName)) { - RefPtr actor(mProcessActors.Get(aName)); - actor.forget(aActor); - return NS_OK; - } - - // Otherwise, we want to create a new instance of this actor. - JS::RootedObject obj(RootingCx()); - ErrorResult result; - ConstructActor(aName, &obj, result); - if (result.Failed()) { - return result.StealNSResult(); - } - - // Unwrap our actor to a JSProcessActorChild object. - RefPtr actor; - nsresult rv = UNWRAP_OBJECT(JSProcessActorChild, &obj, actor); - if (NS_FAILED(rv)) { - return rv; - } - - MOZ_RELEASE_ASSERT(!actor->Manager(), - "mManager was already initialized once!"); - actor->Init(aName, this); - mProcessActors.Put(aName, RefPtr{actor}); - actor.forget(aActor); - return NS_OK; -} - -NS_IMETHODIMP -InProcessChild::GetCanSend(bool* aCanSend) { - *aCanSend = CanSend(); - return NS_OK; -} - -NS_IMETHODIMP_(ContentChild*) -InProcessChild::AsContentChild() { return nullptr; } - //////////////////////////////// // In-Process Actor Utilities // //////////////////////////////// @@ -292,8 +177,7 @@ IProtocol* InProcessChild::ParentActorFor(IProtocol* aActor) { return GetOtherInProcessActor(aActor); } -NS_IMPL_ISUPPORTS(InProcessParent, nsIDOMProcessParent, nsIObserver) -NS_IMPL_ISUPPORTS(InProcessChild, nsIDOMProcessChild) +NS_IMPL_ISUPPORTS(InProcessParent, nsIObserver) -} // namespace dom +} // namespace ipc } // namespace mozilla diff --git a/dom/ipc/InProcessParent.h b/ipc/glue/InProcessParent.h similarity index 67% rename from dom/ipc/InProcessParent.h rename to ipc/glue/InProcessParent.h index b30d6bf3f17e..2e3aa3553442 100644 --- a/dom/ipc/InProcessParent.h +++ b/ipc/glue/InProcessParent.h @@ -4,19 +4,20 @@ * 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_InProcessParent_h -#define mozilla_dom_InProcessParent_h +#ifndef mozilla_ipc_InProcessParent_h +#define mozilla_ipc_InProcessParent_h -#include "mozilla/dom/PInProcessParent.h" -#include "mozilla/dom/JSProcessActorParent.h" -#include "mozilla/dom/ProcessActor.h" +#include "mozilla/ipc/PInProcessParent.h" #include "mozilla/StaticPtr.h" -#include "nsIDOMProcessParent.h" namespace mozilla { namespace dom { class PWindowGlobalParent; class PWindowGlobalChild; +} // namespace dom + +namespace ipc { + class InProcessChild; /** @@ -27,16 +28,12 @@ class InProcessChild; * for async actors which want to communicate uniformly between Content->Chrome * and Chrome->Chrome situations. */ -class InProcessParent final : public nsIDOMProcessParent, - public nsIObserver, - public PInProcessParent, - public ProcessActor { +class InProcessParent final : public nsIObserver, public PInProcessParent { public: friend class InProcessChild; friend class PInProcessParent; NS_DECL_ISUPPORTS - NS_DECL_NSIDOMPROCESSPARENT NS_DECL_NSIOBSERVER // Get the singleton instance of this actor. @@ -47,9 +44,6 @@ class InProcessParent final : public nsIDOMProcessParent, // |nullptr|. static IProtocol* ChildActorFor(IProtocol* aActor); - const nsAString& GetRemoteType() const override { return VoidString(); }; - JSActor::Type GetSide() override { return JSActor::Type::Parent; } - private: // Lifecycle management is implemented in InProcessImpl.cpp virtual void ActorDestroy(ActorDestroyReason aWhy) override; @@ -60,11 +54,9 @@ class InProcessParent final : public nsIDOMProcessParent, static StaticRefPtr sSingleton; static bool sShutdown; - - nsRefPtrHashtable mProcessActors; }; -} // namespace dom +} // namespace ipc } // namespace mozilla -#endif // defined(mozilla_dom_InProcessParent_h) +#endif // defined(mozilla_ipc_InProcessParent_h) diff --git a/dom/ipc/PInProcess.ipdl b/ipc/glue/PInProcess.ipdl similarity index 88% rename from dom/ipc/PInProcess.ipdl rename to ipc/glue/PInProcess.ipdl index 6b14ae36638d..28d7d95b61ad 100644 --- a/dom/ipc/PInProcess.ipdl +++ b/ipc/glue/PInProcess.ipdl @@ -9,14 +9,14 @@ include protocol PWindowGlobal; include DOMTypes; namespace mozilla { -namespace dom { +namespace ipc { /** * PInProcess is intended for use as an alternative actor manager to PContent * for async actors which want to be used uniformly in both Content->Chrome and * Chrome->Chrome circumstances. * - * `mozilla::dom::InProcess{Parent, Child}::Singleton()` should be used to get + * `mozilla::ipc::InProcess{Parent, Child}::Singleton()` should be used to get * an instance of this actor. */ async refcounted protocol PInProcess @@ -24,5 +24,5 @@ async refcounted protocol PInProcess manages PWindowGlobal; }; -} // namespace dom +} // namespace ipc } // namespace mozilla diff --git a/ipc/glue/moz.build b/ipc/glue/moz.build index 21aab170c5ca..feb9281c00ba 100644 --- a/ipc/glue/moz.build +++ b/ipc/glue/moz.build @@ -29,6 +29,8 @@ EXPORTS.mozilla.ipc += [ 'GeckoChildProcessHost.h', 'IdleSchedulerChild.h', 'IdleSchedulerParent.h', + 'InProcessChild.h', + 'InProcessParent.h', 'InputStreamUtils.h', 'IOThreadChild.h', 'IPCStreamAlloc.h', @@ -153,6 +155,7 @@ UNIFIED_SOURCES += [ 'FileDescriptorUtils.cpp', 'IdleSchedulerChild.cpp', 'IdleSchedulerParent.cpp', + 'InProcessImpl.cpp', 'InputStreamUtils.cpp', 'IPCMessageUtils.cpp', 'IPCStreamChild.cpp', @@ -213,6 +216,7 @@ IPDL_SOURCES = [ 'PChildToParentStream.ipdl', 'PFileDescriptorSet.ipdl', 'PIdleScheduler.ipdl', + 'PInProcess.ipdl', 'PParentToChildStream.ipdl', 'ProtocolTypes.ipdlh', 'URIParams.ipdlh',