Skip to content
Snippets Groups Projects
Commit df407eaf authored by scherkus@chromium.org's avatar scherkus@chromium.org
Browse files

Implemented rest of webkit api/glue code needed for HTML5 media canPlayType().

BUG=16636
TEST=we should respect the codecs= parameter when provided as a media mime type

Review URL: http://codereview.chromium.org/160073


git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21607 0039d316-1c4b-4281-b951-d872f2087c98
parent 29acfb30
No related merge requests found
......@@ -37,6 +37,8 @@ class MimeUtil : public PlatformMimeUtil {
bool MatchesMimeType(const std::string &mime_type_pattern,
const std::string &mime_type) const;
bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const;
void ParseCodecString(const std::string& codecs,
std::vector<std::string>* codecs_out);
......@@ -55,6 +57,7 @@ class MimeUtil : public PlatformMimeUtil {
MimeMappings non_image_map_;
MimeMappings javascript_map_;
MimeMappings view_source_map_;
MimeMappings codecs_map_;
}; // class MimeUtil
struct MimeInfo {
......@@ -196,6 +199,19 @@ static const char* const supported_media_types[] = {
#endif
};
// List of supported codecs when passed in with <source type="...">.
//
// Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support
// for more information.
static const char* const supported_media_codecs[] = {
#if defined(GOOGLE_CHROME_BUILD)
"avc1",
"mp4a",
#endif
"theora",
"vorbis",
};
// Note: does not include javascript types list (see supported_javascript_types)
static const char* const supported_non_image_types[] = {
"text/html",
......@@ -270,6 +286,9 @@ void MimeUtil::InitializeMimeTypeMaps() {
for (size_t i = 0; i < arraysize(view_source_types); ++i)
view_source_map_.insert(view_source_types[i]);
for (size_t i = 0; i < arraysize(supported_media_codecs); ++i)
codecs_map_.insert(supported_media_codecs[i]);
}
bool MimeUtil::IsSupportedImageMimeType(const char* mime_type) const {
......@@ -336,6 +355,16 @@ bool MimeUtil::MatchesMimeType(const std::string &mime_type_pattern,
return true;
}
bool MimeUtil::AreSupportedMediaCodecs(
const std::vector<std::string>& codecs) const {
for (size_t i = 0; i < codecs.size(); ++i) {
if (codecs_map_.find(codecs[i]) == codecs_map_.end()) {
return false;
}
}
return true;
}
void MimeUtil::ParseCodecString(const std::string& codecs,
std::vector<std::string>* codecs_out) {
std::string no_quote_codecs;
......@@ -403,6 +432,10 @@ bool MatchesMimeType(const std::string &mime_type_pattern,
return GetMimeUtil()->MatchesMimeType(mime_type_pattern, mime_type);
}
bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) {
return GetMimeUtil()->AreSupportedMediaCodecs(codecs);
}
void ParseCodecString(const std::string& codecs,
std::vector<std::string>* codecs_out) {
GetMimeUtil()->ParseCodecString(codecs, codecs_out);
......
......@@ -46,6 +46,9 @@ bool IsSupportedMimeType(const std::string& mime_type);
bool MatchesMimeType(const std::string &mime_type_pattern,
const std::string &mime_type);
// Returns true if and only if all codecs are supported, false otherwise.
bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs);
// Parses a codec string, populating |codecs_out| with the prefix of each codec
// in the string |codecs_in|. For example, passed "aaa.b.c,dd.eee", |codecs_out|
// will contain {"aaa", "dd"}.
......
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
......@@ -14,7 +14,7 @@
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -38,10 +38,13 @@ namespace WebKit {
class WebMimeRegistry {
public:
virtual bool supportsImageMIMEType(const WebString& mimeType) = 0;
virtual bool supportsJavaScriptMIMEType(const WebString& mimeType) = 0;
virtual bool supportsMediaMIMEType(const WebString& mimeType) = 0;
virtual bool supportsNonImageMIMEType(const WebString& mimeType) = 0;
enum SupportsType { IsNotSupported, IsSupported, MayBeSupported };
virtual SupportsType supportsImageMIMEType(const WebString& mimeType) = 0;
virtual SupportsType supportsJavaScriptMIMEType(const WebString& mimeType) = 0;
virtual SupportsType supportsMediaMIMEType(const WebString& mimeType,
const WebString& codecs) = 0;
virtual SupportsType supportsNonImageMIMEType(const WebString& mimeType) = 0;
virtual WebString mimeTypeForExtension(const WebString& fileExtension) = 0;
virtual WebString mimeTypeFromFile(const WebString& filePath) = 0;
......
......@@ -196,17 +196,20 @@ bool ChromiumBridge::layoutTestMode()
bool ChromiumBridge::isSupportedImageMIMEType(const String& mimeType)
{
return webKitClient()->mimeRegistry()->supportsImageMIMEType(mimeType);
return webKitClient()->mimeRegistry()->supportsImageMIMEType(mimeType)
!= WebMimeRegistry::IsNotSupported;
}
bool ChromiumBridge::isSupportedJavaScriptMIMEType(const String& mimeType)
{
return webKitClient()->mimeRegistry()->supportsJavaScriptMIMEType(mimeType);
return webKitClient()->mimeRegistry()->supportsJavaScriptMIMEType(mimeType)
!= WebMimeRegistry::IsNotSupported;
}
bool ChromiumBridge::isSupportedNonImageMIMEType(const String& mimeType)
{
return webKitClient()->mimeRegistry()->supportsNonImageMIMEType(mimeType);
return webKitClient()->mimeRegistry()->supportsNonImageMIMEType(mimeType)
!= WebMimeRegistry::IsNotSupported;
}
String ChromiumBridge::mimeTypeForExtension(const String& extension)
......
......@@ -377,10 +377,17 @@ void WebMediaPlayerClientImpl::getSupportedTypes(HashSet<String>& supportedTypes
MediaPlayer::SupportsType WebMediaPlayerClientImpl::supportsType(const String& type,
const String& codecs)
{
// FIXME: respect codecs, now we only check for mime-type.
if (webKitClient()->mimeRegistry()->supportsMediaMIMEType(type))
return MediaPlayer::IsSupported;
return MediaPlayer::IsNotSupported;
WebMimeRegistry::SupportsType supportsType =
webKitClient()->mimeRegistry()->supportsMediaMIMEType(type, codecs);
switch (supportsType) {
case WebMimeRegistry::IsNotSupported:
return MediaPlayer::IsNotSupported;
case WebMimeRegistry::IsSupported:
return MediaPlayer::IsSupported;
case WebMimeRegistry::MayBeSupported:
return MediaPlayer::MayBeSupported;
}
}
WebMediaPlayerClientImpl::WebMediaPlayerClientImpl()
......
......@@ -12,27 +12,45 @@
#include "webkit/glue/webkit_glue.h"
using WebKit::WebString;
using WebKit::WebMimeRegistry;
namespace webkit_glue {
bool SimpleWebMimeRegistryImpl::supportsImageMIMEType(
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType(
const WebString& mime_type) {
return net::IsSupportedImageMimeType(UTF16ToASCII(mime_type).c_str());
if (!net::IsSupportedImageMimeType(UTF16ToASCII(mime_type).c_str()))
return WebMimeRegistry::IsNotSupported;
return WebMimeRegistry::IsSupported;
}
bool SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
const WebString& mime_type) {
return net::IsSupportedJavascriptMimeType(UTF16ToASCII(mime_type).c_str());
if (!net::IsSupportedJavascriptMimeType(UTF16ToASCII(mime_type).c_str()))
return WebMimeRegistry::IsNotSupported;
return WebMimeRegistry::IsSupported;
}
bool SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
const WebString& mime_type) {
return net::IsSupportedMediaMimeType(UTF16ToASCII(mime_type).c_str());
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
const WebString& mime_type, const WebString& codecs) {
// Not supporting the container is a flat-out no.
if (!net::IsSupportedMediaMimeType(UTF16ToASCII(mime_type).c_str()))
return IsNotSupported;
// If we don't recognize the codec, it's possible we support it.
std::vector<std::string> parsed_codecs;
net::ParseCodecString(UTF16ToASCII(codecs).c_str(), &parsed_codecs);
if (!net::AreSupportedMediaCodecs(parsed_codecs))
return MayBeSupported;
// Otherwise we have a perfect match.
return IsSupported;
}
bool SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
const WebString& mime_type) {
return net::IsSupportedNonImageMimeType(UTF16ToASCII(mime_type).c_str());
if (!net::IsSupportedNonImageMimeType(UTF16ToASCII(mime_type).c_str()))
return WebMimeRegistry::IsNotSupported;
return WebMimeRegistry::IsSupported;
}
WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension(
......
......@@ -12,10 +12,14 @@ namespace webkit_glue {
class SimpleWebMimeRegistryImpl : public WebKit::WebMimeRegistry {
public:
// WebMimeRegistry methods:
virtual bool supportsImageMIMEType(const WebKit::WebString&);
virtual bool supportsJavaScriptMIMEType(const WebKit::WebString&);
virtual bool supportsMediaMIMEType(const WebKit::WebString&);
virtual bool supportsNonImageMIMEType(const WebKit::WebString&);
virtual WebKit::WebMimeRegistry::SupportsType supportsImageMIMEType(
const WebKit::WebString&);
virtual WebKit::WebMimeRegistry::SupportsType supportsJavaScriptMIMEType(
const WebKit::WebString&);
virtual WebKit::WebMimeRegistry::SupportsType supportsMediaMIMEType(
const WebKit::WebString&, const WebKit::WebString&);
virtual WebKit::WebMimeRegistry::SupportsType supportsNonImageMIMEType(
const WebKit::WebString&);
virtual WebKit::WebString mimeTypeForExtension(const WebKit::WebString&);
virtual WebKit::WebString mimeTypeFromFile(const WebKit::WebString&);
virtual WebKit::WebString preferredExtensionForMIMEType(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment