summaryrefslogtreecommitdiffstats
path: root/webkit/chromeos/fileapi/file_access_permissions.cc
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-16 04:01:08 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-16 04:01:08 +0000
commitb777b3386e10d38944cc717e4192b7858cbdc7fe (patch)
tree85d37a15e729df855d81e0973d9ed1bb3f90d347 /webkit/chromeos/fileapi/file_access_permissions.cc
parent4b59a325a589190ab95622be4e1b6a70bc02914f (diff)
downloadchromium_src-b777b3386e10d38944cc717e4192b7858cbdc7fe.zip
chromium_src-b777b3386e10d38944cc717e4192b7858cbdc7fe.tar.gz
chromium_src-b777b3386e10d38944cc717e4192b7858cbdc7fe.tar.bz2
File API changes needed for safely passing user selected file entities from the file browser component extension to a 3rd party extension.
BUG=chromium-os:11996 TEST=FileAccessPermissionsTest.FileAccessChecks Review URL: http://codereview.chromium.org/6810037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/chromeos/fileapi/file_access_permissions.cc')
-rw-r--r--webkit/chromeos/fileapi/file_access_permissions.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/webkit/chromeos/fileapi/file_access_permissions.cc b/webkit/chromeos/fileapi/file_access_permissions.cc
new file mode 100644
index 0000000..6ab5a04
--- /dev/null
+++ b/webkit/chromeos/fileapi/file_access_permissions.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2011 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.
+
+#include "webkit/chromeos/fileapi/file_access_permissions.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+
+namespace chromeos {
+
+FileAccessPermissions::FileAccessPermissions() {}
+
+FileAccessPermissions::~FileAccessPermissions() {}
+
+
+void FileAccessPermissions::GrantAccessPermission(
+ const std::string& extension_id, const FilePath& path) {
+ base::AutoLock locker(lock_);
+ PathAccessMap::iterator path_map_iter = path_map_.find(extension_id);
+ if (path_map_iter == path_map_.end()) {
+ PathSet path_set;
+ path_set.insert(path);
+ path_map_.insert(PathAccessMap::value_type(extension_id, path_set));
+ } else {
+ if (path_map_iter->second.find(path) != path_map_iter->second.end())
+ return;
+ path_map_iter->second.insert(path);
+ }
+}
+
+bool FileAccessPermissions::HasAccessPermission(
+ const std::string& extension_id, const FilePath& path) {
+ base::AutoLock locker(lock_);
+ PathAccessMap::const_iterator path_map_iter = path_map_.find(extension_id);
+ if (path_map_iter == path_map_.end())
+ return false;
+
+ // Check this file and walk up its directory tree to find if this extension
+ // has access to it.
+ FilePath current_path = path.StripTrailingSeparators();
+ FilePath last_path;
+ while (current_path != last_path) {
+ if (path_map_iter->second.find(current_path) != path_map_iter->second.end())
+ return true;
+ last_path = current_path;
+ current_path = current_path.DirName();
+ }
+ return false;
+}
+
+void FileAccessPermissions::RevokePermissions(
+ const std::string& extension_id) {
+ base::AutoLock locker(lock_);
+ path_map_.erase(extension_id);
+}
+
+}