Bug 1038756: Callsites creating a channel in /widget/windows/ (r=jimm)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Sun, 21 Sep 2014 09:41:56 -0700
changeset 229730 4afe0fb6dd86709d718315246545d9696e030393
parent 229729 20bb35fc802a6ad8aaf2ff24b0ca47edd979b84a
child 229731 1a1712c6b1423954e25c4f31997127b58c17259b
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1038756
milestone35.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 1038756: Callsites creating a channel in /widget/windows/ (r=jimm) * * * [mq]: windows.patch
widget/nsITransferable.idl
widget/windows/WinUtils.cpp
widget/windows/nsDataObj.cpp
widget/windows/nsDataObj.h
widget/windows/nsDragService.cpp
widget/windows/nsSound.cpp
widget/xpwidgets/nsTransferable.cpp
widget/xpwidgets/nsTransferable.h
--- a/widget/nsITransferable.idl
+++ b/widget/nsITransferable.idl
@@ -3,16 +3,17 @@
  * 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 "nsISupports.idl"
 #include "nsISupportsArray.idl"
 #include "nsIFormatConverter.idl"
 
+interface nsIDOMNode;
 
 %{ C++
 
 // these probably shouldn't live here, but in some central repository shared
 // by the entire app.
 #define kTextMime                   "text/plain"
 #define kUnicodeMime                "text/unicode"
 #define kMozTextInternal          "text/x-moz-text-internal"  // text data which isn't suppoed to be parsed by other apps.
@@ -76,17 +77,17 @@ interface nsIFlavorDataProvider : nsISup
     * @param  aFlavor (in parameter) the flavor of data to retrieve
     * @param  aData the data. Some variant of class in nsISupportsPrimitives.idl
     * @param  aDataLen the length of the data
     */
   void getFlavorData(in nsITransferable aTransferable, in string aFlavor, out nsISupports aData, out unsigned long aDataLen);
 };
 
 
