Bug 718274 - Implement ::DispatchUntrustedEvent and ::DispatchEvent for ContentUtils. r=mounir

This commit is contained in:
Matthew Schranz 2012-02-13 18:07:04 -05:00
parent de65bafa67
commit 2756348faf
2 changed files with 54 additions and 4 deletions

View File

@ -950,6 +950,26 @@ public:
bool aCanBubble,
bool aCancelable,
bool *aDefaultAction = nsnull);
/**
* This method creates and dispatches a untrusted event.
* Works only with events which can be created by calling
* nsIDOMDocument::CreateEvent() with parameter "Events".
* @param aDoc The document which will be used to create the event.
* @param aTarget The target of the event, should be QIable to
* nsIDOMEventTarget.
* @param aEventName The name of the event.
* @param aCanBubble Whether the event can bubble.
* @param aCancelable Is the event cancelable.
* @param aDefaultAction Set to true if default action should be taken,
* see nsIDOMEventTarget::DispatchEvent.
*/
static nsresult DispatchUntrustedEvent(nsIDocument* aDoc,
nsISupports* aTarget,
const nsAString& aEventName,
bool aCanBubble,
bool aCancelable,
bool *aDefaultAction = nsnull);
/**
* This method creates and dispatches a trusted event to the chrome
@ -1945,6 +1965,14 @@ private:
const nsIID* aIID, jsval *vp,
nsIXPConnectJSObjectHolder** aHolder,
bool aAllowWrapping);
static nsresult DispatchEvent(nsIDocument* aDoc,
nsISupports* aTarget,
const nsAString& aEventName,
bool aCanBubble,
bool aCancelable,
bool aTrusted,
bool *aDefaultAction = nsnull);
static void InitializeModifierStrings();

View File

@ -3072,7 +3072,7 @@ static
nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget,
const nsAString& aEventName,
bool aCanBubble, bool aCancelable,
nsIDOMEvent** aEvent,
bool aTrusted, nsIDOMEvent** aEvent,
nsIDOMEventTarget** aTargetOut)
{
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aDoc);
@ -3090,7 +3090,7 @@ nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget,
rv = event->InitEvent(aEventName, aCanBubble, aCancelable);
NS_ENSURE_SUCCESS(rv, rv);
rv = privateEvent->SetTrusted(true);
rv = privateEvent->SetTrusted(aTrusted);
NS_ENSURE_SUCCESS(rv, rv);
rv = privateEvent->SetTarget(target);
@ -3107,11 +3107,33 @@ nsContentUtils::DispatchTrustedEvent(nsIDocument* aDoc, nsISupports* aTarget,
const nsAString& aEventName,
bool aCanBubble, bool aCancelable,
bool *aDefaultAction)
{
return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable,
true, aDefaultAction);
}
// static
nsresult
nsContentUtils::DispatchUntrustedEvent(nsIDocument* aDoc, nsISupports* aTarget,
const nsAString& aEventName,
bool aCanBubble, bool aCancelable,
bool *aDefaultAction)
{
return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable,
false, aDefaultAction);
}
// static
nsresult
nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget,
const nsAString& aEventName,
bool aCanBubble, bool aCancelable,
bool aTrusted, bool *aDefaultAction)
{
nsCOMPtr<nsIDOMEvent> event;
nsCOMPtr<nsIDOMEventTarget> target;
nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble,
aCancelable, getter_AddRefs(event),
aCancelable, aTrusted, getter_AddRefs(event),
getter_AddRefs(target));
NS_ENSURE_SUCCESS(rv, rv);
@ -3130,7 +3152,7 @@ nsContentUtils::DispatchChromeEvent(nsIDocument *aDoc,
nsCOMPtr<nsIDOMEvent> event;
nsCOMPtr<nsIDOMEventTarget> target;
nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble,
aCancelable, getter_AddRefs(event),
aCancelable, true, getter_AddRefs(event),
getter_AddRefs(target));
NS_ENSURE_SUCCESS(rv, rv);