1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_DOMParser_h_
7 #define mozilla_dom_DOMParser_h_
10 #include "nsIDocument.h"
11 #include "nsIDOMParser.h"
12 #include "nsWeakReference.h"
13 #include "nsWrapperCache.h"
14 #include "mozilla/ErrorResult.h"
15 #include "mozilla/dom/DOMParserBinding.h"
16 #include "mozilla/dom/TypedArray.h"
23 class DOMParser MOZ_FINAL
: public nsIDOMParser
,
24 public nsSupportsWeakReference
,
27 typedef mozilla::dom::GlobalObject GlobalObject
;
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(DOMParser
,
42 static already_AddRefed
<DOMParser
>
43 Constructor(const GlobalObject
& aOwner
,
44 mozilla::ErrorResult
& rv
);
46 static already_AddRefed
<DOMParser
>
47 Constructor(const GlobalObject
& aOwner
,
48 nsIPrincipal
* aPrincipal
, nsIURI
* aDocumentURI
, nsIURI
* aBaseURI
,
49 mozilla::ErrorResult
& rv
);
51 already_AddRefed
<nsIDocument
>
52 ParseFromString(const nsAString
& aStr
, mozilla::dom::SupportedType aType
,
53 mozilla::ErrorResult
& rv
);
55 already_AddRefed
<nsIDocument
>
56 ParseFromBuffer(const mozilla::dom::Sequence
<uint8_t>& aBuf
,
57 uint32_t aBufLen
, mozilla::dom::SupportedType aType
,
58 mozilla::ErrorResult
& rv
);
60 already_AddRefed
<nsIDocument
>
61 ParseFromBuffer(const mozilla::dom::Uint8Array
& aBuf
, uint32_t aBufLen
,
62 mozilla::dom::SupportedType aType
,
63 mozilla::ErrorResult
& rv
);
65 already_AddRefed
<nsIDocument
>
66 ParseFromStream(nsIInputStream
* aStream
, const nsAString
& aCharset
,
67 int32_t aContentLength
, mozilla::dom::SupportedType aType
,
68 mozilla::ErrorResult
& rv
);
70 void Init(nsIPrincipal
* aPrincipal
, nsIURI
* aDocumentURI
,
71 nsIURI
* aBaseURI
, mozilla::ErrorResult
& rv
);
73 nsISupports
* GetParentObject() const
78 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
80 return mozilla::dom::DOMParserBinding::Wrap(aCx
, this);
84 explicit DOMParser(nsISupports
* aOwner
) : mOwner(aOwner
), mAttemptedInit(false)
89 nsresult
InitInternal(nsISupports
* aOwner
, nsIPrincipal
* prin
,
90 nsIURI
* documentURI
, nsIURI
* baseURI
);
92 nsresult
SetUpDocument(DocumentFlavor aFlavor
, nsIDOMDocument
** aResult
);
94 // Helper for ParseFromString
95 nsresult
ParseFromString(const nsAString
& str
, const char *contentType
,
96 nsIDOMDocument
**aResult
);
98 class AttemptedInitMarker
{
100 explicit AttemptedInitMarker(bool* aAttemptedInit
) :
101 mAttemptedInit(aAttemptedInit
)
104 ~AttemptedInitMarker() {
105 *mAttemptedInit
= true;
109 bool* mAttemptedInit
;
112 nsCOMPtr
<nsISupports
> mOwner
;
113 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
114 nsCOMPtr
<nsIPrincipal
> mOriginalPrincipal
;
115 nsCOMPtr
<nsIURI
> mDocumentURI
;
116 nsCOMPtr
<nsIURI
> mBaseURI
;
117 nsWeakPtr mScriptHandlingObject
;
123 } // namespace mozilla