Bug 824717 - Part 1: Define DOMMobileMessageError:DOMError to hook an additional nsISupports object like nsIDOMMozSmsMessage/nsIDOMMozMmsMessage when error occurs. r=hsinyi, r=smaug

This commit is contained in:
Bevis Tseng 2014-04-28 11:54:07 +08:00
parent 29128617e9
commit 1d46b6404d
6 changed files with 131 additions and 0 deletions

View File

@ -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);
}

View File

@ -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<nsIDOMMozSmsMessage> mSms;
nsCOMPtr<nsIDOMMozMmsMessage> mMms;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_MobileMessageError_h

View File

@ -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',

View File

@ -308,6 +308,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!

View File

@ -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;
};

View File

@ -88,6 +88,7 @@ WEBIDL_FILES = [
'DOMError.webidl',
'DOMException.webidl',
'DOMImplementation.webidl',
'DOMMobileMessageError.webidl',
'DOMParser.webidl',
'DOMPoint.webidl',
'DOMQuad.webidl',