From a8bf5c7379906d680f6aee4d932ac4c82a749132 Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Sun, 8 Feb 2015 17:50:01 -0600 Subject: [PATCH] Bug 1103177 - When tabs are torn out, swap plugin widget parents. r=roc --- dom/base/nsFrameLoader.cpp | 15 +++++++++++++++ dom/base/nsFrameLoader.cpp.rej | 21 +++++++++++++++++++++ dom/plugins/ipc/PluginWidgetParent.cpp | 8 ++++++++ dom/plugins/ipc/PluginWidgetParent.h | 3 +++ 4 files changed, 47 insertions(+) create mode 100644 dom/base/nsFrameLoader.cpp.rej diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index 2105442c3c46..1e6f70676253 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -76,6 +76,8 @@ #include "AppProcessChecker.h" #include "ContentParent.h" #include "TabParent.h" +#include "mozilla/plugins/PPluginWidgetParent.h" +#include "../plugins/ipc/PluginWidgetParent.h" #include "mozilla/AsyncEventDispatcher.h" #include "mozilla/GuardObjects.h" #include "mozilla/Preferences.h" @@ -970,6 +972,8 @@ nsFrameLoader::SwapWithOtherRemoteLoader(nsFrameLoader* aOther, nsRefPtr& aFirstToSwap, nsRefPtr& aSecondToSwap) { + MOZ_ASSERT(NS_IsMainThread()); + Element* ourContent = mOwnerContent; Element* otherContent = aOther->mOwnerContent; @@ -1024,6 +1028,17 @@ nsFrameLoader::SwapWithOtherRemoteLoader(nsFrameLoader* aOther, return rv; } + // Native plugin windows used by this remote content need to be reparented. + const nsTArray& plugins = + aOther->mRemoteBrowser->ManagedPPluginWidgetParent(); + nsPIDOMWindow* newWin = ourDoc->GetWindow(); + if (newWin) { + nsRefPtr newParent = ((nsGlobalWindow*)newWin)->GetMainWidget(); + for (uint32_t idx = 0; idx < plugins.Length(); ++idx) { + static_cast(plugins[idx])->SetParent(newParent); + } + } + SetOwnerContent(otherContent); aOther->SetOwnerContent(ourContent); diff --git a/dom/base/nsFrameLoader.cpp.rej b/dom/base/nsFrameLoader.cpp.rej new file mode 100644 index 000000000000..c3e2d5db193d --- /dev/null +++ b/dom/base/nsFrameLoader.cpp.rej @@ -0,0 +1,21 @@ +--- nsFrameLoader.cpp ++++ nsFrameLoader.cpp +@@ -48,17 +48,17 @@ + #include "nsIDOMHTMLDocument.h" + #include "nsIXULWindow.h" + #include "nsIEditor.h" + #include "nsIMozBrowserFrame.h" + #include "nsIPermissionManager.h" + #include "nsISHistory.h" + #include "nsNullPrincipal.h" + #include "nsIScriptError.h" +- ++#include "nsGlobalWindow.h" + #include "nsLayoutUtils.h" + #include "nsView.h" + + #include "nsIURI.h" + #include "nsIURL.h" + #include "nsNetUtil.h" + + #include "nsGkAtoms.h" diff --git a/dom/plugins/ipc/PluginWidgetParent.cpp b/dom/plugins/ipc/PluginWidgetParent.cpp index 728369b3e4a2..32d60f09e71f 100644 --- a/dom/plugins/ipc/PluginWidgetParent.cpp +++ b/dom/plugins/ipc/PluginWidgetParent.cpp @@ -75,6 +75,14 @@ PluginWidgetParent::GetTabParent() return static_cast(Manager()); } +void +PluginWidgetParent::SetParent(nsIWidget* aParent) +{ + if (mWidget && aParent) { + mWidget->SetParent(aParent); + } +} + #if defined(XP_WIN) // static void diff --git a/dom/plugins/ipc/PluginWidgetParent.h b/dom/plugins/ipc/PluginWidgetParent.h index 024b40d60a67..c013a21e37ab 100644 --- a/dom/plugins/ipc/PluginWidgetParent.h +++ b/dom/plugins/ipc/PluginWidgetParent.h @@ -48,6 +48,9 @@ public: // Called by PBrowser when it receives a Destroy() call from the child. void ParentDestroy(); + // Sets mWidget's parent + void SetParent(nsIWidget* aParent); + private: void ShutdownCommon(bool aParentInitiated);