|
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/. */ |
|
5 |
|
6 #ifndef mozilla_dom_DOMParser_h_ |
|
7 #define mozilla_dom_DOMParser_h_ |
|
8 |
|
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" |
|
17 |
|
18 class nsIDocument; |
|
19 |
|
20 namespace mozilla { |
|
21 namespace dom { |
|
22 |
|
23 class DOMParser MOZ_FINAL : public nsIDOMParser, |
|
24 public nsSupportsWeakReference, |
|
25 public nsWrapperCache |
|
26 { |
|
27 typedef mozilla::dom::GlobalObject GlobalObject; |
|
28 public: |
|
29 DOMParser(); |
|
30 virtual ~DOMParser(); |
|
31 |
|
32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
33 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(DOMParser, |
|
34 nsIDOMParser) |
|
35 |
|
36 // nsIDOMParser |
|
37 NS_DECL_NSIDOMPARSER |
|
38 |
|
39 // WebIDL API |
|
40 static already_AddRefed<DOMParser> |
|
41 Constructor(const GlobalObject& aOwner, |
|
42 mozilla::ErrorResult& rv); |
|
43 |
|
44 static already_AddRefed<DOMParser> |
|
45 Constructor(const GlobalObject& aOwner, |
|
46 nsIPrincipal* aPrincipal, nsIURI* aDocumentURI, nsIURI* aBaseURI, |
|
47 mozilla::ErrorResult& rv); |
|
48 |
|
49 already_AddRefed<nsIDocument> |
|
50 ParseFromString(const nsAString& aStr, mozilla::dom::SupportedType aType, |
|
51 mozilla::ErrorResult& rv); |
|
52 |
|
53 already_AddRefed<nsIDocument> |
|
54 ParseFromBuffer(const mozilla::dom::Sequence<uint8_t>& aBuf, |
|
55 uint32_t aBufLen, mozilla::dom::SupportedType aType, |
|
56 mozilla::ErrorResult& rv); |
|
57 |
|
58 already_AddRefed<nsIDocument> |
|
59 ParseFromBuffer(const mozilla::dom::Uint8Array& aBuf, uint32_t aBufLen, |
|
60 mozilla::dom::SupportedType aType, |
|
61 mozilla::ErrorResult& rv); |
|
62 |
|
63 already_AddRefed<nsIDocument> |
|
64 ParseFromStream(nsIInputStream* aStream, const nsAString& aCharset, |
|
65 int32_t aContentLength, mozilla::dom::SupportedType aType, |
|
66 mozilla::ErrorResult& rv); |
|
67 |
|
68 void Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI, |
|
69 nsIURI* aBaseURI, mozilla::ErrorResult& rv); |
|
70 |
|
71 nsISupports* GetParentObject() const |
|
72 { |
|
73 return mOwner; |
|
74 } |
|
75 |
|
76 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
|
77 { |
|
78 return mozilla::dom::DOMParserBinding::Wrap(aCx, this); |
|
79 } |
|
80 |
|
81 private: |
|
82 DOMParser(nsISupports* aOwner) : mOwner(aOwner), mAttemptedInit(false) |
|
83 { |
|
84 MOZ_ASSERT(aOwner); |
|
85 SetIsDOMBinding(); |
|
86 } |
|
87 |
|
88 nsresult InitInternal(nsISupports* aOwner, nsIPrincipal* prin, |
|
89 nsIURI* documentURI, nsIURI* baseURI); |
|
90 |
|
91 nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult); |
|
92 |
|
93 // Helper for ParseFromString |
|
94 nsresult ParseFromString(const nsAString& str, const char *contentType, |
|
95 nsIDOMDocument **aResult); |
|
96 |
|
97 class AttemptedInitMarker { |
|
98 public: |
|
99 AttemptedInitMarker(bool* aAttemptedInit) : |
|
100 mAttemptedInit(aAttemptedInit) |
|
101 {} |
|
102 |
|
103 ~AttemptedInitMarker() { |
|
104 *mAttemptedInit = true; |
|
105 } |
|
106 |
|
107 private: |
|
108 bool* mAttemptedInit; |
|
109 }; |
|
110 |
|
111 nsCOMPtr<nsISupports> mOwner; |
|
112 nsCOMPtr<nsIPrincipal> mPrincipal; |
|
113 nsCOMPtr<nsIPrincipal> mOriginalPrincipal; |
|
114 nsCOMPtr<nsIURI> mDocumentURI; |
|
115 nsCOMPtr<nsIURI> mBaseURI; |
|
116 nsWeakPtr mScriptHandlingObject; |
|
117 |
|
118 bool mAttemptedInit; |
|
119 }; |
|
120 |
|
121 } // namespace dom |
|
122 } // namespace mozilla |
|
123 |
|
124 #endif |