LCOV - code coverage report
Current view: directory - netwerk/protocol/viewsource - nsViewSourceChannel.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 272 0 0.0 %
Date: 2012-06-02 Functions: 57 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* vim:set ts=4 sw=4 sts=4 et: */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Netscape Communications Corporation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Chak Nanga <chak@netscape.com>
      25                 :  *   Darin Fisher <darin@meer.net>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      29                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #include "nsViewSourceChannel.h"
      42                 : #include "nsIIOService.h"
      43                 : #include "nsIServiceManager.h"
      44                 : #include "nsIInterfaceRequestor.h"
      45                 : #include "nsIInterfaceRequestorUtils.h"
      46                 : #include "nsXPIDLString.h"
      47                 : #include "nsReadableUtils.h"
      48                 : #include "nsMimeTypes.h"
      49                 : #include "nsNetUtil.h"
      50                 : #include "nsIHttpHeaderVisitor.h"
      51                 : 
      52               0 : NS_IMPL_ADDREF(nsViewSourceChannel)
      53               0 : NS_IMPL_RELEASE(nsViewSourceChannel)
      54                 : /*
      55                 :   This QI uses NS_INTERFACE_MAP_ENTRY_CONDITIONAL to check for
      56                 :   non-nullness of mHttpChannel, mCachingChannel, and mUploadChannel.
      57                 : */
      58               0 : NS_INTERFACE_MAP_BEGIN(nsViewSourceChannel)
      59               0 :     NS_INTERFACE_MAP_ENTRY(nsIViewSourceChannel)
      60               0 :     NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
      61               0 :     NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
      62               0 :     NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel)
      63               0 :     NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal, mHttpChannelInternal)
      64               0 :     NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICachingChannel, mCachingChannel)
      65               0 :     NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIUploadChannel, mUploadChannel)
      66               0 :     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIRequest, nsIViewSourceChannel)
      67               0 :     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIChannel, nsIViewSourceChannel)
      68               0 :     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIViewSourceChannel)
      69               0 : NS_INTERFACE_MAP_END
      70                 : 
      71                 : nsresult
      72               0 : nsViewSourceChannel::Init(nsIURI* uri)
      73                 : {
      74               0 :     mOriginalURI = uri;
      75                 : 
      76               0 :     nsCAutoString path;
      77               0 :     nsresult rv = uri->GetPath(path);
      78               0 :     if (NS_FAILED(rv))
      79               0 :       return rv;
      80                 : 
      81               0 :     nsCOMPtr<nsIIOService> pService(do_GetIOService(&rv));
      82               0 :     if (NS_FAILED(rv)) return rv;
      83                 : 
      84               0 :     nsCAutoString scheme;
      85               0 :     rv = pService->ExtractScheme(path, scheme);
      86               0 :     if (NS_FAILED(rv))
      87               0 :       return rv;
      88                 : 
      89                 :     // prevent viewing source of javascript URIs (see bug 204779)
      90               0 :     if (scheme.LowerCaseEqualsLiteral("javascript")) {
      91               0 :       NS_WARNING("blocking view-source:javascript:");
      92               0 :       return NS_ERROR_INVALID_ARG;
      93                 :     }
      94                 : 
      95               0 :     rv = pService->NewChannel(path, nsnull, nsnull, getter_AddRefs(mChannel));
      96               0 :     if (NS_FAILED(rv))
      97               0 :       return rv;
      98                 :  
      99               0 :     mChannel->SetOriginalURI(mOriginalURI);
     100               0 :     mHttpChannel = do_QueryInterface(mChannel);
     101               0 :     mHttpChannelInternal = do_QueryInterface(mChannel);
     102               0 :     mCachingChannel = do_QueryInterface(mChannel);
     103               0 :     mUploadChannel = do_QueryInterface(mChannel);
     104                 :     
     105               0 :     return NS_OK;
     106                 : }
     107                 : 
     108                 : ////////////////////////////////////////////////////////////////////////////////
     109                 : // nsIRequest methods:
     110                 : 
     111                 : NS_IMETHODIMP
     112               0 : nsViewSourceChannel::GetName(nsACString &result)
     113                 : {
     114               0 :     return NS_ERROR_NOT_IMPLEMENTED;
     115                 : }
     116                 : 
     117                 : NS_IMETHODIMP
     118               0 : nsViewSourceChannel::IsPending(bool *result)
     119                 : {
     120               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     121                 : 
     122               0 :     return mChannel->IsPending(result);
     123                 : }
     124                 : 
     125                 : NS_IMETHODIMP
     126               0 : nsViewSourceChannel::GetStatus(nsresult *status)
     127                 : {
     128               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     129                 : 
     130               0 :     return mChannel->GetStatus(status);
     131                 : }
     132                 : 
     133                 : NS_IMETHODIMP
     134               0 : nsViewSourceChannel::Cancel(nsresult status)
     135                 : {
     136               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     137                 : 
     138               0 :     return mChannel->Cancel(status);
     139                 : }
     140                 : 
     141                 : NS_IMETHODIMP
     142               0 : nsViewSourceChannel::Suspend(void)
     143                 : {
     144               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     145                 : 
     146               0 :     return mChannel->Suspend();
     147                 : }
     148                 : 
     149                 : NS_IMETHODIMP
     150               0 : nsViewSourceChannel::Resume(void)
     151                 : {
     152               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     153                 : 
     154               0 :     return mChannel->Resume();
     155                 : }
     156                 : 
     157                 : ////////////////////////////////////////////////////////////////////////////////
     158                 : // nsIChannel methods:
     159                 : 
     160                 : NS_IMETHODIMP
     161               0 : nsViewSourceChannel::GetOriginalURI(nsIURI* *aURI)
     162                 : {
     163               0 :     NS_ASSERTION(aURI, "Null out param!");
     164               0 :     *aURI = mOriginalURI;
     165               0 :     NS_ADDREF(*aURI);
     166               0 :     return NS_OK;
     167                 : }
     168                 : 
     169                 : NS_IMETHODIMP
     170               0 : nsViewSourceChannel::SetOriginalURI(nsIURI* aURI)
     171                 : {
     172               0 :     NS_ENSURE_ARG_POINTER(aURI);
     173               0 :     mOriginalURI = aURI;
     174               0 :     return NS_OK;
     175                 : }
     176                 : 
     177                 : NS_IMETHODIMP
     178               0 : nsViewSourceChannel::GetURI(nsIURI* *aURI)
     179                 : {
     180               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     181                 : 
     182               0 :     nsCOMPtr<nsIURI> uri;
     183               0 :     nsresult rv = mChannel->GetURI(getter_AddRefs(uri));
     184               0 :     if (NS_FAILED(rv))
     185               0 :       return rv;
     186                 : 
     187                 :     // protect ourselves against broken channel implementations
     188               0 :     if (!uri) {
     189               0 :       NS_ERROR("inner channel returned NS_OK and a null URI");
     190               0 :       return NS_ERROR_UNEXPECTED;
     191                 :     }
     192                 : 
     193               0 :     nsCAutoString spec;
     194               0 :     uri->GetSpec(spec);
     195                 : 
     196                 :     /* XXX Gross hack -- NS_NewURI goes into an infinite loop on
     197                 :        non-flat specs.  See bug 136980 */
     198               0 :     return NS_NewURI(aURI, nsCAutoString(NS_LITERAL_CSTRING("view-source:")+spec), nsnull);
     199                 : }
     200                 : 
     201                 : NS_IMETHODIMP
     202               0 : nsViewSourceChannel::Open(nsIInputStream **_retval)
     203                 : {
     204               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     205                 : 
     206               0 :     nsresult rv = mChannel->Open(_retval);
     207               0 :     if (NS_SUCCEEDED(rv)) {
     208               0 :         mOpened = true;
     209                 :     }
     210                 :     
     211               0 :     return rv;
     212                 : }
     213                 : 
     214                 : NS_IMETHODIMP
     215               0 : nsViewSourceChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt)
     216                 : {
     217               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     218                 : 
     219               0 :     mListener = aListener;
     220                 : 
     221                 :     /*
     222                 :      * We want to add ourselves to the loadgroup before opening
     223                 :      * mChannel, since we want to make sure we're in the loadgroup
     224                 :      * when mChannel finishes and fires OnStopRequest()
     225                 :      */
     226                 :     
     227               0 :     nsCOMPtr<nsILoadGroup> loadGroup;
     228               0 :     mChannel->GetLoadGroup(getter_AddRefs(loadGroup));
     229               0 :     if (loadGroup)
     230               0 :         loadGroup->AddRequest(static_cast<nsIViewSourceChannel*>
     231               0 :                                          (this), nsnull);
     232                 :     
     233               0 :     nsresult rv = mChannel->AsyncOpen(this, ctxt);
     234                 : 
     235               0 :     if (NS_FAILED(rv) && loadGroup)
     236               0 :         loadGroup->RemoveRequest(static_cast<nsIViewSourceChannel*>
     237                 :                                             (this),
     238               0 :                                  nsnull, rv);
     239                 : 
     240               0 :     if (NS_SUCCEEDED(rv)) {
     241               0 :         mOpened = true;
     242                 :     }
     243                 :     
     244               0 :     return rv;
     245                 : }
     246                 : 
     247                 : /*
     248                 :  * Both the view source channel and mChannel are added to the
     249                 :  * loadgroup.  There should never be more than one request in the
     250                 :  * loadgroup that has LOAD_DOCUMENT_URI set.  The one that has this
     251                 :  * flag set is the request whose URI is used to refetch the document,
     252                 :  * so it better be the viewsource channel.
     253                 :  *
     254                 :  * Therefore, we need to make sure that
     255                 :  * 1) The load flags on mChannel _never_ include LOAD_DOCUMENT_URI
     256                 :  * 2) The load flags on |this| include LOAD_DOCUMENT_URI when it was
     257                 :  *    set via SetLoadFlags (mIsDocument keeps track of this flag).
     258                 :  */
     259                 : 
     260                 : NS_IMETHODIMP
     261               0 : nsViewSourceChannel::GetLoadFlags(PRUint32 *aLoadFlags)
     262                 : {
     263               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     264                 : 
     265               0 :     nsresult rv = mChannel->GetLoadFlags(aLoadFlags);
     266               0 :     if (NS_FAILED(rv))
     267               0 :       return rv;
     268                 : 
     269                 :     // This should actually be just LOAD_DOCUMENT_URI but the win32 compiler
     270                 :     // fails to deal due to amiguous inheritance.  nsIChannel::LOAD_DOCUMENT_URI
     271                 :     // also fails; the Win32 compiler thinks that's supposed to be a method.
     272               0 :     if (mIsDocument)
     273               0 :       *aLoadFlags |= ::nsIChannel::LOAD_DOCUMENT_URI;
     274                 : 
     275               0 :     return rv;
     276                 : }
     277                 : 
     278                 : NS_IMETHODIMP
     279               0 : nsViewSourceChannel::SetLoadFlags(PRUint32 aLoadFlags)
     280                 : {
     281               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     282                 : 
     283                 :     // "View source" always wants the currently cached content.
     284                 :     // We also want to have _this_ channel, not mChannel to be the
     285                 :     // 'document' channel in the loadgroup. 
     286                 :  
     287                 :     // These should actually be just LOAD_FROM_CACHE and LOAD_DOCUMENT_URI but
     288                 :     // the win32 compiler fails to deal due to amiguous inheritance.
     289                 :     // nsIChannel::LOAD_DOCUMENT_URI/nsIRequest::LOAD_FROM_CACHE also fails; the
     290                 :     // Win32 compiler thinks that's supposed to be a method.
     291               0 :     mIsDocument = (aLoadFlags & ::nsIChannel::LOAD_DOCUMENT_URI) ? true : false;
     292                 : 
     293               0 :     return mChannel->SetLoadFlags((aLoadFlags |
     294                 :                                    ::nsIRequest::LOAD_FROM_CACHE) &
     295               0 :                                   ~::nsIChannel::LOAD_DOCUMENT_URI);
     296                 : }
     297                 : 
     298                 : NS_IMETHODIMP
     299               0 : nsViewSourceChannel::GetContentType(nsACString &aContentType) 
     300                 : {
     301               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     302                 : 
     303               0 :     aContentType.Truncate();
     304                 : 
     305               0 :     if (mContentType.IsEmpty())
     306                 :     {
     307                 :         // Get the current content type
     308                 :         nsresult rv;
     309               0 :         nsCAutoString contentType;
     310               0 :         rv = mChannel->GetContentType(contentType);
     311               0 :         if (NS_FAILED(rv)) return rv;
     312                 : 
     313                 :         // If we don't know our type, just say so.  The unknown
     314                 :         // content decoder will then kick in automatically, and it
     315                 :         // will call our SetOriginalContentType method instead of our
     316                 :         // SetContentType method to set the type it determines.
     317               0 :         if (!contentType.Equals(UNKNOWN_CONTENT_TYPE)) {
     318               0 :           contentType = VIEWSOURCE_CONTENT_TYPE;
     319                 :         }
     320                 : 
     321               0 :         mContentType = contentType;
     322                 :     }
     323                 : 
     324               0 :     aContentType = mContentType;
     325               0 :     return NS_OK;
     326                 : }
     327                 : 
     328                 : NS_IMETHODIMP
     329               0 : nsViewSourceChannel::SetContentType(const nsACString &aContentType)
     330                 : {
     331                 :     // Our GetContentType() currently returns VIEWSOURCE_CONTENT_TYPE
     332                 :     //
     333                 :     // However, during the parsing phase the parser calls our
     334                 :     // channel's GetContentType(). Returning the string above trips up
     335                 :     // the parser. In order to avoid messy changes and not to have the
     336                 :     // parser depend on nsIViewSourceChannel Vidur proposed the
     337                 :     // following solution:
     338                 :     //
     339                 :     // The ViewSourceChannel initially returns a content type of
     340                 :     // VIEWSOURCE_CONTENT_TYPE.  Based on this type decisions to
     341                 :     // create a viewer for doing a view source are made.  After the
     342                 :     // viewer is created, nsLayoutDLF::CreateInstance() calls this
     343                 :     // SetContentType() with the original content type.  When it's
     344                 :     // time for the parser to find out the content type it will call
     345                 :     // our channel's GetContentType() and it will get the original
     346                 :     // content type, such as, text/html and everything is kosher from
     347                 :     // then on.
     348                 : 
     349               0 :     if (!mOpened) {
     350                 :         // We do not take hints
     351               0 :         return NS_ERROR_NOT_AVAILABLE;
     352                 :     }
     353                 :     
     354               0 :     mContentType = aContentType;
     355               0 :     return NS_OK;
     356                 : }
     357                 : 
     358                 : NS_IMETHODIMP
     359               0 : nsViewSourceChannel::GetContentCharset(nsACString &aContentCharset)
     360                 : {
     361               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     362                 : 
     363               0 :     return mChannel->GetContentCharset(aContentCharset);
     364                 : }
     365                 : 
     366                 : NS_IMETHODIMP
     367               0 : nsViewSourceChannel::SetContentCharset(const nsACString &aContentCharset)
     368                 : {
     369               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     370                 : 
     371               0 :     return mChannel->SetContentCharset(aContentCharset);
     372                 : }
     373                 : 
     374                 : NS_IMETHODIMP
     375               0 : nsViewSourceChannel::GetContentDisposition(PRUint32 *aContentDisposition)
     376                 : {
     377               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     378                 : 
     379               0 :     return mChannel->GetContentDisposition(aContentDisposition);
     380                 : }
     381                 : 
     382                 : NS_IMETHODIMP
     383               0 : nsViewSourceChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename)
     384                 : {
     385               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     386                 : 
     387               0 :     return mChannel->GetContentDispositionFilename(aContentDispositionFilename);
     388                 : }
     389                 : 
     390                 : NS_IMETHODIMP
     391               0 : nsViewSourceChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader)
     392                 : {
     393               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     394                 : 
     395               0 :     return mChannel->GetContentDispositionHeader(aContentDispositionHeader);
     396                 : }
     397                 : 
     398                 : NS_IMETHODIMP
     399               0 : nsViewSourceChannel::GetContentLength(PRInt32 *aContentLength)
     400                 : {
     401               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     402                 : 
     403               0 :     return mChannel->GetContentLength(aContentLength);
     404                 : }
     405                 : 
     406                 : NS_IMETHODIMP
     407               0 : nsViewSourceChannel::SetContentLength(PRInt32 aContentLength)
     408                 : {
     409               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     410                 : 
     411               0 :     return mChannel->SetContentLength(aContentLength);
     412                 : }
     413                 : 
     414                 : NS_IMETHODIMP
     415               0 : nsViewSourceChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
     416                 : {
     417               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     418                 : 
     419               0 :     return mChannel->GetLoadGroup(aLoadGroup);
     420                 : }
     421                 : 
     422                 : NS_IMETHODIMP
     423               0 : nsViewSourceChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
     424                 : {
     425               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     426                 : 
     427               0 :     return mChannel->SetLoadGroup(aLoadGroup);
     428                 : }
     429                 : 
     430                 : NS_IMETHODIMP
     431               0 : nsViewSourceChannel::GetOwner(nsISupports* *aOwner)
     432                 : {
     433               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     434                 : 
     435               0 :     return mChannel->GetOwner(aOwner);
     436                 : }
     437                 : 
     438                 : NS_IMETHODIMP
     439               0 : nsViewSourceChannel::SetOwner(nsISupports* aOwner)
     440                 : {
     441               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     442                 : 
     443               0 :     return mChannel->SetOwner(aOwner);
     444                 : }
     445                 : 
     446                 : NS_IMETHODIMP
     447               0 : nsViewSourceChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
     448                 : {
     449               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     450                 : 
     451               0 :     return mChannel->GetNotificationCallbacks(aNotificationCallbacks);
     452                 : }
     453                 : 
     454                 : NS_IMETHODIMP
     455               0 : nsViewSourceChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
     456                 : {
     457               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     458                 : 
     459               0 :     return mChannel->SetNotificationCallbacks(aNotificationCallbacks);
     460                 : }
     461                 : 
     462                 : NS_IMETHODIMP 
     463               0 : nsViewSourceChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
     464                 : {
     465               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     466                 : 
     467               0 :     return mChannel->GetSecurityInfo(aSecurityInfo);
     468                 : }
     469                 : 
     470                 : // nsIViewSourceChannel methods
     471                 : NS_IMETHODIMP
     472               0 : nsViewSourceChannel::GetOriginalContentType(nsACString &aContentType) 
     473                 : {
     474               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     475                 : 
     476               0 :     return mChannel->GetContentType(aContentType);
     477                 : }
     478                 : 
     479                 : NS_IMETHODIMP
     480               0 : nsViewSourceChannel::SetOriginalContentType(const nsACString &aContentType)
     481                 : {
     482               0 :     NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
     483                 : 
     484                 :     // clear our cached content-type value
     485               0 :     mContentType.Truncate();
     486                 : 
     487               0 :     return mChannel->SetContentType(aContentType);
     488                 : }
     489                 : 
     490                 : // nsIRequestObserver methods
     491                 : NS_IMETHODIMP
     492               0 : nsViewSourceChannel::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
     493                 : {
     494               0 :     NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE);
     495                 :     // The channel may have gotten redirected... Time to update our info
     496               0 :     mChannel = do_QueryInterface(aRequest);
     497               0 :     mHttpChannel = do_QueryInterface(aRequest);
     498               0 :     mCachingChannel = do_QueryInterface(aRequest);
     499               0 :     mUploadChannel = do_QueryInterface(aRequest);
     500                 :     
     501               0 :     return mListener->OnStartRequest(static_cast<nsIViewSourceChannel*>
     502                 :                                                 (this),
     503               0 :                                      aContext);
     504                 : }
     505                 : 
     506                 : 
     507                 : NS_IMETHODIMP
     508               0 : nsViewSourceChannel::OnStopRequest(nsIRequest *aRequest, nsISupports* aContext,
     509                 :                                nsresult aStatus)
     510                 : {
     511               0 :     NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE);
     512               0 :     if (mChannel)
     513                 :     {
     514               0 :         nsCOMPtr<nsILoadGroup> loadGroup;
     515               0 :         mChannel->GetLoadGroup(getter_AddRefs(loadGroup));
     516               0 :         if (loadGroup)
     517                 :         {
     518               0 :             loadGroup->RemoveRequest(static_cast<nsIViewSourceChannel*>
     519                 :                                                 (this),
     520               0 :                                      nsnull, aStatus);
     521                 :         }
     522                 :     }
     523               0 :     return mListener->OnStopRequest(static_cast<nsIViewSourceChannel*>
     524                 :                                                (this),
     525               0 :                                     aContext, aStatus);
     526                 : }
     527                 : 
     528                 : 
     529                 : // nsIStreamListener methods
     530                 : NS_IMETHODIMP
     531               0 : nsViewSourceChannel::OnDataAvailable(nsIRequest *aRequest, nsISupports* aContext,
     532                 :                                nsIInputStream *aInputStream, PRUint32 aSourceOffset,
     533                 :                                PRUint32 aLength) 
     534                 : {
     535               0 :     NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE);
     536               0 :     return mListener->OnDataAvailable(static_cast<nsIViewSourceChannel*>
     537                 :                                                  (this),
     538                 :                                       aContext, aInputStream,
     539               0 :                                       aSourceOffset, aLength);
     540                 : }
     541                 : 
     542                 : 
     543                 : // nsIHttpChannel methods
     544                 : 
     545                 : // We want to forward most of nsIHttpChannel over to mHttpChannel, but we want
     546                 : // to override GetRequestHeader and VisitHeaders. The reason is that we don't
     547                 : // want various headers like Link: and Refresh: applying to view-source.
     548                 : NS_IMETHODIMP
     549               0 : nsViewSourceChannel::GetRequestMethod(nsACString & aRequestMethod)
     550                 : {
     551               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     552               0 :         mHttpChannel->GetRequestMethod(aRequestMethod);
     553                 : }
     554                 : 
     555                 : NS_IMETHODIMP
     556               0 : nsViewSourceChannel::SetRequestMethod(const nsACString & aRequestMethod)
     557                 : {
     558               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     559               0 :         mHttpChannel->SetRequestMethod(aRequestMethod);
     560                 : }
     561                 : 
     562                 : NS_IMETHODIMP
     563               0 : nsViewSourceChannel::GetReferrer(nsIURI * *aReferrer)
     564                 : {
     565               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     566               0 :         mHttpChannel->GetReferrer(aReferrer);
     567                 : }
     568                 : 
     569                 : NS_IMETHODIMP
     570               0 : nsViewSourceChannel::SetReferrer(nsIURI * aReferrer)
     571                 : {
     572               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     573               0 :         mHttpChannel->SetReferrer(aReferrer);
     574                 : }
     575                 : 
     576                 : NS_IMETHODIMP
     577               0 : nsViewSourceChannel::GetRequestHeader(const nsACString & aHeader,
     578                 :                                       nsACString & aValue)
     579                 : {
     580               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     581               0 :         mHttpChannel->GetRequestHeader(aHeader, aValue);
     582                 : }
     583                 : 
     584                 : NS_IMETHODIMP
     585               0 : nsViewSourceChannel::SetRequestHeader(const nsACString & aHeader,
     586                 :                                       const nsACString & aValue,
     587                 :                                       bool aMerge)
     588                 : {
     589               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     590               0 :         mHttpChannel->SetRequestHeader(aHeader, aValue, aMerge);
     591                 : }
     592                 : 
     593                 : NS_IMETHODIMP
     594               0 : nsViewSourceChannel::VisitRequestHeaders(nsIHttpHeaderVisitor *aVisitor)
     595                 : {
     596               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     597               0 :         mHttpChannel->VisitRequestHeaders(aVisitor);
     598                 : }
     599                 : 
     600                 : NS_IMETHODIMP
     601               0 : nsViewSourceChannel::GetAllowPipelining(bool *aAllowPipelining)
     602                 : {
     603               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     604               0 :         mHttpChannel->GetAllowPipelining(aAllowPipelining);
     605                 : }
     606                 : 
     607                 : NS_IMETHODIMP
     608               0 : nsViewSourceChannel::SetAllowPipelining(bool aAllowPipelining)
     609                 : {
     610               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     611               0 :         mHttpChannel->SetAllowPipelining(aAllowPipelining);
     612                 : }
     613                 : 
     614                 : NS_IMETHODIMP
     615               0 : nsViewSourceChannel::GetRedirectionLimit(PRUint32 *aRedirectionLimit)
     616                 : {
     617               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     618               0 :         mHttpChannel->GetRedirectionLimit(aRedirectionLimit);
     619                 : }
     620                 : 
     621                 : NS_IMETHODIMP
     622               0 : nsViewSourceChannel::SetRedirectionLimit(PRUint32 aRedirectionLimit)
     623                 : {
     624               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     625               0 :         mHttpChannel->SetRedirectionLimit(aRedirectionLimit);
     626                 : }
     627                 : 
     628                 : NS_IMETHODIMP
     629               0 : nsViewSourceChannel::GetResponseStatus(PRUint32 *aResponseStatus)
     630                 : {
     631               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     632               0 :         mHttpChannel->GetResponseStatus(aResponseStatus);
     633                 : }
     634                 : 
     635                 : NS_IMETHODIMP
     636               0 : nsViewSourceChannel::GetResponseStatusText(nsACString & aResponseStatusText)
     637                 : {
     638               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     639               0 :         mHttpChannel->GetResponseStatusText(aResponseStatusText);
     640                 : }
     641                 : 
     642                 : NS_IMETHODIMP
     643               0 : nsViewSourceChannel::GetRequestSucceeded(bool *aRequestSucceeded)
     644                 : {
     645               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     646               0 :         mHttpChannel->GetRequestSucceeded(aRequestSucceeded);
     647                 : }
     648                 : 
     649                 : NS_IMETHODIMP
     650               0 : nsViewSourceChannel::GetResponseHeader(const nsACString & aHeader,
     651                 :                                        nsACString & aValue)
     652                 : {
     653               0 :     if (!mHttpChannel)
     654               0 :         return NS_ERROR_NULL_POINTER;
     655                 : 
     656               0 :     if (!aHeader.Equals(NS_LITERAL_CSTRING("Content-Type"),
     657               0 :                         nsCaseInsensitiveCStringComparator()) &&
     658               0 :         !aHeader.Equals(NS_LITERAL_CSTRING("X-Content-Security-Policy"),
     659               0 :                         nsCaseInsensitiveCStringComparator()) &&
     660               0 :         !aHeader.Equals(NS_LITERAL_CSTRING("X-Content-Security-Policy-Report-Only"),
     661               0 :                         nsCaseInsensitiveCStringComparator()) &&
     662               0 :         !aHeader.Equals(NS_LITERAL_CSTRING("X-Frame-Options"),
     663               0 :                         nsCaseInsensitiveCStringComparator())) {
     664               0 :         aValue.Truncate();
     665               0 :         return NS_OK;
     666                 :     }
     667                 :         
     668               0 :     return mHttpChannel->GetResponseHeader(aHeader, aValue);
     669                 : }
     670                 : 
     671                 : NS_IMETHODIMP
     672               0 : nsViewSourceChannel::SetResponseHeader(const nsACString & header,
     673                 :                                        const nsACString & value, bool merge)
     674                 : {
     675               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     676               0 :         mHttpChannel->SetResponseHeader(header, value, merge);
     677                 : }
     678                 : 
     679                 : NS_IMETHODIMP
     680               0 : nsViewSourceChannel::VisitResponseHeaders(nsIHttpHeaderVisitor *aVisitor)
     681                 : {
     682               0 :     if (!mHttpChannel)
     683               0 :         return NS_ERROR_NULL_POINTER;
     684                 : 
     685               0 :     NS_NAMED_LITERAL_CSTRING(contentTypeStr, "Content-Type");
     686               0 :     nsCAutoString contentType;
     687                 :     nsresult rv =
     688               0 :         mHttpChannel->GetResponseHeader(contentTypeStr, contentType);
     689               0 :     if (NS_SUCCEEDED(rv))
     690               0 :         aVisitor->VisitHeader(contentTypeStr, contentType);
     691               0 :     return NS_OK;
     692                 : }
     693                 : 
     694                 : NS_IMETHODIMP
     695               0 : nsViewSourceChannel::IsNoStoreResponse(bool *_retval)
     696                 : {
     697               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     698               0 :         mHttpChannel->IsNoStoreResponse(_retval);
     699                 : }
     700                 : 
     701                 : NS_IMETHODIMP
     702               0 : nsViewSourceChannel::IsNoCacheResponse(bool *_retval)
     703                 : {
     704               0 :     return !mHttpChannel ? NS_ERROR_NULL_POINTER :
     705               0 :         mHttpChannel->IsNoCacheResponse(_retval);
     706                 : } 

Generated by: LCOV version 1.7