1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/glue/simple_webmimeregistry_impl.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "net/base/mime_util.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/media/key_systems.h"
using WebKit::WebString;
using WebKit::WebMimeRegistry;
namespace {
// Convert a WebString to ASCII, falling back on an empty string in the case
// of a non-ASCII string.
std::string ToASCIIOrEmpty(const WebString& string) {
return IsStringASCII(string) ? UTF16ToASCII(string) : std::string();
}
} // namespace
namespace webkit_glue {
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType(
const WebString& mime_type) {
return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ?
WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
}
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType(
const WebString& mime_type) {
return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ?
WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
}
WebMimeRegistry::SupportsType
SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
const WebString& mime_type) {
return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ?
WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
}
// When debugging layout tests failures in the test shell,
// see TestShellWebMimeRegistryImpl.
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
const WebString& mime_type, const WebString& codecs) {
return supportsMediaMIMEType(mime_type, codecs, WebString());
}
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
const WebString& mime_type,
const WebString& codecs,
const WebString& key_system) {
const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
// Not supporting the container is a flat-out no.
if (!net::IsSupportedMediaMimeType(mime_type_ascii))
return IsNotSupported;
if (!key_system.isEmpty()) {
// Check whether the key system is supported with the mime_type and codecs.
// Not supporting the key system is a flat-out no.
if (!webkit_media::IsSupportedKeySystem(key_system))
return IsNotSupported;
std::vector<std::string> strict_codecs;
net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false);
if (!webkit_media::IsSupportedKeySystemWithMediaMimeType(
mime_type_ascii, strict_codecs, ToASCIIOrEmpty(key_system)))
return IsNotSupported;
// Continue processing the mime_type and codecs.
}
// Check list of strict codecs to see if it is supported.
if (net::IsStrictMediaMimeType(mime_type_ascii)) {
// We support the container, but no codecs were specified.
if (codecs.isNull())
return MayBeSupported;
// Check if the codecs are a perfect match.
std::vector<std::string> strict_codecs;
net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false);
if (!net::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs))
return IsNotSupported;
// Good to go!
return IsSupported;
}
// If we don't recognize the codec, it's possible we support it.
std::vector<std::string> parsed_codecs;
net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true);
if (!net::AreSupportedMediaCodecs(parsed_codecs))
return MayBeSupported;
// Otherwise we have a perfect match.
return IsSupported;
}
WebMimeRegistry::SupportsType
SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
const WebString& mime_type) {
return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ?
WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
}
WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension(
const WebString& file_extension) {
std::string mime_type;
net::GetMimeTypeFromExtension(WebStringToFilePathString(file_extension),
&mime_type);
return ASCIIToUTF16(mime_type);
}
WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension(
const WebString& file_extension) {
std::string mime_type;
net::GetWellKnownMimeTypeFromExtension(
WebStringToFilePathString(file_extension), &mime_type);
return ASCIIToUTF16(mime_type);
}
WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile(
const WebString& file_path) {
std::string mime_type;
net::GetMimeTypeFromFile(FilePath(WebStringToFilePathString(file_path)),
&mime_type);
return ASCIIToUTF16(mime_type);
}
WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(
const WebString& mime_type) {
FilePath::StringType file_extension;
net::GetPreferredExtensionForMimeType(ToASCIIOrEmpty(mime_type),
&file_extension);
return FilePathStringToWebString(file_extension);
}
} // namespace webkit_glue
|