Bug 1911486: Leave DragSession connected to BrowserChild while sending dragend r=win-reviewers,gstoll

During EndDragSession and the dispatch of the dragend event in a content process
(e.g. in an extension), accessing the event's dataTransfer didn't work because
the session was already disconnected from the BrowserChild.  This broke things
like tab dragging from web-extension-based tabbars.  This leaves the drag
session in place until after EndDragSession is done.  It also makes the
reciprocal change to InvokeDragSession.

Differential Revision: https://phabricator.services.mozilla.com/D218667
This commit is contained in:
David Parks 2024-08-13 22:30:25 +00:00
Родитель 2ddad4db70
Коммит 5899e85856
1 изменённых файлов: 8 добавлений и 6 удалений

Просмотреть файл

@ -43,14 +43,12 @@ nsresult nsDragSessionProxy::InvokeDragSession(
[[maybe_unused]] RefPtr<nsIDragSession> sourceSession =
sourceBrowser->GetDragSession();
MOZ_ASSERT(!sourceSession);
MOZ_ALWAYS_SUCCEEDS(
sourceBrowser->GetWeakReference(getter_AddRefs(mSourceBrowser)));
sourceBrowser->SetDragSession(this);
nsresult rv = nsBaseDragSession::InvokeDragSession(
aWidget, aDOMNode, aPrincipal, aCsp, aCookieJarSettings,
aTransferableArray, aActionType, aContentPolicyType);
if (NS_SUCCEEDED(rv)) {
MOZ_ALWAYS_SUCCEEDS(
sourceBrowser->GetWeakReference(getter_AddRefs(mSourceBrowser)));
sourceBrowser->SetDragSession(this);
}
return rv;
}
@ -179,6 +177,10 @@ void nsDragSessionProxy::SetDragTarget(BrowserChild* aTarget) {
nsresult nsDragSessionProxy::EndDragSessionImpl(bool aDoneDrag,
uint32_t aKeyModifiers) {
// End the drag session before removing it from its BrowserChild(s). This
// leaves the drag session in place while EndDragSessionImpl sends dragend.
nsresult rv = nsBaseDragSession::EndDragSessionImpl(aDoneDrag, aKeyModifiers);
if (mSourceBrowser) {
nsCOMPtr<BrowserChild> sourceBC = do_QueryReferent(mSourceBrowser);
MOZ_ASSERT(sourceBC);
@ -199,5 +201,5 @@ nsresult nsDragSessionProxy::EndDragSessionImpl(bool aDoneDrag,
mTargetBrowser = nullptr;
}
return nsBaseDragSession::EndDragSessionImpl(aDoneDrag, aKeyModifiers);
return rv;
}