Commit a7d22443 authored by kinuko's avatar kinuko Committed by Commit bot

Cleanup WebMIMERegistry implementation and fix LinkLoader behavior

- Now that content/child can also depend on media just implement
  media related mime methods in SimpleWebMIMERegistry and remove
  renderer-only overrides.

- LinkLoader should use supportsMediaMIMEType rather than
  supportsMediaSourceMIMEType in as=media cases, as the latter
  is for MediaSource extension and always fails if empty codecs
  string is given (and that was what happening in the real renderer case)

BUG=658628
TEST=http/tests/preload/preload_with_type.html
TEST=LinkLoaderTest.Preload

Review-Url: https://codereview.chromium.org/2440163002
Cr-Commit-Position: refs/heads/master@{#427037}
parent 19dbf3f3
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/mime_util/mime_util.h" #include "components/mime_util/mime_util.h"
#include "media/base/mime_util.h" #include "media/base/mime_util.h"
#include "media/filters/stream_parser_factory.h"
#include "net/base/mime_util.h" #include "net/base/mime_util.h"
#include "third_party/WebKit/public/platform/FilePathConversion.h" #include "third_party/WebKit/public/platform/FilePathConversion.h"
#include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebString.h"
...@@ -60,21 +61,26 @@ WebMimeRegistry::SupportsType ...@@ -60,21 +61,26 @@ WebMimeRegistry::SupportsType
: WebMimeRegistry::IsNotSupported; : WebMimeRegistry::IsNotSupported;
} }
// When debugging layout tests failures in the test shell,
// see TestShellWebMimeRegistryImpl.
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
const WebString& mime_type, const WebString& mime_type,
const WebString& codecs) { const WebString& codecs) {
// Media features are only supported at the content/renderer/ layer. const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
return IsNotSupported; std::vector<std::string> codec_vector;
media::ParseCodecString(ToASCIIOrEmpty(codecs), &codec_vector, false);
return static_cast<WebMimeRegistry::SupportsType>(
media::IsSupportedMediaFormat(mime_type_ascii, codec_vector));
} }
bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType(
const WebString& mime_type, const WebString& mime_type,
const WebString& codecs) { const WebString& codecs) {
// Media features are only supported at the content/renderer layer.
const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
return media::IsSupportedMediaMimeType(mime_type_ascii); if (mime_type_ascii.empty())
return false;
std::vector<std::string> parsed_codec_ids;
media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false);
return media::StreamParserFactory::IsTypeSupported(mime_type_ascii,
parsed_codec_ids);
} }
WebMimeRegistry::SupportsType WebMimeRegistry::SupportsType
......
...@@ -196,11 +196,6 @@ media::AudioParameters GetAudioHardwareParams() { ...@@ -196,11 +196,6 @@ media::AudioParameters GetAudioHardwareParams() {
class RendererBlinkPlatformImpl::MimeRegistry class RendererBlinkPlatformImpl::MimeRegistry
: public SimpleWebMimeRegistryImpl { : public SimpleWebMimeRegistryImpl {
public: public:
blink::WebMimeRegistry::SupportsType supportsMediaMIMEType(
const blink::WebString& mime_type,
const blink::WebString& codecs) override;
bool supportsMediaSourceMIMEType(const blink::WebString& mime_type,
const blink::WebString& codecs) override;
blink::WebString mimeTypeForExtension( blink::WebString mimeTypeForExtension(
const blink::WebString& file_extension) override; const blink::WebString& file_extension) override;
...@@ -505,30 +500,6 @@ WebString RendererBlinkPlatformImpl::fileSystemCreateOriginIdentifier( ...@@ -505,30 +500,6 @@ WebString RendererBlinkPlatformImpl::fileSystemCreateOriginIdentifier(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
WebMimeRegistry::SupportsType
RendererBlinkPlatformImpl::MimeRegistry::supportsMediaMIMEType(
const WebString& mime_type,
const WebString& codecs) {
const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
std::vector<std::string> codec_vector;
media::ParseCodecString(ToASCIIOrEmpty(codecs), &codec_vector, false);
return static_cast<WebMimeRegistry::SupportsType>(
media::IsSupportedMediaFormat(mime_type_ascii, codec_vector));
}
bool RendererBlinkPlatformImpl::MimeRegistry::supportsMediaSourceMIMEType(
const blink::WebString& mime_type,
const WebString& codecs) {
const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
std::vector<std::string> parsed_codec_ids;
media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false);
if (mime_type_ascii.empty())
return false;
return media::StreamParserFactory::IsTypeSupported(
mime_type_ascii, parsed_codec_ids);
}
WebString RendererBlinkPlatformImpl::MimeRegistry::mimeTypeForExtension( WebString RendererBlinkPlatformImpl::MimeRegistry::mimeTypeForExtension(
const WebString& file_extension) { const WebString& file_extension) {
// The sandbox restricts our access to the registry, so we need to proxy // The sandbox restricts our access to the registry, so we need to proxy
......
<!DOCTYPE html>
<html>
<head></head>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
var t = async_test('Makes sure that preloaded resources trigger the onload event');
var scriptLoaded = false;
var styleLoaded = false;
var imageLoaded = false;
var fontLoaded = false;
var videoLoaded = false;
var audioLoaded = false;
var trackLoaded = false;
var gibberishLoaded = 0;
</script>
<link rel=preload href="../resources/dummy.js" as=script type="text/javascript" onload="scriptLoaded = true;">
<link rel=preload href="../resources/dummy.css" as=style type="text/css" onload="styleLoaded = true;">
<link rel=preload href="../resources/square.png" as=image type="image/png" onload="imageLoaded = true;">
<link rel=preload href="../resources/Ahem.ttf" as=font type="font/ttf" crossorigin onload="fontLoaded = true;">
<link rel=preload href="../resources/test.webm" as=media type="video/webm" onload="videoLoaded = true;">
<link rel=preload href="../resources/test.wav" as=media type="audio/wav" onload="audioLoaded = true;">
<link rel=preload href="../security/resources/captions.vtt" as=track type="text/vtt" onload="trackLoaded = true;">
<link rel=preload href="../resources/dummy.js" as=script type="application/foobar" onload="gibberishLoaded++;">
<link rel=preload href="../resources/dummy.css" as=style type="text/foobar" onload="gibberishLoaded++;">
<link rel=preload href="../resources/square.png" as=image type="image/foobar" onload="gibberishLoaded++;">
<link rel=preload href="../resources/Ahem.ttf" as=font type="font/foobar" crossorigin onload="gibberishLoaded++;">
<link rel=preload href="../resources/test.webm" as=media type="video/foobar" onload="gibberishLoaded++;">
<link rel=preload href="../resources/test.wav" as=media type="audio/foobar" onload="gibberishLoaded++;">
<link rel=preload href="../security/resources/captions.vtt" as=track type="text/foobar" onload="gibberishLoaded++;">
<script src="../resources/slow-script.pl?delay=500"></script>
<script>
window.onload = t.step(function(){
assert_true(styleLoaded, "style triggered load event");
assert_true(scriptLoaded, "script triggered load event");
assert_true(imageLoaded, "image triggered load event");
assert_true(fontLoaded, "font triggered load event");
assert_true(videoLoaded, "video triggered load event");
assert_true(audioLoaded, "audio triggered load event");
assert_true(trackLoaded, "track triggered load event");
assert_equals(gibberishLoaded, 0, "resources with gibberish type should not be loaded");
t.done();
});
</script>
</body>
</html>
...@@ -248,8 +248,7 @@ static bool isSupportedType(Resource::Type resourceType, ...@@ -248,8 +248,7 @@ static bool isSupportedType(Resource::Type resourceType,
case Resource::Font: case Resource::Font:
return MIMETypeRegistry::isSupportedFontMIMEType(mimeType); return MIMETypeRegistry::isSupportedFontMIMEType(mimeType);
case Resource::Media: case Resource::Media:
return MIMETypeRegistry::isSupportedMediaSourceMIMEType(mimeType, return MIMETypeRegistry::isSupportedMediaMIMEType(mimeType, String());
String());
case Resource::TextTrack: case Resource::TextTrack:
return MIMETypeRegistry::isSupportedTextTrackMIMEType(mimeType); return MIMETypeRegistry::isSupportedTextTrackMIMEType(mimeType);
case Resource::Raw: case Resource::Raw:
......
...@@ -92,11 +92,16 @@ bool MIMETypeRegistry::isSupportedNonImageMIMEType(const String& mimeType) { ...@@ -92,11 +92,16 @@ bool MIMETypeRegistry::isSupportedNonImageMIMEType(const String& mimeType) {
mimeType.lower()) != WebMimeRegistry::IsNotSupported; mimeType.lower()) != WebMimeRegistry::IsNotSupported;
} }
bool MIMETypeRegistry::isSupportedMediaMIMEType(const String& mimeType,
const String& codecs) {
return Platform::current()->mimeRegistry()->supportsMediaMIMEType(
mimeType.lower(), codecs);
}
bool MIMETypeRegistry::isSupportedMediaSourceMIMEType(const String& mimeType, bool MIMETypeRegistry::isSupportedMediaSourceMIMEType(const String& mimeType,
const String& codecs) { const String& codecs) {
return !mimeType.isEmpty() && return Platform::current()->mimeRegistry()->supportsMediaSourceMIMEType(
Platform::current()->mimeRegistry()->supportsMediaSourceMIMEType( mimeType.lower(), codecs);
mimeType.lower(), codecs);
} }
bool MIMETypeRegistry::isJavaAppletMIMEType(const String& mimeType) { bool MIMETypeRegistry::isJavaAppletMIMEType(const String& mimeType) {
......
...@@ -65,6 +65,10 @@ class PLATFORM_EXPORT MIMETypeRegistry { ...@@ -65,6 +65,10 @@ class PLATFORM_EXPORT MIMETypeRegistry {
// document in a frame. Includes supported JavaScript MIME types. // document in a frame. Includes supported JavaScript MIME types.
static bool isSupportedNonImageMIMEType(const String& mimeType); static bool isSupportedNonImageMIMEType(const String& mimeType);
// Check to see if the mime type and codecs are supported media MIME types.
static bool isSupportedMediaMIMEType(const String& mimeType,
const String& codecs);
// Check to see if the mime type and codecs are supported by the MediaSource // Check to see if the mime type and codecs are supported by the MediaSource
// implementation. // implementation.
static bool isSupportedMediaSourceMIMEType(const String& mimeType, static bool isSupportedMediaSourceMIMEType(const String& mimeType,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment