Bug 678465 - 'document-element-inserted' doesn't fire on ImageDocument; r=bz

This commit is contained in:
Gabor Krizsanits 2011-12-15 15:10:36 +00:00
parent 94a4c2e190
commit 108063a5d0
7 changed files with 85 additions and 19 deletions

View File

@ -2161,4 +2161,21 @@ private:
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___ */

View File

@ -363,7 +363,7 @@ ImageDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
// Set the script global object on the superclass before doing
// anything that might require it....
nsHTMLDocument::SetScriptGlobalObject(aScriptGlobalObject);
MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
if (aScriptGlobalObject) {
if (!GetRootElement()) {

View File

@ -51,6 +51,7 @@
#include "nsIParser.h" // kCharsetFrom* macro definition
#include "nsIDocumentCharsetInfo.h"
#include "nsNodeInfoManager.h"
#include "nsContentUtils.h"
namespace mozilla {
namespace dom {
@ -130,6 +131,7 @@ const char* const MediaDocument::sFormatNames[4] =
};
MediaDocument::MediaDocument()
: mDocumentElementInserted(false)
{
}
MediaDocument::~MediaDocument()
@ -433,5 +435,16 @@ MediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
}
}
void
MediaDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject)
{
nsHTMLDocument::SetScriptGlobalObject(aGlobalObject);
if (!mDocumentElementInserted && aGlobalObject) {
mDocumentElementInserted = true;
nsContentUtils::AddScriptRunner(
new nsDocElementCreatedNotificationRunner(this));
}
}
} // namespace dom
} // namespace mozilla

View File

@ -64,6 +64,8 @@ public:
bool aReset = true,
nsIContentSink* aSink = nsnull);
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject);
protected:
virtual nsresult CreateSyntheticDocument();
@ -93,9 +95,10 @@ protected:
nsCOMPtr<nsIStringBundle> mStringBundle;
static const char* const sFormatNames[4];
private:
enum {eWithNoInfo, eWithFile, eWithDim, eWithDimAndFile};
bool mDocumentElementInserted;
};

View File

@ -77,6 +77,7 @@ _TEST_FILES = test_bug1682.html \
test_form-parsing.html \
test_viewport.html \
test_documentAll.html \
test_document-element-inserted.html \
test_bug445004.html \
bug445004-inner.js \
bug445004-outer-rel.html \

View File

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media test: document-element-inserted</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<iframe id = 'media'>
</iframe>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var loc;
var observe = function(doc){
if (doc == media.contentDocument) {
ok(media.contentDocument.location.toString().indexOf(loc) != -1,
"The loaded media should be " + loc);
next();
}
}
var media = document.getElementById('media');
var tests = [
"../../../media/test/short-video.ogv",
"../../../media/test/sound.ogg",
"../../content/test/image.png"
]
function next() {
if (tests.length > 0) {
var t = tests.shift();
loc = t.substring(t.indexOf("test"));
media.setAttribute("src",t);
}
else {
SpecialPowers.removeObserver(observe, "document-element-inserted");
SimpleTest.finish();
}
}
SpecialPowers.addObserver(observe, "document-element-inserted", false)
next();
</script>
</pre>
</body>
</html>

View File

@ -233,23 +233,6 @@ nsHtml5TreeOperation::Append(nsIContent* aNode,
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)