OLD | NEW |
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 "webkit/fileapi/file_system_path_manager.h" | 5 #include "webkit/fileapi/file_system_path_manager.h" |
6 | 6 |
7 #include "base/rand_util.h" | 7 #include "base/rand_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_callback_factory.h" | 9 #include "base/memory/scoped_callback_factory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 bool is_incognito, | 40 bool is_incognito, |
41 bool allow_file_access_from_files) | 41 bool allow_file_access_from_files) |
42 : is_incognito_(is_incognito), | 42 : is_incognito_(is_incognito), |
43 allow_file_access_from_files_(allow_file_access_from_files), | 43 allow_file_access_from_files_(allow_file_access_from_files), |
44 sandbox_provider_( | 44 sandbox_provider_( |
45 new SandboxMountPointProvider( | 45 new SandboxMountPointProvider( |
46 ALLOW_THIS_IN_INITIALIZER_LIST(this), | 46 ALLOW_THIS_IN_INITIALIZER_LIST(this), |
47 file_message_loop, | 47 file_message_loop, |
48 profile_path)) { | 48 profile_path)) { |
49 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
50 local_provider_.reset( | 50 external_provider_.reset( |
51 new chromeos::CrosMountPointProvider(special_storage_policy)); | 51 new chromeos::CrosMountPointProvider(special_storage_policy)); |
52 #endif | 52 #endif |
53 } | 53 } |
54 | 54 |
55 FileSystemPathManager::~FileSystemPathManager() {} | 55 FileSystemPathManager::~FileSystemPathManager() {} |
56 | 56 |
57 void FileSystemPathManager::GetFileSystemRootPath( | 57 void FileSystemPathManager::GetFileSystemRootPath( |
58 const GURL& origin_url, fileapi::FileSystemType type, | 58 const GURL& origin_url, fileapi::FileSystemType type, |
59 bool create, GetRootPathCallback* callback_ptr) { | 59 bool create, GetRootPathCallback* callback_ptr) { |
60 | 60 |
61 switch (type) { | 61 switch (type) { |
62 case kFileSystemTypeTemporary: | 62 case kFileSystemTypeTemporary: |
63 case kFileSystemTypePersistent: | 63 case kFileSystemTypePersistent: |
64 sandbox_provider_->GetFileSystemRootPath( | 64 sandbox_provider_->GetFileSystemRootPath( |
65 origin_url, type, create, callback_ptr); | 65 origin_url, type, create, callback_ptr); |
66 break; | 66 break; |
67 case kFileSystemTypeLocal: | 67 case kFileSystemTypeExternal: |
68 if (local_provider_.get()) { | 68 if (external_provider_.get()) { |
69 local_provider_->GetFileSystemRootPath( | 69 external_provider_->GetFileSystemRootPath( |
70 origin_url, type, create, callback_ptr); | 70 origin_url, type, create, callback_ptr); |
71 } else { | 71 } else { |
72 callback_ptr->Run(false, FilePath(), std::string()); | 72 callback_ptr->Run(false, FilePath(), std::string()); |
73 } | 73 } |
74 break; | 74 break; |
75 case kFileSystemTypeUnknown: | 75 case kFileSystemTypeUnknown: |
76 default: | 76 default: |
77 NOTREACHED(); | 77 NOTREACHED(); |
78 callback_ptr->Run(false, FilePath(), std::string()); | 78 callback_ptr->Run(false, FilePath(), std::string()); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 FilePath FileSystemPathManager::GetFileSystemRootPathOnFileThread( | 82 FilePath FileSystemPathManager::GetFileSystemRootPathOnFileThread( |
83 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path, | 83 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path, |
84 bool create) { | 84 bool create) { |
85 switch (type) { | 85 switch (type) { |
86 case kFileSystemTypeTemporary: | 86 case kFileSystemTypeTemporary: |
87 case kFileSystemTypePersistent: | 87 case kFileSystemTypePersistent: |
88 return sandbox_provider_->GetFileSystemRootPathOnFileThread( | 88 return sandbox_provider_->GetFileSystemRootPathOnFileThread( |
89 origin_url, type, virtual_path, create); | 89 origin_url, type, virtual_path, create); |
90 break; | 90 break; |
91 case kFileSystemTypeLocal: | 91 case kFileSystemTypeExternal: |
92 return local_provider_.get() ? | 92 return external_provider_.get() ? |
93 local_provider_->GetFileSystemRootPathOnFileThread( | 93 external_provider_->GetFileSystemRootPathOnFileThread( |
94 origin_url, type, virtual_path, create) : | 94 origin_url, type, virtual_path, create) : |
95 FilePath(); | 95 FilePath(); |
96 case kFileSystemTypeUnknown: | 96 case kFileSystemTypeUnknown: |
97 default: | 97 default: |
98 NOTREACHED(); | 98 NOTREACHED(); |
99 return FilePath(); | 99 return FilePath(); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const { | 103 bool FileSystemPathManager::IsAllowedScheme(const GURL& url) const { |
104 // Basically we only accept http or https. We allow file:// URLs | 104 // Basically we only accept http or https. We allow file:// URLs |
105 // only if --allow-file-access-from-files flag is given. | 105 // only if --allow-file-access-from-files flag is given. |
106 return url.SchemeIs("http") || url.SchemeIs("https") || | 106 return url.SchemeIs("http") || url.SchemeIs("https") || |
107 url.SchemeIs(kExtensionScheme) || | 107 url.SchemeIs(kExtensionScheme) || |
108 (url.SchemeIsFile() && allow_file_access_from_files_); | 108 (url.SchemeIsFile() && allow_file_access_from_files_); |
109 } | 109 } |
110 | 110 |
111 // static | 111 // static |
112 std::string FileSystemPathManager::GetFileSystemTypeString( | 112 std::string FileSystemPathManager::GetFileSystemTypeString( |
113 fileapi::FileSystemType type) { | 113 fileapi::FileSystemType type) { |
114 if (type == fileapi::kFileSystemTypeTemporary) | 114 if (type == fileapi::kFileSystemTypeTemporary) |
115 return fileapi::SandboxMountPointProvider::kTemporaryName; | 115 return fileapi::kTemporaryName; |
116 else if (type == fileapi::kFileSystemTypePersistent) | 116 else if (type == fileapi::kFileSystemTypePersistent) |
117 return fileapi::SandboxMountPointProvider::kPersistentName; | 117 return fileapi::kPersistentName; |
| 118 else if (type == fileapi::kFileSystemTypeExternal) |
| 119 return fileapi::kExternalName; |
118 return std::string(); | 120 return std::string(); |
119 } | 121 } |
120 | 122 |
121 // Checks if a given |name| contains any restricted names/chars in it. | 123 // Checks if a given |name| contains any restricted names/chars in it. |
122 bool FileSystemPathManager::IsRestrictedFileName( | 124 bool FileSystemPathManager::IsRestrictedFileName( |
123 FileSystemType type, const FilePath& filename) { | 125 FileSystemType type, const FilePath& filename) { |
124 switch (type) { | 126 switch (type) { |
125 case kFileSystemTypeTemporary: | 127 case kFileSystemTypeTemporary: |
126 case kFileSystemTypePersistent: | 128 case kFileSystemTypePersistent: |
127 return sandbox_provider_->IsRestrictedFileName(filename); | 129 return sandbox_provider_->IsRestrictedFileName(filename); |
128 case kFileSystemTypeLocal: | 130 case kFileSystemTypeExternal: |
129 return local_provider_.get() ? | 131 return external_provider_.get() ? |
130 local_provider_->IsRestrictedFileName(filename) : true; | 132 external_provider_->IsRestrictedFileName(filename) : true; |
131 case kFileSystemTypeUnknown: | 133 case kFileSystemTypeUnknown: |
132 default: | 134 default: |
133 NOTREACHED(); | 135 NOTREACHED(); |
134 return true; | 136 return true; |
135 } | 137 } |
136 } | 138 } |
137 | 139 |
138 // Checks if an origin has access to a particular filesystem type. | 140 // Checks if an origin has access to a particular filesystem type. |
139 bool FileSystemPathManager::IsAllowedFileSystemType( | 141 bool FileSystemPathManager::IsAccessAllowed( |
140 GURL origin, FileSystemType type) { | 142 const GURL& origin, FileSystemType type, const FilePath& virtual_path) { |
141 switch (type) { | 143 switch (type) { |
142 case kFileSystemTypeTemporary: | 144 case kFileSystemTypeTemporary: |
143 case kFileSystemTypePersistent: | 145 case kFileSystemTypePersistent: |
144 if (!sandbox_provider_->IsAccessAllowed(origin)) | 146 if (!sandbox_provider_->IsAccessAllowed(origin, type, virtual_path)) |
145 return false; | 147 return false; |
146 break; | 148 break; |
147 case kFileSystemTypeLocal: | 149 case kFileSystemTypeExternal: |
148 if (!local_provider_.get() || | 150 if (!external_provider_.get() || |
149 !local_provider_->IsAccessAllowed(origin)) { | 151 !external_provider_->IsAccessAllowed(origin, type, virtual_path)) { |
150 return false; | 152 return false; |
151 } | 153 } |
152 break; | 154 break; |
153 case kFileSystemTypeUnknown: | 155 case kFileSystemTypeUnknown: |
154 default: | 156 default: |
155 NOTREACHED(); | 157 NOTREACHED(); |
156 return false; | 158 return false; |
157 } | 159 } |
158 return true; | 160 return true; |
159 } | 161 } |
160 | 162 |
161 } // namespace fileapi | 163 } // namespace fileapi |
162 | 164 |
163 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ | 165 COMPILE_ASSERT(int(WebFileSystem::TypeTemporary) == \ |
164 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); | 166 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); |
165 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ | 167 COMPILE_ASSERT(int(WebFileSystem::TypePersistent) == \ |
166 int(fileapi::kFileSystemTypePersistent), mismatching_enums); | 168 int(fileapi::kFileSystemTypePersistent), mismatching_enums); |
| 169 COMPILE_ASSERT(int(WebFileSystem::TypeExternal) == \ |
| 170 int(fileapi::kFileSystemTypeExternal), mismatching_enums); |
OLD | NEW |