Bug 777278 - Implement nsIDOMStorageEvent using event implementation codegen, r=mayhemer
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 01 Aug 2012 19:17:19 +0300
changeset 102928 476a189f5cda075980415dd9b819d007cb0520bc
parent 102927 f6daa7cc4dd93c1a6d7e7847f2df86371ede6383
child 102929 4198ceecf0ee583061677538cdc7718cf7256556
push id18
push usershu@rfrn.org
push dateMon, 06 Aug 2012 22:42:45 +0000
reviewersmayhemer
bugs777278
milestone17.0a1
Bug 777278 - Implement nsIDOMStorageEvent using event implementation codegen, r=mayhemer
content/events/src/nsEventDispatcher.cpp
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/base/nsGlobalWindow.cpp
dom/src/storage/nsDOMStorage.cpp
dom/src/storage/nsDOMStorage.h
js/xpconnect/src/dictionary_helper_gen.conf
js/xpconnect/src/event_impl_gen.conf.in
--- a/content/events/src/nsEventDispatcher.cpp
+++ b/content/events/src/nsEventDispatcher.cpp
@@ -861,15 +861,14 @@ nsEventDispatcher::CreateEvent(nsPresCon
     return NS_NewDOMTouchEvent(aDOMEvent, aPresContext, nullptr);
   if (aEventType.LowerCaseEqualsLiteral("hashchangeevent"))
     return NS_NewDOMHashChangeEvent(aDOMEvent, aPresContext, nullptr);
   if (aEventType.LowerCaseEqualsLiteral("customevent"))
     return NS_NewDOMCustomEvent(aDOMEvent, aPresContext, nullptr);
   if (aEventType.LowerCaseEqualsLiteral("mozsmsevent"))
     return NS_NewDOMSmsEvent(aDOMEvent, aPresContext, nullptr);
   if (aEventType.LowerCaseEqualsLiteral("storageevent")) {
-    NS_ADDREF(*aDOMEvent = static_cast<nsDOMEvent*>(new nsDOMStorageEvent()));
-    return NS_OK;
+    return NS_NewDOMStorageEvent(aDOMEvent, aPresContext, nsnull);
   }
     
 
   return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
 }
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -1366,18 +1366,16 @@ static nsDOMClassInfoData sClassInfoData
                            nsIXPCScriptable::WANT_NEWRESOLVE |
                            nsIXPCScriptable::WANT_GETPROPERTY |
                            nsIXPCScriptable::WANT_SETPROPERTY |
                            nsIXPCScriptable::WANT_DELPROPERTY |
                            nsIXPCScriptable::DONT_ENUM_STATIC_PROPS |
                            nsIXPCScriptable::WANT_NEWENUMERATE)
   NS_DEFINE_CLASSINFO_DATA(StorageItem, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
-  NS_DEFINE_CLASSINFO_DATA(StorageEvent, nsDOMGenericSH,
-                           DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(DOMParser, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(XMLSerializer, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(XMLHttpProgressEvent, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
@@ -1744,23 +1742,16 @@ NS_DEFINE_EVENT_CTOR(MozWifiConnectionIn
 
 #define MOZ_GENERATED_EVENT_LIST
 #define MOZ_GENERATED_EVENT(_event_interface) \
   NS_DEFINE_EVENT_CTOR(_event_interface)
 #include "GeneratedEvents.h"
 #undef MOZ_GENERATED_EVENT_LIST
 
 nsresult
-NS_DOMStorageEventCtor(nsISupports** aInstancePtrResult)
-{
-  nsDOMStorageEvent* e = new nsDOMStorageEvent();
-  return CallQueryInterface(e, aInstancePtrResult);
-}
-
-nsresult
 NS_XMLHttpRequestCtor(nsISupports** aInstancePtrResult)
 {
   nsXMLHttpRequest* xhr = new nsXMLHttpRequest();
   return CallQueryInterface(xhr, aInstancePtrResult);
 }
 
 struct nsConstructorFuncMapData
 {
@@ -1777,17 +1768,16 @@ struct nsConstructorFuncMapData
 static const nsConstructorFuncMapData kConstructorFuncMap[] =
 {
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(Blob, nsDOMMultipartFile::NewBlob)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(File, nsDOMFileFile::NewFile)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozBlobBuilder, NS_NewBlobBuilder)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(Event)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(UIEvent)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MouseEvent)
-  NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(StorageEvent)
 #ifdef MOZ_B2G_RIL
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MozWifiStatusChangeEvent)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MozWifiConnectionInfoEvent)
 #endif
 #define MOZ_GENERATED_EVENT_LIST
 #define MOZ_GENERATED_EVENT(_event_interface) \
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(_event_interface)
 #include "GeneratedEvents.h"
@@ -3925,21 +3915,16 @@ nsDOMClassInfo::Init()
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorage)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(StorageItem, nsIDOMStorageItem)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageItem)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMToString)
   DOM_CLASSINFO_MAP_END
 
-  DOM_CLASSINFO_MAP_BEGIN(StorageEvent, nsIDOMStorageEvent)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageEvent)
-    DOM_CLASSINFO_EVENT_MAP_ENTRIES
-  DOM_CLASSINFO_MAP_END
-
   DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(DOMParser, nsIDOMParser)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMParser)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMParserJS)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XMLSerializer, nsIDOMSerializer)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMSerializer)
   DOM_CLASSINFO_MAP_END
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -336,17 +336,16 @@ DOMCI_CLASS(XPathEvaluator)
 DOMCI_CLASS(XPathExpression)
 DOMCI_CLASS(XPathNSResolver)
 DOMCI_CLASS(XPathResult)
 
 // WhatWG WebApps Objects
 DOMCI_CLASS(StorageObsolete)
 DOMCI_CLASS(Storage)
 DOMCI_CLASS(StorageItem)
