LCOV - code coverage report
Current view: top level - netwerk/protocol/http - InterceptedChannel.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 291 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 37 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset:  -*- */
       2             : /* vim:set expandtab ts=2 sw=2 sts=2 cin: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "HttpLog.h"
       8             : 
       9             : #include "InterceptedChannel.h"
      10             : #include "nsInputStreamPump.h"
      11             : #include "nsIPipe.h"
      12             : #include "nsIStreamListener.h"
      13             : #include "nsITimedChannel.h"
      14             : #include "nsHttpChannel.h"
      15             : #include "HttpChannelChild.h"
      16             : #include "nsHttpResponseHead.h"
      17             : #include "nsNetUtil.h"
      18             : #include "mozilla/ConsoleReportCollector.h"
      19             : #include "mozilla/dom/ChannelInfo.h"
      20             : #include "nsIChannelEventSink.h"
      21             : 
      22             : namespace mozilla {
      23             : namespace net {
      24             : 
      25             : extern nsresult
      26             : DoUpdateExpirationTime(nsHttpChannel* aSelf,
      27             :                        nsICacheEntry* aCacheEntry,
      28             :                        nsHttpResponseHead* aResponseHead,
      29             :                        uint32_t& aExpirationTime);
      30             : extern nsresult
      31             : DoAddCacheEntryHeaders(nsHttpChannel *self,
      32             :                        nsICacheEntry *entry,
      33             :                        nsHttpRequestHead *requestHead,
      34             :                        nsHttpResponseHead *responseHead,
      35             :                        nsISupports *securityInfo);
      36             : 
      37           0 : NS_IMPL_ISUPPORTS(InterceptedChannelBase, nsIInterceptedChannel)
      38             : 
      39           0 : InterceptedChannelBase::InterceptedChannelBase(nsINetworkInterceptController* aController)
      40             :   : mController(aController)
      41           0 :   , mReportCollector(new ConsoleReportCollector())
      42             :   , mClosed(false)
      43           0 :   , mSynthesizedOrReset(Invalid)
      44             : {
      45           0 : }
      46             : 
      47           0 : InterceptedChannelBase::~InterceptedChannelBase()
      48             : {
      49           0 : }
      50             : 
      51             : NS_IMETHODIMP
      52           0 : InterceptedChannelBase::GetResponseBody(nsIOutputStream** aStream)
      53             : {
      54           0 :   NS_IF_ADDREF(*aStream = mResponseBody);
      55           0 :   return NS_OK;
      56             : }
      57             : 
      58             : void
      59           0 : InterceptedChannelBase::EnsureSynthesizedResponse()
      60             : {
      61           0 :   if (mSynthesizedResponseHead.isNothing()) {
      62           0 :     mSynthesizedResponseHead.emplace(new nsHttpResponseHead());
      63             :   }
      64           0 : }
      65             : 
      66             : void
      67           0 : InterceptedChannelBase::DoNotifyController()
      68             : {
      69           0 :     nsresult rv = NS_OK;
      70             : 
      71           0 :     if (NS_WARN_IF(!mController)) {
      72           0 :       rv = ResetInterception();
      73           0 :       NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
      74             :                            "Failed to resume intercepted network request");
      75           0 :       return;
      76             :     }
      77             : 
      78           0 :     rv = mController->ChannelIntercepted(this);
      79           0 :     if (NS_WARN_IF(NS_FAILED(rv))) {
      80           0 :       rv = ResetInterception();
      81           0 :       NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
      82             :                            "Failed to resume intercepted network request");
      83             :     }
      84           0 :     mController = nullptr;
      85             : }
      86             : 
      87             : nsresult
      88           0 : InterceptedChannelBase::DoSynthesizeStatus(uint16_t aStatus, const nsACString& aReason)
      89             : {
      90           0 :     EnsureSynthesizedResponse();
      91             : 
      92             :     // Always assume HTTP 1.1 for synthesized responses.
      93           0 :     nsAutoCString statusLine;
      94           0 :     statusLine.AppendLiteral("HTTP/1.1 ");
      95           0 :     statusLine.AppendInt(aStatus);
      96           0 :     statusLine.AppendLiteral(" ");
      97           0 :     statusLine.Append(aReason);
      98             : 
      99           0 :     (*mSynthesizedResponseHead)->ParseStatusLine(statusLine);
     100           0 :     return NS_OK;
     101             : }
     102             : 
     103             : nsresult
     104           0 : InterceptedChannelBase::DoSynthesizeHeader(const nsACString& aName, const nsACString& aValue)
     105             : {
     106           0 :     EnsureSynthesizedResponse();
     107             : 
     108           0 :     nsAutoCString header = aName + NS_LITERAL_CSTRING(": ") + aValue;
     109             :     // Overwrite any existing header.
     110           0 :     nsresult rv = (*mSynthesizedResponseHead)->ParseHeaderLine(header);
     111           0 :     NS_ENSURE_SUCCESS(rv, rv);
     112           0 :     return NS_OK;
     113             : }
     114             : 
     115             : NS_IMETHODIMP
     116           0 : InterceptedChannelBase::GetConsoleReportCollector(nsIConsoleReportCollector** aCollectorOut)
     117             : {
     118           0 :   MOZ_ASSERT(aCollectorOut);
     119           0 :   nsCOMPtr<nsIConsoleReportCollector> ref = mReportCollector;
     120           0 :   ref.forget(aCollectorOut);
     121           0 :   return NS_OK;
     122             : }
     123             : 
     124             : NS_IMETHODIMP
     125           0 : InterceptedChannelBase::SetReleaseHandle(nsISupports* aHandle)
     126             : {
     127           0 :   MOZ_ASSERT(NS_IsMainThread());
     128           0 :   MOZ_ASSERT(!mReleaseHandle);
     129           0 :   MOZ_ASSERT(aHandle);
     130             : 
     131             :   // We need to keep it and mChannel alive until destructor clear it up.
     132           0 :   mReleaseHandle = aHandle;
     133           0 :   return NS_OK;
     134             : }
     135             : 
     136             : NS_IMETHODIMP
     137           0 : InterceptedChannelBase::SaveTimeStamps()
     138             : {
     139           0 :   MOZ_ASSERT(NS_IsMainThread());
     140             : 
     141           0 :   nsCOMPtr<nsIChannel> underlyingChannel;
     142           0 :   nsresult rv = GetChannel(getter_AddRefs(underlyingChannel));
     143           0 :   MOZ_ASSERT(NS_SUCCEEDED(rv));
     144             : 
     145             :   nsCOMPtr<nsITimedChannel> timedChannel =
     146           0 :     do_QueryInterface(underlyingChannel);
     147           0 :   MOZ_ASSERT(timedChannel);
     148             : 
     149           0 :   rv = timedChannel->SetLaunchServiceWorkerStart(mLaunchServiceWorkerStart);
     150           0 :   MOZ_ASSERT(NS_SUCCEEDED(rv));
     151             : 
     152           0 :   rv = timedChannel->SetLaunchServiceWorkerEnd(mLaunchServiceWorkerEnd);
     153           0 :   MOZ_ASSERT(NS_SUCCEEDED(rv));
     154             : 
     155           0 :   rv = timedChannel->SetDispatchFetchEventStart(mDispatchFetchEventStart);
     156           0 :   MOZ_ASSERT(NS_SUCCEEDED(rv));
     157             : 
     158           0 :   rv = timedChannel->SetDispatchFetchEventEnd(mDispatchFetchEventEnd);
     159           0 :   MOZ_ASSERT(NS_SUCCEEDED(rv));
     160             : 
     161           0 :   rv = timedChannel->SetHandleFetchEventStart(mHandleFetchEventStart);
     162           0 :   MOZ_ASSERT(NS_SUCCEEDED(rv));
     163             : 
     164           0 :   rv = timedChannel->SetHandleFetchEventEnd(mHandleFetchEventEnd);
     165           0 :   MOZ_ASSERT(NS_SUCCEEDED(rv));
     166             : 
     167           0 :   nsCOMPtr<nsIChannel> channel;
     168           0 :   GetChannel(getter_AddRefs(channel));
     169           0 :   if (NS_WARN_IF(!channel)) {
     170           0 :     return NS_ERROR_FAILURE;
     171             :   }
     172             : 
     173           0 :   nsCString navigationOrSubresource = nsContentUtils::IsNonSubresourceRequest(channel) ?
     174           0 :     NS_LITERAL_CSTRING("navigation") : NS_LITERAL_CSTRING("subresource");
     175             : 
     176             :   // We may have null timestamps if the fetch dispatch runnable was cancelled
     177             :   // and we defaulted to resuming the request.
     178           0 :   if (!mFinishResponseStart.IsNull() && !mFinishResponseEnd.IsNull()) {
     179           0 :     MOZ_ASSERT(mSynthesizedOrReset != Invalid);
     180             : 
     181           0 :     Telemetry::HistogramID id = (mSynthesizedOrReset == Synthesized) ?
     182             :       Telemetry::SERVICE_WORKER_FETCH_EVENT_FINISH_SYNTHESIZED_RESPONSE_MS :
     183           0 :       Telemetry::SERVICE_WORKER_FETCH_EVENT_CHANNEL_RESET_MS;
     184           0 :     Telemetry::Accumulate(id, navigationOrSubresource,
     185           0 :       static_cast<uint32_t>((mFinishResponseEnd - mFinishResponseStart).ToMilliseconds()));
     186             :   }
     187             : 
     188           0 :   Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_EVENT_DISPATCH_MS,
     189             :     navigationOrSubresource,
     190           0 :     static_cast<uint32_t>((mHandleFetchEventStart - mDispatchFetchEventStart).ToMilliseconds()));
     191             : 
     192           0 :   if (!mFinishResponseEnd.IsNull()) {
     193           0 :     Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_INTERCEPTION_DURATION_MS,
     194             :       navigationOrSubresource,
     195           0 :       static_cast<uint32_t>((mFinishResponseEnd - mDispatchFetchEventStart).ToMilliseconds()));
     196             :   }
     197             : 
     198           0 :   return rv;
     199             : }
     200             : 
     201             : /* static */
     202             : already_AddRefed<nsIURI>
     203           0 : InterceptedChannelBase::SecureUpgradeChannelURI(nsIChannel* aChannel)
     204             : {
     205           0 :   nsCOMPtr<nsIURI> uri;
     206           0 :   nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
     207           0 :   NS_ENSURE_SUCCESS(rv, nullptr);
     208             : 
     209           0 :   nsCOMPtr<nsIURI> upgradedURI;
     210           0 :   rv = NS_GetSecureUpgradedURI(uri, getter_AddRefs(upgradedURI));
     211           0 :   NS_ENSURE_SUCCESS(rv, nullptr);
     212             : 
     213           0 :   return upgradedURI.forget();
     214             : }
     215             : 
     216           0 : InterceptedChannelChrome::InterceptedChannelChrome(nsHttpChannel* aChannel,
     217             :                                                    nsINetworkInterceptController* aController,
     218           0 :                                                    nsICacheEntry* aEntry)
     219             : : InterceptedChannelBase(aController)
     220             : , mChannel(aChannel)
     221           0 : , mSynthesizedCacheEntry(aEntry)
     222             : {
     223           0 :   nsresult rv = mChannel->GetApplyConversion(&mOldApplyConversion);
     224           0 :   if (NS_WARN_IF(NS_FAILED(rv))) {
     225           0 :     mOldApplyConversion = false;
     226             :   }
     227           0 : }
     228             : 
     229             : void
     230           0 : InterceptedChannelChrome::NotifyController()
     231             : {
     232             :   // Intercepted responses should already be decoded.
     233           0 :   mChannel->SetApplyConversion(false);
     234             : 
     235           0 :   nsresult rv = mSynthesizedCacheEntry->OpenOutputStream(0, getter_AddRefs(mResponseBody));
     236           0 :   NS_ENSURE_SUCCESS_VOID(rv);
     237             : 
     238           0 :   DoNotifyController();
     239             : }
     240             : 
     241             : NS_IMETHODIMP
     242           0 : InterceptedChannelChrome::GetChannel(nsIChannel** aChannel)
     243             : {
     244           0 :   NS_IF_ADDREF(*aChannel = mChannel);
     245           0 :   return NS_OK;
     246             : }
     247             : 
     248             : NS_IMETHODIMP
     249           0 : InterceptedChannelChrome::ResetInterception()
     250             : {
     251           0 :   if (mClosed) {
     252           0 :     return NS_ERROR_NOT_AVAILABLE;
     253             :   }
     254             : 
     255           0 :   mReportCollector->FlushConsoleReports(mChannel);
     256             : 
     257           0 :   mSynthesizedCacheEntry->AsyncDoom(nullptr);
     258           0 :   mSynthesizedCacheEntry = nullptr;
     259             : 
     260           0 :   mChannel->SetApplyConversion(mOldApplyConversion);
     261             : 
     262           0 :   nsCOMPtr<nsIURI> uri;
     263           0 :   mChannel->GetURI(getter_AddRefs(uri));
     264             : 
     265           0 :   nsresult rv = mChannel->StartRedirectChannelToURI(uri, nsIChannelEventSink::REDIRECT_INTERNAL);
     266           0 :   NS_ENSURE_SUCCESS(rv, rv);
     267             : 
     268           0 :   mResponseBody->Close();
     269           0 :   mResponseBody = nullptr;
     270           0 :   mClosed = true;
     271             : 
     272           0 :   return NS_OK;
     273             : }
     274             : 
     275             : NS_IMETHODIMP
     276           0 : InterceptedChannelChrome::SynthesizeStatus(uint16_t aStatus, const nsACString& aReason)
     277             : {
     278           0 :   if (!mSynthesizedCacheEntry) {
     279           0 :     return NS_ERROR_NOT_AVAILABLE;
     280             :   }
     281             : 
     282           0 :   return DoSynthesizeStatus(aStatus, aReason);
     283             : }
     284             : 
     285             : NS_IMETHODIMP
     286           0 : InterceptedChannelChrome::SynthesizeHeader(const nsACString& aName, const nsACString& aValue)
     287             : {
     288           0 :   if (!mSynthesizedCacheEntry) {
     289           0 :     return NS_ERROR_NOT_AVAILABLE;
     290             :   }
     291             : 
     292           0 :   return DoSynthesizeHeader(aName, aValue);
     293             : }
     294             : 
     295             : NS_IMETHODIMP
     296           0 : InterceptedChannelChrome::FinishSynthesizedResponse(const nsACString& aFinalURLSpec)
     297             : {
     298           0 :   if (mClosed) {
     299           0 :     return NS_ERROR_NOT_AVAILABLE;
     300             :   }
     301             : 
     302             :   // Make sure the cache entry's output stream is always closed.  If the
     303             :   // channel was intercepted with a null-body response then its possible
     304             :   // the synthesis completed without a stream copy operation.
     305           0 :   mResponseBody->Close();
     306             : 
     307           0 :   mReportCollector->FlushConsoleReports(mChannel);
     308             : 
     309           0 :   EnsureSynthesizedResponse();
     310             : 
     311             :   // If the synthesized response is a redirect, then we want to respect
     312             :   // the encoding of whatever is loaded as a result.
     313           0 :   if (nsHttpChannel::WillRedirect(mSynthesizedResponseHead.ref())) {
     314           0 :     nsresult rv = mChannel->SetApplyConversion(mOldApplyConversion);
     315           0 :     NS_ENSURE_SUCCESS(rv, rv);
     316             :   }
     317             : 
     318           0 :   mChannel->MarkIntercepted();
     319             : 
     320             :   // First we ensure the appropriate metadata is set on the synthesized cache entry
     321             :   // (i.e. the flattened response head)
     322             : 
     323           0 :   nsCOMPtr<nsISupports> securityInfo;
     324           0 :   nsresult rv = mChannel->GetSecurityInfo(getter_AddRefs(securityInfo));
     325           0 :   NS_ENSURE_SUCCESS(rv, rv);
     326             : 
     327           0 :   uint32_t expirationTime = 0;
     328           0 :   rv = DoUpdateExpirationTime(mChannel, mSynthesizedCacheEntry,
     329           0 :                               mSynthesizedResponseHead.ref(),
     330           0 :                               expirationTime);
     331             : 
     332           0 :   rv = DoAddCacheEntryHeaders(mChannel, mSynthesizedCacheEntry,
     333           0 :                               mChannel->GetRequestHead(),
     334           0 :                               mSynthesizedResponseHead.ref(), securityInfo);
     335           0 :   NS_ENSURE_SUCCESS(rv, rv);
     336             : 
     337           0 :   nsCOMPtr<nsIURI> originalURI;
     338           0 :   mChannel->GetURI(getter_AddRefs(originalURI));
     339             : 
     340           0 :   nsCOMPtr<nsIURI> responseURI;
     341           0 :   if (!aFinalURLSpec.IsEmpty()) {
     342           0 :     rv = NS_NewURI(getter_AddRefs(responseURI), aFinalURLSpec);
     343           0 :     NS_ENSURE_SUCCESS(rv, rv);
     344             :   } else {
     345           0 :     responseURI = originalURI;
     346             :   }
     347             : 
     348           0 :   bool equal = false;
     349           0 :   originalURI->Equals(responseURI, &equal);
     350           0 :   if (!equal) {
     351             :     rv =
     352           0 :         mChannel->StartRedirectChannelToURI(responseURI, nsIChannelEventSink::REDIRECT_INTERNAL);
     353           0 :     NS_ENSURE_SUCCESS(rv, rv);
     354             :   } else {
     355           0 :     bool usingSSL = false;
     356           0 :     responseURI->SchemeIs("https", &usingSSL);
     357             : 
     358             :     // Then we open a real cache entry to read the synthesized response from.
     359           0 :     rv = mChannel->OpenCacheEntry(usingSSL);
     360           0 :     NS_ENSURE_SUCCESS(rv, rv);
     361             : 
     362           0 :     mSynthesizedCacheEntry = nullptr;
     363             : 
     364           0 :     if (!mChannel->AwaitingCacheCallbacks()) {
     365           0 :       rv = mChannel->ContinueConnect();
     366           0 :       NS_ENSURE_SUCCESS(rv, rv);
     367             :     }
     368             :   }
     369             : 
     370           0 :   mClosed = true;
     371             : 
     372           0 :   return NS_OK;
     373             : }
     374             : 
     375             : NS_IMETHODIMP
     376           0 : InterceptedChannelChrome::Cancel(nsresult aStatus)
     377             : {
     378           0 :   MOZ_ASSERT(NS_FAILED(aStatus));
     379             : 
     380           0 :   if (mClosed) {
     381           0 :     return NS_ERROR_FAILURE;
     382             :   }
     383             : 
     384           0 :   mReportCollector->FlushConsoleReports(mChannel);
     385             : 
     386             :   // we need to use AsyncAbort instead of Cancel since there's no active pump
     387             :   // to cancel which will provide OnStart/OnStopRequest to the channel.
     388           0 :   nsresult rv = mChannel->AsyncAbort(aStatus);
     389           0 :   NS_ENSURE_SUCCESS(rv, rv);
     390             : 
     391           0 :   mClosed = true;
     392             : 
     393           0 :   return NS_OK;
     394             : }
     395             : 
     396             : NS_IMETHODIMP
     397           0 : InterceptedChannelChrome::SetChannelInfo(dom::ChannelInfo* aChannelInfo)
     398             : {
     399           0 :   if (mClosed) {
     400           0 :     return NS_ERROR_FAILURE;
     401             :   }
     402             : 
     403           0 :   return aChannelInfo->ResurrectInfoOnChannel(mChannel);
     404             : }
     405             : 
     406             : NS_IMETHODIMP
     407           0 : InterceptedChannelChrome::GetInternalContentPolicyType(nsContentPolicyType* aPolicyType)
     408             : {
     409           0 :   NS_ENSURE_ARG(aPolicyType);
     410           0 :   nsCOMPtr<nsILoadInfo> loadInfo;
     411           0 :   nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo));
     412           0 :   NS_ENSURE_SUCCESS(rv, rv);
     413           0 :   if (loadInfo) {
     414           0 :     *aPolicyType = loadInfo->InternalContentPolicyType();
     415             :   }
     416           0 :   return NS_OK;
     417             : }
     418             : 
     419             : NS_IMETHODIMP
     420           0 : InterceptedChannelChrome::GetSecureUpgradedChannelURI(nsIURI** aURI)
     421             : {
     422           0 :   return mChannel->GetURI(aURI);
     423             : }
     424             : 
     425           0 : InterceptedChannelContent::InterceptedChannelContent(HttpChannelChild* aChannel,
     426             :                                                      nsINetworkInterceptController* aController,
     427             :                                                      InterceptStreamListener* aListener,
     428           0 :                                                      bool aSecureUpgrade)
     429             : : InterceptedChannelBase(aController)
     430             : , mChannel(aChannel)
     431             : , mStreamListener(aListener)
     432           0 : , mSecureUpgrade(aSecureUpgrade)
     433             : {
     434           0 : }
     435             : 
     436             : void
     437           0 : InterceptedChannelContent::NotifyController()
     438             : {
     439           0 :   nsresult rv = NS_NewPipe(getter_AddRefs(mSynthesizedInput),
     440           0 :                            getter_AddRefs(mResponseBody),
     441           0 :                            0, UINT32_MAX, true, true);
     442           0 :   NS_ENSURE_SUCCESS_VOID(rv);
     443             : 
     444           0 :   DoNotifyController();
     445             : }
     446             : 
     447             : NS_IMETHODIMP
     448           0 : InterceptedChannelContent::GetChannel(nsIChannel** aChannel)
     449             : {
     450           0 :   NS_IF_ADDREF(*aChannel = mChannel);
     451           0 :   return NS_OK;
     452             : }
     453             : 
     454             : NS_IMETHODIMP
     455           0 : InterceptedChannelContent::ResetInterception()
     456             : {
     457           0 :   if (mClosed) {
     458           0 :     return NS_ERROR_NOT_AVAILABLE;
     459             :   }
     460             : 
     461           0 :   mReportCollector->FlushConsoleReports(mChannel);
     462             : 
     463           0 :   mResponseBody->Close();
     464           0 :   mResponseBody = nullptr;
     465           0 :   mSynthesizedInput = nullptr;
     466             : 
     467           0 :   mChannel->ResetInterception();
     468             : 
     469           0 :   mClosed = true;
     470             : 
     471           0 :   return NS_OK;
     472             : }
     473             : 
     474             : NS_IMETHODIMP
     475           0 : InterceptedChannelContent::SynthesizeStatus(uint16_t aStatus, const nsACString& aReason)
     476             : {
     477           0 :   if (!mResponseBody) {
     478           0 :     return NS_ERROR_NOT_AVAILABLE;
     479             :   }
     480             : 
     481           0 :   return DoSynthesizeStatus(aStatus, aReason);
     482             : }
     483             : 
     484             : NS_IMETHODIMP
     485           0 : InterceptedChannelContent::SynthesizeHeader(const nsACString& aName, const nsACString& aValue)
     486             : {
     487           0 :   if (!mResponseBody) {
     488           0 :     return NS_ERROR_NOT_AVAILABLE;
     489             :   }
     490             : 
     491           0 :   return DoSynthesizeHeader(aName, aValue);
     492             : }
     493             : 
     494             : NS_IMETHODIMP
     495           0 : InterceptedChannelContent::FinishSynthesizedResponse(const nsACString& aFinalURLSpec)
     496             : {
     497           0 :   if (NS_WARN_IF(mClosed)) {
     498           0 :     return NS_ERROR_NOT_AVAILABLE;
     499             :   }
     500             : 
     501             :   // Make sure the body output stream is always closed.  If the channel was
     502             :   // intercepted with a null-body response then its possible the synthesis
     503             :   // completed without a stream copy operation.
     504           0 :   mResponseBody->Close();
     505             : 
     506           0 :   mReportCollector->FlushConsoleReports(mChannel);
     507             : 
     508           0 :   EnsureSynthesizedResponse();
     509             : 
     510           0 :   nsCOMPtr<nsIURI> originalURI;
     511           0 :   mChannel->GetURI(getter_AddRefs(originalURI));
     512             : 
     513           0 :   nsCOMPtr<nsIURI> responseURI;
     514           0 :   if (!aFinalURLSpec.IsEmpty()) {
     515           0 :     nsresult rv = NS_NewURI(getter_AddRefs(responseURI), aFinalURLSpec);
     516           0 :     NS_ENSURE_SUCCESS(rv, rv);
     517           0 :   } else if (mSecureUpgrade) {
     518           0 :     nsresult rv = NS_GetSecureUpgradedURI(originalURI,
     519           0 :                                           getter_AddRefs(responseURI));
     520           0 :     NS_ENSURE_SUCCESS(rv, rv);
     521             :   } else {
     522           0 :     responseURI = originalURI;
     523             :   }
     524             : 
     525           0 :   bool equal = false;
     526           0 :   originalURI->Equals(responseURI, &equal);
     527           0 :   if (!equal) {
     528           0 :     mChannel->ForceIntercepted(mSynthesizedInput);
     529           0 :     mChannel->BeginNonIPCRedirect(responseURI, *mSynthesizedResponseHead.ptr());
     530             :   } else {
     531           0 :     mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(),
     532             :                                               mSynthesizedInput,
     533           0 :                                               mStreamListener);
     534             :   }
     535             : 
     536           0 :   mResponseBody = nullptr;
     537           0 :   mStreamListener = nullptr;
     538           0 :   mClosed = true;
     539             : 
     540           0 :   return NS_OK;
     541             : }
     542             : 
     543             : NS_IMETHODIMP
     544           0 : InterceptedChannelContent::Cancel(nsresult aStatus)
     545             : {
     546           0 :   MOZ_ASSERT(NS_FAILED(aStatus));
     547             : 
     548           0 :   if (mClosed) {
     549           0 :     return NS_ERROR_FAILURE;
     550             :   }
     551             : 
     552           0 :   mReportCollector->FlushConsoleReports(mChannel);
     553             : 
     554             :   // we need to use AsyncAbort instead of Cancel since there's no active pump
     555             :   // to cancel which will provide OnStart/OnStopRequest to the channel.
     556           0 :   nsresult rv = mChannel->AsyncAbort(aStatus);
     557           0 :   NS_ENSURE_SUCCESS(rv, rv);
     558           0 :   mStreamListener = nullptr;
     559           0 :   mClosed = true;
     560             : 
     561           0 :   return NS_OK;
     562             : }
     563             : 
     564             : NS_IMETHODIMP
     565           0 : InterceptedChannelContent::SetChannelInfo(dom::ChannelInfo* aChannelInfo)
     566             : {
     567           0 :   if (mClosed) {
     568           0 :     return NS_ERROR_FAILURE;
     569             :   }
     570             : 
     571           0 :   return aChannelInfo->ResurrectInfoOnChannel(mChannel);
     572             : }
     573             : 
     574             : NS_IMETHODIMP
     575           0 : InterceptedChannelContent::GetInternalContentPolicyType(nsContentPolicyType* aPolicyType)
     576             : {
     577           0 :   NS_ENSURE_ARG(aPolicyType);
     578             : 
     579           0 :   nsCOMPtr<nsILoadInfo> loadInfo;
     580           0 :   nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo));
     581           0 :   NS_ENSURE_SUCCESS(rv, rv);
     582             : 
     583           0 :   if (loadInfo) {
     584           0 :     *aPolicyType = loadInfo->InternalContentPolicyType();
     585             :   }
     586           0 :   return NS_OK;
     587             : }
     588             : 
     589             : NS_IMETHODIMP
     590           0 : InterceptedChannelContent::GetSecureUpgradedChannelURI(nsIURI** aURI)
     591             : {
     592           0 :   nsCOMPtr<nsIURI> uri;
     593           0 :   if (mSecureUpgrade) {
     594           0 :     uri = SecureUpgradeChannelURI(mChannel);
     595             :   } else {
     596           0 :     nsresult rv = mChannel->GetURI(getter_AddRefs(uri));
     597           0 :     NS_ENSURE_SUCCESS(rv, rv);
     598             :   }
     599           0 :   if (uri) {
     600           0 :     uri.forget(aURI);
     601           0 :     return NS_OK;
     602             :   }
     603           0 :   return NS_ERROR_FAILURE;
     604             : }
     605             : 
     606             : } // namespace net
     607             : } // namespace mozilla

Generated by: LCOV version 1.13