Index: chrome/browser/extensions/extension_special_storage_policy.cc |
=================================================================== |
--- chrome/browser/extensions/extension_special_storage_policy.cc (revision 80410) |
+++ chrome/browser/extensions/extension_special_storage_policy.cc (working copy) |
@@ -4,7 +4,9 @@ |
#include "chrome/browser/extensions/extension_special_storage_policy.h" |
+#include "base/command_line.h" |
#include "base/logging.h" |
+#include "chrome/common/chrome_switches.h" |
#include "chrome/common/extensions/extension.h" |
#include "chrome/common/url_constants.h" |
@@ -25,11 +27,17 @@ |
} |
bool ExtensionSpecialStoragePolicy::IsLocalFileSystemAccessAllowed( |
- const GURL& origin) { |
+ const GURL& origin, const FilePath& virtual_path) { |
base::AutoLock locker(lock_); |
- return local_filesystem_extensions_.Contains(origin); |
+ return local_filesystem_extensions_.ContainsPath(origin, virtual_path); |
} |
+void ExtensionSpecialStoragePolicy::GrantLocalFileSystemAccess( |
+ const GURL& origin, const FilePath& virtual_path) { |
+ base::AutoLock locker(lock_); |
+ local_filesystem_extensions_.AddPath(origin, virtual_path); |
+} |
+ |
void ExtensionSpecialStoragePolicy::GrantRightsForExtension( |
const Extension* extension) { |
DCHECK(extension); |
@@ -112,3 +120,85 @@ |
cached_resuts_.clear(); |
extensions_.clear(); |
} |
+ |
+//----------------------------------------------------------------------------- |
+// SpecialPathCollection helper class |
+//----------------------------------------------------------------------------- |
+ |
+ExtensionSpecialStoragePolicy::SpecialPathCollection::SpecialPathCollection() {} |
+ |
+ExtensionSpecialStoragePolicy::SpecialPathCollection::~SpecialPathCollection() { |
+} |
+ |
+void ExtensionSpecialStoragePolicy::SpecialPathCollection::Clear() { |
+ ExtensionSpecialStoragePolicy::SpecialCollection::Clear(); |
+ path_map_.clear(); |
+} |
+ |
+void ExtensionSpecialStoragePolicy::SpecialPathCollection::Remove( |
+ const Extension* extension) { |
+ ExtensionSpecialStoragePolicy::SpecialCollection::Remove(extension); |
+ path_map_.erase(extension); |
+} |
+ |
+void ExtensionSpecialStoragePolicy::SpecialPathCollection::AddPath( |
+ const GURL& origin, const FilePath& path) { |
+ const Extension* extension = GetExtension(origin); |
+ if (!extension) |
+ return; |
+ PathAccessMap::iterator path_map_iter = path_map_.find(extension); |
+ if (path_map_iter == path_map_.end()) { |
+ PathSet path_set; |
+ path_set.insert(path); |
+ path_map_.insert(PathAccessMap::value_type(extension, path_set)); |
+ } else { |
+ if (path_map_iter->second.find(path) != path_map_iter->second.end()) |
+ return; |
+ path_map_iter->second.insert(path); |
+ } |
+} |
+ |
+bool ExtensionSpecialStoragePolicy::SpecialPathCollection::ContainsPath( |
+ const GURL& origin, const FilePath& path) { |
+ const Extension* extension = GetExtension(origin); |
+ if (!extension) |
+ return false; |
+ |
+ // Allow access to any local path from component extensions. |
+ if (extension->location() == Extension::COMPONENT |
+#ifndef NDEBUG |
+ || CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kExposePrivateExtensionApi) |
+#endif |
+ ) { |
+ return true; |
+ } |
+ |
+ PathAccessMap::const_iterator path_map_iter = path_map_.find(extension); |
+ 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; |
+} |
+ |
+const Extension* |
+ ExtensionSpecialStoragePolicy::SpecialPathCollection::GetExtension( |
+ const GURL& origin) { |
+ for (Extensions::const_iterator iter = extensions_.begin(); |
+ iter != extensions_.end(); ++iter) { |
+ if ((*iter)->OverlapsWithOrigin(origin)) |
+ return (*iter); |
+ } |
+ return NULL; |
+} |
+ |