diff --git a/widget/gtk/nsDragService.cpp b/widget/gtk/nsDragService.cpp index 9e59f1842555..a85091c3f48f 100644 --- a/widget/gtk/nsDragService.cpp +++ b/widget/gtk/nsDragService.cpp @@ -303,7 +303,9 @@ NS_IMETHODIMP nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode, nsISupportsArray * aArrayTransferables, nsIScriptableRegion * aRegion, - uint32_t aActionType) + uint32_t aActionType, + nsContentPolicyType aContentPolicyType = + nsIContentPolicy::TYPE_OTHER) { MOZ_LOG(sDragLm, LogLevel::Debug, ("nsDragService::InvokeDragSession")); @@ -315,7 +317,8 @@ nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode, return NS_ERROR_NOT_AVAILABLE; return nsBaseDragService::InvokeDragSession(aDOMNode, aArrayTransferables, - aRegion, aActionType); + aRegion, aActionType, + aContentPolicyType); } // nsBaseDragService diff --git a/widget/gtk/nsDragService.h b/widget/gtk/nsDragService.h index 04a9c975cd00..000de15921c3 100644 --- a/widget/gtk/nsDragService.h +++ b/widget/gtk/nsDragService.h @@ -66,7 +66,8 @@ public: NS_IMETHOD InvokeDragSession (nsIDOMNode *aDOMNode, nsISupportsArray * anArrayTransferables, nsIScriptableRegion * aRegion, - uint32_t aActionType) override; + uint32_t aActionType, + nsContentPolicyType aContentPolicyType) override; NS_IMETHOD StartDragSession() override; NS_IMETHOD EndDragSession(bool aDoneDrag) override; diff --git a/widget/nsBaseDragService.cpp b/widget/nsBaseDragService.cpp index a1ba12f9313b..f225eb27266b 100644 --- a/widget/nsBaseDragService.cpp +++ b/widget/nsBaseDragService.cpp @@ -58,6 +58,7 @@ nsBaseDragService::nsBaseDragService() mDragAction(DRAGDROP_ACTION_NONE), mDragActionFromChildProcess(DRAGDROP_ACTION_UNINITIALIZED), mTargetSize(0,0), mScreenX(-1), mScreenY(-1), mSuppressLevel(0), + mContentPolicyType(nsIContentPolicy::TYPE_OTHER), mInputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE) { } @@ -209,7 +210,9 @@ NS_IMETHODIMP nsBaseDragService::InvokeDragSession(nsIDOMNode *aDOMNode, nsISupportsArray* aTransferableArray, nsIScriptableRegion* aDragRgn, - uint32_t aActionType) + uint32_t aActionType, + nsContentPolicyType aContentPolicyType = + nsIContentPolicy::TYPE_OTHER) { PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER); @@ -219,6 +222,7 @@ nsBaseDragService::InvokeDragSession(nsIDOMNode *aDOMNode, // stash the document of the dom node aDOMNode->GetOwnerDocument(getter_AddRefs(mSourceDocument)); mSourceNode = aDOMNode; + mContentPolicyType = aContentPolicyType; mEndDragPoint = LayoutDeviceIntPoint(0, 0); // When the mouse goes down, the selection code starts a mouse @@ -264,7 +268,8 @@ nsBaseDragService::InvokeDragSessionWithImage(nsIDOMNode* aDOMNode, aDragEvent->GetMozInputSource(&mInputSource); nsresult rv = InvokeDragSession(aDOMNode, aTransferableArray, - aRegion, aActionType); + aRegion, aActionType, + nsIContentPolicy::TYPE_INTERNAL_IMAGE); if (NS_FAILED(rv)) { mImage = nullptr; @@ -304,7 +309,8 @@ nsBaseDragService::InvokeDragSessionWithSelection(nsISelection* aSelection, aSelection->GetFocusNode(getter_AddRefs(node)); nsresult rv = InvokeDragSession(node, aTransferableArray, - nullptr, aActionType); + nullptr, aActionType, + nsIContentPolicy::TYPE_OTHER); if (NS_FAILED(rv)) { mHasImage = false; diff --git a/widget/nsBaseDragService.h b/widget/nsBaseDragService.h index c351d581e6c6..2326b022ce46 100644 --- a/widget/nsBaseDragService.h +++ b/widget/nsBaseDragService.h @@ -156,6 +156,8 @@ protected: nsCOMPtr mSourceNode; nsCOMPtr mSourceDocument; // the document at the drag source. will be null // if it came from outside the app. + nsContentPolicyType mContentPolicyType; // the contentpolicy type passed to the channel + // when initiating the drag session nsCOMPtr mDataTransfer; // used to determine the image to appear on the cursor while dragging diff --git a/widget/nsIDragService.idl b/widget/nsIDragService.idl index d9f0ac153c6c..00ddcdf64aa3 100644 --- a/widget/nsIDragService.idl +++ b/widget/nsIDragService.idl @@ -8,7 +8,7 @@ #include "nsISupportsArray.idl" #include "nsIDragSession.idl" #include "nsIScriptableRegion.idl" - +#include "nsIContentPolicyBase.idl" interface nsIDOMNode; interface nsIDOMDragEvent; @@ -44,9 +44,15 @@ interface nsIDragService : nsISupports * @param aRegion - a region containing rectangles for cursor feedback, * in window coordinates. * @param aActionType - specified which of copy/move/link are allowed + * @param aContentPolicyType - the contentPolicyType that will be + * passed to the loadInfo when creating a new channel + * (defaults to TYPE_OTHER) */ - void invokeDragSession ( in nsIDOMNode aDOMNode, in nsISupportsArray aTransferables, - in nsIScriptableRegion aRegion, in unsigned long aActionType ); + void invokeDragSession (in nsIDOMNode aDOMNode, + in nsISupportsArray aTransferables, + in nsIScriptableRegion aRegion, + in unsigned long aActionType, + [optional] in nsContentPolicyType aContentPolicyType); /** * Starts a modal drag session using an image. The first four arguments are diff --git a/widget/nsITransferable.idl b/widget/nsITransferable.idl index b7363fd45dbe..900d7d9ad32c 100644 --- a/widget/nsITransferable.idl +++ b/widget/nsITransferable.idl @@ -7,6 +7,7 @@ #include "nsISupports.idl" #include "nsISupportsArray.idl" #include "nsIFormatConverter.idl" +#include "nsIContentPolicyBase.idl" interface nsIDOMNode; @@ -199,11 +200,13 @@ interface nsITransferable : nsISupports [noscript] attribute boolean isPrivateData; /** - * The source dom node this transferable was created from. - * Note, currently only in use on Windows for network principal - * information in drag operations. + * The source dom node this transferable was created from and + * the contentPolicyType for the transferable. + * Note, currently only in use on Windows for network principal and + * contentPolicyType information in drag operations. */ [noscript] attribute nsIDOMNode requestingNode; + [noscript] attribute nsContentPolicyType contentPolicyType; }; diff --git a/widget/nsTransferable.cpp b/widget/nsTransferable.cpp index 0540dac06b2c..28d54240e33b 100644 --- a/widget/nsTransferable.cpp +++ b/widget/nsTransferable.cpp @@ -18,6 +18,7 @@ Notes to self: #include "nsReadableUtils.h" #include "nsTArray.h" #include "nsIFormatConverter.h" +#include "nsIContentPolicy.h" #include "nsIComponentManager.h" #include "nsCOMPtr.h" #include "nsXPCOM.h" @@ -218,6 +219,7 @@ DataStruct::ReadCache(nsISupports** aData, uint32_t* aDataLen) //------------------------------------------------------------------------- nsTransferable::nsTransferable() : mPrivateData(false) + , mContentPolicyType(nsIContentPolicy::TYPE_OTHER) #ifdef DEBUG , mInitialized(false) #endif @@ -643,3 +645,18 @@ nsTransferable::SetRequestingNode(nsIDOMNode* aRequestingNode) mRequestingNode = do_GetWeakReference(aRequestingNode); return NS_OK; } + +NS_IMETHODIMP +nsTransferable::GetContentPolicyType(nsContentPolicyType* outContentPolicyType) +{ + NS_ENSURE_ARG_POINTER(outContentPolicyType); + *outContentPolicyType = mContentPolicyType; + return NS_OK; +} + +NS_IMETHODIMP +nsTransferable::SetContentPolicyType(nsContentPolicyType aContentPolicyType) +{ + mContentPolicyType = aContentPolicyType; + return NS_OK; +} diff --git a/widget/nsTransferable.h b/widget/nsTransferable.h index 135f0411d3e0..1d3406782fb1 100644 --- a/widget/nsTransferable.h +++ b/widget/nsTransferable.h @@ -6,6 +6,7 @@ #ifndef nsTransferable_h__ #define nsTransferable_h__ +#include "nsIContentPolicyBase.h" #include "nsIFormatConverter.h" #include "nsITransferable.h" #include "nsCOMPtr.h" @@ -74,6 +75,7 @@ protected: nsCOMPtr mFormatConv; bool mPrivateData; nsWeakPtr mRequestingNode; + nsContentPolicyType mContentPolicyType; #if DEBUG bool mInitialized; #endif diff --git a/widget/windows/nsDataObj.cpp b/widget/windows/nsDataObj.cpp index 8f9027b27497..a8750d615c98 100644 --- a/widget/windows/nsDataObj.cpp +++ b/widget/windows/nsDataObj.cpp @@ -64,6 +64,7 @@ nsDataObj::CStream::~CStream() //----------------------------------------------------------------------------- // helper - initializes the stream nsresult nsDataObj::CStream::Init(nsIURI *pSourceURI, + uint32_t aContentPolicyType, nsINode* aRequestingNode) { // we can not create a channel without a requestingNode @@ -74,14 +75,14 @@ nsresult nsDataObj::CStream::Init(nsIURI *pSourceURI, rv = NS_NewChannel(getter_AddRefs(mChannel), pSourceURI, aRequestingNode, - nsILoadInfo::SEC_NORMAL, - nsIContentPolicy::TYPE_OTHER, + nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS, + aContentPolicyType, nullptr, // loadGroup nullptr, // aCallbacks nsIRequest::LOAD_FROM_CACHE); NS_ENSURE_SUCCESS(rv, rv); - rv = mChannel->AsyncOpen(this, nullptr); + rv = mChannel->AsyncOpen2(this); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } @@ -345,8 +346,10 @@ HRESULT nsDataObj::CreateStream(IStream **outStream) mTransferable->GetRequestingNode(getter_AddRefs(requestingDomNode)); nsCOMPtr requestingNode = do_QueryInterface(requestingDomNode); MOZ_ASSERT(requestingNode, "can not create channel without a node"); - - rv = pStream->Init(sourceURI, requestingNode); + // default transferable content policy is nsIContentPolicy::TYPE_OTHER + uint32_t contentPolicyType = nsIContentPolicy::TYPE_OTHER; + mTransferable->GetContentPolicyType(&contentPolicyType); + rv = pStream->Init(sourceURI, contentPolicyType, requestingNode); if (NS_FAILED(rv)) { pStream->Release(); diff --git a/widget/windows/nsDataObj.h b/widget/windows/nsDataObj.h index 9f842bbfe4ab..90a4de6e7fc2 100644 --- a/widget/windows/nsDataObj.h +++ b/widget/windows/nsDataObj.h @@ -249,7 +249,9 @@ protected: public: CStream(); - nsresult Init(nsIURI *pSourceURI, nsINode* aRequestingNode); + nsresult Init(nsIURI *pSourceURI, + uint32_t aContentPolicyType, + nsINode* aRequestingNode); NS_DECL_ISUPPORTS NS_DECL_NSIREQUESTOBSERVER diff --git a/widget/windows/nsDragService.cpp b/widget/windows/nsDragService.cpp index d26b7c66d3a9..849dd3847353 100644 --- a/widget/windows/nsDragService.cpp +++ b/widget/windows/nsDragService.cpp @@ -207,6 +207,7 @@ nsDragService::InvokeDragSessionImpl(nsISupportsArray* anArrayTransferables, if (trans) { // set the requestingNode on the transferable trans->SetRequestingNode(mSourceNode); + trans->SetContentPolicyType(mContentPolicyType); RefPtr dataObj; rv = nsClipboard::CreateNativeDataObject(trans, getter_AddRefs(dataObj), uri); @@ -226,6 +227,7 @@ nsDragService::InvokeDragSessionImpl(nsISupportsArray* anArrayTransferables, if (trans) { // set the requestingNode on the transferable trans->SetRequestingNode(mSourceNode); + trans->SetContentPolicyType(mContentPolicyType); rv = nsClipboard::CreateNativeDataObject(trans, getter_AddRefs(itemToDrag), uri);