Bug 567357 - Fire a DOMWindowCreated event which matches the observer-service notification in bug 549539 so that extensions/message-manager scripts can add DOM features before any content script runs, r=sicking

--HG--
extra : rebase_source : b1eda0b412952587b9ef12908b2c2f818359ce65
This commit is contained in:
Benjamin Smedberg 2010-06-10 12:23:40 -04:00
parent 4414f690e6
commit 68cbcbc8d1
8 changed files with 101 additions and 3 deletions

View File

@ -2143,11 +2143,25 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
}
}
nsContentUtils::AddScriptRunner(
NS_NewRunnableMethod(this, &nsGlobalWindow::DispatchDOMWindowCreated));
return NS_OK;
}
void
nsGlobalWindow::DispatchDOMWindowCreated()
{
// Fire DOMWindowCreated at chrome event listeners
nsContentUtils::DispatchChromeEvent(mDoc, mDocument, NS_LITERAL_STRING("DOMWindowCreated"),
PR_TRUE /* bubbles */,
PR_FALSE /* not cancellable */);
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (observerService) {
nsAutoString origin;
nsIPrincipal* principal = aDocument->NodePrincipal();
nsIPrincipal* principal = mDoc->NodePrincipal();
nsContentUtils::GetUTFOrigin(principal, origin);
observerService->
NotifyObservers(static_cast<nsIDOMWindow*>(this),
@ -2156,8 +2170,6 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
"content-document-global-created",
origin.get());
}
return NS_OK;
}
void

View File

@ -338,6 +338,7 @@ public:
virtual NS_HIDDEN_(void) SetDocShell(nsIDocShell* aDocShell);
virtual NS_HIDDEN_(nsresult) SetNewDocument(nsIDocument *aDocument,
nsISupports *aState);
void DispatchDOMWindowCreated();
virtual NS_HIDDEN_(void) SetOpenerWindow(nsIDOMWindowInternal *aOpener,
PRBool aOriginalOpener);
virtual NS_HIDDEN_(void) EnsureSizeUpToDate();

View File

@ -116,6 +116,7 @@ _TEST_FILES = \
test_bug563487.html \
test_bug545314.html \
test_bug548828.html \
test_DOMWindowCreated_chromeonly.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<head>
<title>DOMWindowCreated not visible in content</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<body onload="ok(true, 'Test finished'); SimpleTest.finish();">
<p id="display"></p>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
window.addEventListener("DOMWindowCreated", function() { ok(false, "DOMWindowCreated should not have fired"); }, false);
<iframe src="data:text/plain,Hi"></iframe>

View File

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
Test for Persistent Storage in chrome
-->
<window id="sample-window" width="400" height="400"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript">
var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
document.addEventListener("DOMWindowCreated", function(e) {
var otherWindow = e.target.defaultView.wrappedJSObject;
SimpleTest.is(e.type, "DOMWindowCreated", "DOMWindowCreated: " + otherWindow);
otherWindow.doneFunction = function() {
SimpleTest.ok(true, "doneFunction was called");
SimpleTest.finish();
window.close();
};
}, false);
</script>
<iframe type="content" src="http://mochi.test:8888/chrome/dom/tests/mochitest/chrome/DOMWindowCreated_content.html"/>
</window>

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<head>
<title>DOMWindowCreated helper</title>
<script type="application/javascript">
window.doneFunction();
</script>
<body>
<h1>DOMWindowCreated Helper</h1>

View File

@ -62,6 +62,9 @@ _TEST_FILES = \
test_geolocation.xul \
test_activation.xul \
window_activation.xul \
test_DOMWindowCreated.xul \
DOMWindowCreated_chrome.xul \
DOMWindowCreated_content.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
Test for Persistent Storage in chrome
-->
<window id="sample-window" width="400" height="400"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
<script>
SimpleTest.waitForExplicitFinish();
window.open("DOMWindowCreated_chrome.xul", "_blank", "chrome,width=600,height=550");
</script>
</window>