Bug 1329568 - Store original media-content string - r=jya
☠☠ backed out by 4caa61eee820 ☠ ☠
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 28 Dec 2016 18:56:22 +1100
changeset 374182 706da9f85272fdd7f9db7dca77886c7d337b2819
parent 374181 c316c8d24d32836a198286faa93e5a5c8990d0e6
child 374183 8f37ee96bd78e5672e664ebfb156650137a4f63b
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1329568
milestone53.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 1329568 - Store original media-content string - r=jya Some code (mostly logging) needs to know the original full MIME string, which we would normally not need to keep in MediaExtendedMIMEType. MozReview-Commit-ID: Jcd290ScHAb
dom/media/MediaContentType.h
dom/media/MediaMIMETypes.cpp
dom/media/MediaMIMETypes.h
--- a/dom/media/MediaContentType.h
+++ b/dom/media/MediaContentType.h
@@ -30,16 +30,20 @@ public:
   explicit MediaContentType(MediaExtendedMIMEType&& aType)
     : mExtendedMIMEType(Move(aType))
   {
   }
 
   const MediaMIMEType& Type() const { return mExtendedMIMEType.Type(); }
   const MediaExtendedMIMEType& ExtendedType() const { return mExtendedMIMEType; }
 
+  // Original string. Note that "type/subtype" may not be lowercase,
+  // use Type().AsString() instead to get the normalized "type/subtype".
+  const nsACString& OriginalString() const { return mExtendedMIMEType.OriginalString(); }
+
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
 private:
   MediaExtendedMIMEType mExtendedMIMEType;
 };
 
 Maybe<MediaContentType> MakeMediaContentType(const nsAString& aType);
 Maybe<MediaContentType> MakeMediaContentType(const nsACString& aType);
--- a/dom/media/MediaMIMETypes.cpp
+++ b/dom/media/MediaMIMETypes.cpp
@@ -126,38 +126,42 @@ GetParameterAsNumber(const nsContentType
   }
   int32_t number = parameterString.ToInteger(&rv);
   if (MOZ_UNLIKELY(NS_FAILED_impl(rv))) {
     return aErrorReturn;
   }
   return number;
 }
 
-MediaExtendedMIMEType::MediaExtendedMIMEType(const nsACString& aMIMEType,
+MediaExtendedMIMEType::MediaExtendedMIMEType(const nsACString& aOriginalString,
+                                             const nsACString& aMIMEType,
                                              bool aHaveCodecs,
                                              const nsAString& aCodecs,
                                              int32_t aWidth, int32_t aHeight,
                                              int32_t aFramerate, int32_t aBitrate)
-  : mMIMEType(aMIMEType)
+  : mOriginalString(aOriginalString)
+  , mMIMEType(aMIMEType)
   , mHaveCodecs(aHaveCodecs)
   , mCodecs(aCodecs)
   , mWidth(aWidth)
   , mHeight(aHeight)
   , mFramerate(aFramerate)
   , mBitrate(aBitrate)
 {
 }
 
 MediaExtendedMIMEType::MediaExtendedMIMEType(const MediaMIMEType& aType)
-  : mMIMEType(aType)
+  : mOriginalString(aType.AsString())
+  , mMIMEType(aType)
 {
 }
 
 MediaExtendedMIMEType::MediaExtendedMIMEType(MediaMIMEType&& aType)
-  : mMIMEType(Move(aType))
+  : mOriginalString(aType.AsString())
+  , mMIMEType(Move(aType))
 {
 }
 
 Maybe<MediaExtendedMIMEType>
 MakeMediaExtendedMIMEType(const nsAString& aType)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -177,26 +181,28 @@ MakeMediaExtendedMIMEType(const nsAStrin
   rv = parser.GetParameter("codecs", codecs);
   bool haveCodecs = NS_SUCCEEDED(rv);
 
   int32_t width = GetParameterAsNumber(parser, "width", -1);
   int32_t height = GetParameterAsNumber(parser, "height", -1);
   int32_t framerate = GetParameterAsNumber(parser, "framerate", -1);
   int32_t bitrate = GetParameterAsNumber(parser, "bitrate", -1);
 
-  return Some(MediaExtendedMIMEType(mime8,
+  return Some(MediaExtendedMIMEType(NS_ConvertUTF16toUTF8(aType),
+                                    mime8,
                                     haveCodecs, codecs,
                                     width, height,
                                     framerate, bitrate));
 }
 
 size_t
 MediaExtendedMIMEType::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
-  return mMIMEType.SizeOfExcludingThis(aMallocSizeOf)
+  return mOriginalString.SizeOfExcludingThisIfUnshared(aMallocSizeOf)
+         + mMIMEType.SizeOfExcludingThis(aMallocSizeOf)
          + mCodecs.SizeOfExcludingThis(aMallocSizeOf);
 }
 
 Maybe<MediaExtendedMIMEType>
 MakeMediaExtendedMIMEType(const nsACString& aType)
 {
   return MakeMediaExtendedMIMEType(NS_ConvertUTF8toUTF16(aType));
 }
--- a/dom/media/MediaMIMETypes.h
+++ b/dom/media/MediaMIMETypes.h
@@ -162,30 +162,36 @@ public:
   const MediaCodecs& Codecs() const { return mCodecs; }
 
   // Sizes and rates.
   Maybe<int32_t> GetWidth() const { return GetMaybeNumber(mWidth); }
   Maybe<int32_t> GetHeight() const { return GetMaybeNumber(mHeight); }
   Maybe<int32_t> GetFramerate() const { return GetMaybeNumber(mFramerate); }
   Maybe<int32_t> GetBitrate() const { return GetMaybeNumber(mBitrate); }
 
+  // Original string. Note that "type/subtype" may not be lowercase,
+  // use Type().AsString() instead to get the normalized "type/subtype".
+  const nsACString& OriginalString() const { return mOriginalString; }
+
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
 private:
   friend Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(const nsAString& aType);
-  MediaExtendedMIMEType(const nsACString& aMIMEType,
+  MediaExtendedMIMEType(const nsACString& aOriginalString,
+                        const nsACString& aMIMEType,
                         bool aHaveCodecs, const nsAString& aCodecs,
                         int32_t aWidth, int32_t aHeight,
                         int32_t aFramerate, int32_t aBitrate);
 
   Maybe<int32_t> GetMaybeNumber(int32_t aNumber) const
   {
     return (aNumber < 0) ? Maybe<int32_t>(Nothing()) : Some(int32_t(aNumber));
   }
 
+  nsCString mOriginalString; // Original full string.
   MediaMIMEType mMIMEType; // MIME type/subtype.
   bool mHaveCodecs = false; // If false, mCodecs must be empty.
   MediaCodecs mCodecs;
   int32_t mWidth = -1; // -1 if not provided.
   int32_t mHeight = -1; // -1 if not provided.
   int32_t mFramerate = -1; // -1 if not provided.
   int32_t mBitrate = -1; // -1 if not provided.
 };