Bug 814638 - swapFrameLoaders should not reset chrome event handler for chrome subframes. r=bz

This commit is contained in:
Paul Rouget 2012-12-21 12:58:23 +01:00
parent ce9edfa965
commit a4150c7e87
5 changed files with 103 additions and 5 deletions

View File

@ -642,14 +642,16 @@ SetTreeOwnerAndChromeEventHandlerOnDocshellTree(nsIDocShellTreeItem* aItem,
NS_PRECONDITION(aItem, "Must have item");
aItem->SetTreeOwner(aOwner);
nsCOMPtr<nsIDocShell> shell(do_QueryInterface(aItem));
shell->SetChromeEventHandler(aHandler);
int32_t childCount = 0;
aItem->GetChildCount(&childCount);
for (int32_t i = 0; i < childCount; ++i) {
nsCOMPtr<nsIDocShellTreeItem> item;
aItem->GetChildAt(i, getter_AddRefs(item));
if (aHandler) {
nsCOMPtr<nsIDocShell> shell(do_QueryInterface(item));
shell->SetChromeEventHandler(aHandler);
}
SetTreeOwnerAndChromeEventHandlerOnDocshellTree(item, aOwner, aHandler);
}
}
@ -1056,7 +1058,8 @@ nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther,
}
// Also make sure that the two docshells are the same type. Otherwise
// swapping is certainly not safe.
// swapping is certainly not safe. If this needs to be changed then
// the code below needs to be audited as it assumes identical types.
int32_t ourType = nsIDocShellTreeItem::typeChrome;
int32_t otherType = nsIDocShellTreeItem::typeChrome;
ourTreeItem->GetItemType(&ourType);
@ -1205,11 +1208,15 @@ nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther,
ourParentItem->AddChild(otherTreeItem);
otherParentItem->AddChild(ourTreeItem);
// Restore the correct chrome event handlers.
ourDocshell->SetChromeEventHandler(otherChromeEventHandler);
otherDocshell->SetChromeEventHandler(ourChromeEventHandler);
// Restore the correct treeowners
// (and also chrome event handlers for content frames only).
SetTreeOwnerAndChromeEventHandlerOnDocshellTree(ourTreeItem, otherOwner,
otherChromeEventHandler);
ourType == nsIDocShellTreeItem::typeContent ? otherChromeEventHandler : nullptr);
SetTreeOwnerAndChromeEventHandlerOnDocshellTree(otherTreeItem, ourOwner,
ourChromeEventHandler);
ourType == nsIDocShellTreeItem::typeContent ? ourChromeEventHandler : nullptr);
// Switch the owner content before we start calling AddTreeItemToTreeOwner.
// Note that we rely on this to deal with setting mObservingOwnerContent to

View File

@ -50,6 +50,9 @@ MOCHITEST_CHROME_FILES = \
test_bug800386.xul \
test_csp_bug773891.html \
test_domparsing.xul \
test_bug814638.xul \
host_bug814638.xul \
frame_bug814638.xul \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=814638
-->
<window title="Mozilla Bug 814638"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<keyset>
<key key="T" modifiers="control" oncommand="receivedKeyEvent()"/>
</keyset>
<iframe flex="1" src="about:"/>
</window>

View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=814638
-->
<window title="Mozilla Bug 814638"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<iframe flex="1" src="frame_bug814638.xul"/>
</window>

View File

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=814638
-->
<window title="Mozilla Bug 814638"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=814638"
target="_blank" id="link">Mozilla Bug 814638</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 814638 **/
SimpleTest.waitForExplicitFinish();
function startTest() {
let hostURL = "chrome://mochitests/content/chrome/content/base/test/chrome/host_bug814638.xul";
let host1 = window.open(hostURL, "_blank", "chrome");
let host2 = window.open(hostURL, "_blank", "chrome");
let isHost1Loaded = isHost2Loaded = false
host1.onload = function() {
isHost1Loaded = true;
if (isHost2Loaded) swapFrames();
}
host2.onload = function() {
isHost2Loaded = true;
if (isHost1Loaded) swapFrames();
}
function swapFrames() {
let iframe1 = host1.document.querySelector("iframe");
let iframe2 = host2.document.querySelector("iframe");
iframe2.QueryInterface(Components.interfaces.nsIFrameLoaderOwner);
iframe2.swapFrameLoaders(iframe1);
setTimeout(function() {
iframe2.contentWindow.receivedKeyEvent = receivedKeyEvent;
let innerIframe2 = iframe2.contentDocument.querySelector("iframe");
let e = innerIframe2.contentDocument.createEvent("KeyboardEvent");
e.initKeyEvent("keypress", true, true, null, true, false, false, false, 0, "t".charCodeAt(0));
innerIframe2.contentDocument.documentElement.dispatchEvent(e);
host1.close();
host2.close();
}, 0);
}
}
function receivedKeyEvent() {
ok(true, "Received key event");
SimpleTest.finish();
}
addLoadEvent(startTest);
]]>
</script>
</window>