зеркало из https://github.com/mozilla/gecko-dev.git
Bug 835143: Implement StkCommandEvent using event generator. f=vyang. r=smaug
This commit is contained in:
Родитель
3d4fb0d824
Коммит
b9e845fc40
|
@ -250,7 +250,9 @@ const kEventConstructors = {
|
|||
return new MozSmsEvent(aName, aProps);
|
||||
},
|
||||
},
|
||||
MozStkCommandEvent: { create: null, // Cannot create untrusted event from JS.
|
||||
MozStkCommandEvent: { create: function (aName, aProps) {
|
||||
return new MozStkCommandEvent(aName, aProps);
|
||||
},
|
||||
},
|
||||
MozVoicemailEvent: { create: function (aName, aProps) {
|
||||
return new MozVoicemailEvent(aName, aProps);
|
||||
|
|
|
@ -792,10 +792,6 @@ DOMInterfaces = {
|
|||
'nativeType': 'mozilla::dom::PowerManager',
|
||||
},
|
||||
|
||||
'MozStkCommandEvent' : {
|
||||
'nativeType': 'mozilla::dom::StkCommandEvent',
|
||||
},
|
||||
|
||||
'MozTimeManager': {
|
||||
'nativeType': 'mozilla::dom::time::TimeManager',
|
||||
},
|
||||
|
|
|
@ -494,16 +494,6 @@ dictionary MozStkCommand
|
|||
jsval options;
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(21cd2f25-ebea-43f8-8255-eaa4e1182858)]
|
||||
interface nsIDOMMozStkCommandEvent : nsIDOMEvent
|
||||
{
|
||||
/**
|
||||
* See nsIDOMMozStkCommand for the detail of command.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval command;
|
||||
};
|
||||
|
||||
dictionary MozStkResponse
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
#include "mozilla/dom/IccManager.h"
|
||||
|
||||
#include "GeneratedEvents.h"
|
||||
#include "mozilla/dom/StkCommandEvent.h"
|
||||
#include "mozilla/dom/MozStkCommandEvent.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "nsIDOMIccInfo.h"
|
||||
#include "nsJSON.h"
|
||||
#include "SimToolKit.h"
|
||||
|
||||
#define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
|
||||
|
@ -264,10 +265,30 @@ NS_IMPL_EVENT_HANDLER(IccManager, iccinfochange)
|
|||
NS_IMETHODIMP
|
||||
IccManager::NotifyStkCommand(const nsAString& aMessage)
|
||||
{
|
||||
nsRefPtr<StkCommandEvent> event = StkCommandEvent::Create(this, aMessage);
|
||||
NS_ASSERTION(event, "This should never fail!");
|
||||
nsresult rv;
|
||||
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return event->Dispatch(this, NS_LITERAL_STRING("stkcommand"));
|
||||
AutoPushJSContext cx(sc->GetNativeContext());
|
||||
JS::Rooted<JS::Value> value(cx);
|
||||
|
||||
if (!aMessage.IsEmpty()) {
|
||||
nsCOMPtr<nsIJSON> json(new nsJSON());
|
||||
nsresult rv = json->DecodeToJSVal(aMessage, cx, value.address());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else {
|
||||
value = JSVAL_VOID;
|
||||
}
|
||||
|
||||
MozStkCommandEventInit init;
|
||||
init.mBubbles = false;
|
||||
init.mCancelable = false;
|
||||
init.mCommand = value;
|
||||
|
||||
nsRefPtr<MozStkCommandEvent> event =
|
||||
MozStkCommandEvent::Constructor(this, NS_LITERAL_STRING("stkcommand"), init);
|
||||
|
||||
return DispatchTrustedEvent(event);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
/* 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 "mozilla/dom/StkCommandEvent.h"
|
||||
|
||||
#include "jsfriendapi.h"
|
||||
#include "nsJSON.h"
|
||||
#include "SimToolKit.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
already_AddRefed<StkCommandEvent>
|
||||
StkCommandEvent::Create(EventTarget* aOwner,
|
||||
const nsAString& aMessage)
|
||||
{
|
||||
nsRefPtr<StkCommandEvent> event = new StkCommandEvent(aOwner);
|
||||
event->mCommand = aMessage;
|
||||
return event.forget();
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(StkCommandEvent, nsDOMEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(StkCommandEvent, nsDOMEvent)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(StkCommandEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMMozStkCommandEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
||||
|
||||
NS_IMETHODIMP
|
||||
StkCommandEvent::GetCommand(JSContext* aCx, JS::Value* aCommand)
|
||||
|
||||
{
|
||||
nsCOMPtr<nsIJSON> json(new nsJSON());
|
||||
|
||||
if (!mCommand.IsEmpty()) {
|
||||
nsresult rv = json->DecodeToJSVal(mCommand, aCx, aCommand);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else {
|
||||
*aCommand = JSVAL_VOID;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -1,75 +0,0 @@
|
|||
/* 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_StkCommandEvent_h
|
||||
#define mozilla_dom_StkCommandEvent_h
|
||||
|
||||
#include "mozilla/dom/MozStkCommandEventBinding.h"
|
||||
#include "nsDOMEvent.h"
|
||||
#include "SimToolKit.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class StkCommandEvent : public nsDOMEvent,
|
||||
public nsIDOMMozStkCommandEvent
|
||||
{
|
||||
nsString mCommand;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_FORWARD_TO_NSDOMEVENT
|
||||
NS_DECL_NSIDOMMOZSTKCOMMANDEVENT
|
||||
|
||||
static already_AddRefed<StkCommandEvent>
|
||||
Create(EventTarget* aOwner, const nsAString& aMessage);
|
||||
|
||||
nsresult
|
||||
Dispatch(EventTarget* aTarget, const nsAString& aEventType)
|
||||
{
|
||||
NS_ASSERTION(aTarget, "Null pointer!");
|
||||
NS_ASSERTION(!aEventType.IsEmpty(), "Empty event type!");
|
||||
|
||||
nsresult rv = InitEvent(aEventType, false, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
SetTrusted(true);
|
||||
|
||||
nsDOMEvent* thisEvent = this;
|
||||
|
||||
bool dummy;
|
||||
rv = aTarget->DispatchEvent(thisEvent, &dummy);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
|
||||
{
|
||||
return MozStkCommandEventBinding::Wrap(aCx, aScope, this);
|
||||
}
|
||||
|
||||
JS::Value GetCommand(JSContext* aCx, ErrorResult& aRv)
|
||||
{
|
||||
JS::Rooted<JS::Value> retVal(aCx);
|
||||
aRv = GetCommand(aCx, retVal.address());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private:
|
||||
StkCommandEvent(EventTarget* aOwner)
|
||||
: nsDOMEvent(aOwner, nullptr, nullptr)
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
~StkCommandEvent()
|
||||
{ }
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_StkCommandEvent_h
|
|
@ -6,12 +6,10 @@
|
|||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'IccManager.h',
|
||||
'StkCommandEvent.h',
|
||||
]
|
||||
|
||||
SOURCES += [
|
||||
'IccManager.cpp',
|
||||
'StkCommandEvent.cpp',
|
||||
]
|
||||
|
||||
FAIL_ON_WARNINGS = True
|
||||
|
|
|
@ -4,8 +4,14 @@
|
|||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
[Pref="dom.icc.enabled",
|
||||
Constructor(DOMString type, optional MozStkCommandEventInit eventInitDict)]
|
||||
interface MozStkCommandEvent : Event
|
||||
{
|
||||
[Throws]
|
||||
readonly attribute any command;
|
||||
};
|
||||
|
||||
dictionary MozStkCommandEventInit : EventInit
|
||||
{
|
||||
any command = null;
|
||||
};
|
||||
|
|
|
@ -515,7 +515,6 @@ if CONFIG['MOZ_B2G_RIL']:
|
|||
'MozCellBroadcastEvent.webidl',
|
||||
'MozEmergencyCbModeEvent.webidl',
|
||||
'MozOtaStatusEvent.webidl',
|
||||
'MozStkCommandEvent.webidl',
|
||||
'MozVoicemail.webidl',
|
||||
'MozVoicemailEvent.webidl',
|
||||
'USSDReceivedEvent.webidl',
|
||||
|
@ -560,6 +559,7 @@ GENERATED_EVENTS_WEBIDL_FILES = [
|
|||
'MediaStreamEvent.webidl',
|
||||
'MozContactChangeEvent.webidl',
|
||||
'MozInterAppMessageEvent.webidl',
|
||||
'MozStkCommandEvent.webidl',
|
||||
'RTCDataChannelEvent.webidl',
|
||||
'RTCPeerConnectionIceEvent.webidl',
|
||||
'TrackEvent.webidl',
|
||||
|
@ -572,4 +572,3 @@ if CONFIG['MOZ_GAMEPAD']:
|
|||
'GamepadButtonEvent.webidl',
|
||||
'GamepadEvent.webidl',
|
||||
]
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче