Bug 1874739 - Part 11: Make PWebBrowserPersistDocument refcounted, r=ipc-reviewers,mccr8

This is part of removing [ManualDealloc] from all protocols which manage other
protocols.

Differential Revision: https://phabricator.services.mozilla.com/D198621
This commit is contained in:
Nika Layzell 2024-01-19 20:23:21 +00:00
parent 0dad4f65ae
commit a9b47cb20b
10 changed files with 22 additions and 34 deletions

View File

@ -3866,7 +3866,8 @@ bool BrowserParent::AsyncPanZoomEnabled() const {
void BrowserParent::StartPersistence(
CanonicalBrowsingContext* aContext,
nsIWebBrowserPersistDocumentReceiver* aRecv, ErrorResult& aRv) {
auto* actor = new WebBrowserPersistDocumentParent();
RefPtr<WebBrowserPersistDocumentParent> actor =
new WebBrowserPersistDocumentParent();
actor->SetOnReady(aRecv);
bool ok = Manager()->SendPWebBrowserPersistDocumentConstructor(actor, this,
aContext);

View File

@ -3124,10 +3124,10 @@ bool ContentChild::DeallocPContentPermissionRequestChild(
return true;
}
PWebBrowserPersistDocumentChild*
already_AddRefed<PWebBrowserPersistDocumentChild>
ContentChild::AllocPWebBrowserPersistDocumentChild(
PBrowserChild* aBrowser, const MaybeDiscarded<BrowsingContext>& aContext) {
return new WebBrowserPersistDocumentChild();
return MakeAndAddRef<WebBrowserPersistDocumentChild>();
}
mozilla::ipc::IPCResult ContentChild::RecvPWebBrowserPersistDocumentConstructor(
@ -3152,12 +3152,6 @@ mozilla::ipc::IPCResult ContentChild::RecvPWebBrowserPersistDocumentConstructor(
return IPC_OK();
}
bool ContentChild::DeallocPWebBrowserPersistDocumentChild(
PWebBrowserPersistDocumentChild* aActor) {
delete aActor;
return true;
}
mozilla::ipc::IPCResult ContentChild::RecvInvokeDragSession(
const MaybeDiscarded<WindowContext>& aSourceWindowContext,
const MaybeDiscarded<WindowContext>& aSourceTopWindowContext,

View File

@ -203,16 +203,14 @@ class ContentChild final : public PContentChild,
PCycleCollectWithLogsChild* aChild, const bool& aDumpAllTraces,
const FileDescriptor& aGCLog, const FileDescriptor& aCCLog) override;
PWebBrowserPersistDocumentChild* AllocPWebBrowserPersistDocumentChild(
already_AddRefed<PWebBrowserPersistDocumentChild>
AllocPWebBrowserPersistDocumentChild(
PBrowserChild* aBrowser, const MaybeDiscarded<BrowsingContext>& aContext);
virtual mozilla::ipc::IPCResult RecvPWebBrowserPersistDocumentConstructor(
PWebBrowserPersistDocumentChild* aActor, PBrowserChild* aBrowser,
const MaybeDiscarded<BrowsingContext>& aContext) override;
bool DeallocPWebBrowserPersistDocumentChild(
PWebBrowserPersistDocumentChild* aActor);
already_AddRefed<PTestShellChild> AllocPTestShellChild();
virtual mozilla::ipc::IPCResult RecvPTestShellConstructor(

View File

@ -5509,16 +5509,10 @@ bool ContentParent::DeallocPContentPermissionRequestParent(
return true;
}
PWebBrowserPersistDocumentParent*
already_AddRefed<PWebBrowserPersistDocumentParent>
ContentParent::AllocPWebBrowserPersistDocumentParent(
PBrowserParent* aBrowser, const MaybeDiscarded<BrowsingContext>& aContext) {
return new WebBrowserPersistDocumentParent();
}
bool ContentParent::DeallocPWebBrowserPersistDocumentParent(
PWebBrowserPersistDocumentParent* aActor) {
delete aActor;
return true;
return MakeAndAddRef<WebBrowserPersistDocumentParent>();
}
mozilla::ipc::IPCResult ContentParent::CommonCreateWindow(

View File

@ -964,13 +964,11 @@ class ContentParent final : public PContentParent,
PSpeechSynthesisParent* aActor) override;
#endif
PWebBrowserPersistDocumentParent* AllocPWebBrowserPersistDocumentParent(
already_AddRefed<PWebBrowserPersistDocumentParent>
AllocPWebBrowserPersistDocumentParent(
PBrowserParent* aBrowser,
const MaybeDiscarded<BrowsingContext>& aContext);
bool DeallocPWebBrowserPersistDocumentParent(
PWebBrowserPersistDocumentParent* aActor);
mozilla::ipc::IPCResult RecvSetClipboard(const IPCTransferable& aTransferable,
const int32_t& aWhichClipboard);

View File

@ -57,7 +57,6 @@ struct WebBrowserPersistURIMap {
// because that would impose a lifetime relationship that doesn't
// exist in the XPIDL; instead they're all managed by the enclosing
// PContent.
[ManualDealloc]
protocol PWebBrowserPersistDocument {
manager PContent;
manages PWebBrowserPersistResources;

View File

@ -16,8 +16,9 @@ namespace mozilla {
class WebBrowserPersistDocumentChild final
: public PWebBrowserPersistDocumentChild {
public:
NS_INLINE_DECL_REFCOUNTING(WebBrowserPersistDocumentChild, override)
WebBrowserPersistDocumentChild();
~WebBrowserPersistDocumentChild();
// This sends either Attributes or InitFailure and thereby causes
// the actor to leave the START state.
@ -45,6 +46,8 @@ class WebBrowserPersistDocumentChild final
PWebBrowserPersistSerializeChild* aActor);
private:
~WebBrowserPersistDocumentChild();
nsCOMPtr<nsIWebBrowserPersistDocument> mDocument;
};

View File

@ -33,8 +33,9 @@ class WebBrowserPersistRemoteDocument;
class WebBrowserPersistDocumentParent final
: public PWebBrowserPersistDocumentParent {
public:
NS_INLINE_DECL_REFCOUNTING(WebBrowserPersistDocumentParent, override)
WebBrowserPersistDocumentParent();
virtual ~WebBrowserPersistDocumentParent();
// Set a callback to be invoked when the actor leaves the START
// state. This method must be called exactly once while the actor
@ -62,6 +63,8 @@ class WebBrowserPersistDocumentParent final
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
private:
virtual ~WebBrowserPersistDocumentParent();
// This is reset to nullptr when the callback is invoked.
nsCOMPtr<nsIWebBrowserPersistDocumentReceiver> mOnReady;
WebBrowserPersistRemoteDocument* mReflection;

View File

@ -31,7 +31,8 @@ NS_IMETHODIMP
WebBrowserPersistResourcesChild::VisitDocument(
nsIWebBrowserPersistDocument* aDocument,
nsIWebBrowserPersistDocument* aSubDocument) {
auto* subActor = new WebBrowserPersistDocumentChild();
RefPtr<WebBrowserPersistDocumentChild> subActor =
new WebBrowserPersistDocumentChild();
// As a consequence of how PWebBrowserPersistDocumentConstructor
// can be sent by both the parent and the child, we must pass the
// aBrowser and outerWindowID arguments here, but the values are
@ -40,11 +41,8 @@ WebBrowserPersistResourcesChild::VisitDocument(
// see bug 1203602.
if (!Manager()->Manager()->SendPWebBrowserPersistDocumentConstructor(
subActor, nullptr, nullptr)) {
// NOTE: subActor is freed at this point.
return NS_ERROR_FAILURE;
}
// ...but here, IPC won't free subActor until after this returns
// to the event loop.
// The order of these two messages will be preserved, because
// they're the same toplevel protocol and priority.

View File

@ -1707,7 +1707,7 @@ nsWebBrowserPersist::OnWalk::VisitBrowsingContext(
return NS_ERROR_FAILURE;
}
UniquePtr<WebBrowserPersistDocumentParent> actor(
RefPtr<WebBrowserPersistDocumentParent> actor(
new WebBrowserPersistDocumentParent());
nsCOMPtr<nsIWebBrowserPersistDocumentReceiver> receiver =
@ -1719,7 +1719,7 @@ nsWebBrowserPersist::OnWalk::VisitBrowsingContext(
bool ok =
context->GetContentParent()->SendPWebBrowserPersistDocumentConstructor(
actor.release(), browserParent, context);
actor, browserParent, context);
if (NS_WARN_IF(!ok)) {
// (The actor will be destroyed on constructor failure.)