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