Bug 678465 - 'document-element-inserted' doesn't fire on ImageDocument; r=sicking
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Thu, 22 Sep 2011 17:35:25 +0100
changeset 77337 379147b5215f4abe1968e3549973fd83bfdf8bae
parent 77336 154c98ef39474d80d2c085e957fbcd934c6d5580
child 77338 fb6480b0b03f033f30696dc60b26a36f80357345
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerssicking
bugs678465
milestone9.0a1
Bug 678465 - 'document-element-inserted' doesn't fire on ImageDocument; r=sicking
content/base/public/nsContentUtils.h
content/html/document/src/MediaDocument.cpp
parser/html/nsHtml5TreeOperation.cpp
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -2148,9 +2148,26 @@ public:
     return GetParameter(nsnull, aResult);
   }
 
 private:
   NS_ConvertUTF16toUTF8 mString;
   nsIMIMEHeaderParam*   mService;
 };
 
+class nsDocElementCreatedNotificationRunner : public nsRunnable
+{
+public:
+    nsDocElementCreatedNotificationRunner(nsIDocument* aDoc)
+        : mDoc(aDoc)
+    {
+    }
+
+    NS_IMETHOD Run()
+    {
+        nsContentSink::NotifyDocElementCreated(mDoc);
+        return NS_OK;
+    }
+
+    nsCOMPtr<nsIDocument> mDoc;
+};
+
 #endif /* nsContentUtils_h___ */
--- a/content/html/document/src/MediaDocument.cpp
+++ b/content/html/document/src/MediaDocument.cpp
@@ -46,16 +46,17 @@
 #include "nsITextToSubURI.h"
 #include "nsIURL.h"
 #include "nsIContentViewer.h"
 #include "nsIMarkupDocumentViewer.h"
 #include "nsIDocShell.h"
 #include "nsIParser.h" // kCharsetFrom* macro definition
 #include "nsIDocumentCharsetInfo.h" 
 #include "nsNodeInfoManager.h"
+#include "nsContentUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 MediaDocumentStreamListener::MediaDocumentStreamListener(MediaDocument *aDocument)
 {
   mDocument = aDocument;
 }
@@ -246,16 +247,19 @@ MediaDocument::CreateSyntheticDocument()
   if (!root) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   NS_ASSERTION(GetChildCount() == 0, "Shouldn't have any kids");
   rv = AppendChildTo(root, PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  nsContentUtils::AddScriptRunner(
+      new nsDocElementCreatedNotificationRunner(this));
+
   nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::head, nsnull,
                                            kNameSpaceID_XHTML,
                                            nsIDOMNode::ELEMENT_NODE);
   NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
 
   // Create a <head> so our title has somewhere to live
   nsRefPtr<nsGenericHTMLElement> head = NS_NewHTMLHeadElement(nodeInfo.forget());
   if (!head) {
--- a/parser/html/nsHtml5TreeOperation.cpp
+++ b/parser/html/nsHtml5TreeOperation.cpp
@@ -223,33 +223,16 @@ nsHtml5TreeOperation::Append(nsIContent*
   rv = aParent->AppendChildTo(aNode, PR_FALSE);
   if (NS_SUCCEEDED(rv)) {
     nsNodeUtils::ContentAppended(aParent, aNode, childCount);
   }
   parentDoc->EndUpdate(UPDATE_CONTENT_MODEL);
   return rv;
 }
 
-class nsDocElementCreatedNotificationRunner : public nsRunnable
-{
-public:
-  nsDocElementCreatedNotificationRunner(nsIDocument* aDoc)
-    : mDoc(aDoc)
-  {
-  }
-
-  NS_IMETHOD Run()
-  {
-    nsContentSink::NotifyDocElementCreated(mDoc);
-    return NS_OK;
-  }
-
-  nsCOMPtr<nsIDocument> mDoc;
-};
-
 nsresult
 nsHtml5TreeOperation::AppendToDocument(nsIContent* aNode,
                                        nsHtml5TreeOpExecutor* aBuilder)
 {
   nsresult rv = NS_OK;
   aBuilder->FlushPendingAppendNotifications();
   nsIDocument* doc = aBuilder->GetDocument();
   PRUint32 childCount = doc->GetChildCount();