diff --git a/ipc/glue/ProtocolUtils.cpp b/ipc/glue/ProtocolUtils.cpp index 09e2cc062e6c..8f20ce84ee17 100644 --- a/ipc/glue/ProtocolUtils.cpp +++ b/ipc/glue/ProtocolUtils.cpp @@ -529,6 +529,30 @@ IProtocol::SetManager(IProtocol* aManager) mManager = aManager; } +void +IProtocol::SetManagerAndRegister(IProtocol* aManager) +{ + // Set the manager prior to registering so registering properly inherits + // the manager's event target. + SetManager(aManager); + + aManager->Register(this); + + SetIPCChannel(aManager->GetIPCChannel()); +} + +void +IProtocol::SetManagerAndRegister(IProtocol* aManager, int32_t aId) +{ + // Set the manager prior to registering so registering properly inherits + // the manager's event target. + SetManager(aManager); + + aManager->RegisterID(this, aId); + + SetIPCChannel(aManager->GetIPCChannel()); +} + void IProtocol::SetEventTargetForActor(IProtocol* aActor, nsIEventTarget* aEventTarget) { diff --git a/ipc/glue/ProtocolUtils.h b/ipc/glue/ProtocolUtils.h index 185f61c22d11..8676550038ec 100644 --- a/ipc/glue/ProtocolUtils.h +++ b/ipc/glue/ProtocolUtils.h @@ -314,7 +314,16 @@ protected: void SetId(int32_t aId) { mId = aId; } void ResetManager() { mManager = nullptr; } + // We have separate functions because the accessibility code manually + // calls SetManager. void SetManager(IProtocol* aManager); + + // Sets the manager for the protocol and registers the protocol with + // its manager, setting up channels for the protocol as well. Not + // for use outside of IPDL. + void SetManagerAndRegister(IProtocol* aManager); + void SetManagerAndRegister(IProtocol* aManager, int32_t aId); + void SetIPCChannel(MessageChannel* aChannel) { mChannel = aChannel; } static const int32_t kNullActorId = 0; diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 0748c9584b97..3ed117d39313 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -3917,19 +3917,15 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): actortype = ipdl.type.ActorType(actorproto) if idexpr is None: - registerexpr = ExprCall(self.protocol.registerMethod(), - args=[ actorvar ]) + setManagerArgs = [ExprVar.THIS] else: - registerexpr = ExprCall(self.protocol.registerIDMethod(), - args=[ actorvar, idexpr ]) + setManagerArgs = [ExprVar.THIS, idexpr] + setmanager = ExprCall(ExprSelect(actorvar, '->', 'SetManagerAndRegister'), + args=setManagerArgs) return [ self.failIfNullActor(actorvar, errfn, msg="Error constructing actor %s" % actortype.name() + self.side.capitalize()), - # set manager in prior to register to inherit EventTarget from manager. - StmtExpr(ExprCall(ExprSelect(actorvar, '->', 'SetManager'), args=[ExprVar.THIS])), - StmtExpr(registerexpr), - StmtExpr(ExprCall(ExprSelect(actorvar, '->', 'SetIPCChannel'), - args=[self.protocol.callGetChannel()])), + StmtExpr(setmanager), StmtExpr(_callInsertManagedActor( self.protocol.managedVar(md.decl.type.constructedType(), self.side),