Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: net/base/mime_util.cc

Issue 160073: Implemented rest of webkit api/glue code needed for HTML5 media canPlayType(). (Closed)
Patch Set: SupportsType... it's everywhere! Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/mime_util.h ('k') | webkit/api/public/WebMimeRegistry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "net/base/mime_util.h" 7 #include "net/base/mime_util.h"
8 #include "net/base/platform_mime_util.h" 8 #include "net/base/platform_mime_util.h"
9 9
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 19 matching lines...) Expand all
30 bool IsSupportedNonImageMimeType(const char* mime_type) const; 30 bool IsSupportedNonImageMimeType(const char* mime_type) const;
31 bool IsSupportedJavascriptMimeType(const char* mime_type) const; 31 bool IsSupportedJavascriptMimeType(const char* mime_type) const;
32 32
33 bool IsViewSourceMimeType(const char* mime_type) const; 33 bool IsViewSourceMimeType(const char* mime_type) const;
34 34
35 bool IsSupportedMimeType(const std::string& mime_type) const; 35 bool IsSupportedMimeType(const std::string& mime_type) const;
36 36
37 bool MatchesMimeType(const std::string &mime_type_pattern, 37 bool MatchesMimeType(const std::string &mime_type_pattern,
38 const std::string &mime_type) const; 38 const std::string &mime_type) const;
39 39
40 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const;
41
40 void ParseCodecString(const std::string& codecs, 42 void ParseCodecString(const std::string& codecs,
41 std::vector<std::string>* codecs_out); 43 std::vector<std::string>* codecs_out);
42 44
43 private: 45 private:
44 friend struct DefaultSingletonTraits<MimeUtil>; 46 friend struct DefaultSingletonTraits<MimeUtil>;
45 MimeUtil() { 47 MimeUtil() {
46 InitializeMimeTypeMaps(); 48 InitializeMimeTypeMaps();
47 } 49 }
48 50
49 // For faster lookup, keep hash sets. 51 // For faster lookup, keep hash sets.
50 void InitializeMimeTypeMaps(); 52 void InitializeMimeTypeMaps();
51 53
52 typedef base::hash_set<std::string> MimeMappings; 54 typedef base::hash_set<std::string> MimeMappings;
53 MimeMappings image_map_; 55 MimeMappings image_map_;
54 MimeMappings media_map_; 56 MimeMappings media_map_;
55 MimeMappings non_image_map_; 57 MimeMappings non_image_map_;
56 MimeMappings javascript_map_; 58 MimeMappings javascript_map_;
57 MimeMappings view_source_map_; 59 MimeMappings view_source_map_;
60 MimeMappings codecs_map_;
58 }; // class MimeUtil 61 }; // class MimeUtil
59 62
60 struct MimeInfo { 63 struct MimeInfo {
61 const char* mime_type; 64 const char* mime_type;
62 const char* extensions; // comma separated list 65 const char* extensions; // comma separated list
63 }; 66 };
64 67
65 static const MimeInfo primary_mappings[] = { 68 static const MimeInfo primary_mappings[] = {
66 { "text/html", "html,htm" }, 69 { "text/html", "html,htm" },
67 { "text/css", "css" }, 70 { "text/css", "css" },
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // MP3. 199 // MP3.
197 "audio/mp3", 200 "audio/mp3",
198 "audio/x-mp3", 201 "audio/x-mp3",
199 202
200 // Generic MPEG mime-types. 203 // Generic MPEG mime-types.
201 // TODO(fbarchard): Remove these when layout tests stop using mpg. 204 // TODO(fbarchard): Remove these when layout tests stop using mpg.
202 "audio/mpeg", 205 "audio/mpeg",
203 "video/mpeg" 206 "video/mpeg"
204 }; 207 };
205 208
209 // List of supported codecs when passed in with <source type="...">.
210 //
211 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support
212 // for more information.
213 static const char* const supported_media_codecs[] = {
214 #if defined(GOOGLE_CHROME_BUILD)
215 "avc1",
216 "mp4a",
217 #endif
218 "theora",
219 "vorbis",
220 };
221
206 // Note: does not include javascript types list (see supported_javascript_types) 222 // Note: does not include javascript types list (see supported_javascript_types)
207 static const char* const supported_non_image_types[] = { 223 static const char* const supported_non_image_types[] = {
208 "text/html", 224 "text/html",
209 "text/xml", 225 "text/xml",
210 "text/xsl", 226 "text/xsl",
211 "text/plain", 227 "text/plain",
212 // Many users complained about css files served for 228 // Many users complained about css files served for
213 // download instead of displaying in the browser: 229 // download instead of displaying in the browser:
214 // http://code.google.com/p/chromium/issues/detail?id=7192 230 // http://code.google.com/p/chromium/issues/detail?id=7192
215 // So, by including "text/css" into this list we choose Firefox 231 // So, by including "text/css" into this list we choose Firefox
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 286
271 // Initialize the supported media types. 287 // Initialize the supported media types.
272 for (size_t i = 0; i < arraysize(supported_media_types); ++i) 288 for (size_t i = 0; i < arraysize(supported_media_types); ++i)
273 media_map_.insert(supported_media_types[i]); 289 media_map_.insert(supported_media_types[i]);
274 290
275 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) 291 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i)
276 javascript_map_.insert(supported_javascript_types[i]); 292 javascript_map_.insert(supported_javascript_types[i]);
277 293
278 for (size_t i = 0; i < arraysize(view_source_types); ++i) 294 for (size_t i = 0; i < arraysize(view_source_types); ++i)
279 view_source_map_.insert(view_source_types[i]); 295 view_source_map_.insert(view_source_types[i]);
296
297 for (size_t i = 0; i < arraysize(supported_media_codecs); ++i)
298 codecs_map_.insert(supported_media_codecs[i]);
280 } 299 }
281 300
282 bool MimeUtil::IsSupportedImageMimeType(const char* mime_type) const { 301 bool MimeUtil::IsSupportedImageMimeType(const char* mime_type) const {
283 return image_map_.find(mime_type) != image_map_.end(); 302 return image_map_.find(mime_type) != image_map_.end();
284 } 303 }
285 304
286 bool MimeUtil::IsSupportedMediaMimeType(const char* mime_type) const { 305 bool MimeUtil::IsSupportedMediaMimeType(const char* mime_type) const {
287 return media_map_.find(mime_type) != media_map_.end(); 306 return media_map_.find(mime_type) != media_map_.end();
288 } 307 }
289 308
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 if (mime_type.find(left) != 0) 355 if (mime_type.find(left) != 0)
337 return false; 356 return false;
338 357
339 if (!right.empty() && 358 if (!right.empty() &&
340 mime_type.rfind(right) != mime_type.length() - right.length()) 359 mime_type.rfind(right) != mime_type.length() - right.length())
341 return false; 360 return false;
342 361
343 return true; 362 return true;
344 } 363 }
345 364
365 bool MimeUtil::AreSupportedMediaCodecs(
366 const std::vector<std::string>& codecs) const {
367 for (size_t i = 0; i < codecs.size(); ++i) {
368 if (codecs_map_.find(codecs[i]) == codecs_map_.end()) {
369 return false;
370 }
371 }
372 return true;
373 }
374
346 void MimeUtil::ParseCodecString(const std::string& codecs, 375 void MimeUtil::ParseCodecString(const std::string& codecs,
347 std::vector<std::string>* codecs_out) { 376 std::vector<std::string>* codecs_out) {
348 std::string no_quote_codecs; 377 std::string no_quote_codecs;
349 TrimString(codecs, "\"", &no_quote_codecs); 378 TrimString(codecs, "\"", &no_quote_codecs);
350 SplitString(no_quote_codecs, ',', codecs_out); 379 SplitString(no_quote_codecs, ',', codecs_out);
351 380
352 // Truncate each string at the '.' 381 // Truncate each string at the '.'
353 for (std::vector<std::string>::iterator it = codecs_out->begin(); 382 for (std::vector<std::string>::iterator it = codecs_out->begin();
354 it != codecs_out->end(); 383 it != codecs_out->end();
355 ++it) { 384 ++it) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 432
404 bool IsSupportedMimeType(const std::string& mime_type) { 433 bool IsSupportedMimeType(const std::string& mime_type) {
405 return GetMimeUtil()->IsSupportedMimeType(mime_type); 434 return GetMimeUtil()->IsSupportedMimeType(mime_type);
406 } 435 }
407 436
408 bool MatchesMimeType(const std::string &mime_type_pattern, 437 bool MatchesMimeType(const std::string &mime_type_pattern,
409 const std::string &mime_type) { 438 const std::string &mime_type) {
410 return GetMimeUtil()->MatchesMimeType(mime_type_pattern, mime_type); 439 return GetMimeUtil()->MatchesMimeType(mime_type_pattern, mime_type);
411 } 440 }
412 441
442 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) {
443 return GetMimeUtil()->AreSupportedMediaCodecs(codecs);
444 }
445
413 void ParseCodecString(const std::string& codecs, 446 void ParseCodecString(const std::string& codecs,
414 std::vector<std::string>* codecs_out) { 447 std::vector<std::string>* codecs_out) {
415 GetMimeUtil()->ParseCodecString(codecs, codecs_out); 448 GetMimeUtil()->ParseCodecString(codecs, codecs_out);
416 } 449 }
417 450
418 } // namespace net 451 } // namespace net
OLDNEW
« no previous file with comments | « net/base/mime_util.h ('k') | webkit/api/public/WebMimeRegistry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698