netwerk/base/src/nsSimpleNestedURI.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     6 #include "base/basictypes.h"
     8 #include "nsSimpleNestedURI.h"
     9 #include "nsIObjectInputStream.h"
    10 #include "nsIObjectOutputStream.h"
    11 #include "nsNetUtil.h"
    13 NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI)
    15 nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI)
    16     : mInnerURI(innerURI)
    17 {
    18     NS_ASSERTION(innerURI, "Must have inner URI");
    19     NS_TryToSetImmutable(innerURI);
    20 }
    22 // nsISerializable
    24 NS_IMETHODIMP
    25 nsSimpleNestedURI::Read(nsIObjectInputStream* aStream)
    26 {
    27     nsresult rv = nsSimpleURI::Read(aStream);
    28     if (NS_FAILED(rv)) return rv;
    30     NS_ASSERTION(!mMutable, "How did that happen?");
    32     nsCOMPtr<nsISupports> supports;
    33     rv = aStream->ReadObject(true, getter_AddRefs(supports));
    34     if (NS_FAILED(rv)) return rv;
    36     mInnerURI = do_QueryInterface(supports, &rv);
    37     if (NS_FAILED(rv)) return rv;
    39     NS_TryToSetImmutable(mInnerURI);
    41     return rv;
    42 }
    44 NS_IMETHODIMP
    45 nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream)
    46 {
    47     nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mInnerURI);
    48     if (!serializable) {
    49         // We can't serialize ourselves
    50         return NS_ERROR_NOT_AVAILABLE;
    51     }
    53     nsresult rv = nsSimpleURI::Write(aStream);
    54     if (NS_FAILED(rv)) return rv;
    56     rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI),
    57                                       true);
    58     return rv;
    59 }
    61 // nsINestedURI
    63 NS_IMETHODIMP
    64 nsSimpleNestedURI::GetInnerURI(nsIURI** uri)
    65 {
    66     NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
    68     return NS_EnsureSafeToReturn(mInnerURI, uri);
    69 }
    71 NS_IMETHODIMP
    72 nsSimpleNestedURI::GetInnermostURI(nsIURI** uri)
    73 {
    74     return NS_ImplGetInnermostURI(this, uri);
    75 }
    77 // nsSimpleURI overrides
    78 /* virtual */ nsresult
    79 nsSimpleNestedURI::EqualsInternal(nsIURI* other,
    80                                   nsSimpleURI::RefHandlingEnum refHandlingMode,
    81                                   bool* result)
    82 {
    83     *result = false;
    84     NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
    86     if (other) {
    87         bool correctScheme;
    88         nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme);
    89         NS_ENSURE_SUCCESS(rv, rv);
    91         if (correctScheme) {
    92             nsCOMPtr<nsINestedURI> nest = do_QueryInterface(other);
    93             if (nest) {
    94                 nsCOMPtr<nsIURI> otherInner;
    95                 rv = nest->GetInnerURI(getter_AddRefs(otherInner));
    96                 NS_ENSURE_SUCCESS(rv, rv);
    98                 return (refHandlingMode == eHonorRef) ?
    99                     otherInner->Equals(mInnerURI, result) :
   100                     otherInner->EqualsExceptRef(mInnerURI, result);
   101             }
   102         }
   103     }
   105     return NS_OK;
   106 }
   108 /* virtual */ nsSimpleURI*
   109 nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode)
   110 {
   111     NS_ENSURE_TRUE(mInnerURI, nullptr);
   113     nsCOMPtr<nsIURI> innerClone;
   114     nsresult rv = refHandlingMode == eHonorRef ?
   115         mInnerURI->Clone(getter_AddRefs(innerClone)) :
   116         mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone));
   118     if (NS_FAILED(rv)) {
   119         return nullptr;
   120     }
   122     nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone);
   123     url->SetMutable(false);
   125     return url;
   126 }
   128 // nsIClassInfo overrides
   130 NS_IMETHODIMP 
   131 nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
   132 {
   133     static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID);
   135     *aClassIDNoAlloc = kSimpleNestedURICID;
   136     return NS_OK;
   137 }

mercurial