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 | #include "nsXULTemplateResultRDF.h" |
michael@0 | 7 | #include "nsXULContentUtils.h" |
michael@0 | 8 | |
michael@0 | 9 | // XXXndeakin for some reason, making this class have classinfo breaks trees. |
michael@0 | 10 | //#include "nsIDOMClassInfo.h" |
michael@0 | 11 | |
michael@0 | 12 | NS_IMPL_CYCLE_COLLECTION(nsXULTemplateResultRDF, mQuery) |
michael@0 | 13 | |
michael@0 | 14 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULTemplateResultRDF) |
michael@0 | 15 | NS_INTERFACE_MAP_ENTRY(nsIXULTemplateResult) |
michael@0 | 16 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
michael@0 | 17 | NS_INTERFACE_MAP_END |
michael@0 | 18 | |
michael@0 | 19 | NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULTemplateResultRDF) |
michael@0 | 20 | NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULTemplateResultRDF) |
michael@0 | 21 | |
michael@0 | 22 | nsXULTemplateResultRDF::nsXULTemplateResultRDF(nsIRDFResource* aNode) |
michael@0 | 23 | : mQuery(nullptr), |
michael@0 | 24 | mNode(aNode) |
michael@0 | 25 | { |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | nsXULTemplateResultRDF::nsXULTemplateResultRDF(nsRDFQuery* aQuery, |
michael@0 | 29 | const Instantiation& aInst, |
michael@0 | 30 | nsIRDFResource *aNode) |
michael@0 | 31 | : mQuery(aQuery), |
michael@0 | 32 | mNode(aNode), |
michael@0 | 33 | mInst(aInst) |
michael@0 | 34 | { |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | nsXULTemplateResultRDF::~nsXULTemplateResultRDF() |
michael@0 | 38 | { |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | NS_IMETHODIMP |
michael@0 | 42 | nsXULTemplateResultRDF::GetIsContainer(bool* aIsContainer) |
michael@0 | 43 | { |
michael@0 | 44 | *aIsContainer = false; |
michael@0 | 45 | |
michael@0 | 46 | if (mNode) { |
michael@0 | 47 | nsXULTemplateQueryProcessorRDF* processor = GetProcessor(); |
michael@0 | 48 | if (processor) |
michael@0 | 49 | return processor->CheckContainer(mNode, aIsContainer); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | return NS_OK; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | NS_IMETHODIMP |
michael@0 | 56 | nsXULTemplateResultRDF::GetIsEmpty(bool* aIsEmpty) |
michael@0 | 57 | { |
michael@0 | 58 | *aIsEmpty = true; |
michael@0 | 59 | |
michael@0 | 60 | if (mNode) { |
michael@0 | 61 | nsXULTemplateQueryProcessorRDF* processor = GetProcessor(); |
michael@0 | 62 | if (processor) |
michael@0 | 63 | return processor->CheckEmpty(mNode, aIsEmpty); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | return NS_OK; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | NS_IMETHODIMP |
michael@0 | 70 | nsXULTemplateResultRDF::GetMayProcessChildren(bool* aMayProcessChildren) |
michael@0 | 71 | { |
michael@0 | 72 | // RDF always allows recursion |
michael@0 | 73 | *aMayProcessChildren = true; |
michael@0 | 74 | return NS_OK; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | NS_IMETHODIMP |
michael@0 | 78 | nsXULTemplateResultRDF::GetId(nsAString& aId) |
michael@0 | 79 | { |
michael@0 | 80 | if (! mNode) |
michael@0 | 81 | return NS_ERROR_FAILURE; |
michael@0 | 82 | |
michael@0 | 83 | const char* uri; |
michael@0 | 84 | mNode->GetValueConst(&uri); |
michael@0 | 85 | |
michael@0 | 86 | CopyUTF8toUTF16(uri, aId); |
michael@0 | 87 | |
michael@0 | 88 | return NS_OK; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | NS_IMETHODIMP |
michael@0 | 92 | nsXULTemplateResultRDF::GetResource(nsIRDFResource** aResource) |
michael@0 | 93 | { |
michael@0 | 94 | *aResource = mNode; |
michael@0 | 95 | NS_IF_ADDREF(*aResource); |
michael@0 | 96 | return NS_OK; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | NS_IMETHODIMP |
michael@0 | 100 | nsXULTemplateResultRDF::GetType(nsAString& aType) |
michael@0 | 101 | { |
michael@0 | 102 | aType.Truncate(); |
michael@0 | 103 | |
michael@0 | 104 | nsresult rv = NS_OK; |
michael@0 | 105 | |
michael@0 | 106 | nsXULTemplateQueryProcessorRDF* processor = GetProcessor(); |
michael@0 | 107 | if (processor) { |
michael@0 | 108 | bool found; |
michael@0 | 109 | rv = processor->CheckIsSeparator(mNode, &found); |
michael@0 | 110 | if (NS_SUCCEEDED(rv) && found) |
michael@0 | 111 | aType.AssignLiteral("separator"); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | return rv; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | NS_IMETHODIMP |
michael@0 | 118 | nsXULTemplateResultRDF::GetBindingFor(nsIAtom* aVar, nsAString& aValue) |
michael@0 | 119 | { |
michael@0 | 120 | nsCOMPtr<nsIRDFNode> val; |
michael@0 | 121 | GetAssignment(aVar, getter_AddRefs(val)); |
michael@0 | 122 | |
michael@0 | 123 | return nsXULContentUtils::GetTextForNode(val, aValue); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | NS_IMETHODIMP |
michael@0 | 127 | nsXULTemplateResultRDF::GetBindingObjectFor(nsIAtom* aVar, nsISupports** aValue) |
michael@0 | 128 | { |
michael@0 | 129 | GetAssignment(aVar, (nsIRDFNode **)aValue); |
michael@0 | 130 | |
michael@0 | 131 | return NS_OK; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | NS_IMETHODIMP |
michael@0 | 135 | nsXULTemplateResultRDF::RuleMatched(nsISupports* aQuery, nsIDOMNode* aRuleNode) |
michael@0 | 136 | { |
michael@0 | 137 | // when a rule matches, set the bindings that must be used. |
michael@0 | 138 | nsXULTemplateQueryProcessorRDF* processor = GetProcessor(); |
michael@0 | 139 | if (processor) { |
michael@0 | 140 | RDFBindingSet* bindings = processor->GetBindingsForRule(aRuleNode); |
michael@0 | 141 | if (bindings) { |
michael@0 | 142 | nsresult rv = mBindingValues.SetBindingSet(bindings); |
michael@0 | 143 | if (NS_FAILED(rv)) |
michael@0 | 144 | return rv; |
michael@0 | 145 | |
michael@0 | 146 | bindings->AddDependencies(mNode, this); |
michael@0 | 147 | } |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | return NS_OK; |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | NS_IMETHODIMP |
michael@0 | 154 | nsXULTemplateResultRDF::HasBeenRemoved() |
michael@0 | 155 | { |
michael@0 | 156 | // when a result is no longer used, clean up the dependencies and |
michael@0 | 157 | // memory elements that refer to it |
michael@0 | 158 | mBindingValues.RemoveDependencies(mNode, this); |
michael@0 | 159 | |
michael@0 | 160 | nsXULTemplateQueryProcessorRDF* processor = GetProcessor(); |
michael@0 | 161 | if (processor) |
michael@0 | 162 | processor->RemoveMemoryElements(mInst, this); |
michael@0 | 163 | |
michael@0 | 164 | return NS_OK; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | |
michael@0 | 168 | void |
michael@0 | 169 | nsXULTemplateResultRDF::GetAssignment(nsIAtom* aVar, nsIRDFNode** aValue) |
michael@0 | 170 | { |
michael@0 | 171 | // look up a variable in the assignments map |
michael@0 | 172 | *aValue = nullptr; |
michael@0 | 173 | mInst.mAssignments.GetAssignmentFor(aVar, aValue); |
michael@0 | 174 | |
michael@0 | 175 | // if not found, look up the variable in the bindings |
michael@0 | 176 | if (! *aValue) |
michael@0 | 177 | mBindingValues.GetAssignmentFor(this, aVar, aValue); |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | |
michael@0 | 181 | bool |
michael@0 | 182 | nsXULTemplateResultRDF::SyncAssignments(nsIRDFResource* aSubject, |
michael@0 | 183 | nsIRDFResource* aPredicate, |
michael@0 | 184 | nsIRDFNode* aTarget) |
michael@0 | 185 | { |
michael@0 | 186 | // synchronize the bindings when an assertion is added or removed |
michael@0 | 187 | RDFBindingSet* bindingset = mBindingValues.GetBindingSet(); |
michael@0 | 188 | if (bindingset) { |
michael@0 | 189 | return bindingset->SyncAssignments(aSubject, aPredicate, aTarget, |
michael@0 | 190 | (aSubject == mNode) ? mQuery->GetMemberVariable() : nullptr, |
michael@0 | 191 | this, mBindingValues); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | return false; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | bool |
michael@0 | 198 | nsXULTemplateResultRDF::HasMemoryElement(const MemoryElement& aMemoryElement) |
michael@0 | 199 | { |
michael@0 | 200 | MemoryElementSet::ConstIterator last = mInst.mSupport.Last(); |
michael@0 | 201 | for (MemoryElementSet::ConstIterator element = mInst.mSupport.First(); |
michael@0 | 202 | element != last; ++element) { |
michael@0 | 203 | if ((*element).Equals(aMemoryElement)) |
michael@0 | 204 | return true; |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | return false; |
michael@0 | 208 | } |