Bug 1119565: Ensure that a plugin listener's stream type is always set, even when it is STREAM_TYPE_UNKNOWN; r=jimm
authorAaron Klotz <aklotz@mozilla.com>
Mon, 23 Mar 2015 21:46:38 -0600
changeset 266303 0bbc164eb43ab1097bf0c2fc27475791b5f9608d
parent 266302 4e05681220d3f5c9fe9d9dee5eb8f3108805a23c
child 266304 50bbee4a42606646d11394f1ea8f13e1a472d73e
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1119565
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1119565: Ensure that a plugin listener's stream type is always set, even when it is STREAM_TYPE_UNKNOWN; r=jimm
dom/plugins/base/nsNPAPIPluginStreamListener.cpp
dom/plugins/base/nsPluginStreamListenerPeer.cpp
dom/plugins/base/nsPluginStreamListenerPeer.h
dom/plugins/ipc/PluginInstanceParent.cpp
--- a/dom/plugins/base/nsNPAPIPluginStreamListener.cpp
+++ b/dom/plugins/base/nsNPAPIPluginStreamListener.cpp
@@ -329,17 +329,18 @@ nsNPAPIPluginStreamListener::OnStartBind
                  ("NPP NewStream called: this=%p, npp=%p, mime=%s, seek=%d, type=%d, return=%d, url=%s\n",
                   this, npp, (char *)contentType, seekable, streamType, error, mNPStreamWrapper->mNPStream.url));
   
   if (error != NPERR_NO_ERROR)
     return NS_ERROR_FAILURE;
 
   if (streamType == nsPluginStreamListenerPeer::STREAM_TYPE_UNKNOWN) {
     SuspendRequest();
-  } else if (!SetStreamType(streamType, false)) {
+  }
+  if (!SetStreamType(streamType, false)) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 bool
 nsNPAPIPluginStreamListener::SetStreamType(uint16_t aType, bool aNeedsResume)
@@ -359,16 +360,22 @@ nsNPAPIPluginStreamListener::SetStreamTy
       mStreamType = NP_SEEK;
       // Seekable streams should continue to exist even after OnStopRequest
       // is fired, so we AddRef ourself an extra time and Release when the
       // plugin calls NPN_DestroyStream (CleanUpStream). If the plugin never
       // calls NPN_DestroyStream the stream will be destroyed before the plugin
       // instance is destroyed.
       NS_ADDREF_THIS();
       break;
+    case nsPluginStreamListenerPeer::STREAM_TYPE_UNKNOWN:
+      MOZ_ASSERT(!aNeedsResume);
+      mStreamType = nsPluginStreamListenerPeer::STREAM_TYPE_UNKNOWN;
+      // In this case we just want to set mStreamType but we do not want to
+      // execute anything else in this function.
+      return true;
     default:
       return false;
   }
   mStreamState = eStreamTypeSet;
   if (aNeedsResume) {
     if (mStreamListenerPeer) {
       mStreamListenerPeer->OnStreamTypeSet(mStreamType);
     }
--- a/dom/plugins/base/nsPluginStreamListenerPeer.cpp
+++ b/dom/plugins/base/nsPluginStreamListenerPeer.cpp
@@ -1180,34 +1180,33 @@ nsresult nsPluginStreamListenerPeer::Set
   }
 
   return NS_OK;
 }
 
 void
 nsPluginStreamListenerPeer::OnStreamTypeSet(const int32_t aStreamType)
 {
+  MOZ_ASSERT(aStreamType != STREAM_TYPE_UNKNOWN);
   MOZ_ASSERT(mRequest);
   mStreamType = aStreamType;
   if (!mUseLocalCache && mStreamType >= NP_ASFILE) {
     // check it out if this is not a file channel.
     nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(mRequest);
     if (!fileChannel) {
       mUseLocalCache = true;
     }
   }
 
   if (mUseLocalCache) {
     nsCOMPtr<nsIChannel> channel = do_QueryInterface(mRequest);
     SetupPluginCacheFile(channel);
   }
 }
 
-const int32_t nsPluginStreamListenerPeer::STREAM_TYPE_UNKNOWN = UINT16_MAX;
-
 nsresult
 nsPluginStreamListenerPeer::OnFileAvailable(nsIFile* aFile)
 {
   nsresult rv;
   if (!mPStreamListener)
     return NS_ERROR_FAILURE;
 
   nsAutoCString path;
--- a/dom/plugins/base/nsPluginStreamListenerPeer.h
+++ b/dom/plugins/base/nsPluginStreamListenerPeer.h
@@ -126,17 +126,19 @@ public:
     nsCOMArray<nsIRequest> requestsCopy(mRequests);
     for (int32_t i = 0; i < requestsCopy.Count(); ++i)
       requestsCopy[i]->Resume();
   }
 
   // Called by nsNPAPIPluginStreamListener
   void OnStreamTypeSet(const int32_t aStreamType);
 
-  static const int32_t STREAM_TYPE_UNKNOWN;
+  enum {
+    STREAM_TYPE_UNKNOWN = UINT16_MAX
+  };
 
 private:
   nsresult SetUpStreamListener(nsIRequest* request, nsIURI* aURL);
   nsresult SetupPluginCacheFile(nsIChannel* channel);
   nsresult GetInterfaceGlobal(const nsIID& aIID, void** result);
 
   nsCOMPtr<nsIURI> mURL;
   nsCString mURLSpec; // Have to keep this member because GetURL hands out char*
--- a/dom/plugins/ipc/PluginInstanceParent.cpp
+++ b/dom/plugins/ipc/PluginInstanceParent.cpp
@@ -1390,17 +1390,17 @@ PluginInstanceParent::NPP_NewStream(NPMI
     Telemetry::AutoTimer<Telemetry::BLOCKED_ON_PLUGIN_STREAM_INIT_MS>
         timer(Module()->GetHistogramKey());
 
     NPError err = NPERR_NO_ERROR;
     if (mParent->IsStartingAsync()) {
         MOZ_ASSERT(mSurrogate);
         mSurrogate->AsyncCallDeparting();
         if (SendAsyncNPP_NewStream(bs, NullableString(type), seekable)) {
-            *stype = UINT16_MAX;
+            *stype = nsPluginStreamListenerPeer::STREAM_TYPE_UNKNOWN;
         } else {
             err = NPERR_GENERIC_ERROR;
         }
     } else {
         bs->SetAlive();
         if (!CallNPP_NewStream(bs, NullableString(type), seekable, &err, stype)) {
             err = NPERR_GENERIC_ERROR;
         }