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 #include "MediaStreamError.h"
8 #include "mozilla/dom/MediaStreamErrorBinding.h"
9 #include "nsContentUtils.h"
10
11 namespace mozilla {
12
BaseMediaMgrError(Name aName,const nsAString & aMessage,const nsAString & aConstraint)13 BaseMediaMgrError::BaseMediaMgrError(Name aName, const nsAString& aMessage,
14 const nsAString& aConstraint)
15 : mMessage(aMessage), mConstraint(aConstraint), mName(aName) {
16 #define MAP_MEDIAERR(name, msg) \
17 { Name::name, #name, msg }
18
19 static struct {
20 Name mName;
21 const char* mNameString;
22 const char* mMessage;
23 } map[] = {
24 MAP_MEDIAERR(AbortError, "The operation was aborted."),
25 MAP_MEDIAERR(InvalidStateError, "The object is in an invalid state."),
26 MAP_MEDIAERR(NotAllowedError,
27 "The request is not allowed by the user agent "
28 "or the platform in the current context."),
29 MAP_MEDIAERR(NotFoundError, "The object can not be found here."),
30 MAP_MEDIAERR(NotReadableError, "The I/O read operation failed."),
31 MAP_MEDIAERR(NotSupportedError, "The operation is not supported."),
32 MAP_MEDIAERR(OverconstrainedError, "Constraints could be not satisfied."),
33 MAP_MEDIAERR(SecurityError, "The operation is insecure."),
34 MAP_MEDIAERR(TypeError, ""),
35 };
36 for (auto& entry : map) {
37 if (entry.mName == mName) {
38 mNameString.AssignASCII(entry.mNameString);
39 if (mMessage.IsEmpty()) {
40 mMessage.AssignASCII(entry.mMessage);
41 }
42 return;
43 }
44 }
45 MOZ_ASSERT_UNREACHABLE("Unknown error type");
46 }
47
48 NS_IMPL_ISUPPORTS0(MediaMgrError)
49
50 namespace dom {
51
MediaStreamError(nsPIDOMWindowInner * aParent,Name aName,const nsAString & aMessage,const nsAString & aConstraint)52 MediaStreamError::MediaStreamError(nsPIDOMWindowInner* aParent, Name aName,
53 const nsAString& aMessage,
54 const nsAString& aConstraint)
55 : BaseMediaMgrError(aName, aMessage, aConstraint), mParent(aParent) {}
56
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MediaStreamError,mParent)57 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MediaStreamError, mParent)
58 NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaStreamError)
59 NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaStreamError)
60 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaStreamError)
61 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
62 NS_INTERFACE_MAP_ENTRY(nsISupports)
63 NS_INTERFACE_MAP_ENTRY(MediaStreamError)
64 NS_INTERFACE_MAP_END
65
66 JSObject* MediaStreamError::WrapObject(JSContext* aCx,
67 JS::Handle<JSObject*> aGivenProto) {
68 return MediaStreamError_Binding::Wrap(aCx, this, aGivenProto);
69 }
70
GetName(nsAString & aName) const71 void MediaStreamError::GetName(nsAString& aName) const { aName = mNameString; }
72
GetMessage(nsAString & aMessage) const73 void MediaStreamError::GetMessage(nsAString& aMessage) const {
74 aMessage = mMessage;
75 }
76
GetConstraint(nsAString & aConstraint) const77 void MediaStreamError::GetConstraint(nsAString& aConstraint) const {
78 aConstraint = mConstraint;
79 }
80
81 } // namespace dom
82 } // namespace mozilla
83