From e1b3a9ea416bd1b7782a4f9ebf5fd389ceaa98ed Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Mon, 30 Jun 2014 16:00:31 -0700 Subject: [PATCH] Bug 1031051: Part 3 - Migrate CloseEvent to the WebIDL code generator. r=smaug --- content/base/src/WebSocket.cpp | 22 +++++++--------- dom/events/EventDispatcher.cpp | 10 ++++++-- dom/interfaces/events/moz.build | 1 - dom/interfaces/events/nsIDOMCloseEvent.idl | 28 --------------------- dom/webidl/CloseEvent.webidl | 15 ++++++----- dom/webidl/moz.build | 1 + js/xpconnect/src/event_impl_gen.conf.in | 1 - xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp | 3 --- 8 files changed, 25 insertions(+), 56 deletions(-) delete mode 100644 dom/interfaces/events/nsIDOMCloseEvent.idl diff --git a/content/base/src/WebSocket.cpp b/content/base/src/WebSocket.cpp index b2bf682a493a..2101493984fb 100644 --- a/content/base/src/WebSocket.cpp +++ b/content/base/src/WebSocket.cpp @@ -29,7 +29,7 @@ #include "nsIPrompt.h" #include "nsIStringBundle.h" #include "nsIConsoleService.h" -#include "nsIDOMCloseEvent.h" +#include "mozilla/dom/CloseEvent.h" #include "nsICryptoHash.h" #include "nsJSUtils.h" #include "nsIScriptError.h" @@ -928,19 +928,15 @@ WebSocket::CreateAndDispatchCloseEvent(bool aWasClean, return NS_OK; } - // create an event that uses the CloseEvent interface, - // which does not bubble, is not cancelable, and has no default action - - nsCOMPtr event; - rv = NS_NewDOMCloseEvent(getter_AddRefs(event), this, nullptr, nullptr); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr closeEvent = do_QueryInterface(event); - rv = closeEvent->InitCloseEvent(NS_LITERAL_STRING("close"), - false, false, - aWasClean, aCode, aReason); - NS_ENSURE_SUCCESS(rv, rv); + CloseEventInit init; + init.mBubbles = false; + init.mCancelable = false; + init.mWasClean = aWasClean; + init.mCode = aCode; + init.mReason = aReason; + nsRefPtr event = + CloseEvent::Constructor(this, NS_LITERAL_STRING("close"), init); event->SetTrusted(true); return DispatchDOMEvent(nullptr, event, nullptr, nullptr); diff --git a/dom/events/EventDispatcher.cpp b/dom/events/EventDispatcher.cpp index ebef22b8ac52..d62975eb4130 100644 --- a/dom/events/EventDispatcher.cpp +++ b/dom/events/EventDispatcher.cpp @@ -15,6 +15,7 @@ #include "GeckoProfiler.h" #include "GeneratedEvents.h" #include "mozilla/ContentEvents.h" +#include "mozilla/dom/CloseEvent.h" #include "mozilla/dom/EventTarget.h" #include "mozilla/dom/HashChangeEvent.h" #include "mozilla/dom/StorageEvent.h" @@ -823,8 +824,13 @@ EventDispatcher::CreateEvent(EventTarget* aOwner, return NS_NewDOMScrollAreaEvent(aDOMEvent, aOwner, aPresContext, nullptr); if (aEventType.LowerCaseEqualsLiteral("popstateevent")) return NS_NewDOMPopStateEvent(aDOMEvent, aOwner, aPresContext, nullptr); - if (aEventType.LowerCaseEqualsLiteral("closeevent")) - return NS_NewDOMCloseEvent(aDOMEvent, aOwner, aPresContext, nullptr); + if (aEventType.LowerCaseEqualsLiteral("closeevent")) { + CloseEventInit init; + nsRefPtr event = + CloseEvent::Constructor(aOwner, EmptyString(), init); + event.forget(aDOMEvent); + return NS_OK; + } if (aEventType.LowerCaseEqualsLiteral("touchevent") && TouchEvent::PrefEnabled()) return NS_NewDOMTouchEvent(aDOMEvent, aOwner, aPresContext, nullptr); diff --git a/dom/interfaces/events/moz.build b/dom/interfaces/events/moz.build index 2c1f40448a73..63779f628fc1 100644 --- a/dom/interfaces/events/moz.build +++ b/dom/interfaces/events/moz.build @@ -8,7 +8,6 @@ XPIDL_SOURCES += [ 'nsIDOMAnimationEvent.idl', 'nsIDOMBeforeUnloadEvent.idl', 'nsIDOMClipboardEvent.idl', - 'nsIDOMCloseEvent.idl', 'nsIDOMCommandEvent.idl', 'nsIDOMCompositionEvent.idl', 'nsIDOMCustomEvent.idl', diff --git a/dom/interfaces/events/nsIDOMCloseEvent.idl b/dom/interfaces/events/nsIDOMCloseEvent.idl deleted file mode 100644 index 5edce99cc0cb..000000000000 --- a/dom/interfaces/events/nsIDOMCloseEvent.idl +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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 "nsIDOMEvent.idl" - -/** - * The CloseEvent interface is the interface to the event - * close on a WebSocket object. - * - * For more information on this interface, please see - * http://dev.w3.org/html5/websockets/#closeevent - */ -[builtinclass, uuid(0b85dc61-2436-4786-b153-097f5c3a33b6)] -interface nsIDOMCloseEvent : nsIDOMEvent -{ - readonly attribute boolean wasClean; - readonly attribute unsigned short code; - readonly attribute DOMString reason; - - void initCloseEvent(in DOMString aType, - in boolean aCanBubble, - in boolean aCancelable, - in boolean aWasClean, - in unsigned short aReasonCode, - in DOMString aReason); -}; diff --git a/dom/webidl/CloseEvent.webidl b/dom/webidl/CloseEvent.webidl index 220da9c34b88..9a64564bfe02 100644 --- a/dom/webidl/CloseEvent.webidl +++ b/dom/webidl/CloseEvent.webidl @@ -10,21 +10,20 @@ * http://www.whatwg.org/specs/web-apps/current-work/multipage/network.html#closeevent */ -[Constructor(DOMString type, optional CloseEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"] +[Constructor(DOMString type, optional CloseEventInit eventInitDict),LegacyEventInit] interface CloseEvent : Event { readonly attribute boolean wasClean; readonly attribute unsigned short code; readonly attribute DOMString? reason; - // initCloseEvent is a Gecko specific deprecated method. [Throws] - void initCloseEvent(DOMString type, - boolean canBubble, - boolean cancelable, - boolean wasClean, - unsigned short code, - DOMString? reason); + void initCloseEvent(DOMString aType, + boolean aCanBubble, + boolean aCancelable, + boolean aWasClean, + unsigned short aReasonCode, + DOMString? aReason); }; dictionary CloseEventInit : EventInit diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 8819a9f60c11..9173121ca451 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -630,6 +630,7 @@ GENERATED_EVENTS_WEBIDL_FILES = [ 'CallEvent.webidl', 'CallGroupErrorEvent.webidl', 'CFStateChangeEvent.webidl', + 'CloseEvent.webidl', 'DataErrorEvent.webidl', 'DataStoreChangeEvent.webidl', 'DeviceLightEvent.webidl', diff --git a/js/xpconnect/src/event_impl_gen.conf.in b/js/xpconnect/src/event_impl_gen.conf.in index 97d04d3b35cc..0e841ca49206 100644 --- a/js/xpconnect/src/event_impl_gen.conf.in +++ b/js/xpconnect/src/event_impl_gen.conf.in @@ -13,7 +13,6 @@ simple_events = [ 'PageTransitionEvent', 'DOMTransactionEvent', 'PopStateEvent', - 'CloseEvent', 'DeviceOrientationEvent', 'MozApplicationEvent', 'SmartCardEvent', diff --git a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp index d45f08d122ce..b79696cfb6d0 100644 --- a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp @@ -16,7 +16,6 @@ #include "nsIDOMClientRect.h" #include "nsIDOMClientRectList.h" #include "nsIDOMClipboardEvent.h" -#include "nsIDOMCloseEvent.h" #include "nsIDOMCommandEvent.h" #include "nsIDOMComment.h" #include "nsIDOMCompositionEvent.h" @@ -174,7 +173,6 @@ #include "mozilla/dom/DOMRectBinding.h" #include "mozilla/dom/DOMRectListBinding.h" #include "mozilla/dom/ClipboardEventBinding.h" -#include "mozilla/dom/CloseEventBinding.h" #include "mozilla/dom/CommandEventBinding.h" #include "mozilla/dom/CommentBinding.h" #include "mozilla/dom/CompositionEventBinding.h" @@ -384,7 +382,6 @@ const ComponentsInterfaceShimEntry kComponentsInterfaceShimMap[] = DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMClientRect, DOMRectReadOnly), DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMClientRectList, DOMRectList), DEFINE_SHIM(ClipboardEvent), - DEFINE_SHIM(CloseEvent), DEFINE_SHIM(CommandEvent), DEFINE_SHIM(Comment), DEFINE_SHIM(CompositionEvent),