diff --git a/dom/mobilemessage/src/DOMMobileMessageError.cpp b/dom/mobilemessage/src/DOMMobileMessageError.cpp new file mode 100644 index 000000000000..92778317f49e --- /dev/null +++ b/dom/mobilemessage/src/DOMMobileMessageError.cpp @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this file, +* You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "DOMMobileMessageError.h" +#include "mozilla/dom/DOMMobileMessageErrorBinding.h" +#include "mozilla/dom/UnionTypes.h" +#include "nsIDOMMozMmsMessage.h" +#include "nsIDOMMozSmsMessage.h" + +using namespace mozilla::dom; + +NS_IMPL_CYCLE_COLLECTION_CLASS(DOMMobileMessageError) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DOMMobileMessageError, DOMError) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mSms) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mMms) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DOMMobileMessageError, DOMError) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSms) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMms) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMMobileMessageError) +NS_INTERFACE_MAP_END_INHERITING(DOMError) + +NS_IMPL_ADDREF_INHERITED(DOMMobileMessageError, DOMError) +NS_IMPL_RELEASE_INHERITED(DOMMobileMessageError, DOMError) + +DOMMobileMessageError::DOMMobileMessageError(nsPIDOMWindow* aWindow, + const nsAString& aName, + nsIDOMMozSmsMessage* aSms) + : DOMError(aWindow, aName) + , mSms(aSms) + , mMms(nullptr) +{ +} + +DOMMobileMessageError::DOMMobileMessageError(nsPIDOMWindow* aWindow, + const nsAString& aName, + nsIDOMMozMmsMessage* aMms) + : DOMError(aWindow, aName) + , mSms(nullptr) + , mMms(aMms) +{ +} + +void +DOMMobileMessageError::GetData(OwningMozSmsMessageOrMozMmsMessage& aRetVal) const +{ + if (mSms) { + aRetVal.SetAsMozSmsMessage() = mSms; + return; + } + + if (mMms) { + aRetVal.SetAsMozMmsMessage() = mMms; + return; + } + + MOZ_ASSUME_UNREACHABLE("Bad object with invalid mSms and mMms."); +} + +JSObject* +DOMMobileMessageError::WrapObject(JSContext* aCx) +{ + return DOMMobileMessageErrorBinding::Wrap(aCx, this); +} diff --git a/dom/mobilemessage/src/DOMMobileMessageError.h b/dom/mobilemessage/src/DOMMobileMessageError.h new file mode 100644 index 000000000000..a620639aa021 --- /dev/null +++ b/dom/mobilemessage/src/DOMMobileMessageError.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this file, +* You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_MobileMessageError_h +#define mozilla_dom_MobileMessageError_h + +#include "mozilla/dom/DOMError.h" + +class nsIDOMMozMmsMessage; +class nsIDOMMozSmsMessage; + +namespace mozilla { +namespace dom { + +class OwningMozSmsMessageOrMozMmsMessage; + +class DOMMobileMessageError MOZ_FINAL : public DOMError +{ +public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMMobileMessageError, DOMError) + + DOMMobileMessageError(nsPIDOMWindow* aWindow, const nsAString& aName, + nsIDOMMozSmsMessage* aSms); + + DOMMobileMessageError(nsPIDOMWindow* aWindow, const nsAString& aName, + nsIDOMMozMmsMessage* aMms); + + virtual JSObject* + WrapObject(JSContext* aCx) MOZ_OVERRIDE; + + void GetData(OwningMozSmsMessageOrMozMmsMessage& aRetVal) const; + +private: + nsCOMPtr mSms; + nsCOMPtr mMms; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_MobileMessageError_h diff --git a/dom/mobilemessage/src/moz.build b/dom/mobilemessage/src/moz.build index 3bd98ba75679..893fb14e7b50 100644 --- a/dom/mobilemessage/src/moz.build +++ b/dom/mobilemessage/src/moz.build @@ -37,6 +37,7 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']: ] EXPORTS.mozilla.dom += [ + 'DOMMobileMessageError.h', 'MmsMessage.h', 'MobileMessageManager.h', 'SmsFilter.h', @@ -46,6 +47,7 @@ EXPORTS.mozilla.dom += [ UNIFIED_SOURCES += [ 'Constants.cpp', + 'DOMMobileMessageError.cpp', 'ipc/SmsChild.cpp', 'ipc/SmsIPCService.cpp', 'ipc/SmsParent.cpp', diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 352b7b3590fd..9c0fa2d9ac55 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -305,6 +305,8 @@ var interfaceNamesInGlobalScope = "DOMImplementation", // IMPORTANT: Do not change this list without review from a DOM peer! {name: "DOMMMIError", b2g: true, pref: "dom.mobileconnection.enabled"}, +// IMPORTANT: Do not change this list without review from a DOM peer! + {name: "DOMMobileMessageError", b2g: true, pref: "dom.sms.enabled"}, // IMPORTANT: Do not change this list without review from a DOM peer! "DOMParser", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/DOMMobileMessageError.webidl b/dom/webidl/DOMMobileMessageError.webidl new file mode 100644 index 000000000000..fc87c59911d4 --- /dev/null +++ b/dom/webidl/DOMMobileMessageError.webidl @@ -0,0 +1,10 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +[Pref="dom.sms.enabled"] +interface DOMMobileMessageError : DOMError { + readonly attribute (MozSmsMessage or MozMmsMessage) data; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 6a8ee194790a..7f411b341326 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -88,6 +88,7 @@ WEBIDL_FILES = [ 'DOMError.webidl', 'DOMException.webidl', 'DOMImplementation.webidl', + 'DOMMobileMessageError.webidl', 'DOMParser.webidl', 'DOMPoint.webidl', 'DOMQuad.webidl',