Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ |
michael@0 | 2 | /* vim: set ts=2 sw=2 et tw=79: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_dom_Nullable_h |
michael@0 | 8 | #define mozilla_dom_Nullable_h |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/Assertions.h" |
michael@0 | 11 | #include "nsTArrayForwardDeclare.h" |
michael@0 | 12 | #include "mozilla/Move.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | namespace dom { |
michael@0 | 16 | |
michael@0 | 17 | // Support for nullable types |
michael@0 | 18 | template <typename T> |
michael@0 | 19 | struct Nullable |
michael@0 | 20 | { |
michael@0 | 21 | private: |
michael@0 | 22 | // mIsNull MUST COME FIRST because otherwise the casting in our array |
michael@0 | 23 | // conversion operators would shift where it is found in the struct. |
michael@0 | 24 | bool mIsNull; |
michael@0 | 25 | T mValue; |
michael@0 | 26 | |
michael@0 | 27 | public: |
michael@0 | 28 | Nullable() |
michael@0 | 29 | : mIsNull(true) |
michael@0 | 30 | {} |
michael@0 | 31 | |
michael@0 | 32 | explicit Nullable(T aValue) |
michael@0 | 33 | : mIsNull(false) |
michael@0 | 34 | , mValue(aValue) |
michael@0 | 35 | {} |
michael@0 | 36 | |
michael@0 | 37 | explicit Nullable(Nullable<T>&& aOther) |
michael@0 | 38 | : mIsNull(aOther.mIsNull) |
michael@0 | 39 | , mValue(mozilla::Move(aOther.mValue)) |
michael@0 | 40 | {} |
michael@0 | 41 | |
michael@0 | 42 | Nullable(const Nullable<T>& aOther) |
michael@0 | 43 | : mIsNull(aOther.mIsNull) |
michael@0 | 44 | , mValue(aOther.mValue) |
michael@0 | 45 | {} |
michael@0 | 46 | |
michael@0 | 47 | void operator=(const Nullable<T>& aOther) |
michael@0 | 48 | { |
michael@0 | 49 | mIsNull = aOther.mIsNull; |
michael@0 | 50 | mValue = aOther.mValue; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | void SetValue(T aValue) { |
michael@0 | 54 | mValue = aValue; |
michael@0 | 55 | mIsNull = false; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | // For cases when |T| is some type with nontrivial copy behavior, we may want |
michael@0 | 59 | // to get a reference to our internal copy of T and work with it directly |
michael@0 | 60 | // instead of relying on the copying version of SetValue(). |
michael@0 | 61 | T& SetValue() { |
michael@0 | 62 | mIsNull = false; |
michael@0 | 63 | return mValue; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | void SetNull() { |
michael@0 | 67 | mIsNull = true; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | const T& Value() const { |
michael@0 | 71 | MOZ_ASSERT(!mIsNull); |
michael@0 | 72 | return mValue; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | T& Value() { |
michael@0 | 76 | MOZ_ASSERT(!mIsNull); |
michael@0 | 77 | return mValue; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | bool IsNull() const { |
michael@0 | 81 | return mIsNull; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | bool Equals(const Nullable<T>& aOtherNullable) const |
michael@0 | 85 | { |
michael@0 | 86 | return (mIsNull && aOtherNullable.mIsNull) || |
michael@0 | 87 | (!mIsNull && !aOtherNullable.mIsNull && |
michael@0 | 88 | mValue == aOtherNullable.mValue); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | bool operator==(const Nullable<T>& aOtherNullable) const |
michael@0 | 92 | { |
michael@0 | 93 | return Equals(aOtherNullable); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | bool operator!=(const Nullable<T>& aOtherNullable) const |
michael@0 | 97 | { |
michael@0 | 98 | return !Equals(aOtherNullable); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | // Make it possible to use a const Nullable of an array type with other |
michael@0 | 102 | // array types. |
michael@0 | 103 | template<typename U> |
michael@0 | 104 | operator const Nullable< nsTArray<U> >&() const { |
michael@0 | 105 | // Make sure that T is ok to reinterpret to nsTArray<U> |
michael@0 | 106 | const nsTArray<U>& arr = mValue; |
michael@0 | 107 | (void)arr; |
michael@0 | 108 | return *reinterpret_cast<const Nullable< nsTArray<U> >*>(this); |
michael@0 | 109 | } |
michael@0 | 110 | template<typename U> |
michael@0 | 111 | operator const Nullable< FallibleTArray<U> >&() const { |
michael@0 | 112 | // Make sure that T is ok to reinterpret to FallibleTArray<U> |
michael@0 | 113 | const FallibleTArray<U>& arr = mValue; |
michael@0 | 114 | (void)arr; |
michael@0 | 115 | return *reinterpret_cast<const Nullable< FallibleTArray<U> >*>(this); |
michael@0 | 116 | } |
michael@0 | 117 | }; |
michael@0 | 118 | |
michael@0 | 119 | } // namespace dom |
michael@0 | 120 | } // namespace mozilla |
michael@0 | 121 | |
michael@0 | 122 | #endif /* mozilla_dom_Nullable_h */ |