forked from mirrors/gecko-dev
Bug 1557407 - Replace DispatchTrustedEvent with DispatchEventOnlyToChrome for various chrome-only events, r=smaug
Adds an |aChromeOnlyDispatch| flag to DispatchCustomEvent to decide whether to call DispatchTrustEvent or DispatchEventOnlyToChrome. The following chrome-only events are dispatched with DispatchCustomEvent and now make use of the flag: - DOMWindowClose - fullscreen / willenterfullscreen / willexitfullscreen - occlusionstatechange - resolutionchange - XULAlertClose and the following were previously dispatched with DispatchTrustedEvent and now use DispatchEventOnlyToChrome: - MozBeforeInitialXULLayout - MozMouseScrollFailed / MozMouseScrollTransactionTimeout - MozPaintWait / MozPaintWaitFinished - MozPerformDelayedBlur - all events fired by APZCCallbackHelper::NotifyMozMouseScrollEvent Differential Revision: https://phabricator.services.mozilla.com/D76723
This commit is contained in:
parent
517b55f90b
commit
2b8ca16f35
11 changed files with 60 additions and 28 deletions
|
|
@ -4302,9 +4302,10 @@ void nsContentUtils::RequestFrameFocus(Element& aFrameElement, bool aCanRaise,
|
|||
|
||||
nsresult nsContentUtils::DispatchEventOnlyToChrome(
|
||||
Document* aDoc, nsISupports* aTarget, const nsAString& aEventName,
|
||||
CanBubble aCanBubble, Cancelable aCancelable, bool* aDefaultAction) {
|
||||
CanBubble aCanBubble, Cancelable aCancelable, Composed aComposed,
|
||||
bool* aDefaultAction) {
|
||||
return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable,
|
||||
Composed::eDefault, Trusted::eYes, aDefaultAction,
|
||||
aComposed, Trusted::eYes, aDefaultAction,
|
||||
ChromeOnlyDispatch::eYes);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1598,14 +1598,22 @@ class nsContentUtils {
|
|||
* @param aEventName The name of the event.
|
||||
* @param aCanBubble Whether the event can bubble.
|
||||
* @param aCancelable Is the event cancelable.
|
||||
* @param aComposed Is the event composed.
|
||||
* @param aDefaultAction Set to true if default action should be taken,
|
||||
* see EventTarget::DispatchEvent.
|
||||
*/
|
||||
static nsresult DispatchEventOnlyToChrome(Document* aDoc,
|
||||
nsISupports* aTarget,
|
||||
const nsAString& aEventName,
|
||||
CanBubble, Cancelable,
|
||||
bool* aDefaultAction = nullptr);
|
||||
static nsresult DispatchEventOnlyToChrome(
|
||||
Document* aDoc, nsISupports* aTarget, const nsAString& aEventName,
|
||||
CanBubble, Cancelable, Composed aComposed = Composed::eDefault,
|
||||
bool* aDefaultAction = nullptr);
|
||||
|
||||
static nsresult DispatchEventOnlyToChrome(
|
||||
Document* aDoc, nsISupports* aTarget, const nsAString& aEventName,
|
||||
CanBubble aCanBubble, Cancelable aCancelable, bool* aDefaultAction) {
|
||||
return DispatchEventOnlyToChrome(aDoc, aTarget, aEventName, aCanBubble,
|
||||
aCancelable, Composed::eDefault,
|
||||
aDefaultAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if an event attribute name (such as onclick) is valid for
|
||||
|
|
|
|||
|
|
@ -4179,11 +4179,19 @@ already_AddRefed<BrowsingContext> nsGlobalWindowOuter::GetChildWindow(
|
|||
mBrowsingContext->FindChildWithName(aName, *mBrowsingContext));
|
||||
}
|
||||
|
||||
bool nsGlobalWindowOuter::DispatchCustomEvent(const nsAString& aEventName) {
|
||||
bool nsGlobalWindowOuter::DispatchCustomEvent(
|
||||
const nsAString& aEventName, ChromeOnlyDispatch aChromeOnlyDispatch) {
|
||||
bool defaultActionEnabled = true;
|
||||
nsContentUtils::DispatchTrustedEvent(mDoc, ToSupports(this), aEventName,
|
||||
CanBubble::eYes, Cancelable::eYes,
|
||||
&defaultActionEnabled);
|
||||
|
||||
if (aChromeOnlyDispatch == ChromeOnlyDispatch::eYes) {
|
||||
nsContentUtils::DispatchEventOnlyToChrome(
|
||||
mDoc, ToSupports(this), aEventName, CanBubble::eYes, Cancelable::eYes,
|
||||
&defaultActionEnabled);
|
||||
} else {
|
||||
nsContentUtils::DispatchTrustedEvent(mDoc, ToSupports(this), aEventName,
|
||||
CanBubble::eYes, Cancelable::eYes,
|
||||
&defaultActionEnabled);
|
||||
}
|
||||
|
||||
return defaultActionEnabled;
|
||||
}
|
||||
|
|
@ -4671,9 +4679,11 @@ bool nsGlobalWindowOuter::SetWidgetFullscreen(FullscreenReason aReason,
|
|||
/* virtual */
|
||||
void nsGlobalWindowOuter::FullscreenWillChange(bool aIsFullscreen) {
|
||||
if (aIsFullscreen) {
|
||||
DispatchCustomEvent(NS_LITERAL_STRING("willenterfullscreen"));
|
||||
DispatchCustomEvent(NS_LITERAL_STRING("willenterfullscreen"),
|
||||
ChromeOnlyDispatch::eYes);
|
||||
} else {
|
||||
DispatchCustomEvent(NS_LITERAL_STRING("willexitfullscreen"));
|
||||
DispatchCustomEvent(NS_LITERAL_STRING("willexitfullscreen"),
|
||||
ChromeOnlyDispatch::eYes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4708,7 +4718,8 @@ void nsGlobalWindowOuter::FinishFullscreenChange(bool aIsFullscreen) {
|
|||
|
||||
// dispatch a "fullscreen" DOM event so that XUL apps can
|
||||
// respond visually if we are kicked into full screen mode
|
||||
DispatchCustomEvent(NS_LITERAL_STRING("fullscreen"));
|
||||
DispatchCustomEvent(NS_LITERAL_STRING("fullscreen"),
|
||||
ChromeOnlyDispatch::eYes);
|
||||
|
||||
if (!NS_WARN_IF(!IsChromeWindow())) {
|
||||
if (RefPtr<PresShell> presShell =
|
||||
|
|
@ -6112,7 +6123,8 @@ void nsGlobalWindowOuter::CloseOuter(bool aTrustedCaller) {
|
|||
bool wasInClose = mInClose;
|
||||
mInClose = true;
|
||||
|
||||
if (!DispatchCustomEvent(NS_LITERAL_STRING("DOMWindowClose"))) {
|
||||
if (!DispatchCustomEvent(NS_LITERAL_STRING("DOMWindowClose"),
|
||||
ChromeOnlyDispatch::eYes)) {
|
||||
// Someone chose to prevent the default action for this event, if
|
||||
// so, let's not close this window after all...
|
||||
|
||||
|
|
@ -6145,7 +6157,8 @@ void nsGlobalWindowOuter::ForceClose() {
|
|||
|
||||
mInClose = true;
|
||||
|
||||
DispatchCustomEvent(NS_LITERAL_STRING("DOMWindowClose"));
|
||||
DispatchCustomEvent(NS_LITERAL_STRING("DOMWindowClose"),
|
||||
ChromeOnlyDispatch::eYes);
|
||||
|
||||
FinalClose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -331,7 +331,9 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
|||
virtual void ForceClose() override;
|
||||
|
||||
// Outer windows only.
|
||||
virtual bool DispatchCustomEvent(const nsAString& aEventName) override;
|
||||
virtual bool DispatchCustomEvent(
|
||||
const nsAString& aEventName,
|
||||
mozilla::ChromeOnlyDispatch aChromeOnlyDispatch) override;
|
||||
bool DispatchResizeEvent(const mozilla::CSSIntSize& aSize);
|
||||
|
||||
// For accessing protected field mFullscreen
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/dom/EventTarget.h"
|
||||
#include "mozilla/EventForwards.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/TaskCategory.h"
|
||||
#include "js/TypeDecls.h"
|
||||
|
|
@ -964,7 +965,10 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
|
|||
*
|
||||
* Outer windows only.
|
||||
*/
|
||||
virtual bool DispatchCustomEvent(const nsAString& aEventName) = 0;
|
||||
virtual bool DispatchCustomEvent(
|
||||
const nsAString& aEventName,
|
||||
mozilla::ChromeOnlyDispatch aChromeOnlyDispatch =
|
||||
mozilla::ChromeOnlyDispatch::eNo) = 0;
|
||||
|
||||
/**
|
||||
* Like nsIDOMWindow::Open, except that we don't navigate to the given URL.
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ void WheelTransaction::OnFailToScrollTarget() {
|
|||
|
||||
if (StaticPrefs::test_mousescroll()) {
|
||||
// This event is used for automated tests, see bug 442774.
|
||||
nsContentUtils::DispatchTrustedEvent(
|
||||
nsContentUtils::DispatchEventOnlyToChrome(
|
||||
sTargetFrame->GetContent()->OwnerDoc(), sTargetFrame->GetContent(),
|
||||
NS_LITERAL_STRING("MozMouseScrollFailed"), CanBubble::eYes,
|
||||
Cancelable::eYes);
|
||||
|
|
@ -327,7 +327,7 @@ void WheelTransaction::OnTimeout(nsITimer* aTimer, void* aClosure) {
|
|||
|
||||
if (StaticPrefs::test_mousescroll()) {
|
||||
// This event is used for automated tests, see bug 442774.
|
||||
nsContentUtils::DispatchTrustedEvent(
|
||||
nsContentUtils::DispatchEventOnlyToChrome(
|
||||
frame->GetContent()->OwnerDoc(), frame->GetContent(),
|
||||
NS_LITERAL_STRING("MozMouseScrollTransactionTimeout"), CanBubble::eYes,
|
||||
Cancelable::eYes);
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class AsyncPaintWaitEvent : public Runnable {
|
|||
mFinished(aFinished) {}
|
||||
|
||||
NS_IMETHOD Run() override {
|
||||
nsContentUtils::DispatchTrustedEvent(
|
||||
nsContentUtils::DispatchEventOnlyToChrome(
|
||||
mContent->OwnerDoc(), mContent,
|
||||
mFinished ? NS_LITERAL_STRING("MozPaintWaitFinished")
|
||||
: NS_LITERAL_STRING("MozPaintWait"),
|
||||
|
|
@ -1933,7 +1933,7 @@ void nsPluginInstanceOwner::PerformDelayedBlurs() {
|
|||
nsCOMPtr<nsIContent> content = do_QueryReferent(mContent);
|
||||
nsCOMPtr<EventTarget> windowRoot =
|
||||
content->OwnerDoc()->GetWindow()->GetTopWindowRoot();
|
||||
nsContentUtils::DispatchTrustedEvent(
|
||||
nsContentUtils::DispatchEventOnlyToChrome(
|
||||
content->OwnerDoc(), windowRoot,
|
||||
NS_LITERAL_STRING("MozPerformDelayedBlur"), CanBubble::eNo,
|
||||
Cancelable::eNo, nullptr);
|
||||
|
|
|
|||
|
|
@ -608,7 +608,7 @@ nsresult PrototypeDocumentContentSink::DoneWalking() {
|
|||
mDocument->SetReadyStateInternal(Document::READYSTATE_INTERACTIVE);
|
||||
mDocument->NotifyPossibleTitleChange(false);
|
||||
|
||||
nsContentUtils::DispatchTrustedEvent(
|
||||
nsContentUtils::DispatchEventOnlyToChrome(
|
||||
mDocument, ToSupports(mDocument),
|
||||
NS_LITERAL_STRING("MozBeforeInitialXULLayout"), CanBubble::eYes,
|
||||
Cancelable::eNo);
|
||||
|
|
|
|||
|
|
@ -791,8 +791,8 @@ void APZCCallbackHelper::NotifyMozMouseScrollEvent(
|
|||
return;
|
||||
}
|
||||
|
||||
nsContentUtils::DispatchTrustedEvent(ownerDoc, targetContent, aEvent,
|
||||
CanBubble::eYes, Cancelable::eYes);
|
||||
nsContentUtils::DispatchEventOnlyToChrome(ownerDoc, targetContent, aEvent,
|
||||
CanBubble::eYes, Cancelable::eYes);
|
||||
}
|
||||
|
||||
void APZCCallbackHelper::NotifyFlushComplete(PresShell* aPresShell) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/EventForwards.h"
|
||||
#include "mozilla/LookAndFeel.h"
|
||||
#include "mozilla/dom/Notification.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
|
@ -395,7 +396,8 @@ nsXULAlerts::CloseAlert(const nsAString& aAlertName, nsIPrincipal* aPrincipal) {
|
|||
mozIDOMWindowProxy* alert = mNamedWindows.GetWeak(aAlertName);
|
||||
if (nsCOMPtr<nsPIDOMWindowOuter> domWindow =
|
||||
nsPIDOMWindowOuter::From(alert)) {
|
||||
domWindow->DispatchCustomEvent(NS_LITERAL_STRING("XULAlertClose"));
|
||||
domWindow->DispatchCustomEvent(NS_LITERAL_STRING("XULAlertClose"),
|
||||
ChromeOnlyDispatch::eYes);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2700,7 +2700,8 @@ void AppWindow::UIResolutionChanged() {
|
|||
nsCOMPtr<nsPIDOMWindowOuter> ourWindow =
|
||||
mDocShell ? mDocShell->GetWindow() : nullptr;
|
||||
if (ourWindow) {
|
||||
ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("resolutionchange"));
|
||||
ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("resolutionchange"),
|
||||
ChromeOnlyDispatch::eYes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2725,7 +2726,8 @@ void AppWindow::OcclusionStateChanged(bool aIsFullyOccluded) {
|
|||
mDocShell ? mDocShell->GetWindow() : nullptr;
|
||||
if (ourWindow) {
|
||||
// And always fire a user-defined occlusionstatechange event on the window
|
||||
ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("occlusionstatechange"));
|
||||
ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("occlusionstatechange"),
|
||||
ChromeOnlyDispatch::eYes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue