summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/media
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-21 20:50:22 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-21 20:50:22 +0000
commite3ee6633cc5043941be9c880498991df37d1ccf4 (patch)
treef3137ce4624d15339650c9286c40533a42cf887e /webkit/fileapi/media
parent714e758f31f97edbce6795ab3e504cfbd0524c9a (diff)
downloadchromium_src-e3ee6633cc5043941be9c880498991df37d1ccf4.zip
chromium_src-e3ee6633cc5043941be9c880498991df37d1ccf4.tar.gz
chromium_src-e3ee6633cc5043941be9c880498991df37d1ccf4.tar.bz2
[MediaGallery] Filter hidden media files and folders.
BUG=161415 TEST=none Review URL: https://chromiumcodereview.appspot.com/11413060 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169120 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/media')
-rw-r--r--webkit/fileapi/media/filtering_file_enumerator.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/webkit/fileapi/media/filtering_file_enumerator.cc b/webkit/fileapi/media/filtering_file_enumerator.cc
index e1b9cc5..e291697 100644
--- a/webkit/fileapi/media/filtering_file_enumerator.cc
+++ b/webkit/fileapi/media/filtering_file_enumerator.cc
@@ -2,11 +2,69 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/file_path.h"
#include "base/logging.h"
+#include "build/build_config.h"
#include "webkit/fileapi/media/filtering_file_enumerator.h"
+#if defined(OS_WIN)
+#include <windows.h>
+#else
+#include <cstring>
+
+#include "base/string_util.h"
+#endif
+
namespace fileapi {
+namespace {
+
+// Used to skip the hidden folders and files. Returns true if the file specified
+// by |path| should be skipped.
+bool ShouldSkip(const FilePath& path) {
+ const FilePath& base_name = path.BaseName();
+ if (base_name.empty())
+ return false;
+
+ // Dot files (aka hidden files)
+ if (base_name.value()[0] == '.')
+ return true;
+
+ // Mac OS X file.
+ if (base_name.value() == FILE_PATH_LITERAL("__MACOSX"))
+ return true;
+
+#if defined(OS_WIN)
+ DWORD file_attributes = ::GetFileAttributes(path.value().c_str());
+ if ((file_attributes != INVALID_FILE_ATTRIBUTES) &&
+ ((file_attributes & FILE_ATTRIBUTE_HIDDEN) != 0))
+ return true;
+#else
+ // Windows always creates a recycle bin folder in the attached device to store
+ // all the deleted contents. On non-windows operating systems, there is no way
+ // to get the hidden attribute of windows recycle bin folders that are present
+ // on the attached device. Therefore, compare the file path name to the
+ // recycle bin name and exclude those folders. For more details, please refer
+ // to http://support.microsoft.com/kb/171694.
+ const char win_98_recycle_bin_name[] = "RECYCLED";
+ const char win_xp_recycle_bin_name[] = "RECYCLER";
+ const char win_vista_recycle_bin_name[] = "$Recycle.bin";
+ if ((base::strncasecmp(base_name.value().c_str(),
+ win_98_recycle_bin_name,
+ strlen(win_98_recycle_bin_name)) == 0) ||
+ (base::strncasecmp(base_name.value().c_str(),
+ win_xp_recycle_bin_name,
+ strlen(win_xp_recycle_bin_name)) == 0) ||
+ (base::strncasecmp(base_name.value().c_str(),
+ win_vista_recycle_bin_name,
+ strlen(win_vista_recycle_bin_name)) == 0))
+ return true;
+#endif
+ return false;
+}
+
+} // namespace
+
FilteringFileEnumerator::FilteringFileEnumerator(
scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator,
MediaPathFilter* filter)
@@ -22,6 +80,9 @@ FilteringFileEnumerator::~FilteringFileEnumerator() {
FilePath FilteringFileEnumerator::Next() {
while (true) {
FilePath next = base_enumerator_->Next();
+ if (ShouldSkip(next))
+ continue;
+
if (next.empty() ||
base_enumerator_->IsDirectory() ||
filter_->Match(next))