Backed out changeset e84a9df80ec5 (bug 1060179)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Thu, 09 Oct 2014 12:48:31 +0200
changeset 232776 44e07888317ede7bbc4f3afee1181e6e40fe768d
parent 232775 c2d1a64877316e161ade2b66dd1645bc04640536
child 232777 c9595f1fc91ff730ed549d6ef3f02b9c0d42af46
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1060179
milestone35.0a1
backs oute84a9df80ec5e3704ad8673d22b6934be306e975
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
Backed out changeset e84a9df80ec5 (bug 1060179)
content/media/VideoUtils.cpp
content/media/VideoUtils.h
content/media/android/AndroidMediaResourceServer.cpp
--- a/content/media/VideoUtils.cpp
+++ b/content/media/VideoUtils.cpp
@@ -6,19 +6,17 @@
 #include "MediaResource.h"
 #include "mozilla/dom/TimeRanges.h"
 #include "nsMathUtils.h"
 #include "nsSize.h"
 #include "VorbisUtils.h"
 #include "ImageContainer.h"
 #include "SharedThreadPool.h"
 #include "mozilla/Preferences.h"
-#include "mozilla/Base64.h"
-#include "nsIRandomGenerator.h"
-#include "nsIServiceManager.h"
+
 #include <stdint.h>
 
 namespace mozilla {
 
 using layers::PlanarYCbCrImage;
 
 // Converts from number of audio frames to microseconds, given the specified
 // audio rate.
@@ -227,47 +225,9 @@ ExtractH264CodecDetails(const nsAString&
   NS_ENSURE_SUCCESS(rv, false);
 
   aLevel = PromiseFlatString(Substring(aCodec, 9, 2)).ToInteger(&rv, 16);
   NS_ENSURE_SUCCESS(rv, false);
 
   return true;
 }
 
-nsresult
-GenerateRandomPathName(nsCString& aOutSalt, uint32_t aLength)
-{
-  nsresult rv;
-  nsCOMPtr<nsIRandomGenerator> rg =
-    do_GetService("@mozilla.org/security/random-generator;1", &rv);
-  if (NS_FAILED(rv)) return rv;
-
-  // For each three bytes of random data we will get four bytes of
-  // ASCII. Request a bit more to be safe and truncate to the length
-  // we want at the end.
-  const uint32_t requiredBytesLength =
-    static_cast<uint32_t>((aLength + 1) / 4 * 3);
-
-  uint8_t* buffer;
-  rv = rg->GenerateRandomBytes(requiredBytesLength, &buffer);
-  if (NS_FAILED(rv)) return rv;
-
-  nsAutoCString temp;
-  nsDependentCSubstring randomData(reinterpret_cast<const char*>(buffer),
-                                   requiredBytesLength);
-  rv = Base64Encode(randomData, temp);
-  NS_Free(buffer);
-  buffer = nullptr;
-  if (NS_FAILED (rv)) return rv;
-
-  temp.Truncate(aLength);
-
-  // Base64 characters are alphanumeric (a-zA-Z0-9) and '+' and '/', so we need
-  // to replace illegal characters -- notably '/'
-  temp.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '_');
-
-  aOutSalt = temp;
-
-  return NS_OK;
-}
-
-
 } // end namespace mozilla
--- a/content/media/VideoUtils.h
+++ b/content/media/VideoUtils.h
@@ -252,17 +252,11 @@ enum H264_LEVEL {
 // See http://blog.pearce.org.nz/2013/11/what-does-h264avc1-codecs-parameters.html
 // for more details.
 // Returns false on failure.
 bool
 ExtractH264CodecDetails(const nsAString& aCodecs,
                         int16_t& aProfile,
                         int16_t& aLevel);
 
-// Use a cryptographic quality PRNG to generate raw random bytes
-// and convert that to a base64 string suitable for use as a file or URL
-// path. This is based on code from nsExternalAppHandler::SetUpTempFile.
-nsresult
-GenerateRandomPathName(nsCString& aOutSalt, uint32_t aLength);
-
 } // end namespace mozilla
 
 #endif
--- a/content/media/android/AndroidMediaResourceServer.cpp
+++ b/content/media/android/AndroidMediaResourceServer.cpp
@@ -433,29 +433,56 @@ AndroidMediaResourceServer::Stop()
 
 nsresult
 AndroidMediaResourceServer::AppendRandomPath(nsCString& aUrl)
 {
   // Use a cryptographic quality PRNG to generate raw random bytes
   // and convert that to a base64 string for use as an URL path. This
   // is based on code from nsExternalAppHandler::SetUpTempFile.
   nsresult rv;
-  nsAutoCString salt;
-  rv = GenerateRandomPathName(salt, 16);
+  nsCOMPtr<nsIRandomGenerator> rg =
+    do_GetService("@mozilla.org/security/random-generator;1", &rv);
+  if (NS_FAILED(rv)) return rv;
+
+  // For each three bytes of random data we will get four bytes of
+  // ASCII. Request a bit more to be safe and truncate to the length
+  // we want at the end.
+  const uint32_t wantedFileNameLength = 16;
+  const uint32_t requiredBytesLength =
+    static_cast<uint32_t>((wantedFileNameLength + 1) / 4 * 3);
+
+  uint8_t* buffer;
+  rv = rg->GenerateRandomBytes(requiredBytesLength, &buffer);
   if (NS_FAILED(rv)) return rv;
+
+  nsAutoCString tempLeafName;
+  nsDependentCSubstring randomData(reinterpret_cast<const char*>(buffer),
+                                   requiredBytesLength);
+  rv = Base64Encode(randomData, tempLeafName);
+  NS_Free(buffer);
+  buffer = nullptr;
+  if (NS_FAILED (rv)) return rv;
+
+  tempLeafName.Truncate(wantedFileNameLength);
+
+  // Base64 characters are alphanumeric (a-zA-Z0-9) and '+' and '/', so we need
+  // to replace illegal characters -- notably '/'
+  tempLeafName.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '_');
+
   aUrl += "/";
-  aUrl += salt;
+  aUrl += tempLeafName;
+
   return NS_OK;
 }
 
 nsresult
 AndroidMediaResourceServer::AddResource(mozilla::MediaResource* aResource, nsCString& aUrl)
 {
   nsCString url = GetURLPrefix();
-  nsresult rv = GenerateRandomPathName(url, 16);
+  nsresult rv = AppendRandomPath(url);
   if (NS_FAILED (rv)) return rv;
 
   {
     MutexAutoLock lock(mMutex);
 
     // Adding a resource URL that already exists is considered an error.
     if (mResources.find(aUrl) != mResources.end()) return NS_ERROR_FAILURE;
     mResources[url] = aResource;