Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: chrome/browser/extensions/extension_special_storage_policy.cc

Issue 6810037: File API changes needed for safely passing user selected file entities from the file browser comp... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_special_storage_policy.h" 5 #include "chrome/browser/extensions/extension_special_storage_policy.h"
6 6
7 #include "base/command_line.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/common/chrome_switches.h"
8 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
9 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
10 12
11 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy() {} 13 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy() {}
12 14
13 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} 15 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {}
14 16
15 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { 17 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
16 if (origin.SchemeIs(chrome::kExtensionScheme)) 18 if (origin.SchemeIs(chrome::kExtensionScheme))
17 return true; 19 return true;
18 base::AutoLock locker(lock_); 20 base::AutoLock locker(lock_);
19 return protected_apps_.Contains(origin); 21 return protected_apps_.Contains(origin);
20 } 22 }
21 23
22 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { 24 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) {
23 base::AutoLock locker(lock_); 25 base::AutoLock locker(lock_);
24 return unlimited_extensions_.Contains(origin); 26 return unlimited_extensions_.Contains(origin);
25 } 27 }
26 28
27 bool ExtensionSpecialStoragePolicy::IsLocalFileSystemAccessAllowed( 29 bool ExtensionSpecialStoragePolicy::IsLocalFileSystemAccessAllowed(
28 const GURL& origin) { 30 const GURL& origin, const FilePath& virtual_path) {
29 base::AutoLock locker(lock_); 31 base::AutoLock locker(lock_);
30 return local_filesystem_extensions_.Contains(origin); 32 return local_filesystem_extensions_.ContainsPath(origin, virtual_path);
33 }
34
35 void ExtensionSpecialStoragePolicy::GrantLocalFileSystemAccess(
36 const GURL& origin, const FilePath& virtual_path) {
37 base::AutoLock locker(lock_);
38 local_filesystem_extensions_.AddPath(origin, virtual_path);
31 } 39 }
32 40
33 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( 41 void ExtensionSpecialStoragePolicy::GrantRightsForExtension(
34 const Extension* extension) { 42 const Extension* extension) {
35 DCHECK(extension); 43 DCHECK(extension);
36 if (!extension->is_hosted_app() && 44 if (!extension->is_hosted_app() &&
37 !extension->HasApiPermission(Extension::kUnlimitedStoragePermission) && 45 !extension->HasApiPermission(Extension::kUnlimitedStoragePermission) &&
38 !extension->HasApiPermission(Extension::kFileSystemPermission)) { 46 !extension->HasApiPermission(Extension::kFileSystemPermission)) {
39 return; 47 return;
40 } 48 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 //----------------------------------------------------------------------------- 82 //-----------------------------------------------------------------------------
75 // SpecialCollection helper class 83 // SpecialCollection helper class
76 //----------------------------------------------------------------------------- 84 //-----------------------------------------------------------------------------
77 85
78 ExtensionSpecialStoragePolicy::SpecialCollection::SpecialCollection() {} 86 ExtensionSpecialStoragePolicy::SpecialCollection::SpecialCollection() {}
79 87
80 ExtensionSpecialStoragePolicy::SpecialCollection::~SpecialCollection() {} 88 ExtensionSpecialStoragePolicy::SpecialCollection::~SpecialCollection() {}
81 89
82 bool ExtensionSpecialStoragePolicy::SpecialCollection::Contains( 90 bool ExtensionSpecialStoragePolicy::SpecialCollection::Contains(
83 const GURL& origin) { 91 const GURL& origin) {
84 CachedResults::const_iterator found = cached_resuts_.find(origin); 92 CachedResults::const_iterator found = cached_results_.find(origin);
michaeln 2011/04/09 00:16:45 ooops... thnx
85 if (found != cached_resuts_.end()) 93 if (found != cached_results_.end())
86 return found->second; 94 return found->second;
87 95
88 for (Extensions::const_iterator iter = extensions_.begin(); 96 for (Extensions::const_iterator iter = extensions_.begin();
89 iter != extensions_.end(); ++iter) { 97 iter != extensions_.end(); ++iter) {
90 if ((*iter)->OverlapsWithOrigin(origin)) { 98 if ((*iter)->OverlapsWithOrigin(origin)) {
91 cached_resuts_[origin] = true; 99 cached_results_[origin] = true;
92 return true; 100 return true;
93 } 101 }
94 } 102 }
95 cached_resuts_[origin] = false; 103 cached_results_[origin] = false;
96 return false; 104 return false;
97 } 105 }
98 106
99 void ExtensionSpecialStoragePolicy::SpecialCollection::Add( 107 void ExtensionSpecialStoragePolicy::SpecialCollection::Add(
100 const Extension* extension) { 108 const Extension* extension) {
101 cached_resuts_.clear(); 109 cached_results_.clear();
102 extensions_.insert(extension); 110 extensions_.insert(extension);
103 } 111 }
104 112
105 void ExtensionSpecialStoragePolicy::SpecialCollection::Remove( 113 void ExtensionSpecialStoragePolicy::SpecialCollection::Remove(
106 const Extension* extension) { 114 const Extension* extension) {
107 cached_resuts_.clear(); 115 cached_results_.clear();
108 extensions_.erase(extension); 116 extensions_.erase(extension);
109 } 117 }
110 118
111 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { 119 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() {
112 cached_resuts_.clear(); 120 cached_results_.clear();
113 extensions_.clear(); 121 extensions_.clear();
114 } 122 }
123
124 //-----------------------------------------------------------------------------
125 // SpecialPathCollection helper class
126 //-----------------------------------------------------------------------------
127
128 ExtensionSpecialStoragePolicy::SpecialPathCollection::SpecialPathCollection() {}
129
130 ExtensionSpecialStoragePolicy::SpecialPathCollection::~SpecialPathCollection() {
131 }
132
133 void ExtensionSpecialStoragePolicy::SpecialPathCollection::Clear() {
134 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.
135 path_map_.clear();
136 }
137
138 void ExtensionSpecialStoragePolicy::SpecialPathCollection::Remove(
139 const Extension* extension) {
140 ExtensionSpecialStoragePolicy::SpecialCollection::Remove(extension);
141 path_map_.erase(extension);
142 }
143
144 void ExtensionSpecialStoragePolicy::SpecialPathCollection::AddPath(
145 const GURL& origin, const FilePath& path) {
146 const Extension* extension = GetExtension(origin);
147 if (!extension)
148 return;
149 PathAccessMap::iterator path_map_iter = path_map_.find(extension);
150 if (path_map_iter == path_map_.end()) {
151 PathSet path_set;
152 path_set.insert(path);
153 path_map_.insert(PathAccessMap::value_type(extension, path_set));
154 } else {
155 if (path_map_iter->second.find(path) != path_map_iter->second.end())
156 return;
157 path_map_iter->second.insert(path);
158 }
159 }
160
161 bool ExtensionSpecialStoragePolicy::SpecialPathCollection::ContainsPath(
162 const GURL& origin, const FilePath& path) {
163 const Extension* extension = GetExtension(origin);
164 if (!extension)
165 return false;
166
167 // Allow access to any local path from component extensions.
168 if (extension->location() == Extension::COMPONENT
169 #ifndef NDEBUG
170 || CommandLine::ForCurrentProcess()->HasSwitch(
171 switches::kExposePrivateExtensionApi)
172 #endif
173 ) {
174 return true;
175 }
176
177 PathAccessMap::const_iterator path_map_iter = path_map_.find(extension);
178 if (path_map_iter == path_map_.end())
179 return false;
180
181 // Check this file and walk up its directory tree to find if this extension
182 // has access to it.
183 FilePath current_path = path.StripTrailingSeparators();
184 FilePath last_path;
185 while (current_path != last_path) {
186 if (path_map_iter->second.find(current_path) != path_map_iter->second.end())
187 return true;
188 last_path = current_path;
189 current_path = current_path.DirName();
190 }
191 return false;
192 }
193
194 const Extension*
195 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.
196 const GURL& origin) {
197 for (Extensions::const_iterator iter = extensions_.begin();
198 iter != extensions_.end(); ++iter) {
199 if ((*iter)->OverlapsWithOrigin(origin))
200 return (*iter);
201 }
202 return NULL;
203 }
204
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698