Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 | |
michael@0 | 6 | /* atom list for CSS pseudo-elements */ |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/ArrayUtils.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "nsCSSPseudoElements.h" |
michael@0 | 11 | #include "nsAtomListUtils.h" |
michael@0 | 12 | #include "nsStaticAtom.h" |
michael@0 | 13 | #include "nsCSSAnonBoxes.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla; |
michael@0 | 16 | |
michael@0 | 17 | // define storage for all atoms |
michael@0 | 18 | #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ |
michael@0 | 19 | nsICSSPseudoElement* nsCSSPseudoElements::name_; |
michael@0 | 20 | #include "nsCSSPseudoElementList.h" |
michael@0 | 21 | #undef CSS_PSEUDO_ELEMENT |
michael@0 | 22 | |
michael@0 | 23 | #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ |
michael@0 | 24 | NS_STATIC_ATOM_BUFFER(name_##_pseudo_element_buffer, value_) |
michael@0 | 25 | #include "nsCSSPseudoElementList.h" |
michael@0 | 26 | #undef CSS_PSEUDO_ELEMENT |
michael@0 | 27 | |
michael@0 | 28 | static const nsStaticAtom CSSPseudoElements_info[] = { |
michael@0 | 29 | #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ |
michael@0 | 30 | NS_STATIC_ATOM(name_##_pseudo_element_buffer, (nsIAtom**)&nsCSSPseudoElements::name_), |
michael@0 | 31 | #include "nsCSSPseudoElementList.h" |
michael@0 | 32 | #undef CSS_PSEUDO_ELEMENT |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | // Separate from the array above so that we can have an array of |
michael@0 | 36 | // nsStaticAtom (to pass to NS_RegisterStaticAtoms and |
michael@0 | 37 | // nsAtomListUtils::IsMember), but with corresponding indices (so the |
michael@0 | 38 | // i-th element of this array is the flags for the i-th pseudo-element |
michael@0 | 39 | // in the previous array). |
michael@0 | 40 | static const uint32_t CSSPseudoElements_flags[] = { |
michael@0 | 41 | #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ |
michael@0 | 42 | flags_, |
michael@0 | 43 | #include "nsCSSPseudoElementList.h" |
michael@0 | 44 | #undef CSS_PSEUDO_ELEMENT |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | void nsCSSPseudoElements::AddRefAtoms() |
michael@0 | 48 | { |
michael@0 | 49 | NS_RegisterStaticAtoms(CSSPseudoElements_info); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | bool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom) |
michael@0 | 53 | { |
michael@0 | 54 | return nsAtomListUtils::IsMember(aAtom, CSSPseudoElements_info, |
michael@0 | 55 | ArrayLength(CSSPseudoElements_info)); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | /* static */ bool |
michael@0 | 59 | nsCSSPseudoElements::IsCSS2PseudoElement(nsIAtom *aAtom) |
michael@0 | 60 | { |
michael@0 | 61 | // We don't implement this using PseudoElementHasFlags because callers |
michael@0 | 62 | // want to pass things that could be anon boxes. |
michael@0 | 63 | NS_ASSERTION(nsCSSPseudoElements::IsPseudoElement(aAtom) || |
michael@0 | 64 | nsCSSAnonBoxes::IsAnonBox(aAtom), |
michael@0 | 65 | "must be pseudo element or anon box"); |
michael@0 | 66 | bool result = aAtom == nsCSSPseudoElements::after || |
michael@0 | 67 | aAtom == nsCSSPseudoElements::before || |
michael@0 | 68 | aAtom == nsCSSPseudoElements::firstLetter || |
michael@0 | 69 | aAtom == nsCSSPseudoElements::firstLine; |
michael@0 | 70 | NS_ASSERTION(nsCSSAnonBoxes::IsAnonBox(aAtom) || |
michael@0 | 71 | result == |
michael@0 | 72 | PseudoElementHasFlags(GetPseudoType(aAtom), CSS_PSEUDO_ELEMENT_IS_CSS2), |
michael@0 | 73 | "result doesn't match flags"); |
michael@0 | 74 | return result; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | /* static */ nsCSSPseudoElements::Type |
michael@0 | 78 | nsCSSPseudoElements::GetPseudoType(nsIAtom *aAtom) |
michael@0 | 79 | { |
michael@0 | 80 | for (uint32_t i = 0; i < ArrayLength(CSSPseudoElements_info); ++i) { |
michael@0 | 81 | if (*CSSPseudoElements_info[i].mAtom == aAtom) { |
michael@0 | 82 | return Type(i); |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | if (nsCSSAnonBoxes::IsAnonBox(aAtom)) { |
michael@0 | 87 | #ifdef MOZ_XUL |
michael@0 | 88 | if (nsCSSAnonBoxes::IsTreePseudoElement(aAtom)) { |
michael@0 | 89 | return ePseudo_XULTree; |
michael@0 | 90 | } |
michael@0 | 91 | #endif |
michael@0 | 92 | |
michael@0 | 93 | return ePseudo_AnonBox; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | return ePseudo_NotPseudoElement; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | /* static */ nsIAtom* |
michael@0 | 100 | nsCSSPseudoElements::GetPseudoAtom(Type aType) |
michael@0 | 101 | { |
michael@0 | 102 | NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount, |
michael@0 | 103 | "Unexpected type"); |
michael@0 | 104 | return *CSSPseudoElements_info[aType].mAtom; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | /* static */ uint32_t |
michael@0 | 108 | nsCSSPseudoElements::FlagsForPseudoElement(const Type aType) |
michael@0 | 109 | { |
michael@0 | 110 | size_t index = static_cast<size_t>(aType); |
michael@0 | 111 | NS_ASSERTION(index < ArrayLength(CSSPseudoElements_flags), |
michael@0 | 112 | "argument must be a pseudo-element"); |
michael@0 | 113 | return CSSPseudoElements_flags[index]; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | /* static */ bool |
michael@0 | 117 | nsCSSPseudoElements::PseudoElementSupportsUserActionState(const Type aType) |
michael@0 | 118 | { |
michael@0 | 119 | return PseudoElementHasFlags(aType, |
michael@0 | 120 | CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE); |
michael@0 | 121 | } |