Bug 1329568 - Store original media-content string - r?jya draft
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 28 Dec 2016 18:56:22 +1100
changeset 460525 58b6eb38da30fac3d139f447ce93bb61c0ad24e4
parent 460524 46f42dcf95bdd67a7c4d8d2e06c7052064c82986
child 460526 67e62969a1c332cb6aa48e1af6fc20f501573de8
push id41406
push usergsquelart@mozilla.com
push dateFri, 13 Jan 2017 06:23:59 +0000
reviewersjya
bugs1329568
milestone53.0a1
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.
 };