LCOV - code coverage report
Current view: directory - netwerk/protocol/wyciwyg - nsWyciwygProtocolHandler.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 59 17 28.8 %
Date: 2012-06-02 Functions: 12 7 58.3 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  *
       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                 :  *   Radha Kulkarni(radha@netscape.com)
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "nsWyciwyg.h"
      41                 : #include "nsWyciwygChannel.h"
      42                 : #include "nsWyciwygProtocolHandler.h"
      43                 : #include "nsIURL.h"
      44                 : #include "nsIComponentManager.h"
      45                 : #include "nsNetCID.h"
      46                 : #include "nsServiceManagerUtils.h"
      47                 : #include "plstr.h"
      48                 : #include "nsNetUtil.h"
      49                 : 
      50                 : #include "mozilla/net/NeckoChild.h"
      51                 : 
      52                 : using namespace mozilla::net;
      53                 : #include "mozilla/net/WyciwygChannelChild.h"
      54                 : 
      55                 : ////////////////////////////////////////////////////////////////////////////////
      56                 : 
      57               4 : nsWyciwygProtocolHandler::nsWyciwygProtocolHandler() 
      58                 : {
      59                 : #if defined(PR_LOGGING)
      60               4 :   if (!gWyciwygLog)
      61               4 :     gWyciwygLog = PR_NewLogModule("nsWyciwygChannel");
      62                 : #endif
      63                 : 
      64               4 :   LOG(("Creating nsWyciwygProtocolHandler [this=%x].\n", this));
      65               4 : }
      66                 : 
      67               8 : nsWyciwygProtocolHandler::~nsWyciwygProtocolHandler() 
      68                 : {
      69               4 :   LOG(("Deleting nsWyciwygProtocolHandler [this=%x]\n", this));
      70              16 : }
      71                 : 
      72             176 : NS_IMPL_ISUPPORTS1(nsWyciwygProtocolHandler, nsIProtocolHandler)
      73                 : 
      74                 : ////////////////////////////////////////////////////////////////////////////////
      75                 : // nsIProtocolHandler methods:
      76                 : ////////////////////////////////////////////////////////////////////////////////
      77                 : 
      78                 : NS_IMETHODIMP
      79               0 : nsWyciwygProtocolHandler::GetScheme(nsACString &result)
      80                 : {
      81               0 :   result = "wyciwyg";
      82               0 :   return NS_OK;
      83                 : }
      84                 : 
      85                 : NS_IMETHODIMP
      86               0 : nsWyciwygProtocolHandler::GetDefaultPort(PRInt32 *result) 
      87                 : {
      88               0 :   return NS_ERROR_NOT_AVAILABLE;
      89                 : }
      90                 : 
      91                 : NS_IMETHODIMP 
      92               0 : nsWyciwygProtocolHandler::AllowPort(PRInt32 port, const char *scheme, bool *_retval)
      93                 : {
      94                 :   // don't override anything.  
      95               0 :   *_retval = false;
      96               0 :   return NS_OK;
      97                 : }
      98                 : 
      99                 : NS_IMETHODIMP
     100              20 : nsWyciwygProtocolHandler::NewURI(const nsACString &aSpec,
     101                 :                                  const char *aCharset, // ignored
     102                 :                                  nsIURI *aBaseURI,
     103                 :                                  nsIURI **result) 
     104                 : {
     105                 :   nsresult rv;
     106                 : 
     107              40 :   nsCOMPtr<nsIURI> url = do_CreateInstance(NS_SIMPLEURI_CONTRACTID, &rv);
     108              20 :   NS_ENSURE_SUCCESS(rv, rv);
     109                 : 
     110              20 :   rv = url->SetSpec(aSpec);
     111              20 :   NS_ENSURE_SUCCESS(rv, rv);
     112                 : 
     113              20 :   *result = url;
     114              20 :   NS_ADDREF(*result);
     115                 : 
     116              20 :   return rv;
     117                 : }
     118                 : 
     119                 : NS_IMETHODIMP
     120               0 : nsWyciwygProtocolHandler::NewChannel(nsIURI* url, nsIChannel* *result)
     121                 : {
     122               0 :   if (mozilla::net::IsNeckoChild())
     123               0 :     mozilla::net::NeckoChild::InitNeckoChild();
     124                 : 
     125               0 :   NS_ENSURE_ARG_POINTER(url);
     126                 :   nsresult rv;
     127                 : 
     128               0 :   nsCOMPtr<nsIWyciwygChannel> channel;
     129               0 :   if (IsNeckoChild()) {
     130               0 :     NS_ENSURE_TRUE(gNeckoChild != nsnull, NS_ERROR_FAILURE);
     131                 : 
     132                 :     WyciwygChannelChild *wcc = static_cast<WyciwygChannelChild *>(
     133               0 :                                  gNeckoChild->SendPWyciwygChannelConstructor());
     134               0 :     if (!wcc)
     135               0 :       return NS_ERROR_OUT_OF_MEMORY;
     136                 : 
     137               0 :     channel = wcc;
     138               0 :     rv = wcc->Init(url);
     139               0 :     if (NS_FAILED(rv))
     140               0 :       PWyciwygChannelChild::Send__delete__(wcc);
     141                 :   } else
     142                 :   {
     143                 :     // If original channel used https, make sure PSM is initialized
     144                 :     // (this may be first channel to load during a session restore)
     145               0 :     nsCAutoString path;
     146               0 :     rv = url->GetPath(path);
     147               0 :     NS_ENSURE_SUCCESS(rv, rv);
     148               0 :     PRInt32 slashIndex = path.FindChar('/', 2);
     149               0 :     if (slashIndex == kNotFound)
     150               0 :       return NS_ERROR_FAILURE;
     151               0 :     if (path.Length() < (PRUint32)slashIndex + 1 + 5)
     152               0 :       return NS_ERROR_FAILURE;
     153               0 :     if (!PL_strncasecmp(path.get() + slashIndex + 1, "https", 5))
     154               0 :       net_EnsurePSMInit();
     155                 : 
     156               0 :     nsWyciwygChannel *wc = new nsWyciwygChannel();
     157               0 :     channel = wc;
     158               0 :     rv = wc->Init(url);
     159                 :   }
     160                 : 
     161               0 :   if (NS_FAILED(rv))
     162               0 :     return rv;
     163                 : 
     164               0 :   *result = channel.forget().get();
     165               0 :   return NS_OK;
     166                 : }
     167                 : 
     168                 : NS_IMETHODIMP
     169               0 : nsWyciwygProtocolHandler::GetProtocolFlags(PRUint32 *result) 
     170                 : {
     171                 :   // Should this be an an nsINestedURI?  We don't really want random webpages
     172                 :   // loading these URIs...
     173                 : 
     174                 :   // Note that using URI_INHERITS_SECURITY_CONTEXT here is OK -- untrusted code
     175                 :   // is not allowed to link to wyciwyg URIs and users shouldn't be able to get
     176                 :   // at them, and nsDocShell::InternalLoad forbids non-history loads of these
     177                 :   // URIs.  And when loading from history we end up using the principal from
     178                 :   // the history entry, which we put there ourselves, so all is ok.
     179                 :   *result = URI_NORELATIVE | URI_NOAUTH | URI_DANGEROUS_TO_LOAD |
     180               0 :     URI_INHERITS_SECURITY_CONTEXT;
     181               0 :   return NS_OK;
     182                 : }

Generated by: LCOV version 1.7