gecko-dev/toolkit/components/windowwatcher/nsAutoWindowStateHelper.cpp
Aryeh Gregor af57d2df0f Bug 1251198 - Remove various obsolete events from document.createEvent r=smaug
Other browsers do not support any of these (IIRC), telemetry reports
essentially zero usage, and supporting them is contrary to the DOM spec.

Notes on specific events:

CommandEvent and SimpleGestureEvent: These are not supposed to be
web-exposed APIs, so I hid the interfaces from web content too
(necessary to avoid test_all_synthetic_events.html failures).

DataContainerEvent: This was a non-standard substitute for CustomEvent
that seemed to have only one user, so I removed it entirely and switched
the user (MozillaFileLogger.js) to CustomEvent.

ScrollAreaEvent: This is entirely non-standard, but we apparently expose
it deliberately to web content, so I didn't see any reason to remove it
from createEvent.

SimpleGestureEvent and XULCommandEvent: Can still be created from
createEvent(), but not by content.

TimeEvent: This is still in because it has no constructor, so there's no
other way to create it.  Ideally we'd update the SMIL spec to add a
constructor.  I did remove TimeEvents.

MozReview-Commit-ID: 7Yi2oCl9SM2

--HG--
extra : rebase_source : 199ab921acfc531b8b85e77f90fcd799b03c887b
2017-04-20 15:45:37 +03:00

75 lines
2.1 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsAutoWindowStateHelper.h"
#include "mozilla/dom/Event.h"
#include "nsIDocument.h"
#include "nsIDOMEvent.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsString.h"
using namespace mozilla;
using namespace mozilla::dom;
/****************************************************************
****************** nsAutoWindowStateHelper *********************
****************************************************************/
nsAutoWindowStateHelper::nsAutoWindowStateHelper(nsPIDOMWindowOuter* aWindow)
: mWindow(aWindow)
, mDefaultEnabled(DispatchEventToChrome("DOMWillOpenModalDialog"))
{
if (mWindow) {
mWindow->EnterModalState();
}
}
nsAutoWindowStateHelper::~nsAutoWindowStateHelper()
{
if (mWindow) {
mWindow->LeaveModalState();
}
if (mDefaultEnabled) {
DispatchEventToChrome("DOMModalDialogClosed");
}
}
bool
nsAutoWindowStateHelper::DispatchEventToChrome(const char* aEventName)
{
// XXXbz should we skip dispatching the event if the inner changed?
// That is, should we store both the inner and the outer?
if (!mWindow) {
return true;
}
// The functions of nsContentUtils do not provide the required behavior,
// so the following is inlined.
nsIDocument* doc = mWindow->GetExtantDoc();
if (!doc) {
return true;
}
ErrorResult rv;
RefPtr<Event> event = doc->CreateEvent(NS_LITERAL_STRING("Events"),
CallerType::System, rv);
if (rv.Failed()) {
rv.SuppressException();
return false;
}
event->InitEvent(NS_ConvertASCIItoUTF16(aEventName), true, true);
event->SetTrusted(true);
event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
nsCOMPtr<EventTarget> target = do_QueryInterface(mWindow);
bool defaultActionEnabled;
target->DispatchEvent(event, &defaultActionEnabled);
return defaultActionEnabled;
}