Bug 396370 - Set RequestingPrincipal and ContentPolicy in BaseDragService. r=ckerschb
authorTom Schuster <evilpies@gmail.com>
Thu, 04 Oct 2018 10:31:32 +0000
changeset 439554 7790aa7225e2426134e2414b0be0bd79c7479fe9
parent 439553 ce1b5017a90e556d4f70a8a85fbce6470c912b31
child 439555 f49d04b37bb27fbe3cbbe497c29a6d64a3b5ed47
push id34778
push usernbeleuzu@mozilla.com
push dateThu, 04 Oct 2018 15:22:02 +0000
treeherdermozilla-central@01634947caab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs396370
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 396370 - Set RequestingPrincipal and ContentPolicy in BaseDragService. r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D7407
widget/cocoa/nsDragService.mm
widget/nsBaseDragService.cpp
widget/windows/nsDragService.cpp
--- a/widget/cocoa/nsDragService.mm
+++ b/widget/cocoa/nsDragService.mm
@@ -321,19 +321,16 @@ nsDragService::InvokeDragSessionImpl(nsI
 
     for (uint32_t j = 0; j < count; j++) {
       nsCOMPtr<nsITransferable> currentTransferable =
         do_QueryElementAt(aTransferableArray, j);
       if (!currentTransferable) {
         return NS_ERROR_FAILURE;
       }
 
-      // Assign a principal:
-      currentTransferable->SetRequestingPrincipal(mSourceNode->NodePrincipal());
-
       // Transform the transferable to an NSDictionary
       NSDictionary* pasteboardOutputDict =
         nsClipboard::PasteboardDictFromTransferable(currentTransferable);
       if (!pasteboardOutputDict) {
         return NS_ERROR_FAILURE;
       }
 
       // write everything out to the general pasteboard
--- a/widget/nsBaseDragService.cpp
+++ b/widget/nsBaseDragService.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsBaseDragService.h"
 #include "nsITransferable.h"
 
+#include "nsArrayUtils.h"
 #include "nsIServiceManager.h"
 #include "nsITransferable.h"
 #include "nsSize.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "nsCOMPtr.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIFrame.h"
@@ -253,16 +254,27 @@ nsBaseDragService::InvokeDragSession(nsI
   mEndDragPoint = LayoutDeviceIntPoint(0, 0);
 
   // When the mouse goes down, the selection code starts a mouse
   // capture. However, this gets in the way of determining drag
   // feedback for things like trees because the event coordinates
   // are in the wrong coord system, so turn off mouse capture.
   nsIPresShell::ClearMouseCapture(nullptr);
 
+  uint32_t length = 0;
+  mozilla::Unused << aTransferableArray->GetLength(&length);
+  for (uint32_t i = 0; i < length; ++i) {
+    nsCOMPtr<nsITransferable> trans = do_QueryElementAt(aTransferableArray, i);
+    if (trans) {
+      // Set the requestingPrincipal on the transferable.
+      trans->SetRequestingPrincipal(mSourceNode->NodePrincipal());
+      trans->SetContentPolicyType(mContentPolicyType);
+    }
+  }
+
   nsresult rv = InvokeDragSessionImpl(aTransferableArray,
                                       mRegion, aActionType);
 
   if (NS_FAILED(rv)) {
     // Set mDoingDrag so that EndDragSession cleans up and sends the dragend event
     // after the aborted drag.
     mDoingDrag = true;
     EndDragSession(true, 0);
--- a/widget/windows/nsDragService.cpp
+++ b/widget/windows/nsDragService.cpp
@@ -193,38 +193,32 @@ nsDragService::InvokeDragSessionImpl(nsI
     nsDataObjCollection * dataObjCollection = new nsDataObjCollection();
     if (!dataObjCollection)
       return NS_ERROR_OUT_OF_MEMORY;
     itemToDrag = dataObjCollection;
     for (uint32_t i=0; i<numItemsToDrag; ++i) {
       nsCOMPtr<nsITransferable> trans =
           do_QueryElementAt(anArrayTransferables, i);
       if (trans) {
-        // set the requestingPrincipal on the transferable
-        trans->SetRequestingPrincipal(mSourceNode->NodePrincipal());
-        trans->SetContentPolicyType(mContentPolicyType);
         RefPtr<IDataObject> dataObj;
         rv = nsClipboard::CreateNativeDataObject(trans,
                                                  getter_AddRefs(dataObj), uri);
         NS_ENSURE_SUCCESS(rv, rv);
         // Add the flavors to the collection object too
         rv = nsClipboard::SetupNativeDataObject(trans, dataObjCollection);
         NS_ENSURE_SUCCESS(rv, rv);
 
         dataObjCollection->AddDataObject(dataObj);
       }
     }
   } // if dragging multiple items
   else {
     nsCOMPtr<nsITransferable> trans =
         do_QueryElementAt(anArrayTransferables, 0);
     if (trans) {
-      // set the requestingPrincipal on the transferable
-      trans->SetRequestingPrincipal(mSourceNode->NodePrincipal());
-      trans->SetContentPolicyType(mContentPolicyType);
       rv = nsClipboard::CreateNativeDataObject(trans,
                                                getter_AddRefs(itemToDrag),
                                                uri);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   } // else dragging a single object
 
   // Create a drag image if support is available