Bug 536437 - work around a bug in the Mozilla plugin host where NPN_GetURLNotify can return an error and also call NPP_URLNotify, r=cjones
authorBenjamin Smedberg <benjamin@smedbergs.us>
Tue, 05 Jan 2010 12:12:30 -0500
changeset 46493 077bdb4faf063916f5ff1ac5f55769e19de1e683
parent 46492 040f477adedbe9b11e0ec56e8dce52c4a9f06099
child 46494 5d2e3cd990c6a9425ef84f34f565950a4fbc3827
push id14210
push userdougt@mozilla.com
push dateThu, 01 Jul 2010 06:28:42 +0000
treeherdermozilla-central@3aff97777291 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs536437
milestone1.9.3a1pre
Bug 536437 - work around a bug in the Mozilla plugin host where NPN_GetURLNotify can return an error and also call NPP_URLNotify, r=cjones
dom/plugins/PluginInstanceParent.cpp
dom/plugins/StreamNotifyParent.h
--- a/dom/plugins/PluginInstanceParent.cpp
+++ b/dom/plugins/PluginInstanceParent.cpp
@@ -265,33 +265,40 @@ bool
 PluginInstanceParent::AnswerPStreamNotifyConstructor(PStreamNotifyParent* actor,
                                                      const nsCString& url,
                                                      const nsCString& target,
                                                      const bool& post,
                                                      const nsCString& buffer,
                                                      const bool& file,
                                                      NPError* result)
 {
+    bool streamDestroyed = false;
+    static_cast<StreamNotifyParent*>(actor)->
+        SetDestructionFlag(&streamDestroyed);
+
     if (!post) {
         *result = mNPNIface->geturlnotify(mNPP,
                                           NullableStringGet(url),
                                           NullableStringGet(target),
                                           actor);
     }
     else {
         *result = mNPNIface->posturlnotify(mNPP,
                                            NullableStringGet(url),
                                            NullableStringGet(target),
                                            buffer.Length(),
                                            NullableStringGet(buffer),
                                            file, actor);
     }
 
-    if (*result != NPERR_NO_ERROR)
-        PStreamNotifyParent::Call__delete__(actor, NPERR_GENERIC_ERROR);
+    if (!streamDestroyed) {
+        static_cast<StreamNotifyParent*>(actor)->ClearDestructionFlag();
+        if (*result != NPERR_NO_ERROR)
+            PStreamNotifyParent::Call__delete__(actor, NPERR_GENERIC_ERROR);
+    }
 
     return true;
 }
 
 bool
 PluginInstanceParent::DeallocPStreamNotify(PStreamNotifyParent* notifyData)
 {
     delete notifyData;
--- a/dom/plugins/StreamNotifyParent.h
+++ b/dom/plugins/StreamNotifyParent.h
@@ -43,15 +43,34 @@
 
 namespace mozilla {
 namespace plugins {
 
 class StreamNotifyParent : public PStreamNotifyParent
 {
   friend class PluginInstanceParent;
 
-  StreamNotifyParent() { }
+  StreamNotifyParent()
+    : mDestructionFlag(NULL)
+  { }
+  ~StreamNotifyParent() {
+    if (mDestructionFlag)
+      *mDestructionFlag = true;
+  }
+
+public:
+  // If we are destroyed within the call to NPN_GetURLNotify, notify the caller
+  // so that we aren't destroyed again. see bug 536437.
+  void SetDestructionFlag(bool* flag) {
+    mDestructionFlag = flag;
+  }
+  void ClearDestructionFlag() {
+    mDestructionFlag = NULL;
+  }
+
+private:
+  bool* mDestructionFlag;
 };
 
 } // namespace plugins
 } // namespace mozilla
 
 #endif