MediaStreamError.h (3090B)
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/. */ 6 7 #ifndef mozilla_dom_MediaStreamError_h 8 #define mozilla_dom_MediaStreamError_h 9 10 #include "js/TypeDecls.h" 11 #include "mozilla/RefPtr.h" 12 #include "nsPIDOMWindow.h" 13 #include "nsWrapperCache.h" 14 15 #if defined(XP_WIN) && defined(GetMessage) 16 # undef GetMessage 17 #endif 18 19 namespace mozilla { 20 21 namespace dom { 22 23 #define MOZILLA_DOM_MEDIASTREAMERROR_IMPLEMENTATION_IID \ 24 {0x95fa29aa, 0x0cc2, 0x4698, {0x9d, 0xa9, 0xf2, 0xeb, 0x03, 0x91, 0x0b, 0xd1}} 25 26 class MediaStreamError; 27 } // namespace dom 28 29 class BaseMediaMgrError { 30 friend class dom::MediaStreamError; 31 32 public: 33 enum class Name { 34 AbortError, 35 InvalidStateError, 36 NotAllowedError, 37 NotFoundError, 38 NotReadableError, 39 OverconstrainedError, 40 SecurityError, 41 TypeError, 42 }; 43 44 protected: 45 BaseMediaMgrError(Name aName, const nsACString& aMessage, 46 const nsAString& aConstraint); 47 48 public: 49 nsString mNameString; 50 nsCString mMessage; 51 const nsString mConstraint; 52 const Name mName; 53 }; 54 55 class MediaMgrError final : public nsISupports, public BaseMediaMgrError { 56 public: 57 // aMessage should be valid UTF-8, but invalid UTF-8 byte sequences are 58 // replaced with the REPLACEMENT CHARACTER on conversion to UTF-16. 59 explicit MediaMgrError(Name aName, const nsACString& aMessage = ""_ns, 60 const nsAString& aConstraint = u""_ns) 61 : BaseMediaMgrError(aName, aMessage, aConstraint) {} 62 template <int N> 63 explicit MediaMgrError(Name aName, const char (&aMessage)[N], 64 const nsAString& aConstraint = u""_ns) 65 : BaseMediaMgrError(aName, nsLiteralCString(aMessage), aConstraint) {} 66 67 NS_DECL_THREADSAFE_ISUPPORTS 68 69 void Reject(dom::Promise* aPromise) const; 70 71 private: 72 ~MediaMgrError() = default; 73 }; 74 75 namespace dom { 76 class MediaStreamError final : public nsISupports, 77 public BaseMediaMgrError, 78 public nsWrapperCache { 79 public: 80 MediaStreamError(nsPIDOMWindowInner* aParent, const BaseMediaMgrError& aOther) 81 : BaseMediaMgrError(aOther.mName, aOther.mMessage, aOther.mConstraint), 82 mParent(aParent) {} 83 84 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 85 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(MediaStreamError) 86 NS_INLINE_DECL_STATIC_IID(MOZILLA_DOM_MEDIASTREAMERROR_IMPLEMENTATION_IID) 87 88 JSObject* WrapObject(JSContext* aCx, 89 JS::Handle<JSObject*> aGivenProto) override; 90 91 nsPIDOMWindowInner* GetParentObject() const { return mParent; } 92 void GetName(nsAString& aName) const; 93 void GetMessage(nsAString& aMessage) const; 94 void GetConstraint(nsAString& aConstraint) const; 95 96 private: 97 virtual ~MediaStreamError() = default; 98 99 RefPtr<nsPIDOMWindowInner> mParent; 100 }; 101 102 } // namespace dom 103 } // namespace mozilla 104 105 #endif