|
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 nsDOMSerializer_h_ |
|
7 #define nsDOMSerializer_h_ |
|
8 |
|
9 #include "nsIDOMSerializer.h" |
|
10 #include "nsWrapperCache.h" |
|
11 #include "mozilla/ErrorResult.h" |
|
12 #include "mozilla/dom/XMLSerializerBinding.h" |
|
13 #include "nsAutoPtr.h" |
|
14 |
|
15 class nsINode; |
|
16 |
|
17 class nsDOMSerializer MOZ_FINAL : public nsIDOMSerializer, |
|
18 public nsWrapperCache |
|
19 { |
|
20 public: |
|
21 nsDOMSerializer(); |
|
22 virtual ~nsDOMSerializer(); |
|
23 |
|
24 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
25 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMSerializer) |
|
26 |
|
27 // nsIDOMSerializer |
|
28 NS_DECL_NSIDOMSERIALIZER |
|
29 |
|
30 // WebIDL API |
|
31 static already_AddRefed<nsDOMSerializer> |
|
32 Constructor(const mozilla::dom::GlobalObject& aOwner, |
|
33 mozilla::ErrorResult& rv) |
|
34 { |
|
35 nsRefPtr<nsDOMSerializer> domSerializer = new nsDOMSerializer(aOwner.GetAsSupports()); |
|
36 return domSerializer.forget(); |
|
37 } |
|
38 |
|
39 void |
|
40 SerializeToString(nsINode& aRoot, nsAString& aStr, |
|
41 mozilla::ErrorResult& rv); |
|
42 |
|
43 void |
|
44 SerializeToStream(nsINode& aRoot, nsIOutputStream* aStream, |
|
45 const nsAString& aCharset, mozilla::ErrorResult& rv); |
|
46 |
|
47 nsISupports* GetParentObject() const |
|
48 { |
|
49 return mOwner; |
|
50 } |
|
51 |
|
52 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
|
53 { |
|
54 return mozilla::dom::XMLSerializerBinding::Wrap(aCx, this); |
|
55 } |
|
56 |
|
57 private: |
|
58 nsDOMSerializer(nsISupports* aOwner) : mOwner(aOwner) |
|
59 { |
|
60 MOZ_ASSERT(aOwner); |
|
61 SetIsDOMBinding(); |
|
62 } |
|
63 |
|
64 nsCOMPtr<nsISupports> mOwner; |
|
65 }; |
|
66 |
|
67 |
|
68 #endif |
|
69 |