Bumping gaia.json for 8 gaia revision(s) a=gaia-bump
[gecko.git] / dom / base / DOMParser.h
blob287426d4d3a021824f1589ea8be7f5d07d81f57c
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_
9 #include "nsCOMPtr.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"
18 class nsIDocument;
20 namespace mozilla {
21 namespace dom {
23 class DOMParser MOZ_FINAL : public nsIDOMParser,
24 public nsSupportsWeakReference,
25 public nsWrapperCache
27 typedef mozilla::dom::GlobalObject GlobalObject;
29 virtual ~DOMParser();
31 public:
32 DOMParser();
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(DOMParser,
36 nsIDOMParser)
38 // nsIDOMParser
39 NS_DECL_NSIDOMPARSER
41 // WebIDL API
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
75 return mOwner;
78 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
80 return mozilla::dom::DOMParserBinding::Wrap(aCx, this);
83 private:
84 explicit DOMParser(nsISupports* aOwner) : mOwner(aOwner), mAttemptedInit(false)
86 MOZ_ASSERT(aOwner);
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 {
99 public:
100 explicit AttemptedInitMarker(bool* aAttemptedInit) :
101 mAttemptedInit(aAttemptedInit)
104 ~AttemptedInitMarker() {
105 *mAttemptedInit = true;
108 private:
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;
119 bool mAttemptedInit;
122 } // namespace dom
123 } // namespace mozilla
125 #endif