| OLD | NEW |
| 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/fileapi/media/media_path_filter.h" | 5 #include "webkit/fileapi/media/media_path_filter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "net/base/mime_util.h" | 11 #include "net/base/mime_util.h" |
| 12 | 12 |
| 13 namespace fileapi { | 13 namespace fileapi { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const FilePath::CharType* const kExtraSupportedExtensions[] = { | 17 const base::FilePath::CharType* const kExtraSupportedExtensions[] = { |
| 18 FILE_PATH_LITERAL("3gp"), | 18 FILE_PATH_LITERAL("3gp"), |
| 19 FILE_PATH_LITERAL("3gpp"), | 19 FILE_PATH_LITERAL("3gpp"), |
| 20 FILE_PATH_LITERAL("avi"), | 20 FILE_PATH_LITERAL("avi"), |
| 21 FILE_PATH_LITERAL("flv"), | 21 FILE_PATH_LITERAL("flv"), |
| 22 FILE_PATH_LITERAL("mov"), | 22 FILE_PATH_LITERAL("mov"), |
| 23 FILE_PATH_LITERAL("mpeg"), | 23 FILE_PATH_LITERAL("mpeg"), |
| 24 FILE_PATH_LITERAL("mpeg4"), | 24 FILE_PATH_LITERAL("mpeg4"), |
| 25 FILE_PATH_LITERAL("mpegps"), | 25 FILE_PATH_LITERAL("mpegps"), |
| 26 FILE_PATH_LITERAL("mpg"), | 26 FILE_PATH_LITERAL("mpg"), |
| 27 FILE_PATH_LITERAL("wmv"), | 27 FILE_PATH_LITERAL("wmv"), |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 bool IsUnsupportedExtension(const FilePath::StringType& extension) { | 30 bool IsUnsupportedExtension(const base::FilePath::StringType& extension) { |
| 31 std::string mime_type; | 31 std::string mime_type; |
| 32 return !net::GetMimeTypeFromExtension(extension, &mime_type) || | 32 return !net::GetMimeTypeFromExtension(extension, &mime_type) || |
| 33 !net::IsSupportedMimeType(mime_type); | 33 !net::IsSupportedMimeType(mime_type); |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 MediaPathFilter::MediaPathFilter() | 38 MediaPathFilter::MediaPathFilter() |
| 39 : initialized_(false) { | 39 : initialized_(false) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 MediaPathFilter::~MediaPathFilter() { | 42 MediaPathFilter::~MediaPathFilter() { |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool MediaPathFilter::Match(const FilePath& path) { | 45 bool MediaPathFilter::Match(const base::FilePath& path) { |
| 46 EnsureInitialized(); | 46 EnsureInitialized(); |
| 47 return std::binary_search(media_file_extensions_.begin(), | 47 return std::binary_search(media_file_extensions_.begin(), |
| 48 media_file_extensions_.end(), | 48 media_file_extensions_.end(), |
| 49 StringToLowerASCII(path.Extension())); | 49 StringToLowerASCII(path.Extension())); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void MediaPathFilter::EnsureInitialized() { | 52 void MediaPathFilter::EnsureInitialized() { |
| 53 if (initialized_) | 53 if (initialized_) |
| 54 return; | 54 return; |
| 55 | 55 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 66 media_file_extensions_.end(), | 66 media_file_extensions_.end(), |
| 67 &IsUnsupportedExtension); | 67 &IsUnsupportedExtension); |
| 68 media_file_extensions_.erase(new_end, media_file_extensions_.end()); | 68 media_file_extensions_.erase(new_end, media_file_extensions_.end()); |
| 69 | 69 |
| 70 // Add other common extensions. | 70 // Add other common extensions. |
| 71 for (size_t i = 0; i < arraysize(kExtraSupportedExtensions); ++i) | 71 for (size_t i = 0; i < arraysize(kExtraSupportedExtensions); ++i) |
| 72 media_file_extensions_.push_back(kExtraSupportedExtensions[i]); | 72 media_file_extensions_.push_back(kExtraSupportedExtensions[i]); |
| 73 | 73 |
| 74 for (MediaFileExtensionList::iterator itr = media_file_extensions_.begin(); | 74 for (MediaFileExtensionList::iterator itr = media_file_extensions_.begin(); |
| 75 itr != media_file_extensions_.end(); ++itr) | 75 itr != media_file_extensions_.end(); ++itr) |
| 76 *itr = FilePath::kExtensionSeparator + *itr; | 76 *itr = base::FilePath::kExtensionSeparator + *itr; |
| 77 std::sort(media_file_extensions_.begin(), media_file_extensions_.end()); | 77 std::sort(media_file_extensions_.begin(), media_file_extensions_.end()); |
| 78 | 78 |
| 79 initialized_ = true; | 79 initialized_ = true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace fileapi | 82 } // namespace fileapi |
| OLD | NEW |