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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | #include "nsISupports.idl" |
michael@0 | 6 | |
michael@0 | 7 | %{C++ |
michael@0 | 8 | #include "nsStringGlue.h" |
michael@0 | 9 | #include "nsCOMPtr.h" |
michael@0 | 10 | #include "nsStringBuffer.h" |
michael@0 | 11 | %} |
michael@0 | 12 | |
michael@0 | 13 | /* |
michael@0 | 14 | * Should this really be scriptable? Using atoms from script or proxies |
michael@0 | 15 | * could be dangerous since double-wrapping could lead to loss of |
michael@0 | 16 | * pointer identity. |
michael@0 | 17 | */ |
michael@0 | 18 | |
michael@0 | 19 | [scriptable, builtinclass, uuid(1f341018-521a-49de-b806-1bef5c9a00b0)] |
michael@0 | 20 | interface nsIAtom : nsISupports |
michael@0 | 21 | { |
michael@0 | 22 | /** |
michael@0 | 23 | * Get the Unicode or UTF8 value for the string |
michael@0 | 24 | */ |
michael@0 | 25 | [binaryname(ScriptableToString)] AString toString(); |
michael@0 | 26 | [noscript] AUTF8String toUTF8String(); |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * Compare the atom to a specific string value |
michael@0 | 30 | * Note that this will NEVER return/throw an error condition. |
michael@0 | 31 | */ |
michael@0 | 32 | [binaryname(ScriptableEquals)] boolean equals(in AString aString); |
michael@0 | 33 | |
michael@0 | 34 | [noscript, notxpcom] boolean equalsUTF8(in AUTF8String aString); |
michael@0 | 35 | |
michael@0 | 36 | /** |
michael@0 | 37 | * Returns true if the atom is static and false otherwise. |
michael@0 | 38 | */ |
michael@0 | 39 | [noscript, notxpcom] boolean isStaticAtom(); |
michael@0 | 40 | |
michael@0 | 41 | %{C++ |
michael@0 | 42 | // note this is NOT virtual so this won't muck with the vtable! |
michael@0 | 43 | inline bool Equals(const nsAString& aString) const { |
michael@0 | 44 | return aString.Equals(nsDependentString(mString, mLength)); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | inline char16ptr_t GetUTF16String() const { |
michael@0 | 48 | return mString; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | inline const uint32_t GetLength() const { |
michael@0 | 52 | return mLength; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | inline void ToString(nsAString& aBuf) { |
michael@0 | 56 | nsStringBuffer::FromData(mString)->ToString(mLength, aBuf); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | inline nsStringBuffer* GetStringBuffer() const { |
michael@0 | 60 | return nsStringBuffer::FromData(mString); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * A hashcode that is better distributed than the actual atom |
michael@0 | 65 | * pointer, for use in situations that need a well-distributed |
michael@0 | 66 | * hashcode. |
michael@0 | 67 | */ |
michael@0 | 68 | inline uint32_t hash() const { |
michael@0 | 69 | return mHash; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | protected: |
michael@0 | 73 | uint32_t mLength; |
michael@0 | 74 | uint32_t mHash; |
michael@0 | 75 | char16_t* mString; |
michael@0 | 76 | %} |
michael@0 | 77 | }; |
michael@0 | 78 | |
michael@0 | 79 | |
michael@0 | 80 | %{C++ |
michael@0 | 81 | /* |
michael@0 | 82 | * The three forms of NS_NewAtom and do_GetAtom (for use with |
michael@0 | 83 | * |nsCOMPtr<nsIAtom>|) return the atom for the string given. At any |
michael@0 | 84 | * given time there will always be one atom representing a given string. |
michael@0 | 85 | * Atoms are intended to make string comparison cheaper by simplifying |
michael@0 | 86 | * it to pointer equality. A pointer to the atom that does not own a |
michael@0 | 87 | * reference is not guaranteed to be valid. |
michael@0 | 88 | * |
michael@0 | 89 | * The three forms of NS_NewPermanentAtom and do_GetPermanentAtom return |
michael@0 | 90 | * the atom for the given string and ensure that the atom is permanent. |
michael@0 | 91 | * An atom that is permanent will exist (occupy space at a specific |
michael@0 | 92 | * location in memory) until XPCOM is shut down. The advantage of |
michael@0 | 93 | * permanent atoms is that they do not need to maintain a reference |
michael@0 | 94 | * count, which requires locking and hurts performance. |
michael@0 | 95 | */ |
michael@0 | 96 | |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * Find an atom that matches the given UTF-8 string. |
michael@0 | 100 | * The string is assumed to be zero terminated. Never returns null. |
michael@0 | 101 | */ |
michael@0 | 102 | extern already_AddRefed<nsIAtom> NS_NewAtom(const char* aUTF8String); |
michael@0 | 103 | |
michael@0 | 104 | inline already_AddRefed<nsIAtom> do_GetAtom(const char* aUTF8String) |
michael@0 | 105 | { return NS_NewAtom(aUTF8String); } |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * Find an atom that matches the given UTF-8 string. Never returns null. |
michael@0 | 109 | */ |
michael@0 | 110 | extern already_AddRefed<nsIAtom> NS_NewAtom(const nsACString& aUTF8String); |
michael@0 | 111 | inline already_AddRefed<nsIAtom> do_GetAtom(const nsACString& aUTF8String) |
michael@0 | 112 | { return NS_NewAtom(aUTF8String); } |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * Find an atom that matches the given UTF-16 string. |
michael@0 | 116 | * The string is assumed to be zero terminated. Never returns null. |
michael@0 | 117 | */ |
michael@0 | 118 | extern already_AddRefed<nsIAtom> NS_NewAtom(const char16_t* aUTF16String); |
michael@0 | 119 | inline already_AddRefed<nsIAtom> do_GetAtom(const char16_t* aUTF16String) |
michael@0 | 120 | { return NS_NewAtom(aUTF16String); } |
michael@0 | 121 | |
michael@0 | 122 | /** |
michael@0 | 123 | * Find an atom that matches the given UTF-16 string. Never returns null. |
michael@0 | 124 | */ |
michael@0 | 125 | extern already_AddRefed<nsIAtom> NS_NewAtom(const nsAString& aUTF16String); |
michael@0 | 126 | extern nsIAtom* NS_NewPermanentAtom(const nsAString& aUTF16String); |
michael@0 | 127 | inline already_AddRefed<nsIAtom> do_GetAtom(const nsAString& aUTF16String) |
michael@0 | 128 | { return NS_NewAtom(aUTF16String); } |
michael@0 | 129 | |
michael@0 | 130 | /** |
michael@0 | 131 | * Return a count of the total number of atoms currently |
michael@0 | 132 | * alive in the system. |
michael@0 | 133 | */ |
michael@0 | 134 | extern nsrefcnt NS_GetNumberOfAtoms(void); |
michael@0 | 135 | |
michael@0 | 136 | /** |
michael@0 | 137 | * Return a pointer for a static atom for the string or null if there's |
michael@0 | 138 | * no static atom for this string. |
michael@0 | 139 | */ |
michael@0 | 140 | extern nsIAtom* NS_GetStaticAtom(const nsAString& aUTF16String); |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * Seal the static atom table |
michael@0 | 144 | */ |
michael@0 | 145 | extern void NS_SealStaticAtomTable(); |
michael@0 | 146 | |
michael@0 | 147 | class nsAtomString : public nsString |
michael@0 | 148 | { |
michael@0 | 149 | public: |
michael@0 | 150 | nsAtomString(nsIAtom* aAtom) |
michael@0 | 151 | { |
michael@0 | 152 | aAtom->ToString(*this); |
michael@0 | 153 | } |
michael@0 | 154 | }; |
michael@0 | 155 | |
michael@0 | 156 | class nsAtomCString : public nsCString |
michael@0 | 157 | { |
michael@0 | 158 | public: |
michael@0 | 159 | nsAtomCString(nsIAtom* aAtom) |
michael@0 | 160 | { |
michael@0 | 161 | aAtom->ToUTF8String(*this); |
michael@0 | 162 | } |
michael@0 | 163 | }; |
michael@0 | 164 | |
michael@0 | 165 | class nsDependentAtomString : public nsDependentString |
michael@0 | 166 | { |
michael@0 | 167 | public: |
michael@0 | 168 | nsDependentAtomString(nsIAtom* aAtom) |
michael@0 | 169 | : nsDependentString(aAtom->GetUTF16String(), aAtom->GetLength()) |
michael@0 | 170 | { |
michael@0 | 171 | } |
michael@0 | 172 | }; |
michael@0 | 173 | |
michael@0 | 174 | %} |