content/base/src/nsHostObjectURI.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "nsHostObjectURI.h"
     7 #include "nsAutoPtr.h"
     8 #include "nsIObjectInputStream.h"
     9 #include "nsIObjectOutputStream.h"
    10 #include "nsIProgrammingLanguage.h"
    12 static NS_DEFINE_CID(kHOSTOBJECTURICID, NS_HOSTOBJECTURI_CID);
    14 static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
    15                      NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
    17 NS_IMPL_ADDREF_INHERITED(nsHostObjectURI, nsSimpleURI)
    18 NS_IMPL_RELEASE_INHERITED(nsHostObjectURI, nsSimpleURI)
    20 NS_INTERFACE_MAP_BEGIN(nsHostObjectURI)
    21   NS_INTERFACE_MAP_ENTRY(nsIURIWithPrincipal)
    22   if (aIID.Equals(kHOSTOBJECTURICID))
    23     foundInterface = static_cast<nsIURI*>(this);
    24   else if (aIID.Equals(kThisSimpleURIImplementationCID)) {
    25     // Need to return explicitly here, because if we just set foundInterface
    26     // to null the NS_INTERFACE_MAP_END_INHERITING will end up calling into
    27     // nsSimplURI::QueryInterface and finding something for this CID.
    28     *aInstancePtr = nullptr;
    29     return NS_NOINTERFACE;
    30   }
    31   else
    32 NS_INTERFACE_MAP_END_INHERITING(nsSimpleURI)
    34 // nsIURIWithPrincipal methods:
    36 NS_IMETHODIMP
    37 nsHostObjectURI::GetPrincipal(nsIPrincipal** aPrincipal)
    38 {
    39   NS_IF_ADDREF(*aPrincipal = mPrincipal);
    41   return NS_OK;
    42 }
    44 NS_IMETHODIMP
    45 nsHostObjectURI::GetPrincipalUri(nsIURI** aUri)
    46 {
    47   if (mPrincipal) {
    48     mPrincipal->GetURI(aUri);
    49   }
    50   else {
    51     *aUri = nullptr;
    52   }
    54   return NS_OK;
    55 }
    57 // nsISerializable methods:
    59 NS_IMETHODIMP
    60 nsHostObjectURI::Read(nsIObjectInputStream* aStream)
    61 {
    62   nsresult rv = nsSimpleURI::Read(aStream);
    63   NS_ENSURE_SUCCESS(rv, rv);
    65   nsCOMPtr<nsISupports> supports;
    66   rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
    67   NS_ENSURE_SUCCESS(rv, rv);
    69   mPrincipal = do_QueryInterface(supports, &rv);
    70   return rv;
    71 }
    73 NS_IMETHODIMP
    74 nsHostObjectURI::Write(nsIObjectOutputStream* aStream)
    75 {
    76   nsresult rv = nsSimpleURI::Write(aStream);
    77   NS_ENSURE_SUCCESS(rv, rv);
    79   return NS_WriteOptionalCompoundObject(aStream, mPrincipal,
    80                                         NS_GET_IID(nsIPrincipal),
    81                                         true);
    82 }
    84 // nsIURI methods:
    85 nsresult
    86 nsHostObjectURI::CloneInternal(nsSimpleURI::RefHandlingEnum aRefHandlingMode,
    87                                nsIURI** aClone)
    88 {
    89   nsCOMPtr<nsIURI> simpleClone;
    90   nsresult rv =
    91     nsSimpleURI::CloneInternal(aRefHandlingMode, getter_AddRefs(simpleClone));
    92   NS_ENSURE_SUCCESS(rv, rv);
    94 #ifdef DEBUG
    95   nsRefPtr<nsHostObjectURI> uriCheck;
    96   rv = simpleClone->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(uriCheck));
    97   NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) && uriCheck,
    98 		    "Unexpected!");
    99 #endif
   101   nsHostObjectURI* u = static_cast<nsHostObjectURI*>(simpleClone.get());
   103   u->mPrincipal = mPrincipal;
   105   simpleClone.forget(aClone);
   106   return NS_OK;
   107 }
   109 /* virtual */ nsresult
   110 nsHostObjectURI::EqualsInternal(nsIURI* aOther,
   111                                 nsSimpleURI::RefHandlingEnum aRefHandlingMode,
   112                                 bool* aResult)
   113 {
   114   if (!aOther) {
   115     *aResult = false;
   116     return NS_OK;
   117   }
   119   nsRefPtr<nsHostObjectURI> otherUri;
   120   aOther->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(otherUri));
   121   if (!otherUri) {
   122     *aResult = false;
   123     return NS_OK;
   124   }
   126   // Compare the member data that our base class knows about.
   127   if (!nsSimpleURI::EqualsInternal(otherUri, aRefHandlingMode)) {
   128     *aResult = false;
   129     return NS_OK;
   130   }
   132   // Compare the piece of additional member data that we add to base class.
   133   if (mPrincipal && otherUri->mPrincipal) {
   134     // Both of us have mPrincipals. Compare them.
   135     return mPrincipal->Equals(otherUri->mPrincipal, aResult);
   136   }
   137   // else, at least one of us lacks a principal; only equal if *both* lack it.
   138   *aResult = (!mPrincipal && !otherUri->mPrincipal);
   139   return NS_OK;
   140 }
   142 // nsIClassInfo methods:
   143 NS_IMETHODIMP 
   144 nsHostObjectURI::GetInterfaces(uint32_t *count, nsIID * **array)
   145 {
   146   *count = 0;
   147   *array = nullptr;
   148   return NS_OK;
   149 }
   151 NS_IMETHODIMP 
   152 nsHostObjectURI::GetHelperForLanguage(uint32_t language, nsISupports **_retval)
   153 {
   154   *_retval = nullptr;
   155   return NS_OK;
   156 }
   158 NS_IMETHODIMP 
   159 nsHostObjectURI::GetContractID(char * *aContractID)
   160 {
   161   // Make sure to modify any subclasses as needed if this ever
   162   // changes.
   163   *aContractID = nullptr;
   164   return NS_OK;
   165 }
   167 NS_IMETHODIMP 
   168 nsHostObjectURI::GetClassDescription(char * *aClassDescription)
   169 {
   170   *aClassDescription = nullptr;
   171   return NS_OK;
   172 }
   174 NS_IMETHODIMP 
   175 nsHostObjectURI::GetClassID(nsCID * *aClassID)
   176 {
   177   // Make sure to modify any subclasses as needed if this ever
   178   // changes to not call the virtual GetClassIDNoAlloc.
   179   *aClassID = (nsCID*) nsMemory::Alloc(sizeof(nsCID));
   180   NS_ENSURE_TRUE(*aClassID, NS_ERROR_OUT_OF_MEMORY);
   182   return GetClassIDNoAlloc(*aClassID);
   183 }
   185 NS_IMETHODIMP 
   186 nsHostObjectURI::GetImplementationLanguage(uint32_t *aImplementationLanguage)
   187 {
   188   *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
   189   return NS_OK;
   190 }
   192 NS_IMETHODIMP 
   193 nsHostObjectURI::GetFlags(uint32_t *aFlags)
   194 {
   195   *aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
   196   return NS_OK;
   197 }
   199 NS_IMETHODIMP 
   200 nsHostObjectURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
   201 {
   202   *aClassIDNoAlloc = kHOSTOBJECTURICID;
   203   return NS_OK;
   204 }

mercurial