Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef nsXBLProtoImplMember_h__
8 : #define nsXBLProtoImplMember_h__
9 :
10 : #include "nsIAtom.h"
11 : #include "nsString.h"
12 : #include "nsString.h"
13 : #include "nsIServiceManager.h"
14 : #include "nsContentUtils.h" // For NS_CONTENT_DELETE_LIST_MEMBER.
15 : #include "nsCycleCollectionParticipant.h"
16 :
17 : class nsIObjectOutputStream;
18 :
19 : struct nsXBLTextWithLineNumber
20 : {
21 : char16_t* mText;
22 : uint32_t mLineNumber;
23 :
24 0 : nsXBLTextWithLineNumber() :
25 : mText(nullptr),
26 0 : mLineNumber(0)
27 : {
28 0 : MOZ_COUNT_CTOR(nsXBLTextWithLineNumber);
29 0 : }
30 :
31 0 : ~nsXBLTextWithLineNumber() {
32 0 : MOZ_COUNT_DTOR(nsXBLTextWithLineNumber);
33 0 : if (mText) {
34 0 : free(mText);
35 : }
36 0 : }
37 :
38 0 : void AppendText(const nsAString& aText) {
39 0 : if (mText) {
40 0 : char16_t* temp = mText;
41 0 : mText = ToNewUnicode(nsDependentString(temp) + aText);
42 0 : free(temp);
43 : } else {
44 0 : mText = ToNewUnicode(aText);
45 : }
46 0 : }
47 :
48 0 : char16_t* GetText() {
49 0 : return mText;
50 : }
51 :
52 0 : void SetLineNumber(uint32_t aLineNumber) {
53 0 : mLineNumber = aLineNumber;
54 0 : }
55 :
56 0 : uint32_t GetLineNumber() {
57 0 : return mLineNumber;
58 : }
59 : };
60 :
61 : class nsXBLProtoImplMember
62 : {
63 : public:
64 934 : explicit nsXBLProtoImplMember(const char16_t* aName)
65 934 : : mNext(nullptr)
66 934 : , mExposeToUntrustedContent(false)
67 : {
68 934 : mName = ToNewUnicode(nsDependentString(aName));
69 934 : }
70 0 : virtual ~nsXBLProtoImplMember() {
71 0 : free(mName);
72 0 : NS_CONTENT_DELETE_LIST_MEMBER(nsXBLProtoImplMember, this, mNext);
73 0 : }
74 :
75 1723 : nsXBLProtoImplMember* GetNext() { return mNext; }
76 855 : void SetNext(nsXBLProtoImplMember* aNext) { mNext = aNext; }
77 0 : bool ShouldExposeToUntrustedContent() { return mExposeToUntrustedContent; }
78 0 : void SetExposeToUntrustedContent(bool aExpose) { mExposeToUntrustedContent = aExpose; }
79 0 : const char16_t* GetName() { return mName; }
80 :
81 : virtual nsresult InstallMember(JSContext* aCx,
82 : JS::Handle<JSObject*> aTargetClassObject) = 0;
83 : virtual nsresult CompileMember(mozilla::dom::AutoJSAPI& jsapi, const nsString& aClassStr,
84 : JS::Handle<JSObject*> aClassObject) = 0;
85 :
86 : virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure) = 0;
87 :
88 0 : virtual nsresult Write(nsIObjectOutputStream* aStream)
89 : {
90 0 : 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__
|