tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RemoteDragStartData.cpp (3124B)


      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/. */
      4 
      5 #include "RemoteDragStartData.h"
      6 
      7 #include "mozilla/dom/BlobImpl.h"
      8 #include "mozilla/dom/BrowserParent.h"
      9 #include "mozilla/dom/DOMTypes.h"
     10 #include "mozilla/dom/IPCBlobUtils.h"
     11 #include "mozilla/ipc/ProtocolUtils.h"
     12 #include "nsContentAreaDragDrop.h"
     13 #include "nsContentUtils.h"
     14 #include "nsICookieJarSettings.h"
     15 #include "nsVariant.h"
     16 
     17 using namespace mozilla::ipc;
     18 
     19 namespace mozilla::dom {
     20 
     21 RemoteDragStartData::~RemoteDragStartData() = default;
     22 
     23 RemoteDragStartData::RemoteDragStartData(
     24    BrowserParent* aBrowserParent,
     25    nsTArray<IPCTransferableData>&& aTransferableData,
     26    const LayoutDeviceIntRect& aRect, nsIPrincipal* aPrincipal,
     27    nsIPolicyContainer* aPolicyContainer,
     28    nsICookieJarSettings* aCookieJarSettings,
     29    WindowContext* aSourceWindowContext, WindowContext* aSourceTopWindowContext)
     30    : mBrowserParent(aBrowserParent),
     31      mTransferableData(std::move(aTransferableData)),
     32      mRect(aRect),
     33      mPrincipal(aPrincipal),
     34      mPolicyContainer(aPolicyContainer),
     35      mCookieJarSettings(aCookieJarSettings),
     36      mSourceWindowContext(aSourceWindowContext),
     37      mSourceTopWindowContext(aSourceTopWindowContext) {}
     38 
     39 void RemoteDragStartData::AddInitialDnDDataTo(
     40    DataTransfer* aDataTransfer, nsIPrincipal** aPrincipal,
     41    nsIPolicyContainer** aPolicyContainer,
     42    nsICookieJarSettings** aCookieJarSettings) {
     43  NS_IF_ADDREF(*aPrincipal = mPrincipal);
     44  NS_IF_ADDREF(*aPolicyContainer = mPolicyContainer);
     45  NS_IF_ADDREF(*aCookieJarSettings = mCookieJarSettings);
     46 
     47  for (uint32_t i = 0; i < mTransferableData.Length(); ++i) {
     48    nsTArray<IPCTransferableDataItem>& itemArray = mTransferableData[i].items();
     49    for (auto& item : itemArray) {
     50      if (!nsContentUtils::IPCTransferableDataItemHasKnownFlavor(item)) {
     51        NS_WARNING(
     52            "Ignoring unknown flavor in "
     53            "RemoteDragStartData::AddInitialDnDDataTo");
     54        continue;
     55      }
     56 
     57      RefPtr<nsVariantCC> variant = new nsVariantCC();
     58      // Special case kFilePromiseMime so that we get the right
     59      // nsIFlavorDataProvider for it.
     60      if (item.flavor().EqualsLiteral(kFilePromiseMime)) {
     61        RefPtr<nsISupports> flavorDataProvider =
     62            new nsContentAreaDragDropDataProvider();
     63        variant->SetAsISupports(flavorDataProvider);
     64      } else {
     65        nsresult rv =
     66            nsContentUtils::IPCTransferableDataItemToVariant(item, variant);
     67        if (NS_FAILED(rv)) {
     68          continue;
     69        }
     70      }
     71 
     72      // We set aHidden to false, as we don't need to worry about hiding data
     73      // from content in the parent process where there is no content.
     74      aDataTransfer->SetDataWithPrincipalFromOtherProcess(
     75          NS_ConvertUTF8toUTF16(item.flavor()), variant, i, mPrincipal,
     76          /* aHidden = */ false);
     77    }
     78  }
     79 
     80  // Clear things that are no longer needed.
     81  mTransferableData.Clear();
     82  mPrincipal = nullptr;
     83 }
     84 
     85 }  // namespace mozilla::dom