diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index e46b21a7109..2c0bb08e744 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -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(); diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 22e1efb6bcd..cf0d7a0a8ce 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -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 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 event; nsCOMPtr 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 event; nsCOMPtr 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);