summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-03 01:34:14 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-03 01:34:14 +0000
commit4172081a0e4cbb694293dad2d5ed4ba4f2cd26b4 (patch)
tree77cdae20592a241afafa8f86a3f75d4be87c42bf
parent313f73ea0b7fd817741ed866770dcbebd9d6a66a (diff)
downloadchromium_src-4172081a0e4cbb694293dad2d5ed4ba4f2cd26b4.zip
chromium_src-4172081a0e4cbb694293dad2d5ed4ba4f2cd26b4.tar.gz
chromium_src-4172081a0e4cbb694293dad2d5ed4ba4f2cd26b4.tar.bz2
Reland r129998: When input is "" (or " " with trim_whitespace true), SplitString() should return an empty vector, not a vector of one empty string.
Brett and I discussed this for a while and felt this would be wise, whereas dropping all empty segments entirely (e.g. converting "a,,b" to a vector of two elements instead of three) was probably unwise. This also simplifies the code some. Fixing this also required changing the code in mime_util.cc to handle empty vectors to "are codecs valid" oracle functions (in which case we return false). I also fixed some style issues there. It also required avoiding passing the empty string in a test in extension_api_unittest.cc; Aaron assures me that this code is not expected to be defensive against such inputs, but at his suggestion I also added some CHECK()s to the API. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/9958076 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130285 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/string_split.cc19
-rw-r--r--base/string_split_unittest.cc21
-rw-r--r--chrome/common/extensions/api/extension_api.cc2
-rw-r--r--chrome/common/extensions/api/extension_api_unittest.cc1
-rw-r--r--net/base/mime_util.cc148
-rw-r--r--net/base/mime_util.h16
-rw-r--r--net/base/mime_util_unittest.cc18
-rw-r--r--webkit/glue/simple_webmimeregistry_impl.cc52
-rw-r--r--webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc20
-rw-r--r--webkit/tools/test_shell/test_shell_webmimeregistry_impl.h5
10 files changed, 149 insertions, 153 deletions
diff --git a/base/string_split.cc b/base/string_split.cc
index cdf708b..ea694d5 100644
--- a/base/string_split.cc
+++ b/base/string_split.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -17,19 +17,16 @@ static void SplitStringT(const STR& str,
bool trim_whitespace,
std::vector<STR>* r) {
size_t last = 0;
- size_t i;
size_t c = str.size();
- for (i = 0; i <= c; ++i) {
+ for (size_t i = 0; i <= c; ++i) {
if (i == c || str[i] == s) {
- size_t len = i - last;
- STR tmp = str.substr(last, len);
- if (trim_whitespace) {
- STR t_tmp;
- TrimWhitespace(tmp, TRIM_ALL, &t_tmp);
- r->push_back(t_tmp);
- } else {
+ STR tmp(str, last, i - last);
+ if (trim_whitespace)
+ TrimWhitespace(tmp, TRIM_ALL, &tmp);
+ // Avoid converting an empty or all-whitespace source string into a vector
+ // of one empty string.
+ if (i != c || !r->empty() || !tmp.empty())
r->push_back(tmp);
- }
last = i + 1;
}
}
diff --git a/base/string_split_unittest.cc b/base/string_split_unittest.cc
index 83e4d74..5d4dafe 100644
--- a/base/string_split_unittest.cc
+++ b/base/string_split_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -163,8 +163,7 @@ TEST(StringUtilTest, SplitString) {
std::vector<std::wstring> r;
SplitString(L"", L',', &r);
- ASSERT_EQ(1U, r.size());
- EXPECT_EQ(r[0], L"");
+ EXPECT_EQ(0U, r.size());
r.clear();
SplitString(L"a,b,c", L',', &r);
@@ -188,9 +187,8 @@ TEST(StringUtilTest, SplitString) {
EXPECT_EQ(r[2], L"c");
r.clear();
- SplitString(L"", L'*', &r);
- ASSERT_EQ(1U, r.size());
- EXPECT_EQ(r[0], L"");
+ SplitString(L" ", L'*', &r);
+ EXPECT_EQ(0U, r.size());
r.clear();
SplitString(L"foo", L'*', &r);
@@ -266,12 +264,17 @@ TEST(SplitStringUsingSubstrTest, TrailingDelimitersSkipped) {
TEST(StringSplitTest, StringSplitDontTrim) {
std::vector<std::string> r;
- SplitStringDontTrim("\t\ta\t", '\t', &r);
+ SplitStringDontTrim(" ", '*', &r);
+ ASSERT_EQ(1U, r.size());
+ EXPECT_EQ(r[0], " ");
+ r.clear();
+
+ SplitStringDontTrim("\t \ta\t ", '\t', &r);
ASSERT_EQ(4U, r.size());
EXPECT_EQ(r[0], "");
- EXPECT_EQ(r[1], "");
+ EXPECT_EQ(r[1], " ");
EXPECT_EQ(r[2], "a");
- EXPECT_EQ(r[3], "");
+ EXPECT_EQ(r[3], " ");
r.clear();
SplitStringDontTrim("\ta\t\nb\tcc", '\n', &r);
diff --git a/chrome/common/extensions/api/extension_api.cc b/chrome/common/extensions/api/extension_api.cc
index 6bbd8df..3178975 100644
--- a/chrome/common/extensions/api/extension_api.cc
+++ b/chrome/common/extensions/api/extension_api.cc
@@ -268,10 +268,12 @@ bool ExtensionAPI::IsPrivileged(const std::string& full_name) {
std::vector<std::string> split;
base::SplitString(full_name, '.', &split);
std::reverse(split.begin(), split.end());
+ CHECK(!split.empty()); // |full_name| was empty or only whitespace.
api_name = split.back();
split.pop_back();
if (api_name == "experimental") {
+ CHECK(!split.empty()); // |full_name| was "experimental" alone.
api_name += "." + split.back();
split.pop_back();
}
diff --git a/chrome/common/extensions/api/extension_api_unittest.cc b/chrome/common/extensions/api/extension_api_unittest.cc
index bf240e1..1c5a22e3 100644
--- a/chrome/common/extensions/api/extension_api_unittest.cc
+++ b/chrome/common/extensions/api/extension_api_unittest.cc
@@ -26,7 +26,6 @@ TEST(ExtensionAPI, IsPrivileged) {
EXPECT_TRUE(extension_api.IsPrivileged("extension.lastError"));
// Default unknown names to privileged for paranoia's sake.
- EXPECT_TRUE(extension_api.IsPrivileged(""));
EXPECT_TRUE(extension_api.IsPrivileged("<unknown-namespace>"));
EXPECT_TRUE(extension_api.IsPrivileged("extension.<unknown-member>"));
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc
index f9e72a4..85f5d15 100644
--- a/net/base/mime_util.cc
+++ b/net/base/mime_util.cc
@@ -31,12 +31,12 @@ class MimeUtil : public PlatformMimeUtil {
bool GetWellKnownMimeTypeFromExtension(const FilePath::StringType& ext,
std::string* mime_type) const;
- bool IsSupportedImageMimeType(const char* mime_type) const;
- bool IsSupportedMediaMimeType(const char* mime_type) const;
- bool IsSupportedNonImageMimeType(const char* mime_type) const;
- bool IsSupportedJavascriptMimeType(const char* mime_type) const;
+ bool IsSupportedImageMimeType(const std::string& mime_type) const;
+ bool IsSupportedMediaMimeType(const std::string& mime_type) const;
+ bool IsSupportedNonImageMimeType(const std::string& mime_type) const;
+ bool IsSupportedJavascriptMimeType(const std::string& mime_type) const;
- bool IsViewSourceMimeType(const char* mime_type) const;
+ bool IsViewSourceMimeType(const std::string& mime_type) const;
bool IsSupportedMimeType(const std::string& mime_type) const;
@@ -50,23 +50,30 @@ class MimeUtil : public PlatformMimeUtil {
bool strip);
bool IsStrictMediaMimeType(const std::string& mime_type) const;
- bool IsSupportedStrictMediaMimeType(const std::string& mime_type,
+ bool IsSupportedStrictMediaMimeType(
+ const std::string& mime_type,
const std::vector<std::string>& codecs) const;
private:
friend struct base::DefaultLazyInstanceTraits<MimeUtil>;
- MimeUtil() {
- InitializeMimeTypeMaps();
- }
+
+ typedef base::hash_set<std::string> MimeMappings;
+ typedef std::map<std::string, MimeMappings> StrictMappings;
+
+ MimeUtil();
+
+ // Returns true if |codecs| is nonempty and all the items in it are present in
+ // |supported_codecs|.
+ static bool AreSupportedCodecs(const MimeMappings& supported_codecs,
+ const std::vector<std::string>& codecs);
// For faster lookup, keep hash sets.
void InitializeMimeTypeMaps();
- bool GetMimeTypeFromExtensionHelper(
- const FilePath::StringType& ext, bool include_platform_types,
- std::string* mime_type) const;
+ bool GetMimeTypeFromExtensionHelper(const FilePath::StringType& ext,
+ bool include_platform_types,
+ std::string* mime_type) const;
- typedef base::hash_set<std::string> MimeMappings;
MimeMappings image_map_;
MimeMappings media_map_;
MimeMappings non_image_map_;
@@ -74,7 +81,6 @@ class MimeUtil : public PlatformMimeUtil {
MimeMappings view_source_map_;
MimeMappings codecs_map_;
- typedef std::map<std::string, base::hash_set<std::string> > StrictMappings;
StrictMappings strict_format_map_;
}; // class MimeUtil
@@ -158,7 +164,8 @@ bool MimeUtil::GetMimeTypeFromExtension(const FilePath::StringType& ext,
}
bool MimeUtil::GetWellKnownMimeTypeFromExtension(
- const FilePath::StringType& ext, string* result) const {
+ const FilePath::StringType& ext,
+ string* result) const {
return GetMimeTypeFromExtensionHelper(ext, false, result);
}
@@ -170,9 +177,9 @@ bool MimeUtil::GetMimeTypeFromFile(const FilePath& file_path,
return GetMimeTypeFromExtension(file_name_str.substr(1), result);
}
-bool MimeUtil::GetMimeTypeFromExtensionHelper(
- const FilePath::StringType& ext, bool include_platform_types,
- string* result) const {
+bool MimeUtil::GetMimeTypeFromExtensionHelper(const FilePath::StringType& ext,
+ bool include_platform_types,
+ string* result) const {
// Avoids crash when unable to handle a long file path. See crbug.com/48733.
const unsigned kMaxFilePathSize = 65536;
if (ext.length() > kMaxFilePathSize)
@@ -346,6 +353,20 @@ static const MediaFormatStrict format_codec_mappings[] = {
{ "audio/wav", "1" }
};
+MimeUtil::MimeUtil() {
+ InitializeMimeTypeMaps();
+}
+
+// static
+bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs,
+ const std::vector<std::string>& codecs) {
+ for (size_t i = 0; i < codecs.size(); ++i) {
+ if (supported_codecs.find(codecs[i]) == supported_codecs.end())
+ return false;
+ }
+ return !codecs.empty();
+}
+
void MimeUtil::InitializeMimeTypeMaps() {
for (size_t i = 0; i < arraysize(supported_image_types); ++i)
image_map_.insert(supported_image_types[i]);
@@ -385,35 +406,36 @@ void MimeUtil::InitializeMimeTypeMaps() {
}
}
-bool MimeUtil::IsSupportedImageMimeType(const char* mime_type) const {
+bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const {
return image_map_.find(mime_type) != image_map_.end();
}
-bool MimeUtil::IsSupportedMediaMimeType(const char* mime_type) const {
+bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const {
return media_map_.find(mime_type) != media_map_.end();
}
-bool MimeUtil::IsSupportedNonImageMimeType(const char* mime_type) const {
+bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const {
return non_image_map_.find(mime_type) != non_image_map_.end();
}
-bool MimeUtil::IsSupportedJavascriptMimeType(const char* mime_type) const {
+bool MimeUtil::IsSupportedJavascriptMimeType(
+ const std::string& mime_type) const {
return javascript_map_.find(mime_type) != javascript_map_.end();
}
-bool MimeUtil::IsViewSourceMimeType(const char* mime_type) const {
+bool MimeUtil::IsViewSourceMimeType(const std::string& mime_type) const {
return view_source_map_.find(mime_type) != view_source_map_.end();
}
// Mirrors WebViewImpl::CanShowMIMEType()
bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const {
return (mime_type.compare(0, 6, "image/") == 0 &&
- IsSupportedImageMimeType(mime_type.c_str())) ||
- IsSupportedNonImageMimeType(mime_type.c_str());
+ IsSupportedImageMimeType(mime_type)) ||
+ IsSupportedNonImageMimeType(mime_type);
}
-bool MimeUtil::MatchesMimeType(const std::string &mime_type_pattern,
- const std::string &mime_type) const {
+bool MimeUtil::MatchesMimeType(const std::string& mime_type_pattern,
+ const std::string& mime_type) const {
// verify caller is passing lowercase
DCHECK_EQ(StringToLowerASCII(mime_type_pattern), mime_type_pattern);
DCHECK_EQ(StringToLowerASCII(mime_type), mime_type);
@@ -451,12 +473,7 @@ bool MimeUtil::MatchesMimeType(const std::string &mime_type_pattern,
bool MimeUtil::AreSupportedMediaCodecs(
const std::vector<std::string>& codecs) const {
- for (size_t i = 0; i < codecs.size(); ++i) {
- if (codecs_map_.find(codecs[i]) == codecs_map_.end()) {
- return false;
- }
- }
- return true;
+ return AreSupportedCodecs(codecs_map_, codecs);
}
void MimeUtil::ParseCodecString(const std::string& codecs,
@@ -485,20 +502,12 @@ bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const {
return true;
}
-bool MimeUtil::IsSupportedStrictMediaMimeType(const std::string& mime_type,
+bool MimeUtil::IsSupportedStrictMediaMimeType(
+ const std::string& mime_type,
const std::vector<std::string>& codecs) const {
StrictMappings::const_iterator it = strict_format_map_.find(mime_type);
-
- if (it == strict_format_map_.end())
- return false;
-
- const MimeMappings strict_codecs_map = it->second;
- for (size_t i = 0; i < codecs.size(); ++i) {
- if (strict_codecs_map.find(codecs[i]) == strict_codecs_map.end()) {
- return false;
- }
- }
- return true;
+ return (it != strict_format_map_.end()) &&
+ AreSupportedCodecs(it->second, codecs);
}
//----------------------------------------------------------------------------
@@ -525,23 +534,23 @@ bool GetPreferredExtensionForMimeType(const std::string& mime_type,
extension);
}
-bool IsSupportedImageMimeType(const char* mime_type) {
+bool IsSupportedImageMimeType(const std::string& mime_type) {
return g_mime_util.Get().IsSupportedImageMimeType(mime_type);
}
-bool IsSupportedMediaMimeType(const char* mime_type) {
+bool IsSupportedMediaMimeType(const std::string& mime_type) {
return g_mime_util.Get().IsSupportedMediaMimeType(mime_type);
}
-bool IsSupportedNonImageMimeType(const char* mime_type) {
+bool IsSupportedNonImageMimeType(const std::string& mime_type) {
return g_mime_util.Get().IsSupportedNonImageMimeType(mime_type);
}
-bool IsSupportedJavascriptMimeType(const char* mime_type) {
+bool IsSupportedJavascriptMimeType(const std::string& mime_type) {
return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type);
}
-bool IsViewSourceMimeType(const char* mime_type) {
+bool IsViewSourceMimeType(const std::string& mime_type) {
return g_mime_util.Get().IsViewSourceMimeType(mime_type);
}
@@ -549,8 +558,8 @@ bool IsSupportedMimeType(const std::string& mime_type) {
return g_mime_util.Get().IsSupportedMimeType(mime_type);
}
-bool MatchesMimeType(const std::string &mime_type_pattern,
- const std::string &mime_type) {
+bool MatchesMimeType(const std::string& mime_type_pattern,
+ const std::string& mime_type) {
return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type);
}
@@ -646,8 +655,7 @@ void GetExtensionsFromHardCodedMappings(
for (size_t i = 0; i < mappings_len; ++i) {
if (StartsWithASCII(mappings[i].mime_type, leading_mime_type, false)) {
std::vector<string> this_extensions;
- base::SplitStringUsingSubstr(mappings[i].extensions,
- ",",
+ base::SplitStringUsingSubstr(mappings[i].extensions, ",",
&this_extensions);
for (size_t j = 0; j < this_extensions.size(); ++j) {
#if defined(OS_WIN)
@@ -661,11 +669,10 @@ void GetExtensionsFromHardCodedMappings(
}
}
-void GetExtensionsHelper(
- const char** standard_types,
- size_t standard_types_len,
- const std::string& leading_mime_type,
- base::hash_set<FilePath::StringType>* extensions) {
+void GetExtensionsHelper(const char** standard_types,
+ size_t standard_types_len,
+ const std::string& leading_mime_type,
+ base::hash_set<FilePath::StringType>* extensions) {
FilePath::StringType extension;
for (size_t i = 0; i < standard_types_len; ++i) {
if (GetPreferredExtensionForMimeType(standard_types[i], &extension))
@@ -693,36 +700,29 @@ void HashSetToVector(base::hash_set<T>* source, std::vector<T>* target) {
target->resize(old_target_size + source->size());
size_t i = 0;
for (typename base::hash_set<T>::iterator iter = source->begin();
- iter != source->end(); ++iter, ++i) {
- target->at(old_target_size + i) = *iter;
- }
+ iter != source->end(); ++iter, ++i)
+ (*target)[old_target_size + i] = *iter;
}
}
void GetImageExtensions(std::vector<FilePath::StringType>* extensions) {
base::hash_set<FilePath::StringType> unique_extensions;
- GetExtensionsHelper(kStandardImageTypes,
- arraysize(kStandardImageTypes),
- "image/",
- &unique_extensions);
+ GetExtensionsHelper(kStandardImageTypes, arraysize(kStandardImageTypes),
+ "image/", &unique_extensions);
HashSetToVector(&unique_extensions, extensions);
}
void GetAudioExtensions(std::vector<FilePath::StringType>* extensions) {
base::hash_set<FilePath::StringType> unique_extensions;
- GetExtensionsHelper(kStandardAudioTypes,
- arraysize(kStandardAudioTypes),
- "audio/",
- &unique_extensions);
+ GetExtensionsHelper(kStandardAudioTypes, arraysize(kStandardAudioTypes),
+ "audio/", &unique_extensions);
HashSetToVector(&unique_extensions, extensions);
}
void GetVideoExtensions(std::vector<FilePath::StringType>* extensions) {
base::hash_set<FilePath::StringType> unique_extensions;
- GetExtensionsHelper(kStandardVideoTypes,
- arraysize(kStandardVideoTypes),
- "video/",
- &unique_extensions);
+ GetExtensionsHelper(kStandardVideoTypes, arraysize(kStandardVideoTypes),
+ "video/", &unique_extensions);
HashSetToVector(&unique_extensions, extensions);
}
diff --git a/net/base/mime_util.h b/net/base/mime_util.h
index 7640504..adff518 100644
--- a/net/base/mime_util.h
+++ b/net/base/mime_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -40,14 +40,14 @@ NET_EXPORT bool GetPreferredExtensionForMimeType(
FilePath::StringType* extension);
// Check to see if a particular MIME type is in our list.
-NET_EXPORT bool IsSupportedImageMimeType(const char* mime_type);
-NET_EXPORT bool IsSupportedMediaMimeType(const char* mime_type);
-NET_EXPORT bool IsSupportedNonImageMimeType(const char* mime_type);
-NET_EXPORT bool IsSupportedJavascriptMimeType(const char* mime_type);
+NET_EXPORT bool IsSupportedImageMimeType(const std::string& mime_type);
+NET_EXPORT bool IsSupportedMediaMimeType(const std::string& mime_type);
+NET_EXPORT bool IsSupportedNonImageMimeType(const std::string& mime_type);
+NET_EXPORT bool IsSupportedJavascriptMimeType(const std::string& mime_type);
// Get whether this mime type should be displayed in view-source mode.
// (For example, XML.)
-NET_EXPORT bool IsViewSourceMimeType(const char* mime_type);
+NET_EXPORT bool IsViewSourceMimeType(const std::string& mime_type);
// Convenience function.
NET_EXPORT bool IsSupportedMimeType(const std::string& mime_type);
@@ -55,8 +55,8 @@ NET_EXPORT bool IsSupportedMimeType(const std::string& mime_type);
// Returns true if this the mime_type_pattern matches a given mime-type.
// Checks for absolute matching and wildcards. mime-types should be in
// lower case.
-NET_EXPORT bool MatchesMimeType(const std::string &mime_type_pattern,
- const std::string &mime_type);
+NET_EXPORT bool MatchesMimeType(const std::string& mime_type_pattern,
+ const std::string& mime_type);
// Returns true if and only if all codecs are supported, false otherwise.
NET_EXPORT bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs);
diff --git a/net/base/mime_util_unittest.cc b/net/base/mime_util_unittest.cc
index a63c39e..c647294 100644
--- a/net/base/mime_util_unittest.cc
+++ b/net/base/mime_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -104,26 +104,26 @@ TEST(MimeUtilTest, ParseCodecString) {
{ "\"mp4v.20.240, mp4a.40.2\"", 2, { "mp4v", "mp4a" } },
{ "mp4v.20.8, samr", 2, { "mp4v", "samr" } },
{ "\"theora, vorbis\"", 2, { "theora", "vorbis" } },
- { "", 1, { "" } },
- { "\"\"", 1, { "" } },
+ { "", 0, { } },
+ { "\"\"", 0, { } },
+ { "\" \"", 0, { } },
{ ",", 2, { "", "" } },
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
std::vector<std::string> codecs_out;
ParseCodecString(tests[i].original, &codecs_out, true);
- EXPECT_EQ(tests[i].expected_size, codecs_out.size());
- for (size_t j = 0; j < tests[i].expected_size; ++j) {
+ ASSERT_EQ(tests[i].expected_size, codecs_out.size());
+ for (size_t j = 0; j < tests[i].expected_size; ++j)
EXPECT_EQ(tests[i].results[j], codecs_out[j]);
- }
}
// Test without stripping the codec type.
std::vector<std::string> codecs_out;
ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false);
- EXPECT_EQ(2u, codecs_out.size());
- EXPECT_STREQ("avc1.42E01E", codecs_out[0].c_str());
- EXPECT_STREQ("mp4a.40.2", codecs_out[1].c_str());
+ ASSERT_EQ(2u, codecs_out.size());
+ EXPECT_EQ("avc1.42E01E", codecs_out[0]);
+ EXPECT_EQ("mp4a.40.2", codecs_out[1]);
}
} // namespace net
diff --git a/webkit/glue/simple_webmimeregistry_impl.cc b/webkit/glue/simple_webmimeregistry_impl.cc
index 8c91b24..1bc28fa 100644
--- a/webkit/glue/simple_webmimeregistry_impl.cc
+++ b/webkit/glue/simple_webmimeregistry_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -19,9 +19,7 @@ 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) {
- if (!IsStringASCII(string))
- return std::string();
- return UTF16ToASCII(string);
+ return IsStringASCII(string) ? UTF16ToASCII(string) : std::string();
}
} // namespace
@@ -30,43 +28,41 @@ namespace webkit_glue {
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType(
const WebString& mime_type) {
- if (!net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type).c_str()))
- return WebMimeRegistry::IsNotSupported;
- return WebMimeRegistry::IsSupported;
+ return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ?
+ WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
}
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType(
const WebString& mime_type) {
- if (!net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type).c_str()))
- return WebMimeRegistry::IsNotSupported;
- return WebMimeRegistry::IsSupported;
+ return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ?
+ WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
}
-WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
+WebMimeRegistry::SupportsType
+ SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
const WebString& mime_type) {
- if (!net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type).c_str()))
- return WebMimeRegistry::IsNotSupported;
- return WebMimeRegistry::IsSupported;
+ return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ?
+ WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
}
WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
- const WebString& mime_type, const WebString& codecs) {
+ const WebString& mime_type,
+ const WebString& codecs) {
// Not supporting the container is a flat-out no.
- if (!net::IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type).c_str()))
+ if (!net::IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type)))
return IsNotSupported;
// Check list of strict codecs to see if it is supported.
- if (net::IsStrictMediaMimeType(ToASCIIOrEmpty(mime_type).c_str())) {
+ if (net::IsStrictMediaMimeType(ToASCIIOrEmpty(mime_type))) {
// 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).c_str(),
- &strict_codecs,
+ net::ParseCodecString(ToASCIIOrEmpty(codecs).c_str(), &strict_codecs,
false);
- if (!net::IsSupportedStrictMediaMimeType(ToASCIIOrEmpty(mime_type).c_str(),
+ if (!net::IsSupportedStrictMediaMimeType(ToASCIIOrEmpty(mime_type),
strict_codecs))
return IsNotSupported;
@@ -84,18 +80,18 @@ WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
return IsSupported;
}
-WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
+WebMimeRegistry::SupportsType
+ SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
const WebString& mime_type) {
- if (!net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type).c_str()))
- return WebMimeRegistry::IsNotSupported;
- return WebMimeRegistry::IsSupported;
+ 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);
+ net::GetMimeTypeFromExtension(WebStringToFilePathString(file_extension),
+ &mime_type);
return ASCIIToUTF16(mime_type);
}
@@ -110,8 +106,8 @@ WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension(
WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile(
const WebString& file_path) {
std::string mime_type;
- net::GetMimeTypeFromFile(
- FilePath(WebStringToFilePathString(file_path)), &mime_type);
+ net::GetMimeTypeFromFile(FilePath(WebStringToFilePathString(file_path)),
+ &mime_type);
return ASCIIToUTF16(mime_type);
}
diff --git a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc
index a411c21..d0989dd 100644
--- a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc
+++ b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -16,9 +16,7 @@ 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) {
- if (!IsStringASCII(string))
- return std::string();
- return UTF16ToASCII(string);
+ return IsStringASCII(string) ? UTF16ToASCII(string) : std::string();
}
} // namespace
@@ -40,15 +38,16 @@ TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() {
TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {}
WebMimeRegistry::SupportsType
-TestShellWebMimeRegistryImpl::supportsMediaMIMEType(
- const WebString& mime_type, const WebString& codecs) {
+ TestShellWebMimeRegistryImpl::supportsMediaMIMEType(
+ const WebString& mime_type,
+ const WebString& codecs) {
// Not supporting the container is a flat-out no.
- if (!IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type).c_str()))
+ if (!IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type)))
return IsNotSupported;
// If we don't recognize the codec, it's possible we support it.
std::vector<std::string> parsed_codecs;
- net::ParseCodecString(ToASCIIOrEmpty(codecs).c_str(), &parsed_codecs, true);
+ net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true);
if (!AreSupportedMediaCodecs(parsed_codecs))
return MayBeSupported;
@@ -64,9 +63,8 @@ bool TestShellWebMimeRegistryImpl::IsSupportedMediaMimeType(
bool TestShellWebMimeRegistryImpl::AreSupportedMediaCodecs(
const std::vector<std::string>& codecs) {
for (size_t i = 0; i < codecs.size(); ++i) {
- if (codecs_map_.find(codecs[i]) == codecs_map_.end()) {
+ if (codecs_map_.find(codecs[i]) == codecs_map_.end())
return false;
- }
}
- return true;
+ return !codecs.empty();
}
diff --git a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h
index 2c8ad6c..ecf7d4d 100644
--- a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h
+++ b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -26,7 +26,8 @@ class TestShellWebMimeRegistryImpl
// generated against ogg/vorbis/theora content we need to lock down how
// canPlayType() behaves when running layout tests.
virtual WebKit::WebMimeRegistry::SupportsType supportsMediaMIMEType(
- const WebKit::WebString&, const WebKit::WebString&) OVERRIDE;
+ const WebKit::WebString&,
+ const WebKit::WebString&) OVERRIDE;
private:
bool IsSupportedMediaMimeType(const std::string& mime_type);