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

Side by Side Diff: webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc

Issue 9969061: Changed TestShellWebMimeRegistryImpl to blacklist rather than whitelist containers and codecs. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: renamed function Created 8 years, 8 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 | « webkit/tools/test_shell/test_shell_webmimeregistry_impl.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h" 5 #include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h"
6 6
7 #include "base/basictypes.h"
7 #include "base/string_util.h" 8 #include "base/string_util.h"
8 #include "net/base/mime_util.h" 9 #include "net/base/mime_util.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
10 11
11 using WebKit::WebString; 12 using WebKit::WebString;
12 using WebKit::WebMimeRegistry; 13 using WebKit::WebMimeRegistry;
13 14
14 namespace { 15 namespace {
15 16
16 // Convert a WebString to ASCII, falling back on an empty string in the case 17 // Convert a WebString to ASCII, falling back on an empty string in the case
17 // of a non-ASCII string. 18 // of a non-ASCII string.
18 std::string ToASCIIOrEmpty(const WebString& string) { 19 std::string ToASCIIOrEmpty(const WebString& string) {
19 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); 20 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string();
20 } 21 }
21 22
22 } // namespace 23 } // namespace
23 24
24 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() { 25 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() {
25 // Claim we support Ogg+Theora/Vorbis. 26 net::GetMediaTypesBlacklistedForTests(&blacklisted_media_types_);
26 media_map_.insert("video/ogg");
27 media_map_.insert("audio/ogg");
28 media_map_.insert("application/ogg");
29 codecs_map_.insert("theora");
30 codecs_map_.insert("vorbis");
31 27
32 // Claim we support WAV. 28 net::GetMediaCodecsBlacklistedForTests(&blacklisted_media_codecs_);
33 media_map_.insert("audio/wav");
34 media_map_.insert("audio/x-wav");
35 codecs_map_.insert("1"); // PCM for WAV.
36 } 29 }
37 30
38 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {} 31 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {}
39 32
33 // Returns IsNotSupported if mime_type or any of the codecs are not supported.
34 // Otherwse, defers to the real registry.
40 WebMimeRegistry::SupportsType 35 WebMimeRegistry::SupportsType
41 TestShellWebMimeRegistryImpl::supportsMediaMIMEType( 36 TestShellWebMimeRegistryImpl::supportsMediaMIMEType(
42 const WebString& mime_type, 37 const WebString& mime_type,
43 const WebString& codecs) { 38 const WebString& codecs) {
44 // Not supporting the container is a flat-out no. 39 if (IsBlacklistedMediaMimeType(ToASCIIOrEmpty(mime_type)))
45 if (!IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type)))
46 return IsNotSupported; 40 return IsNotSupported;
47 41
48 // If we don't recognize the codec, it's possible we support it.
49 std::vector<std::string> parsed_codecs; 42 std::vector<std::string> parsed_codecs;
50 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); 43 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true);
51 if (!AreSupportedMediaCodecs(parsed_codecs)) 44 if (HasBlacklistedMediaCodecs(parsed_codecs))
52 return MayBeSupported; 45 return IsNotSupported;
53 46
54 // Otherwise we have a perfect match. 47 return SimpleWebMimeRegistryImpl::supportsMediaMIMEType(mime_type, codecs);
55 return IsSupported;
56 } 48 }
57 49
58 bool TestShellWebMimeRegistryImpl::IsSupportedMediaMimeType( 50 bool TestShellWebMimeRegistryImpl::IsBlacklistedMediaMimeType(
59 const std::string& mime_type) { 51 const std::string& mime_type) {
60 return media_map_.find(mime_type) != media_map_.end(); 52 for (size_t i = 0; i < blacklisted_media_types_.size(); ++i) {
53 if (blacklisted_media_types_[i] == mime_type)
54 return true;
55 }
56 return false;
61 } 57 }
62 58
63 bool TestShellWebMimeRegistryImpl::AreSupportedMediaCodecs( 59 bool TestShellWebMimeRegistryImpl::HasBlacklistedMediaCodecs(
64 const std::vector<std::string>& codecs) { 60 const std::vector<std::string>& codecs) {
65 for (size_t i = 0; i < codecs.size(); ++i) { 61 for (size_t i = 0; i < codecs.size(); ++i) {
66 if (codecs_map_.find(codecs[i]) == codecs_map_.end()) 62 for (size_t j = 0; j < blacklisted_media_codecs_.size(); ++j) {
67 return false; 63 if (blacklisted_media_codecs_[j] == codecs[i])
64 return true;
65 }
68 } 66 }
69 return !codecs.empty(); 67 return false;
70 } 68 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/test_shell_webmimeregistry_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698