tor-browser

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

nsIContentSink.h (4219B)


      1 /* -*- Mode: C++; tab-width: 2; 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 #ifndef nsIContentSink_h___
      6 #define nsIContentSink_h___
      7 
      8 /**
      9 * MODULE NOTES:
     10 * @update  gess 4/1/98
     11 *
     12 * This pure virtual interface is used as the "glue" that connects the parsing
     13 * process to the content model construction process.
     14 *
     15 * The icontentsink interface is a very lightweight wrapper that represents the
     16 * content-sink model building process. There is another one that you may care
     17 * about more, which is the IHTMLContentSink interface. (See that file for
     18 * details).
     19 */
     20 #include "nsISupports.h"
     21 #include "nsString.h"
     22 #include "mozilla/FlushType.h"
     23 #include "mozilla/NotNull.h"
     24 
     25 class nsParserBase;
     26 namespace mozilla {
     27 class Encoding;
     28 }
     29 
     30 #define NS_ICONTENT_SINK_IID \
     31  {0xcf9a7cbb, 0xfcbc, 0x4e13, {0x8e, 0xf5, 0x18, 0xef, 0x2d, 0x3d, 0x58, 0x29}}
     32 
     33 class nsIContentSink : public nsISupports {
     34 protected:
     35  using Encoding = mozilla::Encoding;
     36  template <typename T>
     37  using NotNull = mozilla::NotNull<T>;
     38 
     39 public:
     40  NS_INLINE_DECL_STATIC_IID(NS_ICONTENT_SINK_IID)
     41 
     42  /**
     43   * This method is called by the parser when it is entered from
     44   * the event loop. The content sink wants to know how long the
     45   * parser has been active since we last processed events on the
     46   * main event loop and this call calibrates that measurement.
     47   */
     48  NS_IMETHOD WillParse(void) = 0;
     49 
     50  /**
     51   * This method gets called when the parser begins the process
     52   * of building the content model via the content sink.
     53   *
     54   * Default implementation provided since the sink should have the option of
     55   * doing nothing in response to this call.
     56   *
     57   * @update 5/7/98 gess
     58   */
     59  NS_IMETHOD WillBuildModel() { return NS_OK; }
     60 
     61  /**
     62   * This method gets called when the parser concludes the process
     63   * of building the content model via the content sink.
     64   *
     65   * Default implementation provided since the sink should have the option of
     66   * doing nothing in response to this call.
     67   *
     68   * @update 5/7/98 gess
     69   */
     70  NS_IMETHOD DidBuildModel(bool aTerminated) { return NS_OK; }
     71 
     72  /**
     73   * This method gets called when the parser gets i/o blocked,
     74   * and wants to notify the sink that it may be a while before
     75   * more data is available.
     76   *
     77   * @update 5/7/98 gess
     78   */
     79  NS_IMETHOD WillInterrupt(void) = 0;
     80 
     81  /**
     82   * This method gets called when the parser i/o gets unblocked,
     83   * and we're about to start dumping content again to the sink.
     84   */
     85  virtual void WillResume() = 0;
     86 
     87  /**
     88   * This method returns nullptr unless `this` can
     89   * be cast as nsHtml5TreeOpExecutor.
     90   */
     91  virtual nsIContentSink* AsExecutor() { return nullptr; }
     92 
     93  /**
     94   * This method gets called by the parser so that the content
     95   * sink can retain a reference to the parser. The expectation
     96   * is that the content sink will drop the reference when it
     97   * gets the DidBuildModel notification i.e. when parsing is done.
     98   */
     99  NS_IMETHOD SetParser(nsParserBase* aParser) = 0;
    100 
    101  /**
    102   * Flush content so that the content model is in sync with the state
    103   * of the sink.
    104   *
    105   * @param aType the type of flush to perform
    106   */
    107  virtual void FlushPendingNotifications(mozilla::FlushType aType) = 0;
    108 
    109  /**
    110   * Set the document character set. This should be passed on to the
    111   * document itself.
    112   */
    113  virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) = 0;
    114 
    115  /**
    116   * Returns the target object (often a document object) into which
    117   * the content built by this content sink is being added, if any
    118   * (IOW, may return null).
    119   */
    120  virtual nsISupports* GetTarget() = 0;
    121 
    122  /**
    123   * Returns true if there's currently script executing that we need to hold
    124   * parsing for.
    125   */
    126  virtual bool IsScriptExecuting() { return false; }
    127 
    128  virtual void ContinueParsingDocumentAfterCurrentScript() {};
    129 
    130  /**
    131   * Posts a runnable that continues parsing.
    132   */
    133  virtual void ContinueInterruptedParsingAsync() {}
    134 
    135  virtual void InitialTranslationCompleted() {}
    136 };
    137 
    138 #endif /* nsIContentSink_h___ */