Bug 1829570 - part 3: Update an overload of AsyncEventDispatcher::RunDOMEventWhenSafe to make it work with a caller which does not specify ChromeOnlyDispatch r=smaug

The constructor of `AsyncEventDispatcher` used in `XULFrameElement` can be
merged with the first constructor to make `aOnlyChromeDispatch` an optional
argument.

Therefore, we can make the overload which is added by the previous patch
can be work with `XULFrameElement`.

Differential Revision: https://phabricator.services.mozilla.com/D176489
This commit is contained in:
Masayuki Nakano 2023-05-15 01:07:30 +00:00
parent e16a783838
commit 0e970f4c95
4 changed files with 19 additions and 28 deletions

View File

@ -113,11 +113,11 @@ void AsyncEventDispatcher::RunDOMEventWhenSafe() {
// static
void AsyncEventDispatcher::RunDOMEventWhenSafe(
nsINode& aTarget, const nsAString& aEventType, CanBubble aCanBubble,
ChromeOnlyDispatch aOnlyChromeDispatch,
EventTarget& aTarget, const nsAString& aEventType, CanBubble aCanBubble,
ChromeOnlyDispatch aOnlyChromeDispatch /* = ChromeOnlyDispatch::eNo */,
Composed aComposed /* = Composed::eDefault */) {
if (nsContentUtils::IsSafeToRunScript()) {
OwningNonNull<nsINode> target = aTarget;
OwningNonNull<EventTarget> target = aTarget;
DispatchEventOnTarget(target, aEventType, aCanBubble, aOnlyChromeDispatch,
aComposed);
return;

View File

@ -35,9 +35,10 @@ class AsyncEventDispatcher : public CancelableRunnable {
* the event is dispatched to it, otherwise the dispatch path starts
* at the first chrome ancestor of that target.
*/
AsyncEventDispatcher(nsINode* aTarget, const nsAString& aEventType,
AsyncEventDispatcher(
dom::EventTarget* aTarget, const nsAString& aEventType,
CanBubble aCanBubble,
ChromeOnlyDispatch aOnlyChromeDispatch,
ChromeOnlyDispatch aOnlyChromeDispatch = ChromeOnlyDispatch::eNo,
Composed aComposed = Composed::eDefault)
: CancelableRunnable("AsyncEventDispatcher"),
mTarget(aTarget),
@ -65,14 +66,6 @@ class AsyncEventDispatcher : public CancelableRunnable {
MOZ_ASSERT(mEventMessage != eUnidentifiedEvent);
}
AsyncEventDispatcher(dom::EventTarget* aTarget, const nsAString& aEventType,
CanBubble aCanBubble)
: CancelableRunnable("AsyncEventDispatcher"),
mTarget(aTarget),
mEventType(aEventType),
mEventMessage(eUnidentifiedEvent),
mCanBubble(aCanBubble) {}
AsyncEventDispatcher(dom::EventTarget* aTarget,
mozilla::EventMessage aEventMessage,
CanBubble aCanBubble)
@ -119,8 +112,9 @@ class AsyncEventDispatcher : public CancelableRunnable {
* asynchronous dispatching).
*/
MOZ_CAN_RUN_SCRIPT_BOUNDARY static void RunDOMEventWhenSafe(
nsINode& aTarget, const nsAString& aEventType, CanBubble aCanBubble,
ChromeOnlyDispatch aOnlyChromeDispatch,
dom::EventTarget& aTarget, const nsAString& aEventType,
CanBubble aCanBubble,
ChromeOnlyDispatch aOnlyChromeDispatch = ChromeOnlyDispatch::eNo,
Composed aComposed = Composed::eDefault);
/**

View File

@ -106,9 +106,8 @@ void XULFrameElement::LoadSrc() {
return;
}
(new AsyncEventDispatcher(this, u"XULFrameLoaderCreated"_ns,
CanBubble::eYes))
->RunDOMEventWhenSafe();
AsyncEventDispatcher::RunDOMEventWhenSafe(
*this, u"XULFrameLoaderCreated"_ns, CanBubble::eYes);
}
mFrameLoader->LoadFrame(false);

View File

@ -53,15 +53,13 @@ class XULFrameElement final : public nsXULElement, public nsFrameLoaderOwner {
mozilla::ErrorResult& rv);
// nsIContent
virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
virtual void UnbindFromTree(bool aNullParent) override;
virtual void DestroyContent() override;
nsresult BindToTree(BindContext&, nsINode& aParent) override;
void UnbindFromTree(bool aNullParent) override;
void DestroyContent() override;
virtual void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) override;
void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
const nsAttrValue* aValue, const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
NS_IMPL_FROMNODE_HELPER(XULFrameElement,
IsAnyOfXULElements(nsGkAtoms::iframe,