Backout ee13449af6e7 (bug 1127378) on the suspicion that it caused bug 1130734.
authorJim Mathies <jmathies@mozilla.com>
Mon, 09 Feb 2015 12:37:46 -0600
changeset 228188 bca7d6e774869a378979e2f5f1d365495bf3769c
parent 227359 ee13449af6e78d886a07d641aae87f7e7ea24bf5
child 228189 9bdf571458b070127fb2aa6c6f23c44dd74165b1
push idunknown
push userunknown
push dateunknown
bugs1127378, 1130734
milestone38.0a1
backs outee13449af6e78d886a07d641aae87f7e7ea24bf5
Backout ee13449af6e7 (bug 1127378) on the suspicion that it caused bug 1130734.
dom/ipc/PPluginWidget.ipdl
dom/plugins/ipc/PluginWidgetChild.cpp
dom/plugins/ipc/PluginWidgetChild.h
dom/plugins/ipc/PluginWidgetParent.cpp
dom/plugins/ipc/PluginWidgetParent.h
--- a/dom/ipc/PPluginWidget.ipdl
+++ b/dom/ipc/PPluginWidget.ipdl
@@ -42,21 +42,22 @@ parent:
    * window for plugins. On Linux, this returns an XID for a socket widget
    * embedded in the chrome side native window. On Windows this returns the
    * native HWND of the plugin widget.
    */
   sync GetNativePluginPort() returns (uintptr_t value);
 
 child:
   /**
-   * Sent from chrome when the chrome side widget is getting torn down.
-   * @param aParentInitiated - indicates if the shutdown is associated
-   * with a tab closure vs. content reload.
+   * Sent from content when a plugin is unloaded via layout. We shut down
+   * some things in response to this so that we don't end up firing async
+   * msgs after the child is destroyed. We know that after this call
+   * the child actor may not be on the other side.
    */
-  async ParentShutdown(bool aParentInitiated);
+  async ParentShutdown();
 
   /**
    * Requests a full update of the plugin window.
    */
   async UpdateWindow(uintptr_t aChildId);
 };
 
 }
--- a/dom/plugins/ipc/PluginWidgetChild.cpp
+++ b/dom/plugins/ipc/PluginWidgetChild.cpp
@@ -7,75 +7,59 @@
 #include "mozilla/DebugOnly.h"
 #include "nsDebug.h"
 
 #if defined(XP_WIN)
 #include "mozilla/plugins/PluginInstanceParent.h"
 using mozilla::plugins::PluginInstanceParent;
 #endif
 
-#define PWLOG(...)
-//#define PWLOG(...) printf_stderr(__VA_ARGS__)
-
 namespace mozilla {
 namespace plugins {
 
 PluginWidgetChild::PluginWidgetChild() :
   mWidget(nullptr)
 {
   MOZ_COUNT_CTOR(PluginWidgetChild);
 }
 
 PluginWidgetChild::~PluginWidgetChild()
 {
-  PWLOG("PluginWidgetChild::~PluginWidgetChild()\n");
   MOZ_COUNT_DTOR(PluginWidgetChild);
 }
 
 /*
  * Tear down scenarios
  * layout (plugin content unloading):
- *  - PluginWidgetProxy::Destroy(), calls PluginWidgetChild->SendDestroy(), (proxy disabled)
- *  - PluginWidgetParent::RecvDestroy(), sends async ParentShutdown()
- *  - PluginWidgetChild::RecvParentShutdown(), calls Send__delete__()
+ *  - PluginWidgetProxy nsIWidget Destroy()
+ *  - PluginWidgetProxy->PluginWidgetChild->SendDestroy()
+ *  - PluginWidgetParent::RecvDestroy(), sends async Destroyed() to PluginWidgetChild
+ *  - PluginWidgetChild::RecvDestroyed() calls Send__delete__()
  *  - PluginWidgetParent::ActorDestroy() called in response to __delete__.
  * PBrowser teardown (tab closing):
- *  - TabParent::Destroy()
- *  - PluginWidgetParent::ParentDestroy(), sends async ParentShutdown()
- *  - PluginWidgetChild::RecvParentShutdown(), (proxy disabled)
+ *  - PluginWidgetParent::ParentDestroy() called by TabParent::Destroy()
  *  - PluginWidgetParent::ActorDestroy()
  *  - PluginWidgetParent::~PluginWidgetParent() in response to PBrowserParent::DeallocSubtree()
  *  - PluginWidgetChild::ActorDestroy() from PPluginWidgetChild::DestroySubtree
  *  - ~PluginWidgetChild() in response to PBrowserChild::DeallocSubtree()
  **/
 
 void
-PluginWidgetChild::ShutdownProxy()
+PluginWidgetChild::ActorDestroy(ActorDestroyReason aWhy)
 {
   if (mWidget) {
     mWidget->ChannelDestroyed();
   }
   mWidget = nullptr;
 }
 
-void
-PluginWidgetChild::ActorDestroy(ActorDestroyReason aWhy)
+bool
+PluginWidgetChild::RecvParentShutdown()
 {
-  PWLOG("PluginWidgetChild::ActorDestroy(%d)\n", aWhy);
-  ShutdownProxy(); // backup
-}
-
-bool
-PluginWidgetChild::RecvParentShutdown(const bool& aParentInitiated)
-{
-  PWLOG("PluginWidgetChild::RecvParentShutdown(%d)\n", aParentInitiated);
-  ShutdownProxy();
-  if (!aParentInitiated) {
-    Send__delete__(this);
-  }
+  Send__delete__(this);
   return true;
 }
 
 bool
 PluginWidgetChild::RecvUpdateWindow(const uintptr_t& aChildId)
 {
 #if defined(XP_WIN)
   NS_ASSERTION(aChildId, "Expected child hwnd value for remote plugin instance.");
--- a/dom/plugins/ipc/PluginWidgetChild.h
+++ b/dom/plugins/ipc/PluginWidgetChild.h
@@ -16,19 +16,17 @@ namespace plugins {
 class PluginWidgetChild : public PPluginWidgetChild
 {
 public:
   PluginWidgetChild();
   virtual ~PluginWidgetChild();
 
   virtual bool RecvUpdateWindow(const uintptr_t& aChildId) MOZ_OVERRIDE;
   virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
-  virtual bool RecvParentShutdown(const bool& aParentInitiated) MOZ_OVERRIDE;
-
-  void ShutdownProxy();
+  virtual bool RecvParentShutdown() MOZ_OVERRIDE;
 
   mozilla::widget::PluginWidgetProxy* mWidget;
 };
 
 } // namespace plugins
 } // namespace mozilla
 
 #endif // mozilla_plugins_PluginWidgetChild_h
--- a/dom/plugins/ipc/PluginWidgetParent.cpp
+++ b/dom/plugins/ipc/PluginWidgetParent.cpp
@@ -165,53 +165,49 @@ PluginWidgetParent::RecvCreate()
   mWidget->RegisterPluginWindowForRemoteUpdates();
 
   return true;
 }
 
 void
 PluginWidgetParent::ActorDestroy(ActorDestroyReason aWhy)
 {
+  mActorDestroyed = true;
   PWLOG("PluginWidgetParent::ActorDestroy()\n");
 }
 
-void
-PluginWidgetParent::ShutdownCommon(bool aParentInitiated)
-{
-  if (mActorDestroyed || !mWidget) {
-    return;
-  }
-
-  PWLOG("PluginWidgetParent::ShutdownCommon()\n");
-  mWidget->UnregisterPluginWindowForRemoteUpdates();
-  DebugOnly<nsresult> rv = mWidget->Destroy();
-  NS_ASSERTION(NS_SUCCEEDED(rv), "widget destroy failure");
-  mWidget = nullptr;
-  mActorDestroyed = true;
-  unused << SendParentShutdown(aParentInitiated);
-}
-
 // Called by TabParent's Destroy() in response to an early tear down (Early
 // in that this is happening before layout in the child has had a chance
 // to destroy the child widget.) when the tab is closing. We will not receive
 // RecvDestroy here.
 void
 PluginWidgetParent::ParentDestroy()
 {
+  if (mActorDestroyed || !mWidget) {
+    return;
+  }
   PWLOG("PluginWidgetParent::ParentDestroy()\n");
-  ShutdownCommon(true);
+  mWidget->UnregisterPluginWindowForRemoteUpdates();
+  DebugOnly<nsresult> rv = mWidget->Destroy();
+  NS_ASSERTION(NS_SUCCEEDED(rv), "widget destroy failure");
+  mWidget = nullptr;
+  mActorDestroyed = true;
+  return;
 }
 
 // Called by the child when a plugin is torn down within a tab
 // normally.
 bool
 PluginWidgetParent::RecvDestroy()
 {
-  PWLOG("PluginWidgetParent::RecvDestroy()\n");
-  ShutdownCommon(false);
+  bool destroyed = mActorDestroyed;
+  ParentDestroy();
+  if (!destroyed) {
+    unused << SendParentShutdown();
+  }
   return true;
 }
 
 bool
 PluginWidgetParent::RecvSetFocus(const bool& aRaise)
 {
   ENSURE_CHANNEL;
   PWLOG("PluginWidgetParent::RecvSetFocus(%d)\n", aRaise);
--- a/dom/plugins/ipc/PluginWidgetParent.h
+++ b/dom/plugins/ipc/PluginWidgetParent.h
@@ -44,18 +44,16 @@ public:
 
   // Helper for compositor checks on the channel
   bool ActorDestroyed() { return mActorDestroyed; }
 
   // Called by PBrowser when it receives a Destroy() call from the child.
   void ParentDestroy();
 
 private:
-  void ShutdownCommon(bool aParentInitiated);
-
   // The tab our connection is associated with.
   mozilla::dom::TabParent* GetTabParent();
   // The chrome side native widget.
   nsCOMPtr<nsIWidget> mWidget;
 #if defined(MOZ_WIDGET_GTK)
   nsAutoPtr<nsPluginNativeWindowGtk> mWrapper;
 #endif
   bool mActorDestroyed;