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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=79: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsXBLChildrenElement_h___
8 #define nsXBLChildrenElement_h___
10 #include "nsIDOMElement.h"
11 #include "nsINodeList.h"
12 #include "nsBindingManager.h"
13 #include "mozilla/dom/nsXMLElement.h"
15 class nsAnonymousContentList;
17 namespace mozilla {
18 namespace dom {
20 class ExplicitChildIterator;
22 class XBLChildrenElement : public nsXMLElement
23 {
24 public:
25 friend class mozilla::dom::ExplicitChildIterator;
26 friend class nsAnonymousContentList;
27 XBLChildrenElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
28 : nsXMLElement(aNodeInfo)
29 {
30 }
31 XBLChildrenElement(already_AddRefed<nsINodeInfo>&& aNodeInfo)
32 : nsXMLElement(aNodeInfo)
33 {
34 }
35 ~XBLChildrenElement();
37 // nsISupports
38 NS_DECL_ISUPPORTS_INHERITED
40 // nsINode interface methods
41 virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
43 virtual nsXPCClassInfo* GetClassInfo() { return nullptr; }
45 virtual nsIDOMNode* AsDOMNode() { return this; }
47 // nsIContent interface methods
48 virtual nsIAtom *GetIDAttributeName() const;
49 virtual nsIAtom* DoGetID() const;
50 virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
51 bool aNotify);
52 virtual bool ParseAttribute(int32_t aNamespaceID,
53 nsIAtom* aAttribute,
54 const nsAString& aValue,
55 nsAttrValue& aResult);
57 void AppendInsertedChild(nsIContent* aChild)
58 {
59 mInsertedChildren.AppendElement(aChild);
60 aChild->SetXBLInsertionParent(GetParent());
61 }
63 void InsertInsertedChildAt(nsIContent* aChild, uint32_t aIndex)
64 {
65 mInsertedChildren.InsertElementAt(aIndex, aChild);
66 aChild->SetXBLInsertionParent(GetParent());
67 }
69 void RemoveInsertedChild(nsIContent* aChild)
70 {
71 // Can't use this assertion as we cheat for dynamic insertions and
72 // only insert in the innermost insertion point.
73 //NS_ASSERTION(mInsertedChildren.Contains(aChild),
74 // "Removing child that's not there");
75 mInsertedChildren.RemoveElement(aChild);
76 }
78 void ClearInsertedChildren()
79 {
80 for (uint32_t c = 0; c < mInsertedChildren.Length(); ++c) {
81 mInsertedChildren[c]->SetXBLInsertionParent(nullptr);
82 }
83 mInsertedChildren.Clear();
84 }
86 void MaybeSetupDefaultContent()
87 {
88 if (!HasInsertedChildren()) {
89 for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
90 child;
91 child = child->GetNextSibling()) {
92 child->SetXBLInsertionParent(GetParent());
93 }
94 }
95 }
97 void MaybeRemoveDefaultContent()
98 {
99 if (!HasInsertedChildren()) {
100 for (nsIContent* child = static_cast<nsINode*>(this)->GetFirstChild();
101 child;
102 child = child->GetNextSibling()) {
103 child->SetXBLInsertionParent(nullptr);
104 }
105 }
106 }
108 uint32_t InsertedChildrenLength()
109 {
110 return mInsertedChildren.Length();
111 }
113 bool HasInsertedChildren()
114 {
115 return !mInsertedChildren.IsEmpty();
116 }
118 enum {
119 NoIndex = uint32_t(-1)
120 };
121 uint32_t IndexOfInsertedChild(nsIContent* aChild)
122 {
123 return mInsertedChildren.IndexOf(aChild);
124 }
126 bool Includes(nsIContent* aChild)
127 {
128 NS_ASSERTION(!mIncludes.IsEmpty(),
129 "Shouldn't check for includes on default insertion point");
130 return mIncludes.Contains(aChild->Tag());
131 }
133 bool IsDefaultInsertion()
134 {
135 return mIncludes.IsEmpty();
136 }
138 nsTArray<nsIContent*> mInsertedChildren;
140 private:
141 nsTArray<nsCOMPtr<nsIAtom> > mIncludes;
142 };
144 } // namespace dom
145 } // namespace mozilla
147 class nsAnonymousContentList : public nsINodeList
148 {
149 public:
150 nsAnonymousContentList(nsIContent* aParent)
151 : mParent(aParent)
152 {
153 MOZ_COUNT_CTOR(nsAnonymousContentList);
154 SetIsDOMBinding();
155 }
157 virtual ~nsAnonymousContentList()
158 {
159 MOZ_COUNT_DTOR(nsAnonymousContentList);
160 }
162 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
163 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsAnonymousContentList)
164 // nsIDOMNodeList interface
165 NS_DECL_NSIDOMNODELIST
167 // nsINodeList interface
168 virtual int32_t IndexOf(nsIContent* aContent);
169 virtual nsINode* GetParentObject() { return mParent; }
170 virtual nsIContent* Item(uint32_t aIndex);
172 virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
174 bool IsListFor(nsIContent* aContent) {
175 return mParent == aContent;
176 }
178 private:
179 nsCOMPtr<nsIContent> mParent;
180 };
182 #endif // nsXBLChildrenElement_h___