tor-browser

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

DOMParser.h (3642B)


      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 http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_DOMParser_h_
      8 #define mozilla_dom_DOMParser_h_
      9 
     10 #include "mozilla/Span.h"
     11 #include "mozilla/dom/DOMParserBinding.h"
     12 #include "mozilla/dom/Document.h"
     13 #include "mozilla/dom/TypedArray.h"
     14 #include "nsCOMPtr.h"
     15 #include "nsWrapperCache.h"
     16 
     17 class nsIGlobalObject;
     18 class nsIPrincipal;
     19 
     20 namespace mozilla {
     21 class ErrorResult;
     22 
     23 namespace dom {
     24 
     25 class TrustedHTMLOrString;
     26 
     27 class DOMParser final : public nsISupports, public nsWrapperCache {
     28  typedef mozilla::dom::GlobalObject GlobalObject;
     29 
     30  virtual ~DOMParser();
     31 
     32 public:
     33  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     34  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(DOMParser)
     35 
     36  // WebIDL API
     37  static already_AddRefed<DOMParser> Constructor(const GlobalObject& aOwner,
     38                                                 mozilla::ErrorResult& rv);
     39 
     40  already_AddRefed<Document> ParseFromStringInternal(const nsAString& aStr,
     41                                                     SupportedType aType,
     42                                                     ErrorResult& aRv);
     43 
     44  MOZ_CAN_RUN_SCRIPT already_AddRefed<Document> ParseFromString(
     45      const TrustedHTMLOrString& aStr, SupportedType aType,
     46      nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv);
     47 
     48  // Chrome and UI Widgets API
     49  already_AddRefed<Document> ParseFromSafeString(const nsAString& aStr,
     50                                                 SupportedType aType,
     51                                                 ErrorResult& aRv);
     52  // Sequence converts to Span, so we can use this overload for both
     53  // the Sequence case and our internal uses.
     54  already_AddRefed<Document> ParseFromBuffer(Span<const uint8_t> aBuf,
     55                                             SupportedType aType,
     56                                             ErrorResult& aRv);
     57 
     58  already_AddRefed<Document> ParseFromBuffer(const Uint8Array& aBuf,
     59                                             SupportedType aType,
     60                                             ErrorResult& aRv);
     61 
     62  already_AddRefed<Document> ParseFromStream(nsIInputStream* aStream,
     63                                             const nsAString& aCharset,
     64                                             int32_t aContentLength,
     65                                             SupportedType aType,
     66                                             ErrorResult& aRv);
     67 
     68  void ForceEnableXULXBL() {
     69    mForceEnableXULXBL = true;
     70    ForceEnableDTD();
     71  }
     72 
     73  void ForceEnableDTD() { mForceEnableDTD = true; }
     74 
     75  nsIGlobalObject* GetParentObject() const { return mOwner; }
     76 
     77  virtual JSObject* WrapObject(JSContext* aCx,
     78                               JS::Handle<JSObject*> aGivenProto) override {
     79    return mozilla::dom::DOMParser_Binding::Wrap(aCx, this, aGivenProto);
     80  }
     81 
     82  // A way to create a non-global-associated DOMParser from C++.
     83  static already_AddRefed<DOMParser> CreateWithoutGlobal(ErrorResult& aRv);
     84 
     85 private:
     86  DOMParser(nsIGlobalObject* aOwner, nsIPrincipal* aDocPrincipal,
     87            nsIURI* aDocumentURI);
     88 
     89  already_AddRefed<Document> SetUpDocument(DocumentFlavor aFlavor,
     90                                           ErrorResult& aRv);
     91 
     92  nsCOMPtr<nsIGlobalObject> mOwner;
     93  nsCOMPtr<nsIPrincipal> mPrincipal;
     94  nsCOMPtr<nsIURI> mDocumentURI;
     95 
     96  bool mForceEnableXULXBL;
     97  bool mForceEnableDTD;
     98 };
     99 
    100 }  // namespace dom
    101 }  // namespace mozilla
    102 
    103 #endif