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.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsXULTemplateResultRDF.h"
7 #include "nsXULContentUtils.h"
9 // XXXndeakin for some reason, making this class have classinfo breaks trees.
10 //#include "nsIDOMClassInfo.h"
12 NS_IMPL_CYCLE_COLLECTION(nsXULTemplateResultRDF, mQuery)
14 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULTemplateResultRDF)
15 NS_INTERFACE_MAP_ENTRY(nsIXULTemplateResult)
16 NS_INTERFACE_MAP_ENTRY(nsISupports)
17 NS_INTERFACE_MAP_END
19 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULTemplateResultRDF)
20 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULTemplateResultRDF)
22 nsXULTemplateResultRDF::nsXULTemplateResultRDF(nsIRDFResource* aNode)
23 : mQuery(nullptr),
24 mNode(aNode)
25 {
26 }
28 nsXULTemplateResultRDF::nsXULTemplateResultRDF(nsRDFQuery* aQuery,
29 const Instantiation& aInst,
30 nsIRDFResource *aNode)
31 : mQuery(aQuery),
32 mNode(aNode),
33 mInst(aInst)
34 {
35 }
37 nsXULTemplateResultRDF::~nsXULTemplateResultRDF()
38 {
39 }
41 NS_IMETHODIMP
42 nsXULTemplateResultRDF::GetIsContainer(bool* aIsContainer)
43 {
44 *aIsContainer = false;
46 if (mNode) {
47 nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
48 if (processor)
49 return processor->CheckContainer(mNode, aIsContainer);
50 }
52 return NS_OK;
53 }
55 NS_IMETHODIMP
56 nsXULTemplateResultRDF::GetIsEmpty(bool* aIsEmpty)
57 {
58 *aIsEmpty = true;
60 if (mNode) {
61 nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
62 if (processor)
63 return processor->CheckEmpty(mNode, aIsEmpty);
64 }
66 return NS_OK;
67 }
69 NS_IMETHODIMP
70 nsXULTemplateResultRDF::GetMayProcessChildren(bool* aMayProcessChildren)
71 {
72 // RDF always allows recursion
73 *aMayProcessChildren = true;
74 return NS_OK;
75 }
77 NS_IMETHODIMP
78 nsXULTemplateResultRDF::GetId(nsAString& aId)
79 {
80 if (! mNode)
81 return NS_ERROR_FAILURE;
83 const char* uri;
84 mNode->GetValueConst(&uri);
86 CopyUTF8toUTF16(uri, aId);
88 return NS_OK;
89 }
91 NS_IMETHODIMP
92 nsXULTemplateResultRDF::GetResource(nsIRDFResource** aResource)
93 {
94 *aResource = mNode;
95 NS_IF_ADDREF(*aResource);
96 return NS_OK;
97 }
99 NS_IMETHODIMP
100 nsXULTemplateResultRDF::GetType(nsAString& aType)
101 {
102 aType.Truncate();
104 nsresult rv = NS_OK;
106 nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
107 if (processor) {
108 bool found;
109 rv = processor->CheckIsSeparator(mNode, &found);
110 if (NS_SUCCEEDED(rv) && found)
111 aType.AssignLiteral("separator");
112 }
114 return rv;
115 }
117 NS_IMETHODIMP
118 nsXULTemplateResultRDF::GetBindingFor(nsIAtom* aVar, nsAString& aValue)
119 {
120 nsCOMPtr<nsIRDFNode> val;
121 GetAssignment(aVar, getter_AddRefs(val));
123 return nsXULContentUtils::GetTextForNode(val, aValue);
124 }
126 NS_IMETHODIMP
127 nsXULTemplateResultRDF::GetBindingObjectFor(nsIAtom* aVar, nsISupports** aValue)
128 {
129 GetAssignment(aVar, (nsIRDFNode **)aValue);
131 return NS_OK;
132 }
134 NS_IMETHODIMP
135 nsXULTemplateResultRDF::RuleMatched(nsISupports* aQuery, nsIDOMNode* aRuleNode)
136 {
137 // when a rule matches, set the bindings that must be used.
138 nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
139 if (processor) {
140 RDFBindingSet* bindings = processor->GetBindingsForRule(aRuleNode);
141 if (bindings) {
142 nsresult rv = mBindingValues.SetBindingSet(bindings);
143 if (NS_FAILED(rv))
144 return rv;
146 bindings->AddDependencies(mNode, this);
147 }
148 }
150 return NS_OK;
151 }
153 NS_IMETHODIMP
154 nsXULTemplateResultRDF::HasBeenRemoved()
155 {
156 // when a result is no longer used, clean up the dependencies and
157 // memory elements that refer to it
158 mBindingValues.RemoveDependencies(mNode, this);
160 nsXULTemplateQueryProcessorRDF* processor = GetProcessor();
161 if (processor)
162 processor->RemoveMemoryElements(mInst, this);
164 return NS_OK;
165 }
168 void
169 nsXULTemplateResultRDF::GetAssignment(nsIAtom* aVar, nsIRDFNode** aValue)
170 {
171 // look up a variable in the assignments map
172 *aValue = nullptr;
173 mInst.mAssignments.GetAssignmentFor(aVar, aValue);
175 // if not found, look up the variable in the bindings
176 if (! *aValue)
177 mBindingValues.GetAssignmentFor(this, aVar, aValue);
178 }
181 bool
182 nsXULTemplateResultRDF::SyncAssignments(nsIRDFResource* aSubject,
183 nsIRDFResource* aPredicate,
184 nsIRDFNode* aTarget)
185 {
186 // synchronize the bindings when an assertion is added or removed
187 RDFBindingSet* bindingset = mBindingValues.GetBindingSet();
188 if (bindingset) {
189 return bindingset->SyncAssignments(aSubject, aPredicate, aTarget,
190 (aSubject == mNode) ? mQuery->GetMemberVariable() : nullptr,
191 this, mBindingValues);
192 }
194 return false;
195 }
197 bool
198 nsXULTemplateResultRDF::HasMemoryElement(const MemoryElement& aMemoryElement)
199 {
200 MemoryElementSet::ConstIterator last = mInst.mSupport.Last();
201 for (MemoryElementSet::ConstIterator element = mInst.mSupport.First();
202 element != last; ++element) {
203 if ((*element).Equals(aMemoryElement))
204 return true;
205 }
207 return false;
208 }