Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / events / RemoteDragStartData.cpp
blob69d7692bf85b0e75da86448fef8508e580aa77c3
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsContentAreaDragDrop.h"
6 #include "RemoteDragStartData.h"
7 #include "nsContentUtils.h"
8 #include "nsICookieJarSettings.h"
9 #include "nsVariant.h"
10 #include "mozilla/dom/BlobImpl.h"
11 #include "mozilla/dom/BrowserParent.h"
12 #include "mozilla/dom/IPCBlobUtils.h"
13 #include "mozilla/dom/DOMTypes.h"
14 #include "mozilla/ipc/ProtocolUtils.h"
16 using namespace mozilla::ipc;
18 namespace mozilla::dom {
20 RemoteDragStartData::~RemoteDragStartData() = default;
22 RemoteDragStartData::RemoteDragStartData(
23 BrowserParent* aBrowserParent,
24 nsTArray<IPCTransferableData>&& aTransferableData,
25 const LayoutDeviceIntRect& aRect, nsIPrincipal* aPrincipal,
26 nsIContentSecurityPolicy* aCsp, nsICookieJarSettings* aCookieJarSettings,
27 WindowContext* aSourceWindowContext, WindowContext* aSourceTopWindowContext)
28 : mBrowserParent(aBrowserParent),
29 mTransferableData(std::move(aTransferableData)),
30 mRect(aRect),
31 mPrincipal(aPrincipal),
32 mCsp(aCsp),
33 mCookieJarSettings(aCookieJarSettings),
34 mSourceWindowContext(aSourceWindowContext),
35 mSourceTopWindowContext(aSourceTopWindowContext) {}
37 void RemoteDragStartData::AddInitialDnDDataTo(
38 DataTransfer* aDataTransfer, nsIPrincipal** aPrincipal,
39 nsIContentSecurityPolicy** aCsp,
40 nsICookieJarSettings** aCookieJarSettings) {
41 NS_IF_ADDREF(*aPrincipal = mPrincipal);
42 NS_IF_ADDREF(*aCsp = mCsp);
43 NS_IF_ADDREF(*aCookieJarSettings = mCookieJarSettings);
45 for (uint32_t i = 0; i < mTransferableData.Length(); ++i) {
46 nsTArray<IPCTransferableDataItem>& itemArray = mTransferableData[i].items();
47 for (auto& item : itemArray) {
48 if (!nsContentUtils::IPCTransferableDataItemHasKnownFlavor(item)) {
49 NS_WARNING(
50 "Ignoring unknown flavor in "
51 "RemoteDragStartData::AddInitialDnDDataTo");
52 continue;
55 RefPtr<nsVariantCC> variant = new nsVariantCC();
56 // Special case kFilePromiseMime so that we get the right
57 // nsIFlavorDataProvider for it.
58 if (item.flavor().EqualsLiteral(kFilePromiseMime)) {
59 RefPtr<nsISupports> flavorDataProvider =
60 new nsContentAreaDragDropDataProvider();
61 variant->SetAsISupports(flavorDataProvider);
62 } else {
63 nsresult rv =
64 nsContentUtils::IPCTransferableDataItemToVariant(item, variant);
65 if (NS_FAILED(rv)) {
66 continue;
70 // We set aHidden to false, as we don't need to worry about hiding data
71 // from content in the parent process where there is no content.
72 aDataTransfer->SetDataWithPrincipalFromOtherProcess(
73 NS_ConvertUTF8toUTF16(item.flavor()), variant, i, mPrincipal,
74 /* aHidden = */ false);
78 // Clear things that are no longer needed.
79 mTransferableData.Clear();
80 mPrincipal = nullptr;
83 } // namespace mozilla::dom