Tue, 06 Jan 2015 21:39:09 +0100
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.
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 #include "txExpr.h"
7 #include "nsIAtom.h"
8 #include "nsGkAtoms.h"
9 #include "txXPathTreeWalker.h"
10 #include "txIXPathContext.h"
12 txNameTest::txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, int32_t aNSID,
13 uint16_t aNodeType)
14 :mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID),
15 mNodeType(aNodeType)
16 {
17 if (aPrefix == nsGkAtoms::_empty)
18 mPrefix = 0;
19 NS_ASSERTION(aLocalName, "txNameTest without a local name?");
20 NS_ASSERTION(aNodeType == txXPathNodeType::DOCUMENT_NODE ||
21 aNodeType == txXPathNodeType::ELEMENT_NODE ||
22 aNodeType == txXPathNodeType::ATTRIBUTE_NODE,
23 "Go fix txNameTest::matches");
24 }
26 bool txNameTest::matches(const txXPathNode& aNode, txIMatchContext* aContext)
27 {
28 if ((mNodeType == txXPathNodeType::ELEMENT_NODE &&
29 !txXPathNodeUtils::isElement(aNode)) ||
30 (mNodeType == txXPathNodeType::ATTRIBUTE_NODE &&
31 !txXPathNodeUtils::isAttribute(aNode)) ||
32 (mNodeType == txXPathNodeType::DOCUMENT_NODE &&
33 !txXPathNodeUtils::isRoot(aNode))) {
34 return false;
35 }
37 // Totally wild?
38 if (mLocalName == nsGkAtoms::_asterix && !mPrefix)
39 return true;
41 // Compare namespaces
42 if (mNamespace != txXPathNodeUtils::getNamespaceID(aNode)
43 && !(mNamespace == kNameSpaceID_None &&
44 txXPathNodeUtils::isHTMLElementInHTMLDocument(aNode))
45 )
46 return false;
48 // Name wild?
49 if (mLocalName == nsGkAtoms::_asterix)
50 return true;
52 // Compare local-names
53 return txXPathNodeUtils::localNameEquals(aNode, mLocalName);
54 }
56 /*
57 * Returns the default priority of this txNodeTest
58 */
59 double txNameTest::getDefaultPriority()
60 {
61 if (mLocalName == nsGkAtoms::_asterix) {
62 if (!mPrefix)
63 return -0.5;
64 return -0.25;
65 }
66 return 0;
67 }
69 txNodeTest::NodeTestType
70 txNameTest::getType()
71 {
72 return NAME_TEST;
73 }
75 bool
76 txNameTest::isSensitiveTo(Expr::ContextSensitivity aContext)
77 {
78 return !!(aContext & Expr::NODE_CONTEXT);
79 }
81 #ifdef TX_TO_STRING
82 void
83 txNameTest::toString(nsAString& aDest)
84 {
85 if (mPrefix) {
86 nsAutoString prefix;
87 mPrefix->ToString(prefix);
88 aDest.Append(prefix);
89 aDest.Append(char16_t(':'));
90 }
91 nsAutoString localName;
92 mLocalName->ToString(localName);
93 aDest.Append(localName);
94 }
95 #endif