Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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/. */
7 /* Copyright © 2013 Deutsche Telekom, Inc. */
9 #ifndef mozilla_dom_MozNDEFRecord_h__
10 #define mozilla_dom_MozNDEFRecord_h__
12 #include "mozilla/Attributes.h"
13 #include "mozilla/ErrorResult.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsWrapperCache.h"
16 #include "jsapi.h"
18 #include "nsIDocument.h"
20 #include "mozilla/dom/TypedArray.h"
21 #include "jsfriendapi.h"
22 #include "js/GCAPI.h"
24 struct JSContext;
26 namespace mozilla {
27 namespace dom {
29 class MozNDEFRecord MOZ_FINAL : public nsISupports,
30 public nsWrapperCache
31 {
32 public:
33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
34 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MozNDEFRecord)
36 public:
38 MozNDEFRecord(JSContext* aCx, nsPIDOMWindow* aWindow, uint8_t aTnf,
39 const Optional<Uint8Array>& aType,
40 const Optional<Uint8Array>& aId,
41 const Optional<Uint8Array>& aPlayload);
43 ~MozNDEFRecord();
45 nsIDOMWindow* GetParentObject() const
46 {
47 return mWindow;
48 }
50 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
52 static already_AddRefed<MozNDEFRecord>
53 Constructor(const GlobalObject& aGlobal, uint8_t aTnf,
54 const Optional<Uint8Array>& aType,
55 const Optional<Uint8Array>& aId,
56 const Optional<Uint8Array>& aPayload, ErrorResult& aRv);
58 uint8_t Tnf() const
59 {
60 return mTnf;
61 }
63 void GetType(JSContext* cx, JS::MutableHandle<JSObject*> retval) const
64 {
65 if (mType) {
66 JS::ExposeObjectToActiveJS(mType);
67 }
68 retval.set(mType);
69 }
71 void GetId(JSContext* cx, JS::MutableHandle<JSObject*> retval) const
72 {
73 if (mId) {
74 JS::ExposeObjectToActiveJS(mId);
75 }
76 retval.set(mId);
77 }
79 void GetPayload(JSContext* cx, JS::MutableHandle<JSObject*> retval) const
80 {
81 if (mPayload) {
82 JS::ExposeObjectToActiveJS(mPayload);
83 }
84 retval.set(mPayload);
85 }
87 private:
88 MozNDEFRecord() MOZ_DELETE;
89 nsRefPtr<nsPIDOMWindow> mWindow;
90 void HoldData();
91 void DropData();
93 uint8_t mTnf;
94 JS::Heap<JSObject*> mType;
95 JS::Heap<JSObject*> mId;
96 JS::Heap<JSObject*> mPayload;
97 };
99 } // namespace dom
100 } // namespace mozilla
102 #endif // mozilla_dom_MozNDEFRecord_h__