Bug 1893119: Part 16 - Make nsBaseDragService weakly remember PBrowsers instead of PContents r=nika,win-reviewers,rkraesig

nsBaseDragService keeps track of the processes that might need to cancel a drag with EndDragSession and this is technically correct since the drag session is a singleton in the child process, but this series of patches changes those sessions to be per-PuppetWidget/BrowserChild.  This allows content processes to distinguish which of its browsers is engaged in a drag.

Differential Revision: https://phabricator.services.mozilla.com/D211062
This commit is contained in:
David P
2024-07-04 07:48:09 +00:00
parent 808c72fba0
commit c32e8a504a
15 changed files with 286 additions and 264 deletions

View File

@@ -201,7 +201,6 @@
#include "nsServiceManagerUtils.h"
#include "nsStyleSheetService.h"
#include "nsThreadManager.h"
#include "nsVariant.h"
#include "nsXULAppAPI.h"
#include "IHistory.h"
#include "ReferrerInfo.h"
@@ -3218,111 +3217,6 @@ mozilla::ipc::IPCResult ContentChild::RecvPWebBrowserPersistDocumentConstructor(
return IPC_OK();
}
static already_AddRefed<DataTransfer> ConvertToDataTransfer(
nsTArray<IPCTransferableData>&& aTransferables, EventMessage aMessage) {
// Check if we are receiving any file objects. If we are we will want
// to hide any of the other objects coming in from content.
bool hasFiles = false;
for (uint32_t i = 0; i < aTransferables.Length() && !hasFiles; ++i) {
auto& items = aTransferables[i].items();
for (uint32_t j = 0; j < items.Length() && !hasFiles; ++j) {
if (items[j].data().type() ==
IPCTransferableDataType::TIPCTransferableDataBlob) {
hasFiles = true;
}
}
}
// Add the entries from the IPC to the new DataTransfer
RefPtr<DataTransfer> dataTransfer =
new DataTransfer(nullptr, aMessage, false, -1);
for (uint32_t i = 0; i < aTransferables.Length(); ++i) {
auto& items = aTransferables[i].items();
for (uint32_t j = 0; j < items.Length(); ++j) {
const IPCTransferableDataItem& item = items[j];
RefPtr<nsVariantCC> variant = new nsVariantCC();
nsresult rv =
nsContentUtils::IPCTransferableDataItemToVariant(item, variant);
if (NS_FAILED(rv)) {
continue;
}
// We should hide this data from content if we have a file, and we
// aren't a file.
bool hidden =
hasFiles && item.data().type() !=
IPCTransferableDataType::TIPCTransferableDataBlob;
dataTransfer->SetDataWithPrincipalFromOtherProcess(
NS_ConvertUTF8toUTF16(item.flavor()), variant, i,
nsContentUtils::GetSystemPrincipal(), hidden);
}
}
return dataTransfer.forget();
}
mozilla::ipc::IPCResult ContentChild::RecvInvokeDragSession(
const MaybeDiscarded<WindowContext>& aSourceWindowContext,
const MaybeDiscarded<WindowContext>& aSourceTopWindowContext,
nsTArray<IPCTransferableData>&& aTransferables, const uint32_t& aAction) {
if (nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1")) {
dragService->StartDragSession();
nsCOMPtr<nsIDragSession> session;
dragService->GetCurrentSession(getter_AddRefs(session));
if (session) {
session->SetSourceWindowContext(aSourceWindowContext.GetMaybeDiscarded());
session->SetSourceTopWindowContext(
aSourceTopWindowContext.GetMaybeDiscarded());
session->SetDragAction(aAction);
RefPtr<DataTransfer> dataTransfer =
ConvertToDataTransfer(std::move(aTransferables), eDragStart);
session->SetDataTransfer(dataTransfer);
}
}
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvUpdateDragSession(
nsTArray<IPCTransferableData>&& aTransferables,
EventMessage aEventMessage) {
if (nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1")) {
nsCOMPtr<nsIDragSession> session;
dragService->GetCurrentSession(getter_AddRefs(session));
if (session) {
nsCOMPtr<DataTransfer> dataTransfer =
ConvertToDataTransfer(std::move(aTransferables), aEventMessage);
session->SetDataTransfer(dataTransfer);
}
}
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvEndDragSession(
const bool& aDoneDrag, const bool& aUserCancelled,
const LayoutDeviceIntPoint& aDragEndPoint, const uint32_t& aKeyModifiers,
const uint32_t& aDropEffect) {
nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1");
if (dragService) {
nsCOMPtr<nsIDragSession> dragSession;
dragService->GetCurrentSession(getter_AddRefs(dragSession));
if (dragSession) {
if (aUserCancelled) {
dragSession->UserCancelled();
}
RefPtr<DataTransfer> dataTransfer = dragSession->GetDataTransfer();
if (dataTransfer) {
dataTransfer->SetDropEffectInt(aDropEffect);
}
dragSession->SetDragEndPoint(aDragEndPoint.x, aDragEndPoint.y);
}
dragService->EndDragSession(aDoneDrag, aKeyModifiers);
}
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvPush(const nsCString& aScope,
nsIPrincipal* aPrincipal,
const nsString& aMessageId) {