Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / base / DOMParser.h
blob2ac2647d1909e37ee66526d492fa1dea1a24ad87
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_
10 #include "nsCOMPtr.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;
19 namespace mozilla {
20 class ErrorResult;
22 namespace dom {
24 class TrustedHTMLOrString;
26 class DOMParser final : public nsISupports, public nsWrapperCache {
27 typedef mozilla::dom::GlobalObject GlobalObject;
29 virtual ~DOMParser();
31 public:
32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
33 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(DOMParser)
35 // WebIDL API
36 static already_AddRefed<DOMParser> Constructor(const GlobalObject& aOwner,
37 mozilla::ErrorResult& rv);
39 already_AddRefed<Document> ParseFromStringInternal(const nsAString& aStr,
40 SupportedType aType,
41 ErrorResult& aRv);
43 MOZ_CAN_RUN_SCRIPT already_AddRefed<Document> ParseFromString(
44 const TrustedHTMLOrString& aStr, SupportedType aType, ErrorResult& aRv);
46 // ChromeOnly API
47 already_AddRefed<Document> ParseFromSafeString(const nsAString& aStr,
48 SupportedType aType,
49 ErrorResult& aRv);
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,
53 SupportedType aType,
54 ErrorResult& aRv);
56 already_AddRefed<Document> ParseFromBuffer(const Uint8Array& aBuf,
57 SupportedType aType,
58 ErrorResult& aRv);
60 already_AddRefed<Document> ParseFromStream(nsIInputStream* aStream,
61 const nsAString& aCharset,
62 int32_t aContentLength,
63 SupportedType aType,
64 ErrorResult& aRv);
66 void ForceEnableXULXBL() {
67 mForceEnableXULXBL = true;
68 ForceEnableDTD();
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);
83 private:
84 DOMParser(nsIGlobalObject* aOwner, nsIPrincipal* aDocPrincipal,
85 nsIURI* aDocumentURI);
87 already_AddRefed<Document> SetUpDocument(DocumentFlavor aFlavor,
88 ErrorResult& aRv);
90 nsCOMPtr<nsIGlobalObject> mOwner;
91 nsCOMPtr<nsIPrincipal> mPrincipal;
92 nsCOMPtr<nsIURI> mDocumentURI;
94 bool mForceEnableXULXBL;
95 bool mForceEnableDTD;
98 } // namespace dom
99 } // namespace mozilla
101 #endif