Chromium Code Reviews| Index: chrome/browser/extensions/extension_special_storage_policy.cc |
| =================================================================== |
| --- chrome/browser/extensions/extension_special_storage_policy.cc (revision 80841) |
| +++ 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); |
| @@ -81,34 +89,116 @@ |
| bool ExtensionSpecialStoragePolicy::SpecialCollection::Contains( |
| const GURL& origin) { |
| - CachedResults::const_iterator found = cached_resuts_.find(origin); |
| - if (found != cached_resuts_.end()) |
| + CachedResults::const_iterator found = cached_results_.find(origin); |
|
michaeln
2011/04/09 00:16:45
ooops... thnx
|
| + if (found != cached_results_.end()) |
| return found->second; |
| for (Extensions::const_iterator iter = extensions_.begin(); |
| iter != extensions_.end(); ++iter) { |
| if ((*iter)->OverlapsWithOrigin(origin)) { |
| - cached_resuts_[origin] = true; |
| + cached_results_[origin] = true; |
| return true; |
| } |
| } |
| - cached_resuts_[origin] = false; |
| + cached_results_[origin] = false; |
| return false; |
| } |
| void ExtensionSpecialStoragePolicy::SpecialCollection::Add( |
| const Extension* extension) { |
| - cached_resuts_.clear(); |
| + cached_results_.clear(); |
| extensions_.insert(extension); |
| } |
| void ExtensionSpecialStoragePolicy::SpecialCollection::Remove( |
| const Extension* extension) { |
| - cached_resuts_.clear(); |
| + cached_results_.clear(); |
| extensions_.erase(extension); |
| } |
| void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
| - cached_resuts_.clear(); |
| + cached_results_.clear(); |
| extensions_.clear(); |
| } |
| + |
| +//----------------------------------------------------------------------------- |
| +// SpecialPathCollection helper class |
| +//----------------------------------------------------------------------------- |
| + |
| +ExtensionSpecialStoragePolicy::SpecialPathCollection::SpecialPathCollection() {} |
| + |
| +ExtensionSpecialStoragePolicy::SpecialPathCollection::~SpecialPathCollection() { |
| +} |
| + |
| +void ExtensionSpecialStoragePolicy::SpecialPathCollection::Clear() { |
| + ExtensionSpecialStoragePolicy::SpecialCollection::Clear(); |
|
michaeln
2011/04/09 00:16:45
i think you may not need the ExtensionSpecialStora
zel
2011/04/13 00:44:26
Done.
|
| + 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( |
|
michaeln
2011/04/09 00:16:45
i've seen other wrapping styles for this in the pr
zel
2011/04/13 00:44:26
Done.
|
| + const GURL& origin) { |
| + for (Extensions::const_iterator iter = extensions_.begin(); |
| + iter != extensions_.end(); ++iter) { |
| + if ((*iter)->OverlapsWithOrigin(origin)) |
| + return (*iter); |
| + } |
| + return NULL; |
| +} |
| + |