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 TrustedHTMLOrString
;
26 class DOMParser final
: public nsISupports
, public nsWrapperCache
{
27 typedef mozilla::dom::GlobalObject GlobalObject
;
32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
33 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(DOMParser
)
36 static already_AddRefed
<DOMParser
> Constructor(const GlobalObject
& aOwner
,
37 mozilla::ErrorResult
& rv
);
39 already_AddRefed
<Document
> ParseFromStringInternal(const nsAString
& aStr
,
43 MOZ_CAN_RUN_SCRIPT already_AddRefed
<Document
> ParseFromString(
44 const TrustedHTMLOrString
& aStr
, SupportedType aType
, ErrorResult
& aRv
);
47 already_AddRefed
<Document
> ParseFromSafeString(const nsAString
& aStr
,
50 // Sequence converts to Span, so we can use this overload for both
51 // the Sequence case and our internal uses.
52 already_AddRefed
<Document
> ParseFromBuffer(Span
<const uint8_t> aBuf
,
56 already_AddRefed
<Document
> ParseFromBuffer(const Uint8Array
& aBuf
,
60 already_AddRefed
<Document
> ParseFromStream(nsIInputStream
* aStream
,
61 const nsAString
& aCharset
,
62 int32_t aContentLength
,
66 void ForceEnableXULXBL() {
67 mForceEnableXULXBL
= true;
71 void ForceEnableDTD() { mForceEnableDTD
= true; }
73 nsIGlobalObject
* GetParentObject() const { return mOwner
; }
75 virtual JSObject
* WrapObject(JSContext
* aCx
,
76 JS::Handle
<JSObject
*> aGivenProto
) override
{
77 return mozilla::dom::DOMParser_Binding::Wrap(aCx
, this, aGivenProto
);
80 // A way to create a non-global-associated DOMParser from C++.
81 static already_AddRefed
<DOMParser
> CreateWithoutGlobal(ErrorResult
& aRv
);
84 DOMParser(nsIGlobalObject
* aOwner
, nsIPrincipal
* aDocPrincipal
,
85 nsIURI
* aDocumentURI
);
87 already_AddRefed
<Document
> SetUpDocument(DocumentFlavor aFlavor
,
90 nsCOMPtr
<nsIGlobalObject
> mOwner
;
91 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
92 nsCOMPtr
<nsIURI
> mDocumentURI
;
94 bool mForceEnableXULXBL
;
99 } // namespace mozilla