tor-browser

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

PrototypeDocumentParser.h (4402B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_parser_PrototypeDocumentParser_h
      8 #define mozilla_parser_PrototypeDocumentParser_h
      9 
     10 #include "nsCycleCollectionParticipant.h"
     11 #include "nsIContentSink.h"
     12 #include "nsIParser.h"
     13 #include "nsXULPrototypeDocument.h"
     14 
     15 class nsIExpatSink;
     16 
     17 namespace mozilla {
     18 namespace dom {
     19 class PrototypeDocumentContentSink;
     20 }  // namespace dom
     21 }  // namespace mozilla
     22 
     23 namespace mozilla {
     24 namespace parser {
     25 
     26 // The PrototypeDocumentParser is more of a stub than a real parser. It is
     27 // responsible for loading an nsXULPrototypeDocument either from the startup
     28 // cache or creating a new prototype from the original source if a cached
     29 // version does not exist. Once the parser finishes loading the prototype it
     30 // will notify the content sink.
     31 class PrototypeDocumentParser final : public nsIParser,
     32                                      public nsIStreamListener {
     33 public:
     34  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     35 
     36  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PrototypeDocumentParser, nsIParser)
     37 
     38  explicit PrototypeDocumentParser(nsIURI* aDocumentURI,
     39                                   dom::Document* aDocument);
     40 
     41  NS_DECL_NSIREQUESTOBSERVER
     42  NS_DECL_NSISTREAMLISTENER
     43 
     44  // Start nsIParser
     45  // Ideally, this would just implement nsBaseParser since most of these are
     46  // stubs, but Document.h expects an nsIParser.
     47  NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink) override;
     48 
     49  NS_IMETHOD_(nsIContentSink*) GetContentSink() override;
     50 
     51  NS_IMETHOD_(void) GetCommand(nsCString& aCommand) override {}
     52 
     53  NS_IMETHOD_(void) SetCommand(const char* aCommand) override {}
     54 
     55  NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand) override {}
     56 
     57  virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding,
     58                                  int32_t aSource,
     59                                  bool aForceAutoDetection) override {}
     60 
     61  virtual nsIStreamListener* GetStreamListener() override;
     62 
     63  NS_IMETHOD ContinueInterruptedParsing() override {
     64    return NS_ERROR_NOT_IMPLEMENTED;
     65  }
     66 
     67  NS_IMETHOD_(void) BlockParser() override {}
     68 
     69  NS_IMETHOD_(void) UnblockParser() override {}
     70 
     71  NS_IMETHOD_(void) ContinueInterruptedParsingAsync() override {}
     72 
     73  NS_IMETHOD_(bool) IsParserEnabled() override { return true; }
     74 
     75  NS_IMETHOD_(bool) IsComplete() override;
     76 
     77  NS_IMETHOD Parse(nsIURI* aURL) override;
     78 
     79  NS_IMETHOD Terminate() override { return NS_ERROR_NOT_IMPLEMENTED; }
     80 
     81  virtual bool IsInsertionPointDefined() override { return false; }
     82 
     83  void IncrementScriptNestingLevel() final {}
     84 
     85  void DecrementScriptNestingLevel() final {}
     86 
     87  bool HasNonzeroScriptNestingLevel() const final { return false; }
     88 
     89  virtual bool IsScriptCreated() override { return false; }
     90 
     91  virtual bool IsAboutBlankMode() override { return false; }
     92 
     93  // End nsIParser
     94 
     95 private:
     96  virtual ~PrototypeDocumentParser();
     97 
     98 protected:
     99  nsresult PrepareToLoadPrototype(nsIURI* aURI,
    100                                  nsIPrincipal* aDocumentPrincipal,
    101                                  nsIParser** aResult);
    102 
    103  // This is invoked whenever the prototype for this document is loaded
    104  // and should be walked, regardless of whether the XUL cache is
    105  // disabled, whether the protototype was loaded, whether the
    106  // prototype was loaded from the cache or created by parsing the
    107  // actual XUL source, etc.
    108  nsresult OnPrototypeLoadDone();
    109 
    110  nsCOMPtr<nsIURI> mDocumentURI;
    111  RefPtr<dom::PrototypeDocumentContentSink> mOriginalSink;
    112  RefPtr<dom::Document> mDocument;
    113 
    114  // The XML parser that data is forwarded to when the prototype does not exist
    115  // and must be parsed from disk.
    116  nsCOMPtr<nsIStreamListener> mStreamListener;
    117 
    118  // The current prototype that we are walking to construct the
    119  // content model.
    120  RefPtr<nsXULPrototypeDocument> mCurrentPrototype;
    121 
    122  // True if there was a prototype in the cache and it finished loading
    123  // already.
    124  bool mPrototypeAlreadyLoaded;
    125 
    126  // True after the parser has notified the content sink that it is done.
    127  bool mIsComplete;
    128 };
    129 
    130 }  // namespace parser
    131 }  // namespace mozilla
    132 
    133 #endif  // mozilla_parser_PrototypeDocumentParser_h