dom/quota/PersistenceType.h

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 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef mozilla_dom_quota_persistencetype_h__
     8 #define mozilla_dom_quota_persistencetype_h__
    10 #include "mozilla/dom/quota/QuotaCommon.h"
    12 #include "mozilla/dom/StorageTypeBinding.h"
    14 BEGIN_QUOTA_NAMESPACE
    16 enum PersistenceType
    17 {
    18   PERSISTENCE_TYPE_PERSISTENT = 0,
    19   PERSISTENCE_TYPE_TEMPORARY,
    21   // Only needed for IPC serialization helper, should never be used in code.
    22   PERSISTENCE_TYPE_INVALID
    23 };
    25 inline void
    26 PersistenceTypeToText(PersistenceType aPersistenceType, nsACString& aText)
    27 {
    28   switch (aPersistenceType) {
    29     case PERSISTENCE_TYPE_PERSISTENT:
    30       aText.AssignLiteral("persistent");
    31       return;
    32     case PERSISTENCE_TYPE_TEMPORARY:
    33       aText.AssignLiteral("temporary");
    34       return;
    36     case PERSISTENCE_TYPE_INVALID:
    37     default:
    38       MOZ_CRASH("Bad persistence type value!");
    39   }
    41   MOZ_ASSUME_UNREACHABLE("Should never get here!");
    42 }
    44 inline PersistenceType
    45 PersistenceTypeFromText(const nsACString& aText)
    46 {
    47   if (aText.EqualsLiteral("persistent")) {
    48     return PERSISTENCE_TYPE_PERSISTENT;
    49   }
    51   if (aText.EqualsLiteral("temporary")) {
    52     return PERSISTENCE_TYPE_TEMPORARY;
    53   }
    55   MOZ_ASSUME_UNREACHABLE("Should never get here!");
    56 }
    58 inline nsresult
    59 NullablePersistenceTypeFromText(const nsACString& aText,
    60                                 Nullable<PersistenceType> *aPersistenceType)
    61 {
    62   if (aText.IsVoid()) {
    63     *aPersistenceType = Nullable<PersistenceType>();
    64     return NS_OK;
    65   }
    67   if (aText.EqualsLiteral("persistent")) {
    68     *aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT);
    69     return NS_OK;
    70   }
    72   if (aText.EqualsLiteral("temporary")) {
    73     *aPersistenceType = Nullable<PersistenceType>(PERSISTENCE_TYPE_TEMPORARY);
    74     return NS_OK;
    75   }
    77   return NS_ERROR_UNEXPECTED;
    78 }
    80 inline mozilla::dom::StorageType
    81 PersistenceTypeToStorage(PersistenceType aPersistenceType)
    82 {
    83   return mozilla::dom::StorageType(static_cast<int>(aPersistenceType));
    84 }
    86 inline PersistenceType
    87 PersistenceTypeFromStorage(const Optional<mozilla::dom::StorageType>& aStorage,
    88                            PersistenceType aDefaultPersistenceType)
    89 {
    90   if (aStorage.WasPassed()) {
    91     return PersistenceType(static_cast<int>(aStorage.Value()));
    92   }
    94   return aDefaultPersistenceType;
    95 }
    97 END_QUOTA_NAMESPACE
    99 #endif // mozilla_dom_quota_persistencetype_h__

mercurial