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 /**
7 * An XML Utility class
8 **/
10 #ifndef MITRE_XMLUTILS_H
11 #define MITRE_XMLUTILS_H
13 #include "txCore.h"
14 #include "nsCOMPtr.h"
15 #include "nsDependentSubstring.h"
16 #include "nsIAtom.h"
17 #include "txXPathNode.h"
19 #define kExpatSeparatorChar 0xFFFF
21 extern "C" int MOZ_XMLIsLetter(const char* ptr);
22 extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
24 class nsIAtom;
25 class txNamespaceMap;
27 class txExpandedName {
28 public:
29 txExpandedName() : mNamespaceID(kNameSpaceID_None)
30 {
31 }
33 txExpandedName(int32_t aNsID,
34 nsIAtom* aLocalName) : mNamespaceID(aNsID),
35 mLocalName(aLocalName)
36 {
37 }
39 txExpandedName(const txExpandedName& aOther) :
40 mNamespaceID(aOther.mNamespaceID),
41 mLocalName(aOther.mLocalName)
42 {
43 }
45 nsresult init(const nsAString& aQName, txNamespaceMap* aResolver,
46 bool aUseDefault);
48 void reset()
49 {
50 mNamespaceID = kNameSpaceID_None;
51 mLocalName = nullptr;
52 }
54 bool isNull()
55 {
56 return mNamespaceID == kNameSpaceID_None && !mLocalName;
57 }
59 txExpandedName& operator = (const txExpandedName& rhs)
60 {
61 mNamespaceID = rhs.mNamespaceID;
62 mLocalName = rhs.mLocalName;
63 return *this;
64 }
66 bool operator == (const txExpandedName& rhs) const
67 {
68 return ((mLocalName == rhs.mLocalName) &&
69 (mNamespaceID == rhs.mNamespaceID));
70 }
72 bool operator != (const txExpandedName& rhs) const
73 {
74 return ((mLocalName != rhs.mLocalName) ||
75 (mNamespaceID != rhs.mNamespaceID));
76 }
78 int32_t mNamespaceID;
79 nsCOMPtr<nsIAtom> mLocalName;
80 };
82 class XMLUtils {
84 public:
85 static nsresult splitExpatName(const char16_t *aExpatName,
86 nsIAtom **aPrefix, nsIAtom **aLocalName,
87 int32_t* aNameSpaceID);
88 static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix,
89 nsIAtom** aLocalName);
91 /*
92 * Returns true if the given character is whitespace.
93 */
94 static bool isWhitespace(const char16_t& aChar)
95 {
96 return (aChar <= ' ' &&
97 (aChar == ' ' || aChar == '\r' ||
98 aChar == '\n'|| aChar == '\t'));
99 }
101 /**
102 * Returns true if the given string has only whitespace characters
103 */
104 static bool isWhitespace(const nsAFlatString& aText);
106 /**
107 * Normalizes the value of a XML processingInstruction
108 **/
109 static void normalizePIValue(nsAString& attValue);
111 /**
112 * Returns true if the given string is a valid XML QName
113 */
114 static bool isValidQName(const nsAFlatString& aQName,
115 const char16_t** aColon);
117 /**
118 * Returns true if the given character represents an Alpha letter
119 */
120 static bool isLetter(char16_t aChar)
121 {
122 return !!MOZ_XMLIsLetter(reinterpret_cast<const char*>(&aChar));
123 }
125 /**
126 * Returns true if the given character is an allowable NCName character
127 */
128 static bool isNCNameChar(char16_t aChar)
129 {
130 return !!MOZ_XMLIsNCNameChar(reinterpret_cast<const char*>(&aChar));
131 }
133 /*
134 * Walks up the document tree and returns true if the closest xml:space
135 * attribute is "preserve"
136 */
137 static bool getXMLSpacePreserve(const txXPathNode& aNode);
138 };
140 #endif