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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | #ifndef nsRDFBinding_h__ |
michael@0 | 7 | #define nsRDFBinding_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsAutoPtr.h" |
michael@0 | 10 | #include "nsIAtom.h" |
michael@0 | 11 | #include "nsIRDFResource.h" |
michael@0 | 12 | #include "nsISupportsImpl.h" |
michael@0 | 13 | |
michael@0 | 14 | class nsXULTemplateResultRDF; |
michael@0 | 15 | class nsBindingValues; |
michael@0 | 16 | |
michael@0 | 17 | /* |
michael@0 | 18 | * Classes related to storing bindings for RDF handling. |
michael@0 | 19 | */ |
michael@0 | 20 | |
michael@0 | 21 | /* |
michael@0 | 22 | * a <binding> descriptors |
michael@0 | 23 | */ |
michael@0 | 24 | class RDFBinding { |
michael@0 | 25 | |
michael@0 | 26 | public: |
michael@0 | 27 | |
michael@0 | 28 | nsCOMPtr<nsIAtom> mSubjectVariable; |
michael@0 | 29 | nsCOMPtr<nsIRDFResource> mPredicate; |
michael@0 | 30 | nsCOMPtr<nsIAtom> mTargetVariable; |
michael@0 | 31 | |
michael@0 | 32 | // indicates whether a binding is dependant on the result from a |
michael@0 | 33 | // previous binding |
michael@0 | 34 | bool mHasDependency; |
michael@0 | 35 | |
michael@0 | 36 | RDFBinding* mNext; |
michael@0 | 37 | |
michael@0 | 38 | private: |
michael@0 | 39 | |
michael@0 | 40 | friend class RDFBindingSet; |
michael@0 | 41 | |
michael@0 | 42 | RDFBinding(nsIAtom* aSubjectVariable, |
michael@0 | 43 | nsIRDFResource* aPredicate, |
michael@0 | 44 | nsIAtom* aTargetVariable) |
michael@0 | 45 | : mSubjectVariable(aSubjectVariable), |
michael@0 | 46 | mPredicate(aPredicate), |
michael@0 | 47 | mTargetVariable(aTargetVariable), |
michael@0 | 48 | mHasDependency(false), |
michael@0 | 49 | mNext(nullptr) |
michael@0 | 50 | { |
michael@0 | 51 | MOZ_COUNT_CTOR(RDFBinding); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | ~RDFBinding() |
michael@0 | 55 | { |
michael@0 | 56 | MOZ_COUNT_DTOR(RDFBinding); |
michael@0 | 57 | } |
michael@0 | 58 | }; |
michael@0 | 59 | |
michael@0 | 60 | /* |
michael@0 | 61 | * a collection of <binding> descriptors. This object is refcounted by |
michael@0 | 62 | * nsBindingValues objects and the query processor. |
michael@0 | 63 | */ |
michael@0 | 64 | class RDFBindingSet MOZ_FINAL |
michael@0 | 65 | { |
michael@0 | 66 | private: |
michael@0 | 67 | // Private destructor, to discourage deletion outside of Release(): |
michael@0 | 68 | ~RDFBindingSet(); |
michael@0 | 69 | |
michael@0 | 70 | // the number of bindings |
michael@0 | 71 | int32_t mCount; |
michael@0 | 72 | |
michael@0 | 73 | // pointer to the first binding in a linked list |
michael@0 | 74 | RDFBinding* mFirst; |
michael@0 | 75 | |
michael@0 | 76 | public: |
michael@0 | 77 | |
michael@0 | 78 | RDFBindingSet() |
michael@0 | 79 | : mCount(0), |
michael@0 | 80 | mFirst(nullptr) |
michael@0 | 81 | { |
michael@0 | 82 | MOZ_COUNT_CTOR(RDFBindingSet); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | NS_INLINE_DECL_REFCOUNTING(RDFBindingSet) |
michael@0 | 86 | |
michael@0 | 87 | int32_t Count() const { return mCount; } |
michael@0 | 88 | |
michael@0 | 89 | /* |
michael@0 | 90 | * Add a binding (aRef -> aPredicate -> aVar) to the set |
michael@0 | 91 | */ |
michael@0 | 92 | nsresult |
michael@0 | 93 | AddBinding(nsIAtom* aVar, nsIAtom* aRef, nsIRDFResource* aPredicate); |
michael@0 | 94 | |
michael@0 | 95 | /* |
michael@0 | 96 | * Return true if the binding set contains a binding which would cause |
michael@0 | 97 | * the result to need resynchronizing for an RDF triple. The member |
michael@0 | 98 | * variable may be supplied as an optimization since bindings most |
michael@0 | 99 | * commonly use the member variable as the subject. If aMemberVariable |
michael@0 | 100 | * is set, aSubject must be the value of the member variable for the |
michael@0 | 101 | * result. The supplied binding values aBindingValues must be values |
michael@0 | 102 | * using this binding set (that is aBindingValues->GetBindingSet() == this) |
michael@0 | 103 | * |
michael@0 | 104 | * @param aSubject subject of the RDF triple |
michael@0 | 105 | * @param aPredicate predicate of the RDF triple |
michael@0 | 106 | * @param aTarget target of the RDF triple |
michael@0 | 107 | * @param aMemberVariable member variable for the query for the binding |
michael@0 | 108 | * @param aResult result to synchronize |
michael@0 | 109 | * @param aBindingValues the values for the bindings for the result |
michael@0 | 110 | */ |
michael@0 | 111 | bool |
michael@0 | 112 | SyncAssignments(nsIRDFResource* aSubject, |
michael@0 | 113 | nsIRDFResource* aPredicate, |
michael@0 | 114 | nsIRDFNode* aTarget, |
michael@0 | 115 | nsIAtom* aMemberVariable, |
michael@0 | 116 | nsXULTemplateResultRDF* aResult, |
michael@0 | 117 | nsBindingValues& aBindingValues); |
michael@0 | 118 | |
michael@0 | 119 | /* |
michael@0 | 120 | * The query processor maintains a map of subjects to an array of results. |
michael@0 | 121 | * This is used such that when a new assertion is added to the RDF graph, |
michael@0 | 122 | * the results associated with the subject of that triple may be checked |
michael@0 | 123 | * to see if their bindings have changed. The AddDependencies method adds |
michael@0 | 124 | * these subject dependencies to the map. |
michael@0 | 125 | */ |
michael@0 | 126 | void |
michael@0 | 127 | AddDependencies(nsIRDFResource* aSubject, |
michael@0 | 128 | nsXULTemplateResultRDF* aResult); |
michael@0 | 129 | |
michael@0 | 130 | /* |
michael@0 | 131 | * Remove the results from the dependencies map when results are deleted. |
michael@0 | 132 | */ |
michael@0 | 133 | void |
michael@0 | 134 | RemoveDependencies(nsIRDFResource* aSubject, |
michael@0 | 135 | nsXULTemplateResultRDF* aResult); |
michael@0 | 136 | |
michael@0 | 137 | /* |
michael@0 | 138 | * The nsBindingValues classes stores an array of values, one for each |
michael@0 | 139 | * target symbol that could be set by the bindings in the set. |
michael@0 | 140 | * LookupTargetIndex determines the index into the array for a given |
michael@0 | 141 | * target symbol. |
michael@0 | 142 | */ |
michael@0 | 143 | int32_t |
michael@0 | 144 | LookupTargetIndex(nsIAtom* aTargetVariable, RDFBinding** aBinding); |
michael@0 | 145 | }; |
michael@0 | 146 | |
michael@0 | 147 | /* |
michael@0 | 148 | * A set of values of bindings. This object is used once per result. |
michael@0 | 149 | * This stores a reference to the binding set and an array of node values. |
michael@0 | 150 | * Since the binding set is used once per query and the values are |
michael@0 | 151 | * used once per result, we reduce size by only storing the value array's |
michael@0 | 152 | * length in the binding set. This is possible since the array is always |
michael@0 | 153 | * a fixed length for a particular binding set. |
michael@0 | 154 | * |
michael@0 | 155 | * XXX ndeakin We may want to revisit this later since it makes the code |
michael@0 | 156 | * more complicated. |
michael@0 | 157 | */ |
michael@0 | 158 | class nsBindingValues |
michael@0 | 159 | { |
michael@0 | 160 | protected: |
michael@0 | 161 | |
michael@0 | 162 | // the binding set |
michael@0 | 163 | nsRefPtr<RDFBindingSet> mBindings; |
michael@0 | 164 | |
michael@0 | 165 | /* |
michael@0 | 166 | * A set of values for variable bindings. To look up a binding value, |
michael@0 | 167 | * scan through the binding set in mBindings for the right target atom. |
michael@0 | 168 | * Its index will correspond to the index in this array. The size of this |
michael@0 | 169 | * array is determined by the RDFBindingSet's Count(). |
michael@0 | 170 | */ |
michael@0 | 171 | nsCOMPtr<nsIRDFNode>* mValues; |
michael@0 | 172 | |
michael@0 | 173 | public: |
michael@0 | 174 | |
michael@0 | 175 | nsBindingValues() |
michael@0 | 176 | : mBindings(nullptr), |
michael@0 | 177 | mValues(nullptr) |
michael@0 | 178 | { |
michael@0 | 179 | MOZ_COUNT_CTOR(nsBindingValues); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | ~nsBindingValues(); |
michael@0 | 183 | |
michael@0 | 184 | |
michael@0 | 185 | /** |
michael@0 | 186 | * Clear the binding set, to be called when the nsBindingValues is deleted |
michael@0 | 187 | * or a new binding set is being set. |
michael@0 | 188 | */ |
michael@0 | 189 | void ClearBindingSet(); |
michael@0 | 190 | |
michael@0 | 191 | RDFBindingSet* GetBindingSet() { return mBindings; } |
michael@0 | 192 | |
michael@0 | 193 | /** |
michael@0 | 194 | * Set the binding set to use. This needs to be called once a rule matches |
michael@0 | 195 | * since it is then known which bindings will apply. |
michael@0 | 196 | */ |
michael@0 | 197 | nsresult SetBindingSet(RDFBindingSet* aBindings); |
michael@0 | 198 | |
michael@0 | 199 | nsCOMPtr<nsIRDFNode>* ValuesArray() { return mValues; } |
michael@0 | 200 | |
michael@0 | 201 | /* |
michael@0 | 202 | * Retrieve the assignment for a particular variable |
michael@0 | 203 | */ |
michael@0 | 204 | void |
michael@0 | 205 | GetAssignmentFor(nsXULTemplateResultRDF* aResult, |
michael@0 | 206 | nsIAtom* aVar, |
michael@0 | 207 | nsIRDFNode** aValue); |
michael@0 | 208 | |
michael@0 | 209 | /* |
michael@0 | 210 | * Remove depenedencies the bindings have on particular resources |
michael@0 | 211 | */ |
michael@0 | 212 | void |
michael@0 | 213 | RemoveDependencies(nsIRDFResource* aSubject, |
michael@0 | 214 | nsXULTemplateResultRDF* aResult); |
michael@0 | 215 | }; |
michael@0 | 216 | |
michael@0 | 217 | #endif // nsRDFBinding_h__ |