-DOMCI_CLASS(StorageEvent)
 
 // DOMParser, XMLSerializer
 DOMCI_CLASS(DOMParser)
 DOMCI_CLASS(XMLSerializer)
 
 // XMLHttpRequest
 DOMCI_CLASS(XMLHttpProgressEvent)
 DOMCI_CLASS(XMLHttpRequest)
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -192,17 +192,17 @@
 // belonging to the back-end like nsIContentPolicy
 #include "nsIPopupWindowManager.h"
 
 #include "nsIDragService.h"
 #include "mozilla/dom/Element.h"
 #include "nsFrameLoader.h"
 #include "nsISupportsPrimitives.h"
 #include "nsXPCOMCID.h"
-
+#include "GeneratedEvents.h"
 #include "mozilla/FunctionTimer.h"
 #include "mozIThirdPartyUtil.h"
 
 #ifdef MOZ_LOGGING
 // so we can get logging even in release builds
 #define FORCE_PR_LOG 1
 #endif
 #include "prlog.h"
@@ -9011,17 +9011,18 @@ nsGlobalWindow::CloneStorageEvent(const 
   domEvent->GetCancelable(&cancelable);
 
   aEvent->GetKey(key);
   aEvent->GetOldValue(oldValue);
   aEvent->GetNewValue(newValue);
   aEvent->GetUrl(url);
   aEvent->GetStorageArea(getter_AddRefs(storageArea));
 
-  aEvent = new nsDOMStorageEvent();
+  NS_NewDOMStorageEvent(getter_AddRefs(domEvent), nsnull, nsnull);
+  aEvent = do_QueryInterface(domEvent);
   return aEvent->InitStorageEvent(aType, canBubble, cancelable,
                                   key, oldValue, newValue,
                                   url, storageArea);
 }
 
 nsresult
 nsGlobalWindow::FireDelayedDOMEvents()
 {
--- a/dom/src/storage/nsDOMStorage.cpp
+++ b/dom/src/storage/nsDOMStorage.cpp
@@ -33,16 +33,17 @@ using mozilla::dom::ContentChild;
 #include "nsIJSContextStack.h"
 #include "nsIPrivateBrowsingService.h"
 #include "nsDOMString.h"
 #include "nsNetCID.h"
 #include "mozilla/Preferences.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Telemetry.h"
 #include "DictionaryHelpers.h"
+#include "GeneratedEvents.h"
 
 // calls FlushAndDeleteTemporaryTables(false)
 #define NS_DOMSTORAGE_FLUSH_TIMER_TOPIC "domstorage-flush-timer"
 
 // calls FlushAndDeleteTemporaryTables(true)
 #define NS_DOMSTORAGE_FLUSH_FORCE_TOPIC "domstorage-flush-force"
 
 using namespace mozilla;
@@ -1888,17 +1889,19 @@ StorageNotifierRunnable::Run()
 } // anonymous namespace
 
 void
 nsDOMStorage2::BroadcastChangeNotification(const nsSubstring &aKey,
                                            const nsSubstring &aOldValue,
                                            const nsSubstring &aNewValue)
 {
   nsresult rv;
-  nsCOMPtr<nsIDOMStorageEvent> event = new nsDOMStorageEvent();
+  nsCOMPtr<nsIDOMEvent> domEvent;
+  NS_NewDOMStorageEvent(getter_AddRefs(domEvent), nsnull, nsnull);
+  nsCOMPtr<nsIDOMStorageEvent> event = do_QueryInterface(domEvent);
   rv = event->InitStorageEvent(NS_LITERAL_STRING("storage"),
                                false,
                                false,
                                aKey,
                                aOldValue,
                                aNewValue,
                                mDocumentURI,
                                static_cast<nsIDOMStorage*>(this));
@@ -2074,102 +2077,8 @@ nsDOMStorageItem::SetValue(const nsAStri
 }
 
 NS_IMETHODIMP
 nsDOMStorageItem::ToString(nsAString& aStr)
 {
   return GetValue(aStr);
 }
 
-// Cycle collection implementation for nsDOMStorageEvent
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMStorageEvent)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMStorageEvent, nsDOMEvent)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mStorageArea)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMStorageEvent, nsDOMEvent)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mStorageArea)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_ADDREF_INHERITED(nsDOMStorageEvent, nsDOMEvent)
-NS_IMPL_RELEASE_INHERITED(nsDOMStorageEvent, nsDOMEvent)
-
-DOMCI_DATA(StorageEvent, nsDOMStorageEvent)
-
-// QueryInterface implementation for nsDOMStorageEvent
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMStorageEvent)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMStorageEvent)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(StorageEvent)
-NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
-
-
-/* readonly attribute DOMString key; */
-NS_IMETHODIMP nsDOMStorageEvent::GetKey(nsAString & aKey)
-{
-  aKey = mKey;
-  return NS_OK;
-}
-
-/* readonly attribute DOMString oldValue; */
-NS_IMETHODIMP nsDOMStorageEvent::GetOldValue(nsAString & aOldValue)
-{
-  aOldValue = mOldValue;
-  return NS_OK;
-}
-
-/* readonly attribute DOMString newValue; */
-NS_IMETHODIMP nsDOMStorageEvent::GetNewValue(nsAString & aNewValue)
-{
-  aNewValue = mNewValue;
-  return NS_OK;
-}
-
-/* readonly attribute DOMString url; */
-NS_IMETHODIMP nsDOMStorageEvent::GetUrl(nsAString & aUrl)
-{
-  aUrl = mUrl;
-  return NS_OK;
-}
-
-/* readonly attribute nsIDOMStorage storageArea; */
-NS_IMETHODIMP nsDOMStorageEvent::GetStorageArea(nsIDOMStorage * *aStorageArea)
-{
-  NS_ENSURE_ARG_POINTER(aStorageArea);
-
-  NS_IF_ADDREF(*aStorageArea = mStorageArea);
-  return NS_OK;
-}
-
-/* void initStorageEvent (in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in DOMString keyArg, in DOMString oldValueArg, in DOMString newValueArg, in DOMString urlArg, in nsIDOMStorage storageAreaArg); */
-NS_IMETHODIMP nsDOMStorageEvent::InitStorageEvent(const nsAString & typeArg,
-                                                  bool canBubbleArg,
-                                                  bool cancelableArg,
-                                                  const nsAString & keyArg,
-                                                  const nsAString & oldValueArg,
-                                                  const nsAString & newValueArg,
-                                                  const nsAString & urlArg,
-                                                  nsIDOMStorage *storageAreaArg)
-{
-  nsresult rv;
-
-  rv = InitEvent(typeArg, canBubbleArg, cancelableArg);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  mKey = keyArg;
-  mOldValue = oldValueArg;
-  mNewValue = newValueArg;
-  mUrl = urlArg;
-  mStorageArea = storageAreaArg;
-
-  return NS_OK;
-}
-
-nsresult
-nsDOMStorageEvent::InitFromCtor(const nsAString& aType,
-                                JSContext* aCx, jsval* aVal)
-{
-  mozilla::dom::StorageEventInit d;
-  nsresult rv = d.Init(aCx, aVal);
-  NS_ENSURE_SUCCESS(rv, rv);
-  return InitStorageEvent(aType, d.bubbles, d.cancelable, d.key, d.oldValue,
-                          d.newValue, d.url, d.storageArea);
-}
--- a/dom/src/storage/nsDOMStorage.h
+++ b/dom/src/storage/nsDOMStorage.h
@@ -495,47 +495,16 @@ protected:
   // value of the item
   nsString mValue;
 
   // If this item came from the db, mStorage points to the storage
   // object where this item came from.
   nsRefPtr<DOMStorageBase> mStorage;
 };
 
