Bug 1136930 - Hook PluginAsyncSurrogate into NPP_DestroyStream. r=jimm, a=lsblakk
authorAaron Klotz <aklotz@mozilla.com>
Wed, 25 Feb 2015 16:25:33 -0700
changeset 257800 9797a33e3b82d643a4db69b6f8b94c445f4c9ba7
parent 257799 e84f4f61eea19048396886786a6e1ce6e77fabcd
child 257801 bf384c919c3342a7ae49fee94cb4ad216c61616b
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, lsblakk
bugs1136930
milestone38.0a2
Bug 1136930 - Hook PluginAsyncSurrogate into NPP_DestroyStream. r=jimm, a=lsblakk
dom/plugins/ipc/PluginAsyncSurrogate.cpp
dom/plugins/ipc/PluginAsyncSurrogate.h
dom/plugins/ipc/PluginModuleParent.cpp
--- a/dom/plugins/ipc/PluginAsyncSurrogate.cpp
+++ b/dom/plugins/ipc/PluginAsyncSurrogate.cpp
@@ -167,21 +167,21 @@ PluginAsyncSurrogate::NP_GetEntryPoints(
   aFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
   aFuncs->destroy = &NPP_Destroy;
   aFuncs->getvalue = &NPP_GetValue;
   aFuncs->setvalue = &NPP_SetValue;
   aFuncs->newstream = &NPP_NewStream;
   aFuncs->setwindow = &NPP_SetWindow;
   aFuncs->writeready = &NPP_WriteReady;
   aFuncs->event = &NPP_HandleEvent;
+  aFuncs->destroystream = &NPP_DestroyStream;
   // We need to set these so that content code doesn't make assumptions
   // about these operations not being supported
   aFuncs->write = &PluginModuleParent::NPP_Write;
   aFuncs->asfile = &PluginModuleParent::NPP_StreamAsFile;
-  aFuncs->destroystream = &PluginModuleParent::NPP_DestroyStream;
 }
 
 NPError
 PluginAsyncSurrogate::NPP_Destroy(NPSavedData** aSave)
 {
   if (!WaitForInit()) {
     return NPERR_GENERIC_ERROR;
   }
@@ -262,16 +262,29 @@ PluginAsyncSurrogate::NPP_HandleEvent(vo
 int32_t
 PluginAsyncSurrogate::NPP_WriteReady(NPStream* aStream)
 {
   // We'll tell the browser to retry in a bit. Eventually NPP_WriteReady
   // will resolve to the plugin's NPP_WriteReady and this should all just work.
   return 0;
 }
 
+NPError
+PluginAsyncSurrogate::NPP_DestroyStream(NPStream* aStream, NPReason aReason)
+{
+  for (uint32_t idx = 0, len = mPendingNewStreamCalls.Length(); idx < len; ++idx) {
+    PendingNewStreamCall& curPendingCall = mPendingNewStreamCalls[idx];
+    if (curPendingCall.mStream == aStream) {
+      mPendingNewStreamCalls.RemoveElementAt(idx);
+      break;
+    }
+  }
+  return NPERR_NO_ERROR;
+}
+
 /* static */ NPError
 PluginAsyncSurrogate::NPP_Destroy(NPP aInstance, NPSavedData** aSave)
 {
   PluginAsyncSurrogate* rawSurrogate = Cast(aInstance);
   MOZ_ASSERT(rawSurrogate);
   PluginModuleParent* module = rawSurrogate->GetParent();
   if (module && !module->IsInitialized()) {
     // Take ownership of pdata's surrogate since we're going to release it
@@ -345,16 +358,26 @@ PluginAsyncSurrogate::NPP_HandleEvent(NP
 /* static */ int32_t
 PluginAsyncSurrogate::NPP_WriteReady(NPP aInstance, NPStream* aStream)
 {
   PluginAsyncSurrogate* surrogate = Cast(aInstance);
   MOZ_ASSERT(surrogate);
   return surrogate->NPP_WriteReady(aStream);
 }
 
+/* static */ NPError
+PluginAsyncSurrogate::NPP_DestroyStream(NPP aInstance,
+                                        NPStream* aStream,
+                                        NPReason aReason)
+{
+  PluginAsyncSurrogate* surrogate = Cast(aInstance);
+  MOZ_ASSERT(surrogate);
+  return surrogate->NPP_DestroyStream(aStream, aReason);
+}
+
 PluginAsyncSurrogate::PendingNewStreamCall::PendingNewStreamCall(
     NPMIMEType aType, NPStream* aStream, NPBool aSeekable)
   : mType(NullableString(aType))
   , mStream(aStream)
   , mSeekable(aSeekable)
 {
 }
 
@@ -398,17 +421,17 @@ PluginAsyncSurrogate::OnInstanceCreated(
     PendingNewStreamCall& curPendingCall = mPendingNewStreamCalls[i];
     uint16_t streamType = NP_NORMAL;
     NPError curError = aInstance->NPP_NewStream(
                     const_cast<char*>(NullableStringGet(curPendingCall.mType)),
                     curPendingCall.mStream, curPendingCall.mSeekable,
                     &streamType);
     if (curError != NPERR_NO_ERROR) {
       // If we failed here then the send failed and we need to clean up
-      parent::_destroystream(mInstance, curPendingCall.mStream, NPRES_DONE);
+      DestroyAsyncStream(curPendingCall.mStream);
     }
   }
   mPendingNewStreamCalls.Clear();
   mInstantiated = true;
 }
 
 /**
  * During asynchronous initialization it might be necessary to wait for the
--- a/dom/plugins/ipc/PluginAsyncSurrogate.h
+++ b/dom/plugins/ipc/PluginAsyncSurrogate.h
@@ -37,16 +37,17 @@ public:
   NPError NPP_SetValue(NPNVariable aVariable, void* aValue);
   NPError NPP_NewStream(NPMIMEType aType, NPStream* aStream, NPBool aSeekable,
                         uint16_t* aStype);
   NPError NPP_SetWindow(NPWindow* aWindow);
   nsresult AsyncSetWindow(NPWindow* aWindow);
   void NPP_Print(NPPrint* aPrintInfo);
   int16_t NPP_HandleEvent(void* aEvent);
   int32_t NPP_WriteReady(NPStream* aStream);
+  NPError NPP_DestroyStream(NPStream* aStream, NPReason aReason);
   void OnInstanceCreated(PluginInstanceParent* aInstance);
   static bool Create(PluginModuleParent* aParent, NPMIMEType aPluginType,
                      NPP aInstance, uint16_t aMode, int16_t aArgc,
                      char* aArgn[], char* aArgv[]);
   static const NPClass* GetClass() { return &sNPClass; }
   static void NP_GetEntryPoints(NPPluginFuncs* aFuncs);
   static PluginAsyncSurrogate* Cast(NPP aInstance);
 
@@ -93,16 +94,18 @@ private:
   static NPError NPP_GetValue(NPP aInstance, NPPVariable aVariable, void* aRetval);
   static NPError NPP_SetValue(NPP aInstance, NPNVariable aVariable, void* aValue);
   static NPError NPP_NewStream(NPP aInstance, NPMIMEType aType, NPStream* aStream,
                                NPBool aSeekable, uint16_t* aStype);
   static NPError NPP_SetWindow(NPP aInstance, NPWindow* aWindow);
   static void NPP_Print(NPP aInstance, NPPrint* aPrintInfo);
   static int16_t NPP_HandleEvent(NPP aInstance, void* aEvent);
   static int32_t NPP_WriteReady(NPP aInstance, NPStream* aStream);
+  static NPError NPP_DestroyStream(NPP aInstance, NPStream* aStream,
+                                   NPReason aReason);
 
   static NPObject* ScriptableAllocate(NPP aInstance, NPClass* aClass);
   static void ScriptableInvalidate(NPObject* aObject);
   static void ScriptableDeallocate(NPObject* aObject);
   static bool ScriptableHasMethod(NPObject* aObject, NPIdentifier aName);
   static bool ScriptableInvoke(NPObject* aObject, NPIdentifier aName,
                                const NPVariant* aArgs, uint32_t aArgCount,
                                NPVariant* aResult);
--- a/dom/plugins/ipc/PluginModuleParent.cpp
+++ b/dom/plugins/ipc/PluginModuleParent.cpp
@@ -1429,21 +1429,17 @@ PluginModuleParent::NPP_SetWindow(NPP in
     RESOLVE_AND_CALL(instance, NPP_SetWindow(window));
 }
 
 NPError
 PluginModuleParent::NPP_DestroyStream(NPP instance,
                                       NPStream* stream,
                                       NPReason reason)
 {
-    PluginInstanceParent* i = PluginInstanceParent::Cast(instance);
-    if (!i)
-        return NPERR_GENERIC_ERROR;
-
-    return i->NPP_DestroyStream(stream, reason);
+    RESOLVE_AND_CALL(instance, NPP_DestroyStream(stream, reason));
 }
 
 int32_t
 PluginModuleParent::NPP_WriteReady(NPP instance,
                                    NPStream* stream)
 {
     PluginAsyncSurrogate* surrogate = nullptr;
     BrowserStreamParent* s = StreamCast(instance, stream, &surrogate);