dom/xbl/XBLChildrenElement.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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

mercurial