Bug 1536353 - part 3: Make nsIDOMWindowUtils.dispatchDOMEventViaPresShell() dispatch only trusted event r=smaug

In normal cases, `PresShell::EventHandler` won't receive untrusted event.
However, only `nsIDOMWindowUtils.dispatchDOMEventViaPresShell()` may send
untrusted event if its `aTrusted` is false.  Currently, this is not used by
chrome so that we don't need to keep supporting it for dispatching untrusted
events.

This patch removes `aTrusted` argument from it.

Differential Revision: https://phabricator.services.mozilla.com/D24870

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-03-26 10:10:22 +00:00
parent dbf37b7d62
commit e35cfd926c
10 changed files with 15 additions and 14 deletions

View File

@ -1673,9 +1673,9 @@ nsDOMWindowUtils::GetFullZoom(float* aFullZoom) {
NS_IMETHODIMP
nsDOMWindowUtils::DispatchDOMEventViaPresShell(nsINode* aTarget, Event* aEvent,
bool aTrusted, bool* aRetVal) {
bool* aRetVal) {
NS_ENSURE_STATE(aEvent);
aEvent->SetTrusted(aTrusted);
aEvent->SetTrusted(true);
WidgetEvent* internalEvent = aEvent->WidgetEventPtr();
NS_ENSURE_STATE(internalEvent);
nsCOMPtr<nsIContent> content = do_QueryInterface(aTarget);

View File

@ -7,5 +7,5 @@
bubbles: true
});
let utils = SpecialPowers.getDOMWindowUtils(window);
utils.dispatchDOMEventViaPresShell(document.documentElement, e, false);
utils.dispatchDOMEventViaPresShell(document.documentElement, e);
</script>

View File

@ -13,7 +13,7 @@ var gGotNotHandlingDrop = false;
SimpleTest.waitForExplicitFinish();
function fireEvent(target, event) {
SpecialPowers.DOMWindowUtils.dispatchDOMEventViaPresShell(target, event, true);
SpecialPowers.DOMWindowUtils.dispatchDOMEventViaPresShell(target, event);
}
function fireDrop(element, shouldAllowDrop, shouldAllowOnlyChromeDrop) {

View File

@ -31,7 +31,7 @@ function completeTest(aBox) {
function fireEvent(target, event) {
var win = target.ownerGlobal;
var utils = win.windowUtils;
utils.dispatchDOMEventViaPresShell(target, event, true);
utils.dispatchDOMEventViaPresShell(target, event);
}
function RunTest() {

View File

@ -30,7 +30,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=593959
var e = document.createEvent("MouseEvent");
e.initEvent("mousedown", false, false, window, 0, 1, 1, 1, 1,
false, false, false, false, 0, null);
utils.dispatchDOMEventViaPresShell(document.body, e, true);
utils.dispatchDOMEventViaPresShell(document.body, e);
is(document.querySelector("body:active"), document.body, "body should be active!")
@ -41,7 +41,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=593959
var e2 = ifrwindow.document.createEvent("MouseEvent");
e2.initEvent("mouseup", false, false, ifrwindow, 0, 1, 1, 1, 1,
false, false, false, false, 0, null);
utils2.dispatchDOMEventViaPresShell(ifrwindow.document.body, e2, true);
utils2.dispatchDOMEventViaPresShell(ifrwindow.document.body, e2);
isnot(document.querySelector("body:active"), document.body, "body shouldn't be active!")

View File

@ -937,7 +937,8 @@ interface nsIDOMWindowUtils : nsISupports {
readonly attribute float fullZoom;
/**
* Dispatches aEvent via the nsIPresShell object of the window's document.
* Dispatches aEvent as a trusted event via the nsIPresShell object of the
* window's document.
* The event is dispatched to aTarget, which should be an object
* which implements nsIContent interface (#element, #text, etc).
*
@ -948,9 +949,9 @@ interface nsIDOMWindowUtils : nsISupports {
* @note Event handlers won't get aEvent as parameter, but a similar event.
* Also, aEvent should not be reused.
*/
[can_run_script]
boolean dispatchDOMEventViaPresShell(in Node aTarget,
in Event aEvent,
in boolean aTrusted);
in Event aEvent);
/**
* Sets WidgetEvent::mFlags::mOnlyChromeDispatch to true to ensure that

View File

@ -49,7 +49,7 @@ function sendMouseUp(el) {
function fireEvent(target, event) {
var utils = SpecialPowers.getDOMWindowUtils(window);
utils.dispatchDOMEventViaPresShell(target, event, true);
utils.dispatchDOMEventViaPresShell(target, event);
}
function fireDrop(element) {

View File

@ -260,7 +260,7 @@ function sendDragEvent(aEvent, aTarget, aWindow = window) {
}
var utils = _getDOMWindowUtils(aWindow);
return utils.dispatchDOMEventViaPresShell(aTarget, event, true);
return utils.dispatchDOMEventViaPresShell(aTarget, event);
}
/**

View File

@ -85,7 +85,7 @@ function dispatchMouseEvent(target, type) {
e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
false, false, false, false, 0, null);
var utils = SpecialPowers.getDOMWindowUtils(win);
utils.dispatchDOMEventViaPresShell(target, e, true);
utils.dispatchDOMEventViaPresShell(target, e);
ok(true, type + " sent to " + target.id);
}

View File

@ -193,7 +193,7 @@ function dispatchMouseEvent(target, type) {
e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
false, false, false, false, 0, null);
var utils = SpecialPowers.getDOMWindowUtils(win);
utils.dispatchDOMEventViaPresShell(SpecialPowers.unwrap(target), e, true);
utils.dispatchDOMEventViaPresShell(SpecialPowers.unwrap(target), e);
}
</script>
</body>