Bug 839103 - part 3 - send StyleSheet{Added,Removed} chrome notifications when stylesheets are added/removed; r=bz
authorNathan Froyd <froydnj@mozilla.com>
Wed, 27 Mar 2013 14:16:50 -0400
changeset 127500 90c602d8475a013f2c331876bf5913fbd2710881
parent 127499 7dbef35abf2a97744fdb5a556c53d96fec484709
child 127501 c0e889e95154b5ab5c8a5cf93e3e8e845d5fa224
push id24506
push userryanvm@gmail.com
push dateWed, 03 Apr 2013 22:14:39 +0000
treeherdermozilla-central@475dc5f51bdb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs839103
milestone23.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 839103 - part 3 - send StyleSheet{Added,Removed} chrome notifications when stylesheets are added/removed; r=bz
content/base/src/nsDocument.cpp
dom/interfaces/events/moz.build
dom/interfaces/events/nsIDOMStyleSheetAddedEvent.idl
dom/interfaces/events/nsIDOMStyleSheetRemovedEvent.idl
dom/tests/mochitest/general/test_interfaces.html
js/xpconnect/src/event_impl_gen.conf.in
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -135,16 +135,18 @@
 #include "nsIDocumentLoaderFactory.h"
 #include "nsIDocumentLoader.h"
 #include "nsIContentViewer.h"
 #include "nsIXMLContentSink.h"
 #include "nsIXULDocument.h"
 #include "nsIPrompt.h"
 #include "nsIPropertyBag2.h"
 #include "nsIDOMPageTransitionEvent.h"
+#include "nsIDOMStyleSheetAddedEvent.h"
+#include "nsIDOMStyleSheetRemovedEvent.h"
 #include "nsJSUtils.h"
 #include "nsFrameLoader.h"
 #include "nsEscape.h"
 #include "nsObjectLoadingContent.h"
 #include "nsHtml5TreeOpExecutor.h"
 #include "nsIDOMElementReplaceEvent.h"
 #ifdef MOZ_MEDIA
 #include "mozilla/dom/HTMLMediaElement.h"
@@ -174,16 +176,17 @@
 #include "mozilla/dom/DOMImplementation.h"
 #include "mozilla/dom/Comment.h"
 #include "nsTextNode.h"
 #include "mozilla/dom/Link.h"
 #include "mozilla/dom/HTMLElementBinding.h"
 #include "nsXULAppAPI.h"
 #include "nsDOMTouchEvent.h"
 #include "DictionaryHelpers.h"
+#include "GeneratedEvents.h"
 
 #include "mozilla/Preferences.h"
 
 #include "imgILoader.h"
 #include "imgRequestProxy.h"
 #include "nsWrapperCacheInlines.h"
 #include "nsSandboxFlags.h"
 #include "nsIAppsService.h"
@@ -3653,27 +3656,62 @@ void
 nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
 {
   nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     shell->StyleSet()->AddDocStyleSheet(aSheet, this);
   }
 }
 
+#define DO_STYLESHEET_NOTIFICATION(createFunc, initMethod, concreteInterface, type) \
+  do {                                                                  \
+    nsCOMPtr<nsIDOMEvent> event;                                        \
+    nsresult rv = createFunc(getter_AddRefs(event), this,               \
+                             mPresShell ?                               \
+                             mPresShell->GetPresContext() : nullptr,    \
+                             nullptr);                                  \
+    if (NS_FAILED(rv)) {                                                \
+      return;                                                           \
+    }                                                                   \
+    nsCOMPtr<nsIDOMCSSStyleSheet> cssSheet(do_QueryInterface(aSheet));  \
+    if (!cssSheet) {                                                    \
+      return;                                                           \
+    }                                                                   \
+    nsCOMPtr<concreteInterface> ssEvent(do_QueryInterface(event));      \
+    MOZ_ASSERT(ssEvent);                                                \
+    ssEvent->initMethod(NS_LITERAL_STRING(type), true, true,            \
+                        cssSheet, aDocumentSheet);                      \
+    event->SetTrusted(true);                                            \
+    event->SetTarget(this);                                             \
+    nsRefPtr<nsAsyncDOMEvent> asyncEvent = new nsAsyncDOMEvent(this, event); \
+    asyncEvent->mDispatchChromeOnly = true;                             \
+    asyncEvent->PostDOMEvent();                                         \
+  } while (0);
+
 void
 nsDocument::NotifyStyleSheetAdded(nsIStyleSheet* aSheet, bool aDocumentSheet)
 {
   NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (this, aSheet, aDocumentSheet));
+  DO_STYLESHEET_NOTIFICATION(NS_NewDOMStyleSheetAddedEvent,
+                             InitStyleSheetAddedEvent,
+                             nsIDOMStyleSheetAddedEvent,
+                             "StyleSheetAdded");
 }
 
 void
 nsDocument::NotifyStyleSheetRemoved(nsIStyleSheet* aSheet, bool aDocumentSheet)
 {
   NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetRemoved, (this, aSheet, aDocumentSheet));
