From ed93ab4007a7fc63d4fb2ea5762a70f03ac0bc4c Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Fri, 21 Dec 2012 12:58:23 +0100 Subject: [PATCH 1/9] Bug 814638 - swapFrameLoaders should not reset chrome event handler for chrome subframes. r=bz --- content/base/src/nsFrameLoader.cpp | 17 ++++-- content/base/test/chrome/Makefile.in | 3 + content/base/test/chrome/frame_bug814638.xul | 15 +++++ content/base/test/chrome/host_bug814638.xul | 9 +++ content/base/test/chrome/test_bug814638.xul | 64 ++++++++++++++++++++ 5 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 content/base/test/chrome/frame_bug814638.xul create mode 100644 content/base/test/chrome/host_bug814638.xul create mode 100644 content/base/test/chrome/test_bug814638.xul diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index 71e24d0a1649..82ddf488e369 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -642,14 +642,16 @@ SetTreeOwnerAndChromeEventHandlerOnDocshellTree(nsIDocShellTreeItem* aItem, NS_PRECONDITION(aItem, "Must have item"); aItem->SetTreeOwner(aOwner); - nsCOMPtr shell(do_QueryInterface(aItem)); - shell->SetChromeEventHandler(aHandler); int32_t childCount = 0; aItem->GetChildCount(&childCount); for (int32_t i = 0; i < childCount; ++i) { nsCOMPtr item; aItem->GetChildAt(i, getter_AddRefs(item)); + if (aHandler) { + nsCOMPtr 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 diff --git a/content/base/test/chrome/Makefile.in b/content/base/test/chrome/Makefile.in index 8c7be4f8a606..b6eb355f19d1 100644 --- a/content/base/test/chrome/Makefile.in +++ b/content/base/test/chrome/Makefile.in @@ -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 diff --git a/content/base/test/chrome/frame_bug814638.xul b/content/base/test/chrome/frame_bug814638.xul new file mode 100644 index 000000000000..3543a42c330a --- /dev/null +++ b/content/base/test/chrome/frame_bug814638.xul @@ -0,0 +1,15 @@ + + + + + + + + + +