Bug 716107 part 4 - Dispatch MozEnteredDomFullscreen to document which requests fullscreen. r=smaug

This commit is contained in:
Chris Pearce 2012-05-09 09:47:19 +12:00
parent cad06a23d5
commit 69fad75f3b
6 changed files with 165 additions and 0 deletions

View File

@ -8758,6 +8758,21 @@ nsDocument::RestorePreviousFullScreenState()
} else {
// Else we popped the top of the stack, and there's still another
// element in there, so that will become the full-screen element.
if (fullScreenDoc != doc) {
// We've popped so enough off the stack that we've rolled back to
// a fullscreen element in a parent document. If this document isn't
// authorized for fullscreen, dispatch an event to chrome so it
// knows to show the authorization UI.
if (!nsContentUtils::IsSitePermAllow(doc->NodePrincipal(), "fullscreen")) {
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(doc,
NS_LITERAL_STRING("MozEnteredDomFullscreen"),
true,
true);
e->PostDOMEvent();
}
}
sFullScreenDoc = do_GetWeakReference(doc);
break;
}
@ -9076,6 +9091,13 @@ nsDocument::RequestFullScreen(Element* aElement, bool aWasCallerChrome)
DispatchFullScreenChange(changed[changed.Length() - i - 1]);
}
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(this,
NS_LITERAL_STRING("MozEnteredDomFullscreen"),
true,
true);
e->PostDOMEvent();
// Remember this is the requesting full-screen document.
sFullScreenDoc = do_GetWeakReference(static_cast<nsIDocument*>(this));

View File

@ -45,6 +45,8 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_MozEnteredDomFullscreen_event.xul \
MozEnteredDomFullscreen_chrome.xul \
test_dom_fullscreen_warning.xul \
dom_fullscreen_warning.xul \
test_fullscreen.xul \

View File

@ -0,0 +1,83 @@
<?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 that "MozEnteredFullscreen" is dispatched to chrome on documents that enter fullscreen.
Test Description:
This chrome window has a browser. The browser's contentDocument (the "outer document")
in turn has an iframe (the "inner document").
We request fullscreen in the outer document, and check that MozEnteredDomFullscreen is
dispatched to chrome, targeted at the outer document.
Then we request fullscreen in the inner document, and check that MozEnteredDomFullscreen
is dispatched to chrome, targeted at the inner document.
Then we cancel fullscreen in the inner document, and check that MozEnteredDomFullscreen is
dispatched again to chrome, targeted at the outer document. This still happens, since the
outer document's domain was never approved for fullscreen.
-->
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="start();">
<script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"><![CDATA[
function ok(condition, msg) {
window.opener.wrappedJSObject.ok(condition, msg);
}
function is(a, b, msg) {
window.opener.wrappedJSObject.is(a, b, msg);
}
var gBrowser = null;
var gOuterDoc = null;
var gInnerDoc = null;
function firstEntry(event) {
is(event.target, gOuterDoc, "First MozEnteredDomFullscreen should be targeted at outer doc");
window.removeEventListener("MozEnteredDomFullscreen", firstEntry, false);
ok(gOuterDoc.mozFullScreenElement != null, "Outer doc should be in fullscreen");
gInnerDoc = gOuterDoc.getElementById("innerFrame").contentDocument;
window.addEventListener("MozEnteredDomFullscreen", secondEntry, false);
gInnerDoc.defaultView.focus();
gInnerDoc.body.mozRequestFullScreen();
}
function secondEntry(event) {
is(event.target, gInnerDoc, "Second MozEnteredDomFullscreen should be targeted at inner doc");
ok(gInnerDoc.mozFullScreenElement != null, "Inner doc should be in fullscreen");
window.removeEventListener("MozEnteredDomFullscreen", secondEntry, false);
window.addEventListener("MozEnteredDomFullscreen", thirdEntry, false);
gInnerDoc.mozCancelFullScreen();
}
function thirdEntry(event) {
is(event.target, gOuterDoc, "Third MozEnteredDomFullscreen should be targeted at outer doc");
ok(gOuterDoc.mozFullScreenElement != null, "Outer doc return to fullscreen after cancel fullscreen in inner doc");
window.removeEventListener("MozEnteredDomFullscreen", thirdEntry, false);
gOuterDoc.mozCancelFullScreen();
window.opener.wrappedJSObject.done();
}
function start() {
SimpleTest.waitForFocus(
function() {
gBrowser = document.getElementById("browser");
gOuterDoc = gBrowser.contentDocument;
gBrowser.contentWindow.focus();
window.addEventListener("MozEnteredDomFullscreen", firstEntry, false);
gOuterDoc.body.mozRequestFullScreen();
});
}
]]>
</script>
<!-- chrome://mochitests/content/chrome/dom/tests/mochitest/chrome/test_MozEnteredDomFullscreen_event.xul -->
<browser type="content" id="browser" width="400" height="400" src="http://mochi.test:8888/tests/dom/tests/mochitest/general/file_MozEnteredDomFullscreen.html"/>
</window>

View File

@ -0,0 +1,49 @@
<?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 that "MozShowFullScreenWarning" is dispatched to chrome on restricted keypress.
-->
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" width="400" height="400">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script>
SimpleTest.waitForExplicitFinish();
// Ensure the full-screen api is enabled, and will be disabled on test exit.
var gPrevEnabled = SpecialPowers.getBoolPref("full-screen-api.enabled");
SpecialPowers.setBoolPref("full-screen-api.enabled", true);
var gPrevTrusted = SpecialPowers.getBoolPref("full-screen-api.allow-trusted-requests-only");
SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
const Cc = Components.classes;
const Ci = Components.interfaces;
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
return ios.newURI(url, null, null);
}
// Ensure "fullscreen" permissions are not present on the test URI.
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
var uri = make_uri("http://mochi.test:8888");
pm.remove(uri.host, "fullscreen");
newwindow = window.open("MozEnteredDomFullscreen_chrome.xul", "_blank","chrome,resizable=yes,width=400,height=400");
function done()
{
newwindow.close();
SpecialPowers.setBoolPref("full-screen-api.enabled", gPrevEnabled);
SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", gPrevTrusted);
SimpleTest.finish();
}
</script>
<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
</window>

View File

@ -45,6 +45,7 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
file_MozEnteredDomFullscreen.html \
test_outerHTML.html \
test_outerHTML.xhtml \
497633.html \

View File

@ -0,0 +1,8 @@
<html>
<head>
</head>
<body style="background-color: blue;">
<p>Outer doc</p>
<iframe id="innerFrame" src="data:text/html,<html><body style='background-color: red;'><p>Inner doc</p></body></html>"></iframe>
</body>
</html>