-}
+  DO_STYLESHEET_NOTIFICATION(NS_NewDOMStyleSheetRemovedEvent,
+                             InitStyleSheetRemovedEvent,
+                             nsIDOMStyleSheetRemovedEvent,
+                             "StyleSheetRemoved");
+}
+
+#undef DO_STYLESHEET_NOTIFICATION
 
 void
 nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
 {
   NS_PRECONDITION(aSheet, "null arg");
   mStyleSheets.AppendObject(aSheet);
   aSheet->SetOwningDocument(this);
 
--- a/dom/interfaces/events/moz.build
+++ b/dom/interfaces/events/moz.build
@@ -38,16 +38,18 @@ XPIDL_SOURCES += [
     'nsIDOMPaintRequest.idl',
     'nsIDOMPaintRequestList.idl',
     'nsIDOMPopStateEvent.idl',
     'nsIDOMPopupBlockedEvent.idl',
     'nsIDOMProgressEvent.idl',
     'nsIDOMScrollAreaEvent.idl',
     'nsIDOMSimpleGestureEvent.idl',
     'nsIDOMSmartCardEvent.idl',
+    'nsIDOMStyleSheetAddedEvent.idl',
+    'nsIDOMStyleSheetRemovedEvent.idl',
     'nsIDOMTouchEvent.idl',
     'nsIDOMTransitionEvent.idl',
     'nsIDOMUIEvent.idl',
     'nsIDOMUserProximityEvent.idl',
     'nsIDOMWheelEvent.idl',
     'nsIDOMGamepadButtonEvent.idl',
     'nsIDOMGamepadAxisMoveEvent.idl',
     'nsIDOMGamepadEvent.idl',
new file mode 100644
--- /dev/null
+++ b/dom/interfaces/events/nsIDOMStyleSheetAddedEvent.idl
@@ -0,0 +1,27 @@
+/* -*- 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"
+
+interface nsIDOMCSSStyleSheet;
+
+[scriptable, builtinclass, uuid(05a78874-43d7-459d-be32-ba9271527153)]
+interface nsIDOMStyleSheetAddedEvent : nsIDOMEvent
+{
+  readonly attribute nsIDOMCSSStyleSheet stylesheet;
+  readonly attribute boolean documentSheet;
+  [noscript] void initStyleSheetAddedEvent(in DOMString aTypeArg,
+                                           in boolean aCanBubbleArg,
+                                           in boolean aCancelableArg,
+                                           in nsIDOMCSSStyleSheet aStyleSheet,
+                                           in boolean aDocumentSheet);
+};
+
+dictionary StyleSheetAddedEventInit : EventInit
+{
+  nsIDOMCSSStyleSheet stylesheet;
+  boolean documentSheet;
+};
+
new file mode 100644
--- /dev/null
+++ b/dom/interfaces/events/nsIDOMStyleSheetRemovedEvent.idl
@@ -0,0 +1,27 @@
+/* -*- 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"
+
+interface nsIDOMCSSStyleSheet;
+
+[scriptable, builtinclass, uuid(76a7afe1-5b7b-48ee-aef0-7e89b5b0b8e6)]
+interface nsIDOMStyleSheetRemovedEvent : nsIDOMEvent
+{
+  readonly attribute nsIDOMCSSStyleSheet stylesheet;
+  readonly attribute boolean documentSheet;
+  [noscript] void initStyleSheetRemovedEvent(in DOMString aTypeArg,
+                                             in boolean aCanBubbleArg,
+                                             in boolean aCancelableArg,
+                                             in nsIDOMCSSStyleSheet aStyleSheet,
+                                             in boolean aDocumentSheet);
+};
+
+dictionary StyleSheetRemovedEventInit : EventInit
+{
+  nsIDOMCSSStyleSheet stylesheet;
+  boolean documentSheet;
+};
+
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -542,17 +542,19 @@ var interfaceNamesInGlobalScope =
     "DOMCursor",
     "BlobEvent",
     "Gamepad",
     "GamepadEvent",
     "GamepadButtonEvent",
     "GamepadAxisMoveEvent",
     "SpeechRecognitionEvent",
     "SpeechRecognitionError",
-    "PushManager"
+    "PushManager",
+    "StyleSheetAddedEvent",
+    "StyleSheetRemovedEvent"
   ]
 
 for (var i in SpecialPowers.Components.interfaces) {
   var s = i.toString();
   var name = null;
   if (s.indexOf("nsIDOM") == 0) {
     name = s.substring("nsIDOM".length);
   } else if (s.indexOf("nsI") == 0) {
--- a/js/xpconnect/src/event_impl_gen.conf.in
+++ b/js/xpconnect/src/event_impl_gen.conf.in
@@ -19,16 +19,18 @@ simple_events = [
     'PopStateEvent',
     'HashChangeEvent',
     'CloseEvent',
     'MozContactChangeEvent',
     'DeviceOrientationEvent',
     'DeviceLightEvent',
     'MozApplicationEvent',
     'SmartCardEvent',
+    'StyleSheetAddedEvent',
+    'StyleSheetRemovedEvent',
 #ifdef MOZ_B2G_BT
     'BluetoothDeviceEvent',
 #endif
 #ifdef MOZ_B2G_RIL
     'CallEvent',
     'CFStateChangeEvent',
     'DataErrorEvent',
     'ICCCardLockErrorEvent',