Bug 910088 - Use webIDL dictionaries for DOMWindowResize event details r=bz
authorKan-Ru Chen (陳侃如) <kanru@kanru.info>
Thu, 29 Aug 2013 11:54:31 +0800
changeset 158696 f3d8e568ec114f7595494a151fb486676226833c
parent 158695 4e447da277456891fd285d769b68c773e4f60bc1
child 158697 297f7e9f0e548109ef32f67dc7170826ea12a059
push id407
push userlsblakk@mozilla.com
push dateTue, 03 Dec 2013 03:32:50 +0000
treeherdermozilla-release@babf8c9ebc52 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs910088
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 910088 - Use webIDL dictionaries for DOMWindowResize event details r=bz
dom/base/moz.build
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/base/nsDOMWindowResizeEventDetail.cpp
dom/base/nsDOMWindowResizeEventDetail.h
dom/base/nsGlobalWindow.cpp
dom/base/nsIDOMDOMWindowResizeEventDetail.idl
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/BrowserElementDictionaries.webidl
dom/webidl/DummyBinding.webidl
--- a/dom/base/moz.build
+++ b/dom/base/moz.build
@@ -4,17 +4,16 @@
 # 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/.
 
 TEST_DIRS += ['test']
 
 XPIDL_SOURCES += [
     'nsIDOMDOMCursor.idl',
     'nsIDOMDOMRequest.idl',
-    'nsIDOMDOMWindowResizeEventDetail.idl',
     'nsIEntropyCollector.idl',
     'nsIScriptChannel.idl',
     'nsISiteSpecificUserAgent.idl',
 ]
 
 MODULE = 'dom'
 
 EXPORTS += [
@@ -69,17 +68,16 @@ CPP_SOURCES += [
     'DOMRequest.cpp',
     'Navigator.cpp',
     'nsContentPermissionHelper.cpp',
     'nsDOMClassInfo.cpp',
     'nsDOMException.cpp',
     'nsDOMNavigationTiming.cpp',
     'nsDOMScriptObjectFactory.cpp',
     'nsDOMWindowList.cpp',
-    'nsDOMWindowResizeEventDetail.cpp',
     'nsDOMWindowUtils.cpp',
     'nsFocusManager.cpp',
     'nsGlobalWindow.cpp',
     'nsGlobalWindowCommands.cpp',
     'nsHistory.cpp',
     'nsJSEnvironment.cpp',
     'nsJSTimeoutHandler.cpp',
     'nsJSUtils.cpp',
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -179,17 +179,16 @@
 #include "FMRadio.h"
 #endif
 
 #ifdef MOZ_B2G_BT
 #include "BluetoothDevice.h"
 #endif
 
 #include "nsIDOMCameraManager.h"
-#include "nsIDOMDOMWindowResizeEventDetail.h"
 #include "nsIDOMGlobalObjectConstructor.h"
 #include "nsIDOMLockedFile.h"
 #include "nsDebug.h"
 
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/Likely.h"
 #include "WindowNamedPropertiesHandler.h"
 
@@ -544,19 +543,16 @@ static nsDOMClassInfoData sClassInfoData
 #ifdef MOZ_B2G_BT
   NS_DEFINE_CLASSINFO_DATA(BluetoothDevice, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
 #endif
 
   NS_DEFINE_CLASSINFO_DATA(CameraCapabilities, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
-  NS_DEFINE_CLASSINFO_DATA(DOMWindowResizeEventDetail, nsDOMGenericSH,
-                           DOM_DEFAULT_SCRIPTABLE_FLAGS)
-
   NS_DEFINE_CLASSINFO_DATA(LockedFile, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 
   NS_DEFINE_CLASSINFO_DATA(UserDataHandler, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(LoadStatus, nsDOMGenericSH,
@@ -1412,20 +1408,16 @@ nsDOMClassInfo::Init()
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothDevice)
   DOM_CLASSINFO_MAP_END
 #endif
 
   DOM_CLASSINFO_MAP_BEGIN(CameraCapabilities, nsICameraCapabilities)
     DOM_CLASSINFO_MAP_ENTRY(nsICameraCapabilities)
   DOM_CLASSINFO_MAP_END
 
-  DOM_CLASSINFO_MAP_BEGIN(DOMWindowResizeEventDetail, nsIDOMDOMWindowResizeEventDetail)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMWindowResizeEventDetail)
-  DOM_CLASSINFO_MAP_END
-
   DOM_CLASSINFO_MAP_BEGIN(LockedFile, nsIDOMLockedFile)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMLockedFile)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(CSSFontFeatureValuesRule, nsIDOMCSSFontFeatureValuesRule)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule)
   DOM_CLASSINFO_MAP_END
 
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -132,18 +132,16 @@ DOMCI_CLASS(MozIccManager)
 #endif
 
 #ifdef MOZ_B2G_BT
 DOMCI_CLASS(BluetoothDevice)
 #endif
 
 DOMCI_CLASS(CameraCapabilities)
 
-DOMCI_CLASS(DOMWindowResizeEventDetail)
-
 DOMCI_CLASS(LockedFile)
 
 DOMCI_CLASS(CSSFontFeatureValuesRule)
 
 DOMCI_CLASS(UserDataHandler)
 DOMCI_CLASS(LoadStatus)
 DOMCI_CLASS(XPathNamespace)
 DOMCI_CLASS(XULControlElement)
deleted file mode 100644
--- a/dom/base/nsDOMWindowResizeEventDetail.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/* 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 "nsDOMWindowResizeEventDetail.h"
-#include "nsDOMClassInfoID.h" // DOMCI_DATA
-
-DOMCI_DATA(DOMWindowResizeEventDetail, nsDOMWindowResizeEventDetail)
-
-NS_INTERFACE_MAP_BEGIN(nsDOMWindowResizeEventDetail)
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMDOMWindowResizeEventDetail)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMWindowResizeEventDetail)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(nsDOMWindowResizeEventDetail)
-NS_IMPL_RELEASE(nsDOMWindowResizeEventDetail)
-
-NS_IMETHODIMP
-nsDOMWindowResizeEventDetail::GetWidth(int32_t* aOut)
-{
-  *aOut = mSize.width;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMWindowResizeEventDetail::GetHeight(int32_t* aOut)
-{
-  *aOut = mSize.height;
-  return NS_OK;
-}
deleted file mode 100644
--- a/dom/base/nsDOMWindowResizeEventDetail.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* 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 "nsIDOMDOMWindowResizeEventDetail.h"
-#include "nsSize.h"
-
-class nsDOMWindowResizeEventDetail : public nsIDOMDOMWindowResizeEventDetail
-{
-public:
-  nsDOMWindowResizeEventDetail(const nsIntSize& aSize)
-    : mSize(aSize)
-  {}
-
-  virtual ~nsDOMWindowResizeEventDetail() {}
-
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIDOMDOMWINDOWRESIZEEVENTDETAIL
-
-private:
-  const nsIntSize mSize;
-};
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -29,17 +29,16 @@
 #include "nsArrayUtils.h"
 #include "nsIDOMWindowCollection.h"
 #include "nsDOMWindowList.h"
 #include "nsIDOMWakeLock.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIPermissionManager.h"
 #include "nsIScriptContext.h"
 #include "nsIScriptTimeoutHandler.h"
-#include "nsDOMWindowResizeEventDetail.h"
 
 #ifdef XP_WIN
 // Thanks so much, Microsoft! :(
 #ifdef GetClassName
 #undef GetClassName
 #endif // GetClassName
 #ifdef CreateEvent
 #undef CreateEvent
@@ -174,16 +173,17 @@
 
 #include "nsIDragService.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/Selection.h"
 #include "nsFrameLoader.h"
 #include "nsISupportsPrimitives.h"
 #include "nsXPCOMCID.h"
 #include "GeneratedEvents.h"
+#include "GeneratedEventClasses.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"
 #include "prenv.h"
@@ -204,16 +204,17 @@
 #include "nsLocation.h"
 #include "nsHTMLDocument.h"
 #include "nsWrapperCacheInlines.h"
 #include "nsDOMEventTargetHelper.h"
 #include "prrng.h"
 #include "nsSandboxFlags.h"
 #include "TimeChangeObserver.h"
 #include "mozilla/dom/AudioContext.h"
+#include "mozilla/dom/BrowserElementDictionariesBinding.h"
 #include "mozilla/dom/FunctionBinding.h"
 #include "mozilla/dom/WindowBinding.h"
 
 #ifdef MOZ_WEBSPEECH
 #include "mozilla/dom/SpeechSynthesis.h"
 #endif
 
 #ifdef MOZ_JSDEBUGGER
@@ -4951,41 +4952,50 @@ nsGlobalWindow::DispatchCustomEvent(cons
 
   return defaultActionEnabled;
 }
 
 // NOTE: Arguments to this function should be CSS pixels, not device pixels.
 bool
 nsGlobalWindow::DispatchResizeEvent(const nsIntSize& aSize)
 {
-  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mDoc);
-  nsCOMPtr<nsIDOMEvent> event;
-  nsresult rv = domDoc->CreateEvent(NS_LITERAL_STRING("CustomEvent"),
-                                    getter_AddRefs(event));
-  NS_ENSURE_SUCCESS(rv, false);
-
-  nsCOMPtr<nsIWritableVariant> detailVariant = new nsVariant();
-  nsCOMPtr<nsIDOMDOMWindowResizeEventDetail> detail =
-    new nsDOMWindowResizeEventDetail(aSize);
-  rv = detailVariant->SetAsISupports(detail);
-  NS_ENSURE_SUCCESS(rv, false);
-
-  nsCOMPtr<nsIDOMCustomEvent> customEvent = do_QueryInterface(event);
-  customEvent->InitCustomEvent(NS_LITERAL_STRING("DOMWindowResize"),
+  ErrorResult res;
+  nsRefPtr<nsDOMEvent> domEvent =
+    mDoc->CreateEvent(NS_LITERAL_STRING("CustomEvent"), res);
+  if (res.Failed()) {
+    return false;
+  }
+
+  AutoSafeJSContext cx;
+  JSAutoCompartment ac(cx, mJSObject);
+  DOMWindowResizeEventDetailInitializer detail;
+  detail.mWidth = aSize.width;
+  detail.mHeight = aSize.height;
+  JS::Rooted<JS::Value> detailValue(cx);
+  detail.ToObject(cx, JS::NullPtr(), &detailValue);
+
+  CustomEvent* customEvent = static_cast<CustomEvent*>(domEvent.get());
+  customEvent->InitCustomEvent(cx,
+                               NS_LITERAL_STRING("DOMWindowResize"),
                                /* bubbles = */ true,
                                /* cancelable = */ true,
-                               detailVariant);
-  customEvent->SetTrusted(true);
-  customEvent->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
+                               detailValue,
+                               res);
+  if (res.Failed()) {
+    return false;
+  }
+
+  domEvent->SetTrusted(true);
+  domEvent->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
 
   nsCOMPtr<EventTarget> target = do_QueryInterface(GetOuterWindow());
-  customEvent->SetTarget(target);
+  domEvent->SetTarget(target);
 
   bool defaultActionEnabled = true;
-  target->DispatchEvent(event, &defaultActionEnabled);
+  target->DispatchEvent(domEvent, &defaultActionEnabled);
 
   return defaultActionEnabled;
 }
 
 void
 nsGlobalWindow::RefreshCompartmentPrincipal()
 {
   FORWARD_TO_INNER(RefreshCompartmentPrincipal, (), /* void */ );
deleted file mode 100644
--- a/dom/base/nsIDOMDOMWindowResizeEventDetail.idl
+++ /dev/null
@@ -1,12 +0,0 @@
-/* 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 "nsISupports.idl"
-
-[scriptable, uuid(166fa8f4-ff40-4150-ab31-272e8246e362)]
-interface nsIDOMDOMWindowResizeEventDetail : nsISupports
-{
-  readonly attribute long width;
-  readonly attribute long height;
-};
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -167,17 +167,16 @@ var interfaceNamesInGlobalScope =
     "DOMMMIError",
     "DOMParser",
     "DOMRequest",
     "DOMSettableTokenList",
     "DOMStringList",
     "DOMStringMap",
     "DOMTokenList",
     "DOMTransactionEvent",
-    "DOMWindowResizeEventDetail",
     "DragEvent",
     "DynamicsCompressorNode",
     "Element",
     "ElementReplaceEvent",
     "Event",
     "EventListenerInfo",
     "EventSource",
     "EventTarget",
--- a/dom/webidl/BrowserElementDictionaries.webidl
+++ b/dom/webidl/BrowserElementDictionaries.webidl
@@ -17,8 +17,13 @@ dictionary AsyncScrollEventDetail {
 };
 
 dictionary OpenWindowEventDetail {
   DOMString url = "";
   DOMString name = "";
   DOMString features = "";
   Node? frameElement = null;
 };
+
+dictionary DOMWindowResizeEventDetail {
+  long width = 0;
+  long height = 0;
+};
--- a/dom/webidl/DummyBinding.webidl
+++ b/dom/webidl/DummyBinding.webidl
@@ -18,15 +18,16 @@ interface DummyInterface {
   void funcDNSCacheDict(optional DNSCacheDict arg);
   void funcDNSLookupDict(optional DNSLookupDict arg);
   void funcConnStatusDict(optional ConnStatusDict arg);
   void frameRequestCallback(FrameRequestCallback arg);
   void MmsParameters(optional MmsParameters arg);
   void MmsAttachment(optional MmsAttachment arg);
   void AsyncScrollEventDetail(optional AsyncScrollEventDetail arg);
   void OpenWindowEventDetail(optional OpenWindowEventDetail arg);
+  void DOMWindowResizeEventDetail(optional DOMWindowResizeEventDetail arg);
   void WifiOptions(optional WifiCommandOptions arg1,
                    optional WifiResultOptions arg2);
 };
 
 interface DummyInterfaceWorkers {
   BlobPropertyBag blobBag();
 };