-[scriptable, uuid(5a611a60-e5b5-11e1-aff1-0800200c9a66)]
+[scriptable, uuid(97e0c418-1c1e-4106-bad1-9fcb11dff2fe)]
 interface nsITransferable : nsISupports
 {
   const long kFlavorHasDataProvider = 0;
 
   /**
    * Initializes a transferable object.  This should be called on all
    * transferable objects.  Failure to do so will result in fatal assertions in
    * debug builds.
@@ -189,10 +190,17 @@ interface nsITransferable : nsISupports
 
   /**
    * Use of the SetIsPrivateData() method generated by isPrivateData attribute should 
    * be avoided as much as possible because the value set may not reflect the status 
    * of the context in which the transferable was created.
    */
   [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.
+   */
+  [noscript] attribute nsIDOMNode requestingNode;
+
 };
 
--- a/widget/windows/WinUtils.cpp
+++ b/widget/windows/WinUtils.cpp
@@ -12,16 +12,18 @@
 #include "nsWindowDefs.h"
 #include "KeyboardLayout.h"
 #include "nsIDOMMouseEvent.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/DataSurfaceHelpers.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/WindowsVersion.h"
+#include "nsIContentPolicy.h"
+#include "nsContentUtils.h"
 
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #endif // MOZ_LOGGING
 #include "prlog.h"
 
 #include "nsString.h"
 #include "nsDirectoryServiceUtils.h"
@@ -54,18 +56,18 @@
 #ifdef PR_LOGGING
 PRLogModuleInfo* gWindowsLog = nullptr;
 #endif
 
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace widget {
-
-#define ENTRY(_msg) { #_msg, _msg }
+
+#define ENTRY(_msg) { #_msg, _msg }
 EventMsgInfo gAllEvents[] = {
   ENTRY(WM_NULL),
   ENTRY(WM_CREATE),
   ENTRY(WM_DESTROY),
   ENTRY(WM_MOVE),
   ENTRY(WM_SIZE),
   ENTRY(WM_ACTIVATE),
   ENTRY(WM_SETFOCUS),
@@ -1054,17 +1056,22 @@ nsresult AsyncFaviconDataReady::OnFavico
 
   nsCOMPtr<nsIURI> mozIconURI;
   rv = NS_NewURI(getter_AddRefs(mozIconURI), "moz-icon://.html?size=32");
   if (NS_FAILED(rv)) {
     return rv;
   }
  
   nsCOMPtr<nsIChannel> channel;
-  rv = NS_NewChannel(getter_AddRefs(channel), mozIconURI);
+  rv = NS_NewChannel(getter_AddRefs(channel),
+                     mozIconURI,
+                     nsContentUtils::GetSystemPrincipal(),
+                     nsILoadInfo::SEC_NORMAL,
+                     nsIContentPolicy::TYPE_IMAGE);
+
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDownloadObserver> downloadObserver = new myDownloadObserver;
   nsCOMPtr<nsIStreamListener> listener;
   rv = NS_NewDownloader(getter_AddRefs(listener), downloadObserver, icoFile);
   NS_ENSURE_SUCCESS(rv, rv);
 
   channel->AsyncOpen(listener, nullptr);
--- a/widget/windows/nsDataObj.cpp
+++ b/widget/windows/nsDataObj.cpp
@@ -24,16 +24,19 @@
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsXPCOMStrings.h"
 #include "nscore.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsITimer.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Preferences.h"
+#include "nsIContentPolicy.h"
+#include "nsContentUtils.h"
+#include "nsINode.h"
 
 #include "WinUtils.h"
 #include "mozilla/LazyIdleThread.h"
 #include "mozilla/WindowsVersion.h"
 #include <algorithm>
 
 
 using namespace mozilla;
@@ -53,22 +56,34 @@ nsDataObj::CStream::CStream() :
 
 //-----------------------------------------------------------------------------
 nsDataObj::CStream::~CStream()
 {
 }
 
 //-----------------------------------------------------------------------------
 // helper - initializes the stream
-nsresult nsDataObj::CStream::Init(nsIURI *pSourceURI)
+nsresult nsDataObj::CStream::Init(nsIURI *pSourceURI,
+                                  nsINode* aRequestingNode)
 {
+  // we can not create a channel without a requestingNode
+  if (!aRequestingNode) {
+    return NS_ERROR_FAILURE;
+  }
   nsresult rv;
-  rv = NS_NewChannel(getter_AddRefs(mChannel), pSourceURI,
-                     nullptr, nullptr, nullptr,
+  rv = NS_NewChannel(getter_AddRefs(mChannel),
+                     pSourceURI,
+                     aRequestingNode,
+                     nsILoadInfo::SEC_NORMAL,
+                     nsIContentPolicy::TYPE_OTHER,
+                     nullptr,   // aChannelPolicy
+                     nullptr,   // loadGroup
+                     nullptr,   // aCallbacks
                      nsIRequest::LOAD_FROM_CACHE);
+
   NS_ENSURE_SUCCESS(rv, rv);
   rv = mChannel->AsyncOpen(this, nullptr);
   NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 // IUnknown's QueryInterface, nsISupport's AddRef and Release are shared by
@@ -319,17 +334,23 @@ HRESULT nsDataObj::CreateStream(IStream 
   if(FAILED(res))
     return res;
 
   nsDataObj::CStream *pStream = new nsDataObj::CStream();
   NS_ENSURE_TRUE(pStream, E_OUTOFMEMORY);
 
   pStream->AddRef();
 
-  rv = pStream->Init(sourceURI);
+  // query the requestingNode from the transferable and add it to the new channel
+  nsCOMPtr<nsIDOMNode> requestingDomNode;
+  mTransferable->GetRequestingNode(getter_AddRefs(requestingDomNode));
+  nsCOMPtr<nsINode> requestingNode = do_QueryInterface(requestingDomNode);
+  MOZ_ASSERT(requestingNode, "can not create channel without a node");
+
+  rv = pStream->Init(sourceURI, requestingNode);
   if (NS_FAILED(rv))
   {
     pStream->Release();
     return E_FAIL;
   }
   *outStream = pStream;
 
   return S_OK;
--- a/widget/windows/nsDataObj.h
+++ b/widget/windows/nsDataObj.h
@@ -15,16 +15,17 @@
 #include "nsIURI.h"
 #include "nsIInputStream.h"
 #include "nsIStreamListener.h"
 #include "nsIChannel.h"
 #include "nsCOMArray.h"
 #include "nsITimer.h"
 
 class nsIThread;
+class nsINode;
 
 // The SDK shipping with VC11 has renamed IAsyncOperation to
 // IDataObjectAsyncCapability.  We try to detect this, and rename this in our
 // code too to make sure that we pick the correct name when building.
 #ifdef __IDataObjectAsyncCapability_INTERFACE_DEFINED__
 #define IAsyncOperation IDataObjectAsyncCapability
 #define IID_IAsyncOperation IID_IDataObjectAsyncCapability
 #else
@@ -243,17 +244,17 @@ protected:
       uint32_t mStreamRead;
 
     protected:
       virtual ~CStream();
       nsresult WaitForCompletion();
 
     public:
       CStream();
-      nsresult Init(nsIURI *pSourceURI);
+      nsresult Init(nsIURI *pSourceURI, nsINode* aRequestingNode);
 
       NS_DECL_ISUPPORTS
       NS_DECL_NSIREQUESTOBSERVER
       NS_DECL_NSISTREAMLISTENER
 
       // IUnknown
       STDMETHOD(QueryInterface)(REFIID refiid, void** ppvResult);
 
--- a/widget/windows/nsDragService.cpp
+++ b/widget/windows/nsDragService.cpp
@@ -209,16 +209,18 @@ nsDragService::InvokeDragSession(nsIDOMN
     if (!dataObjCollection)
       return NS_ERROR_OUT_OF_MEMORY;
     itemToDrag = dataObjCollection;
     for (uint32_t i=0; i<numItemsToDrag; ++i) {
       nsCOMPtr<nsISupports> supports;
       anArrayTransferables->GetElementAt(i, getter_AddRefs(supports));
       nsCOMPtr<nsITransferable> trans(do_QueryInterface(supports));
       if (trans) {
+        // set the requestingNode on the transferable
+        trans->SetRequestingNode(aDOMNode);
         nsRefPtr<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);
 
@@ -226,16 +228,18 @@ nsDragService::InvokeDragSession(nsIDOMN
       }
     }
   } // if dragging multiple items
   else {
     nsCOMPtr<nsISupports> supports;
     anArrayTransferables->GetElementAt(0, getter_AddRefs(supports));
     nsCOMPtr<nsITransferable> trans(do_QueryInterface(supports));
     if (trans) {
+      // set the requestingNode on the transferable
+      trans->SetRequestingNode(aDOMNode);
       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
--- a/widget/windows/nsSound.cpp
+++ b/widget/windows/nsSound.cpp
@@ -11,16 +11,17 @@
 #include <windows.h>
 
 // mmsystem.h is needed to build with WIN32_LEAN_AND_MEAN
 #include <mmsystem.h>
 
 #include "nsSound.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
+#include "nsContentUtils.h"
 #include "nsCRT.h"
 
 #include "prlog.h"
 #include "prtime.h"
 #include "prprf.h"
 #include "prmem.h"
 
 #include "nsNativeCharsetUtils.h"
@@ -204,18 +205,22 @@ NS_IMETHODIMP nsSound::Play(nsIURL *aURL
 #ifdef DEBUG_SOUND
   char *url;
   aURL->GetSpec(&url);
   PR_LOG(gWin32SoundLog, PR_LOG_ALWAYS,
          ("%s\n", url));
 #endif
 
   nsCOMPtr<nsIStreamLoader> loader;
-  rv = NS_NewStreamLoader(getter_AddRefs(loader), aURL, this);
-
+  rv = NS_NewStreamLoader(getter_AddRefs(loader),
+                          aURL,
+                          this, // aObserver
+                          nsContentUtils::GetSystemPrincipal(),
+                          nsILoadInfo::SEC_NORMAL,
+                          nsIContentPolicy::TYPE_OTHER);
   return rv;
 }
 
 
 NS_IMETHODIMP nsSound::Init()
 {
   // This call halts a sound if it was still playing.
   // We have to use the sound library for something to make sure
--- a/widget/xpwidgets/nsTransferable.cpp
+++ b/widget/xpwidgets/nsTransferable.cpp
@@ -621,8 +621,22 @@ nsTransferable::SetIsPrivateData(bool aI
 {
   MOZ_ASSERT(mInitialized);
 
   mPrivateData = aIsPrivateData;
 
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsTransferable::GetRequestingNode(nsIDOMNode** outRequestingNode)
+{
+  nsCOMPtr<nsIDOMNode> node = do_QueryReferent(mRequestingNode);
+  node.forget(outRequestingNode);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsTransferable::SetRequestingNode(nsIDOMNode* aRequestingNode)
+{
+  mRequestingNode = do_GetWeakReference(aRequestingNode);
+  return NS_OK;
+}
--- a/widget/xpwidgets/nsTransferable.h
+++ b/widget/xpwidgets/nsTransferable.h
@@ -6,16 +6,17 @@
 #ifndef nsTransferable_h__
 #define nsTransferable_h__
 
 #include "nsIFormatConverter.h"
 #include "nsITransferable.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsTArray.h"
+#include "nsWeakPtr.h"
 
 class nsString;
 class nsDataObj;
 
 //
 // DataStruct
 //
 // Holds a flavor (a mime type) that describes the data and the associated data.
@@ -68,15 +69,16 @@ protected:
   virtual ~nsTransferable();
 
     // get flavors w/out converter
   nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList);
  
   nsTArray<DataStruct> mDataArray;
   nsCOMPtr<nsIFormatConverter> mFormatConv;
   bool mPrivateData;
+  nsWeakPtr mRequestingNode;
 #if DEBUG
   bool mInitialized;
 #endif
 
 };
 
 #endif // nsTransferable_h__