tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

txIXPathContext.h (3988B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      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/. */
      5 
      6 #ifndef __TX_I_XPATH_CONTEXT
      7 #define __TX_I_XPATH_CONTEXT
      8 
      9 #include "nsISupportsImpl.h"
     10 #include "nsStringFwd.h"
     11 #include "nscore.h"
     12 
     13 class FunctionCall;
     14 class nsAtom;
     15 class txAExprResult;
     16 class txResultRecycler;
     17 class txXPathNode;
     18 
     19 /*
     20 * txIParseContext
     21 *
     22 * This interface describes the context needed to create
     23 * XPath Expressions and XSLT Patters.
     24 * (not completely though. key() requires the ProcessorState, which is
     25 * not part of this interface.)
     26 */
     27 
     28 class txIParseContext {
     29 public:
     30  virtual ~txIParseContext() = default;
     31 
     32  /*
     33   * Return a namespaceID for a given prefix.
     34   */
     35  virtual int32_t resolveNamespacePrefix(nsAtom* aPrefix) = 0;
     36 
     37  /*
     38   * Create a FunctionCall, needed for extension function calls and
     39   * XSLT. XPath function calls are resolved by the Parser.
     40   */
     41  virtual nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
     42                                       FunctionCall** aFunction) = 0;
     43 
     44  /**
     45   * Should nametests parsed in this context be case-sensitive
     46   */
     47  virtual bool caseInsensitiveNameTests() = 0;
     48 
     49  /*
     50   * Callback to be used by the Parser if errors are detected.
     51   */
     52  virtual void SetErrorOffset(uint32_t aOffset) = 0;
     53 
     54  enum Allowed { KEY_FUNCTION = 1 << 0 };
     55  virtual bool allowed(Allowed aAllowed) { return true; }
     56 };
     57 
     58 /*
     59 * txIMatchContext
     60 *
     61 * Interface used for matching XSLT Patters.
     62 * This is the part of txIEvalContext (see below), that is independent
     63 * of the context node when evaluating a XPath expression, too.
     64 * When evaluating a XPath expression, |txIMatchContext|s are used
     65 * to transport the information from Step to Step.
     66 */
     67 class txIMatchContext {
     68 public:
     69  virtual ~txIMatchContext() = default;
     70 
     71  /*
     72   * Return the ExprResult associated with the variable with the
     73   * given namespace and local name.
     74   */
     75  virtual nsresult getVariable(int32_t aNamespace, nsAtom* aLName,
     76                               txAExprResult*& aResult) = 0;
     77 
     78  /*
     79   * Is whitespace stripping allowed for the given node?
     80   * See http://www.w3.org/TR/xslt#strip
     81   */
     82  virtual nsresult isStripSpaceAllowed(const txXPathNode& aNode,
     83                                       bool& aAllowed) = 0;
     84 
     85  /**
     86   * Returns a pointer to the private context
     87   */
     88  virtual void* getPrivateContext() = 0;
     89 
     90  virtual txResultRecycler* recycler() = 0;
     91 
     92  /*
     93   * Callback to be used by the expression/pattern if errors are detected.
     94   */
     95  virtual void receiveError(const nsAString& aMsg, nsresult aRes) = 0;
     96 };
     97 
     98 #define TX_DECL_MATCH_CONTEXT                                            \
     99  nsresult getVariable(int32_t aNamespace, nsAtom* aLName,               \
    100                       txAExprResult*& aResult) override;                \
    101  nsresult isStripSpaceAllowed(const txXPathNode& aNode, bool& aAllowed) \
    102      override;                                                          \
    103  void* getPrivateContext() override;                                    \
    104  txResultRecycler* recycler() override;                                 \
    105  void receiveError(const nsAString& aMsg, nsresult aRes) override
    106 
    107 class txIEvalContext : public txIMatchContext {
    108 public:
    109  /*
    110   * Get the context node.
    111   */
    112  virtual const txXPathNode& getContextNode() = 0;
    113 
    114  /*
    115   * Get the size of the context node set.
    116   */
    117  virtual uint32_t size() = 0;
    118 
    119  /*
    120   * Get the position of the context node in the context node set,
    121   * starting with 1.
    122   */
    123  virtual uint32_t position() = 0;
    124 };
    125 
    126 #define TX_DECL_EVAL_CONTEXT                    \
    127  TX_DECL_MATCH_CONTEXT;                        \
    128  const txXPathNode& getContextNode() override; \
    129  uint32_t size() override;                     \
    130  uint32_t position() override
    131 
    132 #endif  // __TX_I_XPATH_CONTEXT