dom/xbl/XBLChildrenElement.cpp

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 #include "mozilla/dom/XBLChildrenElement.h"
michael@0 8 #include "nsCharSeparatedTokenizer.h"
michael@0 9 #include "mozilla/dom/NodeListBinding.h"
michael@0 10
michael@0 11 namespace mozilla {
michael@0 12 namespace dom {
michael@0 13
michael@0 14 XBLChildrenElement::~XBLChildrenElement()
michael@0 15 {
michael@0 16 }
michael@0 17
michael@0 18 NS_IMPL_ADDREF_INHERITED(XBLChildrenElement, Element)
michael@0 19 NS_IMPL_RELEASE_INHERITED(XBLChildrenElement, Element)
michael@0 20
michael@0 21 NS_INTERFACE_TABLE_HEAD(XBLChildrenElement)
michael@0 22 NS_INTERFACE_TABLE_INHERITED(XBLChildrenElement, nsIDOMNode,
michael@0 23 nsIDOMElement)
michael@0 24 NS_ELEMENT_INTERFACE_TABLE_TO_MAP_SEGUE
michael@0 25 NS_INTERFACE_MAP_END_INHERITING(Element)
michael@0 26
michael@0 27 NS_IMPL_ELEMENT_CLONE(XBLChildrenElement)
michael@0 28
michael@0 29 nsIAtom*
michael@0 30 XBLChildrenElement::GetIDAttributeName() const
michael@0 31 {
michael@0 32 return nullptr;
michael@0 33 }
michael@0 34
michael@0 35 nsIAtom*
michael@0 36 XBLChildrenElement::DoGetID() const
michael@0 37 {
michael@0 38 return nullptr;
michael@0 39 }
michael@0 40
michael@0 41 nsresult
michael@0 42 XBLChildrenElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
michael@0 43 bool aNotify)
michael@0 44 {
michael@0 45 if (aAttribute == nsGkAtoms::includes &&
michael@0 46 aNameSpaceID == kNameSpaceID_None) {
michael@0 47 mIncludes.Clear();
michael@0 48 }
michael@0 49
michael@0 50 return Element::UnsetAttr(aNameSpaceID, aAttribute, aNotify);
michael@0 51 }
michael@0 52
michael@0 53 bool
michael@0 54 XBLChildrenElement::ParseAttribute(int32_t aNamespaceID,
michael@0 55 nsIAtom* aAttribute,
michael@0 56 const nsAString& aValue,
michael@0 57 nsAttrValue& aResult)
michael@0 58 {
michael@0 59 if (aAttribute == nsGkAtoms::includes &&
michael@0 60 aNamespaceID == kNameSpaceID_None) {
michael@0 61 mIncludes.Clear();
michael@0 62 nsCharSeparatedTokenizer tok(aValue, '|',
michael@0 63 nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
michael@0 64 while (tok.hasMoreTokens()) {
michael@0 65 nsCOMPtr<nsIAtom> atom = do_GetAtom(tok.nextToken());
michael@0 66 mIncludes.AppendElement(atom);
michael@0 67 }
michael@0 68 }
michael@0 69
michael@0 70 return false;
michael@0 71 }
michael@0 72
michael@0 73 } // namespace mozilla
michael@0 74 } // namespace dom
michael@0 75
michael@0 76 using namespace mozilla::dom;
michael@0 77
michael@0 78 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsAnonymousContentList, mParent)
michael@0 79
michael@0 80 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsAnonymousContentList)
michael@0 81 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsAnonymousContentList)
michael@0 82
michael@0 83 NS_INTERFACE_TABLE_HEAD(nsAnonymousContentList)
michael@0 84 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
michael@0 85 NS_INTERFACE_TABLE_INHERITED(nsAnonymousContentList, nsINodeList,
michael@0 86 nsIDOMNodeList)
michael@0 87 NS_INTERFACE_TABLE_TO_MAP_SEGUE
michael@0 88 NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsAnonymousContentList)
michael@0 89 NS_INTERFACE_MAP_ENTRY(nsISupports)
michael@0 90 NS_INTERFACE_MAP_END
michael@0 91
michael@0 92 NS_IMETHODIMP
michael@0 93 nsAnonymousContentList::GetLength(uint32_t* aLength)
michael@0 94 {
michael@0 95 if (!mParent) {
michael@0 96 *aLength = 0;
michael@0 97 return NS_OK;
michael@0 98 }
michael@0 99
michael@0 100 uint32_t count = 0;
michael@0 101 for (nsIContent* child = mParent->GetFirstChild();
michael@0 102 child;
michael@0 103 child = child->GetNextSibling()) {
michael@0 104 if (child->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) {
michael@0 105 XBLChildrenElement* point = static_cast<XBLChildrenElement*>(child);
michael@0 106 if (!point->mInsertedChildren.IsEmpty()) {
michael@0 107 count += point->mInsertedChildren.Length();
michael@0 108 }
michael@0 109 else {
michael@0 110 count += point->GetChildCount();
michael@0 111 }
michael@0 112 }
michael@0 113 else {
michael@0 114 ++count;
michael@0 115 }
michael@0 116 }
michael@0 117
michael@0 118 *aLength = count;
michael@0 119
michael@0 120 return NS_OK;
michael@0 121 }
michael@0 122
michael@0 123 NS_IMETHODIMP
michael@0 124 nsAnonymousContentList::Item(uint32_t aIndex, nsIDOMNode** aReturn)
michael@0 125 {
michael@0 126 nsIContent* item = Item(aIndex);
michael@0 127 if (!item) {
michael@0 128 return NS_ERROR_FAILURE;
michael@0 129 }
michael@0 130
michael@0 131 return CallQueryInterface(item, aReturn);
michael@0 132 }
michael@0 133
michael@0 134 nsIContent*
michael@0 135 nsAnonymousContentList::Item(uint32_t aIndex)
michael@0 136 {
michael@0 137 if (!mParent) {
michael@0 138 return nullptr;
michael@0 139 }
michael@0 140
michael@0 141 uint32_t remIndex = aIndex;
michael@0 142 for (nsIContent* child = mParent->GetFirstChild();
michael@0 143 child;
michael@0 144 child = child->GetNextSibling()) {
michael@0 145 if (child->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) {
michael@0 146 XBLChildrenElement* point = static_cast<XBLChildrenElement*>(child);
michael@0 147 if (!point->mInsertedChildren.IsEmpty()) {
michael@0 148 if (remIndex < point->mInsertedChildren.Length()) {
michael@0 149 return point->mInsertedChildren[remIndex];
michael@0 150 }
michael@0 151 remIndex -= point->mInsertedChildren.Length();
michael@0 152 }
michael@0 153 else {
michael@0 154 if (remIndex < point->GetChildCount()) {
michael@0 155 return point->GetChildAt(remIndex);
michael@0 156 }
michael@0 157 remIndex -= point->GetChildCount();
michael@0 158 }
michael@0 159 }
michael@0 160 else {
michael@0 161 if (remIndex == 0) {
michael@0 162 return child;
michael@0 163 }
michael@0 164 --remIndex;
michael@0 165 }
michael@0 166 }
michael@0 167
michael@0 168 return nullptr;
michael@0 169 }
michael@0 170
michael@0 171 int32_t
michael@0 172 nsAnonymousContentList::IndexOf(nsIContent* aContent)
michael@0 173 {
michael@0 174 NS_ASSERTION(!aContent->NodeInfo()->Equals(nsGkAtoms::children,
michael@0 175 kNameSpaceID_XBL),
michael@0 176 "Looking for insertion point");
michael@0 177
michael@0 178 if (!mParent) {
michael@0 179 return -1;
michael@0 180 }
michael@0 181
michael@0 182 uint32_t index = 0;
michael@0 183 for (nsIContent* child = mParent->GetFirstChild();
michael@0 184 child;
michael@0 185 child = child->GetNextSibling()) {
michael@0 186 if (child->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) {
michael@0 187 XBLChildrenElement* point = static_cast<XBLChildrenElement*>(child);
michael@0 188 if (!point->mInsertedChildren.IsEmpty()) {
michael@0 189 uint32_t insIndex = point->mInsertedChildren.IndexOf(aContent);
michael@0 190 if (insIndex != point->mInsertedChildren.NoIndex) {
michael@0 191 return index + insIndex;
michael@0 192 }
michael@0 193 index += point->mInsertedChildren.Length();
michael@0 194 }
michael@0 195 else {
michael@0 196 int32_t insIndex = point->IndexOf(aContent);
michael@0 197 if (insIndex != -1) {
michael@0 198 return index + (uint32_t)insIndex;
michael@0 199 }
michael@0 200 index += point->GetChildCount();
michael@0 201 }
michael@0 202 }
michael@0 203 else {
michael@0 204 if (child == aContent) {
michael@0 205 return index;
michael@0 206 }
michael@0 207 ++index;
michael@0 208 }
michael@0 209 }
michael@0 210
michael@0 211 return -1;
michael@0 212 }
michael@0 213
michael@0 214 JSObject*
michael@0 215 nsAnonymousContentList::WrapObject(JSContext *cx)
michael@0 216 {
michael@0 217 return mozilla::dom::NodeListBinding::Wrap(cx, this);
michael@0 218 }

mercurial