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 #ifndef nsTemplateMatch_h__
7 #define nsTemplateMatch_h__
9 #include "nsIContent.h"
10 #include "nsIXULTemplateQueryProcessor.h"
11 #include "nsIXULTemplateResult.h"
12 #include "nsRuleNetwork.h"
14 /**
15 * A match object, where each match object is associated with one result.
16 * There will be one match list for each unique id generated. However, since
17 * there are multiple querysets and each may generate results with the same
18 * id, they are all chained together in a linked list, ordered in the same
19 * order as the respective <queryset> elements they were generated from.
20 * A match can be identified by the container and id. The id is retrievable
21 * from the result.
22 *
23 * Only one match per container and id pair is active at a time, but which
24 * match is active may change as new results are added or removed. When a
25 * match is active, content is generated for that match.
26 *
27 * Matches are stored and owned by the mMatchToMap hash in the template
28 * builder.
29 */
31 class nsTemplateRule;
32 class nsTemplateQuerySet;
34 class nsTemplateMatch {
35 private:
36 // Hide so that only Create() and Destroy() can be used to
37 // allocate and deallocate from the heap
38 void* operator new(size_t) CPP_THROW_NEW { MOZ_ASSERT(0); return nullptr; }
39 void operator delete(void*, size_t) { MOZ_ASSERT(0); }
41 public:
42 nsTemplateMatch(uint16_t aQuerySetPriority,
43 nsIXULTemplateResult* aResult,
44 nsIContent* aContainer)
45 : mRuleIndex(-1),
46 mQuerySetPriority(aQuerySetPriority),
47 mContainer(aContainer),
48 mResult(aResult),
49 mNext(nullptr)
50 {
51 MOZ_COUNT_CTOR(nsTemplateMatch);
52 }
54 ~nsTemplateMatch()
55 {
56 MOZ_COUNT_DTOR(nsTemplateMatch);
57 }
59 static nsTemplateMatch*
60 Create(uint16_t aQuerySetPriority,
61 nsIXULTemplateResult* aResult,
62 nsIContent* aContainer) {
63 return ::new nsTemplateMatch(aQuerySetPriority, aResult, aContainer);
64 }
66 static void Destroy(nsTemplateMatch*& aMatch, bool aRemoveResult);
68 // return true if the the match is active, and has generated output
69 bool IsActive() {
70 return mRuleIndex >= 0;
71 }
73 // indicate that a rule is no longer active, used when a query with a
74 // lower priority has overriden the match
75 void SetInactive() {
76 mRuleIndex = -1;
77 }
79 // return matching rule index
80 int16_t RuleIndex() {
81 return mRuleIndex;
82 }
84 // return priority of query set
85 uint16_t QuerySetPriority() {
86 return mQuerySetPriority;
87 }
89 // return container, not addrefed. May be null.
90 nsIContent* GetContainer() {
91 return mContainer;
92 }
94 nsresult RuleMatched(nsTemplateQuerySet* aQuerySet,
95 nsTemplateRule* aRule,
96 int16_t aRuleIndex,
97 nsIXULTemplateResult* aResult);
99 private:
101 /**
102 * The index of the rule that matched, or -1 if the match is not active.
103 */
104 int16_t mRuleIndex;
106 /**
107 * The priority of the queryset for this rule
108 */
109 uint16_t mQuerySetPriority;
111 /**
112 * The container the content generated for the match is inside.
113 */
114 nsCOMPtr<nsIContent> mContainer;
116 public:
118 /**
119 * The result associated with this match
120 */
121 nsCOMPtr<nsIXULTemplateResult> mResult;
123 /**
124 * Matches are stored in a linked list, in priority order. This first
125 * match that has a rule set (mRule) is the active match and generates
126 * content. The next match is owned by the builder, which will delete
127 * template matches when needed.
128 */
129 nsTemplateMatch *mNext;
131 private:
133 nsTemplateMatch(const nsTemplateMatch& aMatch); // not to be implemented
134 void operator=(const nsTemplateMatch& aMatch); // not to be implemented
135 };
137 #endif // nsTemplateMatch_h__