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/. */
7 #ifndef mozilla_dom_DOMParser_h_
8 #define mozilla_dom_DOMParser_h_
11 #include "mozilla/dom/Document.h"
12 #include "nsWrapperCache.h"
13 #include "mozilla/Span.h"
14 #include "mozilla/dom/DOMParserBinding.h"
15 #include "mozilla/dom/TypedArray.h"
17 class nsIGlobalObject
;
24 class DOMParser final
: public nsISupports
, public nsWrapperCache
{
25 typedef mozilla::dom::GlobalObject GlobalObject
;
30 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
31 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMParser
)
34 static already_AddRefed
<DOMParser
> Constructor(const GlobalObject
& aOwner
,
35 mozilla::ErrorResult
& rv
);
37 already_AddRefed
<Document
> ParseFromString(const nsAString
& aStr
,
42 already_AddRefed
<Document
> ParseFromSafeString(const nsAString
& aStr
,
45 // Sequence converts to Span, so we can use this overload for both
46 // the Sequence case and our internal uses.
47 already_AddRefed
<Document
> ParseFromBuffer(Span
<const uint8_t> aBuf
,
51 already_AddRefed
<Document
> ParseFromBuffer(const Uint8Array
& aBuf
,
55 already_AddRefed
<Document
> ParseFromStream(nsIInputStream
* aStream
,
56 const nsAString
& aCharset
,
57 int32_t aContentLength
,
61 void ForceEnableXULXBL() {
62 mForceEnableXULXBL
= true;
66 void ForceEnableDTD() { mForceEnableDTD
= true; }
68 nsIGlobalObject
* GetParentObject() const { return mOwner
; }
70 virtual JSObject
* WrapObject(JSContext
* aCx
,
71 JS::Handle
<JSObject
*> aGivenProto
) override
{
72 return mozilla::dom::DOMParser_Binding::Wrap(aCx
, this, aGivenProto
);
75 // A way to create a non-global-associated DOMParser from C++.
76 static already_AddRefed
<DOMParser
> CreateWithoutGlobal(ErrorResult
& aRv
);
79 DOMParser(nsIGlobalObject
* aOwner
, nsIPrincipal
* aDocPrincipal
,
80 nsIURI
* aDocumentURI
, nsIURI
* aBaseURI
);
82 already_AddRefed
<Document
> SetUpDocument(DocumentFlavor aFlavor
,
85 nsCOMPtr
<nsIGlobalObject
> mOwner
;
86 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
87 nsCOMPtr
<nsIURI
> mDocumentURI
;
88 nsCOMPtr
<nsIURI
> mBaseURI
;
90 bool mForceEnableXULXBL
;
95 } // namespace mozilla