Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| index b20a17edb06b0a4bee5031030d34d2891a6fd04a..7ed3cc3128cdcfdbeccb905d49ada402cb9642b7 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| @@ -81,6 +81,7 @@ |
| #include "platform/audio/AudioSourceProviderClient.h" |
| #include "platform/graphics/GraphicsLayer.h" |
| #include "platform/mediastream/MediaStreamDescriptor.h" |
| +#include "platform/network/ParsedContentType.h" |
| #include "platform/network/mime/ContentType.h" |
| #include "platform/network/mime/MIMETypeFromURL.h" |
| #include "platform/weborigin/SecurityOrigin.h" |
| @@ -138,6 +139,43 @@ enum MediaControlsShow { |
| MediaControlsShowMax |
| }; |
| +// These values are used for the Media.MediaElement.ContentTypeResult histogram. |
| +// Do not reorder. |
| +enum ContentTypeParseableResult { |
| + IsSupportedParseable = 0, |
| + MayBeSupportedParseable, |
| + IsNotSupportedParseable, |
| + IsSupportedNotParseable, |
| + MayBeSupportedNotParseable, |
| + IsNotSupportedNotParseable, |
| + ContentTypeParseableMax |
| +}; |
| + |
| +void ReportContentTypeResultToUMA(String contentType, |
| + MIMETypeRegistry::SupportsType result) { |
| + DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| + EnumerationHistogram, contentTypeParseableHistogram, |
| + new EnumerationHistogram("Media.MediaElement.ContentTypeParseable", |
| + ContentTypeParseableMax)); |
| + ParsedContentType parsedContentType(contentType); |
| + ContentTypeParseableResult umaResult; |
| + switch (result) { |
| + case MIMETypeRegistry::IsSupported: |
| + umaResult = parsedContentType.isValid() ? IsSupportedParseable |
| + : IsSupportedNotParseable; |
| + break; |
| + case MIMETypeRegistry::MayBeSupported: |
| + umaResult = parsedContentType.isValid() ? MayBeSupportedParseable |
| + : MayBeSupportedNotParseable; |
| + break; |
| + case MIMETypeRegistry::IsNotSupported: |
| + umaResult = parsedContentType.isValid() ? IsNotSupportedParseable |
| + : IsNotSupportedNotParseable; |
| + break; |
| + } |
| + contentTypeParseableHistogram.count(umaResult); |
| +} |
| + |
| String urlForLoggingMedia(const KURL& url) { |
| static const unsigned maximumURLLengthForLogging = 128; |
| @@ -243,11 +281,12 @@ const AtomicString& VideoKindToString( |
| return emptyAtom; |
| } |
| -bool canLoadURL(const KURL& url, const ContentType& contentType) { |
| +bool canLoadURL(const KURL& url, const String& contentType) { |
| DEFINE_STATIC_LOCAL(const String, codecs, ("codecs")); |
| - String contentMIMEType = contentType.type().lower(); |
| - String contentTypeCodecs = contentType.parameter(codecs); |
| + ContentType type(contentType); |
| + String contentMIMEType = type.type().lower(); |
| + String contentTypeCodecs = type.parameter(codecs); |
| // If the MIME type is missing or is not meaningful, try to figure it out from |
| // the URL. |
| @@ -269,7 +308,8 @@ bool canLoadURL(const KURL& url, const ContentType& contentType) { |
| if (contentMIMEType != "application/octet-stream" || |
| contentTypeCodecs.isEmpty()) { |
| return MIMETypeRegistry::supportsMediaMIMEType(contentMIMEType, |
| - contentTypeCodecs); |
| + contentTypeCodecs) == |
| + MIMETypeRegistry::IsSupported; |
|
jrummell
2017/03/03 21:52:47
This is wrong (should be != IsNotSupported).
|
| } |
| return false; |
| @@ -343,7 +383,13 @@ MIMETypeRegistry::SupportsType HTMLMediaElement::supportsType( |
| if (type == "application/octet-stream") |
| return MIMETypeRegistry::IsNotSupported; |
| - return MIMETypeRegistry::supportsMediaMIMEType(type, typeCodecs); |
| + // Check if stricter parsing of |contentType| will cause problems. |
| + // TODO(jrummell): Either switch to ParsedContentType or remove this UMA, |
| + // depending on the results reported. |
| + MIMETypeRegistry::SupportsType result = |
| + MIMETypeRegistry::supportsMediaMIMEType(type, typeCodecs); |
| + ReportContentTypeResultToUMA(contentType.raw(), result); |
| + return result; |
| } |
| URLRegistry* HTMLMediaElement::s_mediaStreamRegistry = 0; |
| @@ -1027,8 +1073,7 @@ void HTMLMediaElement::loadSourceFromObject() { |
| // No type is available when the resource comes from the 'srcObject' |
| // attribute. |
| - loadResource(WebMediaPlayerSource(WebMediaStream(m_srcObject)), |
| - ContentType((String()))); |
| + loadResource(WebMediaPlayerSource(WebMediaStream(m_srcObject)), String()); |
| } |
| void HTMLMediaElement::loadSourceFromAttribute() { |
| @@ -1052,11 +1097,11 @@ void HTMLMediaElement::loadSourceFromAttribute() { |
| // No type is available when the url comes from the 'src' attribute so |
| // MediaPlayer will have to pick a media engine based on the file extension. |
| - loadResource(WebMediaPlayerSource(WebURL(mediaURL)), ContentType((String()))); |
| + loadResource(WebMediaPlayerSource(WebURL(mediaURL)), String()); |
| } |
| void HTMLMediaElement::loadNextSourceChild() { |
| - ContentType contentType((String())); |
| + String contentType; |
| KURL mediaURL = selectNextSourceChild(&contentType, Complain); |
| if (!mediaURL.isValid()) { |
| waitForSourceChange(); |
| @@ -1071,15 +1116,14 @@ void HTMLMediaElement::loadNextSourceChild() { |
| } |
| void HTMLMediaElement::loadResource(const WebMediaPlayerSource& source, |
| - const ContentType& contentType) { |
| + const String& contentType) { |
| DCHECK(isMainThread()); |
| KURL url; |
| if (source.isURL()) { |
| url = source.getAsURL(); |
| DCHECK(isSafeToLoadURL(url, Complain)); |
| BLINK_MEDIA_LOG << "loadResource(" << (void*)this << ", " |
| - << urlForLoggingMedia(url) << ", " << contentType.raw() |
| - << ")"; |
| + << urlForLoggingMedia(url) << ", " << contentType << ")"; |
| } |
| LocalFrame* frame = document().frame(); |
| @@ -2870,7 +2914,7 @@ bool HTMLMediaElement::havePotentialSourceChild() { |
| HTMLSourceElement* currentSourceNode = m_currentSourceNode; |
| Node* nextNode = m_nextChildNodeToConsider; |
| - KURL nextURL = selectNextSourceChild(0, DoNothing); |
| + KURL nextURL = selectNextSourceChild(nullptr, DoNothing); |
| m_currentSourceNode = currentSourceNode; |
| m_nextChildNodeToConsider = nextNode; |
| @@ -2878,7 +2922,7 @@ bool HTMLMediaElement::havePotentialSourceChild() { |
| return nextURL.isValid(); |
| } |
| -KURL HTMLMediaElement::selectNextSourceChild(ContentType* contentType, |
| +KURL HTMLMediaElement::selectNextSourceChild(String* contentType, |
| InvalidURLAction actionIfInvalid) { |
| // Don't log if this was just called to find out if there are any valid |
| // <source> elements. |
| @@ -2962,7 +3006,7 @@ KURL HTMLMediaElement::selectNextSourceChild(ContentType* contentType, |
| if (canUseSourceElement) { |
| if (contentType) |
| - *contentType = ContentType(type); |
| + *contentType = type; |
| m_currentSourceNode = source; |
| m_nextChildNodeToConsider = source->nextSibling(); |
| } else { |