xpcom/ds/nsINIParserImpl.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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 "nsINIParserImpl.h"
     7 #include "nsINIParser.h"
     8 #include "nsStringEnumerator.h"
     9 #include "nsTArray.h"
    10 #include "mozilla/Attributes.h"
    12 class nsINIParserImpl MOZ_FINAL :
    13   public nsIINIParser
    14 {
    15 public:
    16   NS_DECL_ISUPPORTS
    17   NS_DECL_NSIINIPARSER
    19   nsresult Init(nsIFile* aINIFile) {
    20     return mParser.Init(aINIFile);
    21   }
    23 private:
    24   nsINIParser mParser;
    25 };
    27 NS_IMPL_ISUPPORTS(nsINIParserFactory,
    28                   nsIINIParserFactory,
    29                   nsIFactory)
    31 NS_IMETHODIMP
    32 nsINIParserFactory::CreateINIParser(nsIFile* aINIFile,
    33                                     nsIINIParser* *aResult)
    34 {
    35   *aResult = nullptr;
    37   nsRefPtr<nsINIParserImpl> p(new nsINIParserImpl());
    38   if (!p)
    39     return NS_ERROR_OUT_OF_MEMORY;
    41   nsresult rv = p->Init(aINIFile);
    43   if (NS_SUCCEEDED(rv))
    44     NS_ADDREF(*aResult = p);
    46   return rv;
    47 }
    49 NS_IMETHODIMP
    50 nsINIParserFactory::CreateInstance(nsISupports* aOuter,
    51                                    REFNSIID aIID,
    52                                    void **aResult)
    53 {
    54   if (NS_WARN_IF(aOuter))
    55     return NS_ERROR_NO_AGGREGATION;
    57   // We are our own singleton.
    58   return QueryInterface(aIID, aResult);
    59 }
    61 NS_IMETHODIMP
    62 nsINIParserFactory::LockFactory(bool aLock)
    63 {
    64   return NS_OK;
    65 }
    67 NS_IMPL_ISUPPORTS(nsINIParserImpl,
    68                   nsIINIParser)
    70 static bool
    71 SectionCB(const char* aSection, void *aClosure)
    72 {
    73   nsTArray<nsCString> *strings = static_cast<nsTArray<nsCString>*>(aClosure);
    75   strings->AppendElement(nsDependentCString(aSection));
    76   return true;
    77 }
    79 NS_IMETHODIMP
    80 nsINIParserImpl::GetSections(nsIUTF8StringEnumerator* *aResult)
    81 {
    82   nsTArray<nsCString> *strings = new nsTArray<nsCString>;
    83   if (!strings)
    84     return NS_ERROR_OUT_OF_MEMORY;
    86   nsresult rv = mParser.GetSections(SectionCB, strings);
    87   if (NS_SUCCEEDED(rv))
    88     rv = NS_NewAdoptingUTF8StringEnumerator(aResult, strings);
    90   if (NS_FAILED(rv))
    91     delete strings;
    93   return rv;
    94 }
    96 static bool
    97 KeyCB(const char* aKey, const char *aValue, void *aClosure)
    98 {
    99   nsTArray<nsCString> *strings = static_cast<nsTArray<nsCString>*>(aClosure);
   101   strings->AppendElement(nsDependentCString(aKey));
   102   return true;
   103 }
   105 NS_IMETHODIMP
   106 nsINIParserImpl::GetKeys(const nsACString& aSection,
   107                          nsIUTF8StringEnumerator* *aResult)
   108 {
   109   nsTArray<nsCString> *strings = new nsTArray<nsCString>;
   110   if (!strings)
   111     return NS_ERROR_OUT_OF_MEMORY;
   113   nsresult rv = mParser.GetStrings(PromiseFlatCString(aSection).get(),
   114                                    KeyCB, strings);
   115   if (NS_SUCCEEDED(rv))
   116     rv = NS_NewAdoptingUTF8StringEnumerator(aResult, strings);
   118   if (NS_FAILED(rv))
   119     delete strings;
   121   return rv;
   123 }
   125 NS_IMETHODIMP
   126 nsINIParserImpl::GetString(const nsACString& aSection,
   127                            const nsACString& aKey,
   128                            nsACString& aResult)
   129 {
   130   return mParser.GetString(PromiseFlatCString(aSection).get(),
   131                            PromiseFlatCString(aKey).get(),
   132                            aResult);
   133 }

mercurial