|
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 nsXBLProtoImplMember_h__ |
|
7 #define nsXBLProtoImplMember_h__ |
|
8 |
|
9 #include "nsIAtom.h" |
|
10 #include "nsString.h" |
|
11 #include "nsString.h" |
|
12 #include "nsIServiceManager.h" |
|
13 #include "nsContentUtils.h" // For NS_CONTENT_DELETE_LIST_MEMBER. |
|
14 #include "nsCycleCollectionParticipant.h" |
|
15 |
|
16 class nsIContent; |
|
17 class nsIObjectOutputStream; |
|
18 |
|
19 struct nsXBLTextWithLineNumber |
|
20 { |
|
21 char16_t* mText; |
|
22 uint32_t mLineNumber; |
|
23 |
|
24 nsXBLTextWithLineNumber() : |
|
25 mText(nullptr), |
|
26 mLineNumber(0) |
|
27 { |
|
28 MOZ_COUNT_CTOR(nsXBLTextWithLineNumber); |
|
29 } |
|
30 |
|
31 ~nsXBLTextWithLineNumber() { |
|
32 MOZ_COUNT_DTOR(nsXBLTextWithLineNumber); |
|
33 if (mText) { |
|
34 nsMemory::Free(mText); |
|
35 } |
|
36 } |
|
37 |
|
38 void AppendText(const nsAString& aText) { |
|
39 if (mText) { |
|
40 char16_t* temp = mText; |
|
41 mText = ToNewUnicode(nsDependentString(temp) + aText); |
|
42 nsMemory::Free(temp); |
|
43 } else { |
|
44 mText = ToNewUnicode(aText); |
|
45 } |
|
46 } |
|
47 |
|
48 char16_t* GetText() { |
|
49 return mText; |
|
50 } |
|
51 |
|
52 void SetLineNumber(uint32_t aLineNumber) { |
|
53 mLineNumber = aLineNumber; |
|
54 } |
|
55 |
|
56 uint32_t GetLineNumber() { |
|
57 return mLineNumber; |
|
58 } |
|
59 }; |
|
60 |
|
61 class nsXBLProtoImplMember |
|
62 { |
|
63 public: |
|
64 nsXBLProtoImplMember(const char16_t* aName) |
|
65 : mNext(nullptr) |
|
66 , mExposeToUntrustedContent(false) |
|
67 { |
|
68 mName = ToNewUnicode(nsDependentString(aName)); |
|
69 } |
|
70 virtual ~nsXBLProtoImplMember() { |
|
71 nsMemory::Free(mName); |
|
72 NS_CONTENT_DELETE_LIST_MEMBER(nsXBLProtoImplMember, this, mNext); |
|
73 } |
|
74 |
|
75 nsXBLProtoImplMember* GetNext() { return mNext; } |
|
76 void SetNext(nsXBLProtoImplMember* aNext) { mNext = aNext; } |
|
77 bool ShouldExposeToUntrustedContent() { return mExposeToUntrustedContent; } |
|
78 void SetExposeToUntrustedContent(bool aExpose) { mExposeToUntrustedContent = aExpose; } |
|
79 const char16_t* GetName() { return mName; } |
|
80 |
|
81 virtual nsresult InstallMember(JSContext* aCx, |
|
82 JS::Handle<JSObject*> aTargetClassObject) = 0; |
|
83 virtual nsresult CompileMember(const nsCString& aClassStr, |
|
84 JS::Handle<JSObject*> aClassObject) = 0; |
|
85 |
|
86 virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure) = 0; |
|
87 |
|
88 virtual nsresult Write(nsIObjectOutputStream* aStream) |
|
89 { |
|
90 return NS_OK; |
|
91 } |
|
92 |
|
93 protected: |
|
94 nsXBLProtoImplMember* mNext; // The members of an implementation are chained. |
|
95 char16_t* mName; // The name of the field, method, or property. |
|
96 |
|
97 bool mExposeToUntrustedContent; // If this binding is installed on an element |
|
98 // in an untrusted scope, should this |
|
99 // implementation member be accessible to the |
|
100 // content? |
|
101 }; |
|
102 |
|
103 #endif // nsXBLProtoImplMember_h__ |