dom/xslt/xpath/txNodeTypeTest.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.

     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 "txIXPathContext.h"
     9 #include "txXPathTreeWalker.h"
    11 bool txNodeTypeTest::matches(const txXPathNode& aNode,
    12                                txIMatchContext* aContext)
    13 {
    14     switch (mNodeType) {
    15         case COMMENT_TYPE:
    16         {
    17             return txXPathNodeUtils::isComment(aNode);
    18         }
    19         case TEXT_TYPE:
    20         {
    21             return txXPathNodeUtils::isText(aNode) &&
    22                    !aContext->isStripSpaceAllowed(aNode);
    23         }
    24         case PI_TYPE:
    25         {
    26             return txXPathNodeUtils::isProcessingInstruction(aNode) &&
    27                    (!mNodeName ||
    28                     txXPathNodeUtils::localNameEquals(aNode, mNodeName));
    29         }
    30         case NODE_TYPE:
    31         {
    32             return !txXPathNodeUtils::isText(aNode) ||
    33                    !aContext->isStripSpaceAllowed(aNode);
    34         }
    35     }
    36     return true;
    37 }
    39 txNodeTest::NodeTestType
    40 txNodeTypeTest::getType()
    41 {
    42     return NODETYPE_TEST;
    43 }
    45 /*
    46  * Returns the default priority of this txNodeTest
    47  */
    48 double txNodeTypeTest::getDefaultPriority()
    49 {
    50     return mNodeName ? 0 : -0.5;
    51 }
    53 bool
    54 txNodeTypeTest::isSensitiveTo(Expr::ContextSensitivity aContext)
    55 {
    56     return !!(aContext & Expr::NODE_CONTEXT);
    57 }
    59 #ifdef TX_TO_STRING
    60 void
    61 txNodeTypeTest::toString(nsAString& aDest)
    62 {
    63     switch (mNodeType) {
    64         case COMMENT_TYPE:
    65             aDest.Append(NS_LITERAL_STRING("comment()"));
    66             break;
    67         case TEXT_TYPE:
    68             aDest.Append(NS_LITERAL_STRING("text()"));
    69             break;
    70         case PI_TYPE:
    71             aDest.AppendLiteral("processing-instruction(");
    72             if (mNodeName) {
    73                 nsAutoString str;
    74                 mNodeName->ToString(str);
    75                 aDest.Append(char16_t('\''));
    76                 aDest.Append(str);
    77                 aDest.Append(char16_t('\''));
    78             }
    79             aDest.Append(char16_t(')'));
    80             break;
    81         case NODE_TYPE:
    82             aDest.Append(NS_LITERAL_STRING("node()"));
    83             break;
    84     }
    85 }
    86 #endif

mercurial