Bug 1478823: Add a chrome DOM event signalling that the head element's children have been parsed. r=bzbarsky
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 03 Aug 2018 21:16:04 +0000
changeset 430168 c5386a64522c7cb575050a13c4659f8de2bb1836
parent 430167 1748bdd2dcafd2345c273f917616b9e651cbcbe9
child 430169 741a654c2f4c183a14c717f3367828f5003078e5
push id106075
push userdvarga@mozilla.com
push dateSat, 04 Aug 2018 22:08:41 +0000
treeherdermozilla-inbound@259a2e4d857f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1478823
milestone63.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 1478823: Add a chrome DOM event signalling that the head element's children have been parsed. r=bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D2612
dom/html/HTMLSharedElement.cpp
dom/html/HTMLSharedElement.h
parser/html/nsHtml5TreeBuilderCppSupplement.h
--- a/dom/html/HTMLSharedElement.cpp
+++ b/dom/html/HTMLSharedElement.cpp
@@ -7,16 +7,17 @@
 #include "mozilla/dom/HTMLSharedElement.h"
 #include "mozilla/dom/HTMLBaseElementBinding.h"
 #include "mozilla/dom/HTMLDirectoryElementBinding.h"
 #include "mozilla/dom/HTMLHeadElementBinding.h"
 #include "mozilla/dom/HTMLHtmlElementBinding.h"
 #include "mozilla/dom/HTMLParamElementBinding.h"
 #include "mozilla/dom/HTMLQuoteElementBinding.h"
 
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/MappedDeclarations.h"
 #include "nsAttrValueInlines.h"
 #include "nsStyleConsts.h"
 #include "nsMappedAttributes.h"
 #include "nsContentUtils.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsIURI.h"
 
@@ -51,16 +52,31 @@ HTMLSharedElement::GetHref(nsAString& aV
     return;
   }
 
   nsAutoCString spec;
   uri->GetSpec(spec);
   CopyUTF8toUTF16(spec, aValue);
 }
 
+void
+HTMLSharedElement::DoneAddingChildren(bool aHaveNotified)
+{
+  if (mNodeInfo->Equals(nsGkAtoms::head)) {
+    RefPtr<AsyncEventDispatcher> asyncDispatcher =
+      new AsyncEventDispatcher(this,
+                              NS_LITERAL_STRING("DOMHeadElementParsed"),
+                              CanBubble::eYes,
+                              ChromeOnlyDispatch::eYes);
+    // Always run async in order to avoid running script when the content
+    // sink isn't expecting it.
+    asyncDispatcher->PostDOMEvent();
+  }
+}
+
 bool
 HTMLSharedElement::ParseAttribute(int32_t aNamespaceID,
                                   nsAtom* aAttribute,
                                   const nsAString& aValue,
                                   nsIPrincipal* aMaybeScriptedPrincipal,
                                   nsAttrValue& aResult)
 {
   if (aNamespaceID == kNameSpaceID_None &&
--- a/dom/html/HTMLSharedElement.h
+++ b/dom/html/HTMLSharedElement.h
@@ -25,16 +25,18 @@ public:
   {
     if (mNodeInfo->Equals(nsGkAtoms::head) ||
         mNodeInfo->Equals(nsGkAtoms::html)) {
       SetHasWeirdParserInsertionMode();
     }
   }
 
   // nsIContent
+  virtual void DoneAddingChildren(bool aHaveNotified) override;
+
   virtual bool ParseAttribute(int32_t aNamespaceID,
                                 nsAtom* aAttribute,
                                 const nsAString& aValue,
                                 nsIPrincipal* aMaybeScriptedPrincipal,
                                 nsAttrValue& aResult) override;
 
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent) override;
--- a/parser/html/nsHtml5TreeBuilderCppSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h
@@ -1104,17 +1104,18 @@ nsHtml5TreeBuilder::elementPopped(int32_
     }
     return;
   }
   // we now have only HTML
   // Some HTML nodes need DoneAddingChildren() called to initialize
   // properly (e.g. form state restoration).
   // XXX expose ElementName group here and do switch
   if (aName == nsGkAtoms::object || aName == nsGkAtoms::select ||
-      aName == nsGkAtoms::textarea || aName == nsGkAtoms::output) {
+      aName == nsGkAtoms::textarea || aName == nsGkAtoms::output ||
+      aName == nsGkAtoms::head) {
     if (mBuilder) {
       nsHtml5TreeOperation::DoneAddingChildren(
         static_cast<nsIContent*>(aElement));
       return;
     }
     nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(mozilla::fallible);
     if (MOZ_UNLIKELY(!treeOp)) {
       MarkAsBrokenAndRequestSuspensionWithoutBuilder(NS_ERROR_OUT_OF_MEMORY);