simple_webmimeregistry_impl.cc revision 010d83a9304c5a91596085d917d248abff47903a
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "content/child/simple_webmimeregistry_impl.h" 6 7#include "base/files/file_path.h" 8#include "base/strings/string_util.h" 9#include "base/strings/sys_string_conversions.h" 10#include "base/strings/utf_string_conversions.h" 11#include "net/base/mime_util.h" 12#include "third_party/WebKit/public/platform/WebString.h" 13 14using blink::WebString; 15using blink::WebMimeRegistry; 16 17namespace content { 18 19//static 20std::string SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString& string) { 21 return base::IsStringASCII(string) ? base::UTF16ToASCII(string) 22 : std::string(); 23} 24 25WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType( 26 const WebString& mime_type) { 27 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ? 28 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 29} 30 31WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( 32 const WebString& mime_type) { 33 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ? 34 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 35} 36 37WebMimeRegistry::SupportsType 38 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( 39 const WebString& mime_type) { 40 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ? 41 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 42} 43 44// When debugging layout tests failures in the test shell, 45// see TestShellWebMimeRegistryImpl. 46WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( 47 const WebString& mime_type, 48 const WebString& codecs, 49 const WebString& key_system) { 50 // Media features are only supported at the content/renderer/ layer. 51 return IsNotSupported; 52} 53 54bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( 55 const WebString& mime_type, 56 const WebString& codecs) { 57 // Media features are only supported at the content/renderer layer. 58 return false; 59} 60 61bool SimpleWebMimeRegistryImpl::supportsEncryptedMediaMIMEType( 62 const blink::WebString& key_system, 63 const blink::WebString& mime_type, 64 const blink::WebString& codecs) { 65 // Media features are only supported at the content/renderer layer. 66 return false; 67} 68 69WebMimeRegistry::SupportsType 70 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( 71 const WebString& mime_type) { 72 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ? 73 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 74} 75 76WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( 77 const WebString& file_extension) { 78 std::string mime_type; 79 net::GetMimeTypeFromExtension( 80 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); 81 return WebString::fromUTF8(mime_type); 82} 83 84WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension( 85 const WebString& file_extension) { 86 std::string mime_type; 87 net::GetWellKnownMimeTypeFromExtension( 88 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); 89 return WebString::fromUTF8(mime_type); 90} 91 92WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile( 93 const WebString& file_path) { 94 std::string mime_type; 95 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path), 96 &mime_type); 97 return WebString::fromUTF8(mime_type); 98} 99 100} // namespace content 101