LCOV - code coverage report
Current view: top level - netwerk/base - nsSimpleNestedURI.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 27 81 33.3 %
Date: 2017-07-14 16:53:18 Functions: 7 13 53.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "base/basictypes.h"
       7             : 
       8             : #include "nsNetCID.h"
       9             : #include "nsNetUtil.h"
      10             : #include "nsSimpleNestedURI.h"
      11             : #include "nsIObjectInputStream.h"
      12             : #include "nsIObjectOutputStream.h"
      13             : 
      14             : #include "mozilla/ipc/URIUtils.h"
      15             : 
      16             : namespace mozilla {
      17             : namespace net {
      18             : 
      19        2104 : NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI)
      20             : 
      21          32 : nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI)
      22          32 :     : mInnerURI(innerURI)
      23             : {
      24          32 :     NS_ASSERTION(innerURI, "Must have inner URI");
      25          32 :     NS_TryToSetImmutable(innerURI);
      26          32 : }
      27             : 
      28             : // nsISerializable
      29             : 
      30             : NS_IMETHODIMP
      31           0 : nsSimpleNestedURI::Read(nsIObjectInputStream* aStream)
      32             : {
      33           0 :     nsresult rv = nsSimpleURI::Read(aStream);
      34           0 :     if (NS_FAILED(rv)) return rv;
      35             : 
      36           0 :     NS_ASSERTION(!mMutable, "How did that happen?");
      37             : 
      38           0 :     nsCOMPtr<nsISupports> supports;
      39           0 :     rv = aStream->ReadObject(true, getter_AddRefs(supports));
      40           0 :     if (NS_FAILED(rv)) return rv;
      41             : 
      42           0 :     mInnerURI = do_QueryInterface(supports, &rv);
      43           0 :     if (NS_FAILED(rv)) return rv;
      44             : 
      45           0 :     NS_TryToSetImmutable(mInnerURI);
      46             : 
      47           0 :     return rv;
      48             : }
      49             : 
      50             : NS_IMETHODIMP
      51           0 : nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream)
      52             : {
      53           0 :     nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mInnerURI);
      54           0 :     if (!serializable) {
      55             :         // We can't serialize ourselves
      56           0 :         return NS_ERROR_NOT_AVAILABLE;
      57             :     }
      58             : 
      59           0 :     nsresult rv = nsSimpleURI::Write(aStream);
      60           0 :     if (NS_FAILED(rv)) return rv;
      61             : 
      62             :     rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI),
      63           0 :                                       true);
      64           0 :     return rv;
      65             : }
      66             : 
      67             : // nsIIPCSerializableURI
      68             : void
      69           0 : nsSimpleNestedURI::Serialize(mozilla::ipc::URIParams& aParams)
      70             : {
      71             :     using namespace mozilla::ipc;
      72             : 
      73           0 :     SimpleNestedURIParams params;
      74           0 :     URIParams simpleParams;
      75             : 
      76           0 :     nsSimpleURI::Serialize(simpleParams);
      77           0 :     params.simpleParams() = simpleParams;
      78             : 
      79           0 :     SerializeURI(mInnerURI, params.innerURI());
      80             : 
      81           0 :     aParams = params;
      82           0 : }
      83             : 
      84             : bool
      85           0 : nsSimpleNestedURI::Deserialize(const mozilla::ipc::URIParams& aParams)
      86             : {
      87             :     using namespace mozilla::ipc;
      88             : 
      89           0 :     if (aParams.type() != URIParams::TSimpleNestedURIParams) {
      90           0 :         NS_ERROR("Received unknown parameters from the other process!");
      91           0 :         return false;
      92             :     }
      93             : 
      94           0 :     const SimpleNestedURIParams& params = aParams.get_SimpleNestedURIParams();
      95           0 :     if (!nsSimpleURI::Deserialize(params.simpleParams()))
      96           0 :         return false;
      97             : 
      98           0 :     mInnerURI = DeserializeURI(params.innerURI());
      99             : 
     100           0 :     NS_TryToSetImmutable(mInnerURI);
     101           0 :     return true;
     102             : }
     103             : 
     104             : // nsINestedURI
     105             : 
     106             : NS_IMETHODIMP
     107          31 : nsSimpleNestedURI::GetInnerURI(nsIURI** uri)
     108             : {
     109          31 :     NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
     110             : 
     111          31 :     return NS_EnsureSafeToReturn(mInnerURI, uri);
     112             : }
     113             : 
     114             : NS_IMETHODIMP
     115          11 : nsSimpleNestedURI::GetInnermostURI(nsIURI** uri)
     116             : {
     117          11 :     return NS_ImplGetInnermostURI(this, uri);
     118             : }
     119             : 
     120             : // nsSimpleURI overrides
     121             : /* virtual */ nsresult
     122           9 : nsSimpleNestedURI::EqualsInternal(nsIURI* other,
     123             :                                   nsSimpleURI::RefHandlingEnum refHandlingMode,
     124             :                                   bool* result)
     125             : {
     126           9 :     *result = false;
     127           9 :     NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
     128             : 
     129           9 :     if (other) {
     130             :         bool correctScheme;
     131           9 :         nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme);
     132           9 :         NS_ENSURE_SUCCESS(rv, rv);
     133             : 
     134           9 :         if (correctScheme) {
     135           3 :             nsCOMPtr<nsINestedURI> nest = do_QueryInterface(other);
     136           3 :             if (nest) {
     137           6 :                 nsCOMPtr<nsIURI> otherInner;
     138           3 :                 rv = nest->GetInnerURI(getter_AddRefs(otherInner));
     139           3 :                 NS_ENSURE_SUCCESS(rv, rv);
     140             : 
     141           6 :                 return (refHandlingMode == eHonorRef) ?
     142           1 :                     otherInner->Equals(mInnerURI, result) :
     143           5 :                     otherInner->EqualsExceptRef(mInnerURI, result);
     144             :             }
     145             :         }
     146             :     }
     147             : 
     148           6 :     return NS_OK;
     149             : }
     150             : 
     151             : /* virtual */ nsSimpleURI*
     152           0 : nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode,
     153             :                               const nsACString& newRef)
     154             : {
     155           0 :     NS_ENSURE_TRUE(mInnerURI, nullptr);
     156             : 
     157           0 :     nsCOMPtr<nsIURI> innerClone;
     158             :     nsresult rv;
     159           0 :     if (refHandlingMode == eHonorRef) {
     160           0 :         rv = mInnerURI->Clone(getter_AddRefs(innerClone));
     161           0 :     } else if (refHandlingMode == eReplaceRef) {
     162           0 :         rv = mInnerURI->CloneWithNewRef(newRef, getter_AddRefs(innerClone));
     163             :     } else {
     164           0 :         rv = mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone));
     165             :     }
     166             : 
     167           0 :     if (NS_FAILED(rv)) {
     168           0 :         return nullptr;
     169             :     }
     170             : 
     171           0 :     nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone);
     172           0 :     SetRefOnClone(url, refHandlingMode, newRef);
     173           0 :     url->SetMutable(false);
     174             : 
     175           0 :     return url;
     176             : }
     177             : 
     178             : // nsIClassInfo overrides
     179             : 
     180             : NS_IMETHODIMP
     181           0 : nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
     182             : {
     183             :     static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID);
     184             : 
     185           0 :     *aClassIDNoAlloc = kSimpleNestedURICID;
     186           0 :     return NS_OK;
     187             : }
     188             : 
     189             : } // namespace net
     190             : } // namespace mozilla

Generated by: LCOV version 1.13