-class nsDOMStorageEvent : public nsDOMEvent,
-                          public nsIDOMStorageEvent
-{
-public:
-  nsDOMStorageEvent()
-    : nsDOMEvent(nullptr, nullptr)
-  {
-  }
-
-  virtual ~nsDOMStorageEvent()
-  {
-  }
-
-  nsresult Init();
-
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMStorageEvent, nsDOMEvent)
-
-  NS_DECL_NSIDOMSTORAGEEVENT
-  NS_FORWARD_NSIDOMEVENT(nsDOMEvent::)
-
-  virtual nsresult InitFromCtor(const nsAString& aType,
-                                JSContext* aCx, jsval* aVal);
-protected:
-  nsString mKey;
-  nsString mOldValue;
-  nsString mNewValue;
-  nsString mUrl;
-  nsCOMPtr<nsIDOMStorage> mStorageArea;
-};
-
 nsresult
 NS_NewDOMStorage2(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
 PRUint32
 GetOfflinePermission(const nsACString &aDomain);
 
 bool
 IsOfflineAllowed(const nsACString &aDomain);
--- a/js/xpconnect/src/dictionary_helper_gen.conf
+++ b/js/xpconnect/src/dictionary_helper_gen.conf
@@ -4,17 +4,16 @@
 
 # Dictionary interface name, interface file name
 dictionaries = [
      [ 'EventInit', 'nsIDOMEvent.idl' ],
      [ 'UIEventInit', 'nsIDOMUIEvent.idl' ],
      [ 'MouseEventInit', 'nsIDOMMouseEvent.idl' ],
      [ 'IDBObjectStoreParameters', 'nsIIDBDatabase.idl' ],
      [ 'IDBIndexParameters', 'nsIIDBObjectStore.idl' ],
-     [ 'StorageEventInit', 'nsIDOMStorageEvent.idl' ],
      [ 'BlobPropertyBag', 'nsIDOMFile.idl' ],
      [ 'MutationObserverInit', 'nsIDOMMutationObserver.idl' ],
      [ 'WifiConnectionInfoEventInit', 'nsIWifiEventInits.idl' ],
      [ 'WifiStatusChangeEventInit', 'nsIWifiEventInits.idl' ],
      [ 'GeoPositionOptions', 'nsIDOMGeoGeolocation.idl' ],
      [ 'DOMFileMetadataParameters', 'nsIDOMLockedFile.idl' ],
      [ 'XMLHttpRequestParameters', 'nsIXMLHttpRequest.idl' ],
      [ 'DeviceStorageEnumerationParameters', 'nsIDOMDeviceStorage.idl' ],
--- a/js/xpconnect/src/event_impl_gen.conf.in
+++ b/js/xpconnect/src/event_impl_gen.conf.in
@@ -3,16 +3,17 @@
  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/.
 
  The name of the event which real interface should have nsIDOM-prefix,
  and should be in nsIDOM<name>.idl file and which should have
  <name>Init dictionary for the event constructor. """
 
 simple_events = [
+    'StorageEvent',
     'DeviceProximityEvent',
     'MozSettingsEvent',
     'UserProximityEvent',
     'CustomEvent',
     'PageTransitionEvent',
     'PopStateEvent',
     'HashChangeEvent',
     'CloseEvent',