Index: chrome/browser/extensions/extension_special_storage_policy.cc |
=================================================================== |
--- chrome/browser/extensions/extension_special_storage_policy.cc (revision 81212) |
+++ 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,17 +27,23 @@ |
} |
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); |
if (!extension->is_hosted_app() && |
!extension->HasApiPermission(Extension::kUnlimitedStoragePermission) && |
- !extension->HasApiPermission(Extension::kFileSystemPermission)) { |
+ !extension->HasApiPermission(Extension::kFileBrowserHandlerPermission)) { |
return; |
} |
base::AutoLock locker(lock_); |
@@ -43,7 +51,7 @@ |
protected_apps_.Add(extension); |
if (extension->HasApiPermission(Extension::kUnlimitedStoragePermission)) |
unlimited_extensions_.Add(extension); |
- if (extension->HasApiPermission(Extension::kFileSystemPermission)) |
+ if (extension->HasApiPermission(Extension::kFileBrowserHandlerPermission)) |
local_filesystem_extensions_.Add(extension); |
} |
@@ -52,7 +60,7 @@ |
DCHECK(extension); |
if (!extension->is_hosted_app() && |
!extension->HasApiPermission(Extension::kUnlimitedStoragePermission) && |
- !extension->HasApiPermission(Extension::kFileSystemPermission)) { |
+ !extension->HasApiPermission(Extension::kFileBrowserHandlerPermission)) { |
return; |
} |
base::AutoLock locker(lock_); |
@@ -60,7 +68,7 @@ |
protected_apps_.Remove(extension); |
if (extension->HasApiPermission(Extension::kUnlimitedStoragePermission)) |
unlimited_extensions_.Remove(extension); |
- if (extension->HasApiPermission(Extension::kFileSystemPermission)) |
+ if (extension->HasApiPermission(Extension::kFileBrowserHandlerPermission)) |
local_filesystem_extensions_.Remove(extension); |
} |
@@ -81,34 +89,115 @@ |
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); |
+ if (found != cached_results_.end()) |
return found->second; |
for (Extensions::const_iterator iter = extensions_.begin(); |
iter != extensions_.end(); ++iter) { |
if (iter->second->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_[extension->id()] = extension; |
} |
void ExtensionSpecialStoragePolicy::SpecialCollection::Remove( |
const Extension* extension) { |
- cached_resuts_.clear(); |
+ cached_results_.clear(); |
extensions_.erase(extension->id()); |
} |
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() { |
+ SpecialCollection::Clear(); |
+ path_map_.clear(); |
+} |
+ |
+void ExtensionSpecialStoragePolicy::SpecialPathCollection::Remove( |
+ const Extension* extension) { |
+ SpecialCollection::Remove(extension); |
+ path_map_.erase(extension); |
+} |
+ |
+void ExtensionSpecialStoragePolicy::SpecialPathCollection::AddPath( |
+ const GURL& origin, const FilePath& path) { |
+ scoped_refptr<const Extension> extension = GetExtension(origin); |
+ if (!extension.get()) |
+ 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) { |
+ scoped_refptr<const Extension> extension = GetExtension(origin); |
+ if (!extension.get()) |
+ 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; |
+} |
+ |
+scoped_refptr<const Extension> |
+ExtensionSpecialStoragePolicy::SpecialPathCollection::GetExtension( |
+ const GURL& origin) { |
+ for (Extensions::const_iterator iter = extensions_.begin(); |
+ iter != extensions_.end(); ++iter) { |
+ if (iter->second->OverlapsWithOrigin(origin)) |
michaeln
2011/04/14 01:26:26
ooops... forgot to hit send earlier today...
Cons
|
+ return iter->second; |
+ } |
+ return scoped_refptr<const Extension>(); |
+} |