Bug 1404367: Pass LoadInfo of channel to nsViewSourceChannel::Init. r=Gijs
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Fri, 16 Aug 2019 11:35:57 +0000
changeset 488515 61a0b22d978af8c1c29a4ac84c023727d0621d66
parent 488514 b00c70075119601d370255e5962eb62429d2cf95
child 488516 9e7ec636635a4ef562b761e8ec7c1b41899a3ed4
push id36446
push usermalexandru@mozilla.com
push dateFri, 16 Aug 2019 21:53:14 +0000
treeherdermozilla-central@1d4db40e38dd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1404367
milestone70.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 1404367: Pass LoadInfo of channel to nsViewSourceChannel::Init. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D42296
netwerk/protocol/viewsource/nsViewSourceChannel.cpp
netwerk/protocol/viewsource/nsViewSourceChannel.h
netwerk/protocol/viewsource/nsViewSourceHandler.cpp
--- a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp
+++ b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp
@@ -36,17 +36,17 @@ NS_INTERFACE_MAP_BEGIN(nsViewSourceChann
                                      mApplicationCacheChannel)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIUploadChannel, mUploadChannel)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIFormPOSTActionChannel, mPostChannel)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIRequest, nsIViewSourceChannel)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIChannel, nsIViewSourceChannel)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIViewSourceChannel)
 NS_INTERFACE_MAP_END
 
-nsresult nsViewSourceChannel::Init(nsIURI* uri) {
+nsresult nsViewSourceChannel::Init(nsIURI* uri, nsILoadInfo* aLoadInfo) {
   mOriginalURI = uri;
 
   nsAutoCString path;
   nsresult rv = uri->GetPathQueryRef(path);
   if (NS_FAILED(rv)) return rv;
 
   nsCOMPtr<nsIIOService> pService(do_GetIOService(&rv));
   if (NS_FAILED(rv)) return rv;
@@ -56,33 +56,22 @@ nsresult nsViewSourceChannel::Init(nsIUR
   if (NS_FAILED(rv)) return rv;
 
   // prevent viewing source of javascript URIs (see bug 204779)
   if (scheme.EqualsLiteral("javascript")) {
     NS_WARNING("blocking view-source:javascript:");
     return NS_ERROR_INVALID_ARG;
   }
 
-  // This function is called from within nsViewSourceHandler::NewChannel
-  // and sets the right loadInfo right after returning from this function.
-  // Until then we follow the principal of least privilege and use
-  // nullPrincipal as the loadingPrincipal and the least permissive
-  // securityflag.
-  nsCOMPtr<nsIPrincipal> nullPrincipal =
-      mozilla::NullPrincipal::CreateWithoutOriginAttributes();
+  nsCOMPtr<nsIURI> newChannelURI;
+  rv = pService->NewURI(path, nullptr, nullptr, getter_AddRefs(newChannelURI));
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = pService->NewChannel(
-      path,
-      nullptr,  // aOriginCharset
-      nullptr,  // aCharSet
-      nullptr,  // aLoadingNode
-      nullPrincipal,
-      nullptr,  // aTriggeringPrincipal
-      nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
-      nsIContentPolicy::TYPE_OTHER, getter_AddRefs(mChannel));
+  rv = pService->NewChannelFromURIWithLoadInfo(newChannelURI, aLoadInfo,
+                                               getter_AddRefs(mChannel));
   NS_ENSURE_SUCCESS(rv, rv);
 
   mIsSrcdocChannel = false;
 
   mChannel->SetOriginalURI(mOriginalURI);
   mHttpChannel = do_QueryInterface(mChannel);
   mHttpChannelInternal = do_QueryInterface(mChannel);
   mCachingChannel = do_QueryInterface(mChannel);
--- a/netwerk/protocol/viewsource/nsViewSourceChannel.h
+++ b/netwerk/protocol/viewsource/nsViewSourceChannel.h
@@ -41,17 +41,17 @@ class nsViewSourceChannel final : public
   NS_FORWARD_SAFE_NSIUPLOADCHANNEL(mUploadChannel)
   NS_FORWARD_SAFE_NSIFORMPOSTACTIONCHANNEL(mPostChannel)
   NS_FORWARD_SAFE_NSIHTTPCHANNELINTERNAL(mHttpChannelInternal)
 
   // nsViewSourceChannel methods:
   nsViewSourceChannel()
       : mIsDocument(false), mOpened(false), mIsSrcdocChannel(false) {}
 
-  MOZ_MUST_USE nsresult Init(nsIURI* uri);
+  MOZ_MUST_USE nsresult Init(nsIURI* uri, nsILoadInfo* aLoadInfo);
 
   MOZ_MUST_USE nsresult InitSrcdoc(nsIURI* aURI, nsIURI* aBaseURI,
                                    const nsAString& aSrcdoc,
                                    nsILoadInfo* aLoadInfo);
 
   // Updates or sets the result principal URI of the underlying channel's
   // loadinfo to be prefixed with the "view-source:" schema as:
   //
--- a/netwerk/protocol/viewsource/nsViewSourceHandler.cpp
+++ b/netwerk/protocol/viewsource/nsViewSourceHandler.cpp
@@ -103,23 +103,17 @@ nsresult nsViewSourceHandler::CreateNewU
 }
 
 NS_IMETHODIMP
 nsViewSourceHandler::NewChannel(nsIURI* uri, nsILoadInfo* aLoadInfo,
                                 nsIChannel** result) {
   NS_ENSURE_ARG_POINTER(uri);
   RefPtr<nsViewSourceChannel> channel = new nsViewSourceChannel();
 
-  nsresult rv = channel->Init(uri);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  // set the loadInfo on the new channel
-  rv = channel->SetLoadInfo(aLoadInfo);
+  nsresult rv = channel->Init(uri, aLoadInfo);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   *result = channel.forget().downcast<nsIViewSourceChannel>().take();
   return NS_OK;
 }