dom/xslt/xpath/txNodeSetAdaptor.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "txNodeSetAdaptor.h"
michael@0 7 #include "txXPathTreeWalker.h"
michael@0 8
michael@0 9 txNodeSetAdaptor::txNodeSetAdaptor()
michael@0 10 : txXPathObjectAdaptor(),
michael@0 11 mWritable(true)
michael@0 12 {
michael@0 13 }
michael@0 14
michael@0 15 txNodeSetAdaptor::txNodeSetAdaptor(txNodeSet *aNodeSet)
michael@0 16 : txXPathObjectAdaptor(aNodeSet),
michael@0 17 mWritable(false)
michael@0 18 {
michael@0 19 }
michael@0 20
michael@0 21 NS_IMPL_ISUPPORTS_INHERITED(txNodeSetAdaptor, txXPathObjectAdaptor, txINodeSet)
michael@0 22
michael@0 23 nsresult
michael@0 24 txNodeSetAdaptor::Init()
michael@0 25 {
michael@0 26 if (!mValue) {
michael@0 27 mValue = new txNodeSet(nullptr);
michael@0 28 }
michael@0 29
michael@0 30 return mValue ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
michael@0 31 }
michael@0 32
michael@0 33 NS_IMETHODIMP
michael@0 34 txNodeSetAdaptor::Item(uint32_t aIndex, nsIDOMNode **aResult)
michael@0 35 {
michael@0 36 *aResult = nullptr;
michael@0 37
michael@0 38 if (aIndex > (uint32_t)NodeSet()->size()) {
michael@0 39 return NS_ERROR_ILLEGAL_VALUE;
michael@0 40 }
michael@0 41
michael@0 42 return txXPathNativeNode::getNode(NodeSet()->get(aIndex), aResult);
michael@0 43 }
michael@0 44
michael@0 45 NS_IMETHODIMP
michael@0 46 txNodeSetAdaptor::ItemAsNumber(uint32_t aIndex, double *aResult)
michael@0 47 {
michael@0 48 if (aIndex > (uint32_t)NodeSet()->size()) {
michael@0 49 return NS_ERROR_ILLEGAL_VALUE;
michael@0 50 }
michael@0 51
michael@0 52 nsAutoString result;
michael@0 53 txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), result);
michael@0 54
michael@0 55 *aResult = txDouble::toDouble(result);
michael@0 56
michael@0 57 return NS_OK;
michael@0 58 }
michael@0 59
michael@0 60 NS_IMETHODIMP
michael@0 61 txNodeSetAdaptor::ItemAsString(uint32_t aIndex, nsAString &aResult)
michael@0 62 {
michael@0 63 if (aIndex > (uint32_t)NodeSet()->size()) {
michael@0 64 return NS_ERROR_ILLEGAL_VALUE;
michael@0 65 }
michael@0 66
michael@0 67 txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), aResult);
michael@0 68
michael@0 69 return NS_OK;
michael@0 70 }
michael@0 71
michael@0 72 NS_IMETHODIMP
michael@0 73 txNodeSetAdaptor::GetLength(uint32_t *aLength)
michael@0 74 {
michael@0 75 *aLength = (uint32_t)NodeSet()->size();
michael@0 76
michael@0 77 return NS_OK;
michael@0 78 }
michael@0 79
michael@0 80 NS_IMETHODIMP
michael@0 81 txNodeSetAdaptor::Add(nsIDOMNode *aNode)
michael@0 82 {
michael@0 83 NS_ENSURE_TRUE(mWritable, NS_ERROR_FAILURE);
michael@0 84
michael@0 85 nsAutoPtr<txXPathNode> node(txXPathNativeNode::createXPathNode(aNode,
michael@0 86 true));
michael@0 87
michael@0 88 return node ? NodeSet()->add(*node) : NS_ERROR_OUT_OF_MEMORY;
michael@0 89 }

mercurial