OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/file_manager/file_browser_handlers.h" | 5 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "content/public/browser/site_instance.h" | 25 #include "content/public/browser/site_instance.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
28 #include "extensions/browser/extension_host.h" | 28 #include "extensions/browser/extension_host.h" |
29 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
30 #include "extensions/browser/extension_util.h" | 30 #include "extensions/browser/extension_util.h" |
31 #include "extensions/browser/lazy_background_task_queue.h" | 31 #include "extensions/browser/lazy_background_task_queue.h" |
32 #include "extensions/common/extension_set.h" | 32 #include "extensions/common/extension_set.h" |
33 #include "extensions/common/manifest_handlers/background_info.h" | 33 #include "extensions/common/manifest_handlers/background_info.h" |
34 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
35 #include "webkit/browser/fileapi/file_system_context.h" | 35 #include "storage/browser/fileapi/file_system_context.h" |
36 #include "webkit/browser/fileapi/file_system_url.h" | 36 #include "storage/browser/fileapi/file_system_url.h" |
37 #include "webkit/common/fileapi/file_system_info.h" | 37 #include "storage/common/fileapi/file_system_info.h" |
38 #include "webkit/common/fileapi/file_system_util.h" | 38 #include "storage/common/fileapi/file_system_util.h" |
39 | 39 |
40 using content::BrowserThread; | 40 using content::BrowserThread; |
41 using content::ChildProcessSecurityPolicy; | 41 using content::ChildProcessSecurityPolicy; |
42 using content::SiteInstance; | 42 using content::SiteInstance; |
43 using content::WebContents; | 43 using content::WebContents; |
44 using extensions::Extension; | 44 using extensions::Extension; |
45 using fileapi::FileSystemURL; | 45 using storage::FileSystemURL; |
46 using file_manager::util::EntryDefinition; | 46 using file_manager::util::EntryDefinition; |
47 using file_manager::util::EntryDefinitionList; | 47 using file_manager::util::EntryDefinitionList; |
48 using file_manager::util::FileDefinition; | 48 using file_manager::util::FileDefinition; |
49 using file_manager::util::FileDefinitionList; | 49 using file_manager::util::FileDefinitionList; |
50 | 50 |
51 namespace file_manager { | 51 namespace file_manager { |
52 namespace file_browser_handlers { | 52 namespace file_browser_handlers { |
53 namespace { | 53 namespace { |
54 | 54 |
55 // Returns process id of the process the extension is running in. | 55 // Returns process id of the process the extension is running in. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void Execute(const std::vector<FileSystemURL>& file_urls, | 158 void Execute(const std::vector<FileSystemURL>& file_urls, |
159 const file_tasks::FileTaskFinishedCallback& done); | 159 const file_tasks::FileTaskFinishedCallback& done); |
160 | 160 |
161 private: | 161 private: |
162 // This object is responsible to delete itself. | 162 // This object is responsible to delete itself. |
163 virtual ~FileBrowserHandlerExecutor(); | 163 virtual ~FileBrowserHandlerExecutor(); |
164 | 164 |
165 // Checks legitimacy of file url and grants file RO access permissions from | 165 // Checks legitimacy of file url and grants file RO access permissions from |
166 // handler (target) extension and its renderer process. | 166 // handler (target) extension and its renderer process. |
167 static scoped_ptr<FileDefinitionList> SetupFileAccessPermissions( | 167 static scoped_ptr<FileDefinitionList> SetupFileAccessPermissions( |
168 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, | 168 scoped_refptr<storage::FileSystemContext> file_system_context_handler, |
169 const scoped_refptr<const Extension>& handler_extension, | 169 const scoped_refptr<const Extension>& handler_extension, |
170 const std::vector<FileSystemURL>& file_urls); | 170 const std::vector<FileSystemURL>& file_urls); |
171 | 171 |
172 void ExecuteDoneOnUIThread(bool success); | 172 void ExecuteDoneOnUIThread(bool success); |
173 void ExecuteAfterSetupFileAccess(scoped_ptr<FileDefinitionList> file_list); | 173 void ExecuteAfterSetupFileAccess(scoped_ptr<FileDefinitionList> file_list); |
174 void ExecuteFileActionsOnUIThread( | 174 void ExecuteFileActionsOnUIThread( |
175 scoped_ptr<FileDefinitionList> file_definition_list, | 175 scoped_ptr<FileDefinitionList> file_definition_list, |
176 scoped_ptr<EntryDefinitionList> entry_definition_list); | 176 scoped_ptr<EntryDefinitionList> entry_definition_list); |
177 void SetupPermissionsAndDispatchEvent( | 177 void SetupPermissionsAndDispatchEvent( |
178 scoped_ptr<FileDefinitionList> file_definition_list, | 178 scoped_ptr<FileDefinitionList> file_definition_list, |
(...skipping 13 matching lines...) Expand all Loading... |
192 const std::string action_id_; | 192 const std::string action_id_; |
193 file_tasks::FileTaskFinishedCallback done_; | 193 file_tasks::FileTaskFinishedCallback done_; |
194 base::WeakPtrFactory<FileBrowserHandlerExecutor> weak_ptr_factory_; | 194 base::WeakPtrFactory<FileBrowserHandlerExecutor> weak_ptr_factory_; |
195 | 195 |
196 DISALLOW_COPY_AND_ASSIGN(FileBrowserHandlerExecutor); | 196 DISALLOW_COPY_AND_ASSIGN(FileBrowserHandlerExecutor); |
197 }; | 197 }; |
198 | 198 |
199 // static | 199 // static |
200 scoped_ptr<FileDefinitionList> | 200 scoped_ptr<FileDefinitionList> |
201 FileBrowserHandlerExecutor::SetupFileAccessPermissions( | 201 FileBrowserHandlerExecutor::SetupFileAccessPermissions( |
202 scoped_refptr<fileapi::FileSystemContext> file_system_context_handler, | 202 scoped_refptr<storage::FileSystemContext> file_system_context_handler, |
203 const scoped_refptr<const Extension>& handler_extension, | 203 const scoped_refptr<const Extension>& handler_extension, |
204 const std::vector<FileSystemURL>& file_urls) { | 204 const std::vector<FileSystemURL>& file_urls) { |
205 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 205 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
206 DCHECK(handler_extension.get()); | 206 DCHECK(handler_extension.get()); |
207 | 207 |
208 fileapi::ExternalFileSystemBackend* backend = | 208 storage::ExternalFileSystemBackend* backend = |
209 file_system_context_handler->external_backend(); | 209 file_system_context_handler->external_backend(); |
210 | 210 |
211 scoped_ptr<FileDefinitionList> file_definition_list(new FileDefinitionList); | 211 scoped_ptr<FileDefinitionList> file_definition_list(new FileDefinitionList); |
212 for (size_t i = 0; i < file_urls.size(); ++i) { | 212 for (size_t i = 0; i < file_urls.size(); ++i) { |
213 const FileSystemURL& url = file_urls[i]; | 213 const FileSystemURL& url = file_urls[i]; |
214 | 214 |
215 // Check if this file system entry exists first. | 215 // Check if this file system entry exists first. |
216 base::File::Info file_info; | 216 base::File::Info file_info; |
217 | 217 |
218 base::FilePath local_path = url.path(); | 218 base::FilePath local_path = url.path(); |
219 base::FilePath virtual_path = url.virtual_path(); | 219 base::FilePath virtual_path = url.virtual_path(); |
220 | 220 |
221 const bool is_drive_file = url.type() == fileapi::kFileSystemTypeDrive; | 221 const bool is_drive_file = url.type() == storage::kFileSystemTypeDrive; |
222 DCHECK(!is_drive_file || drive::util::IsUnderDriveMountPoint(local_path)); | 222 DCHECK(!is_drive_file || drive::util::IsUnderDriveMountPoint(local_path)); |
223 | 223 |
224 const bool is_native_file = | 224 const bool is_native_file = |
225 url.type() == fileapi::kFileSystemTypeNativeLocal || | 225 url.type() == storage::kFileSystemTypeNativeLocal || |
226 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal; | 226 url.type() == storage::kFileSystemTypeRestrictedNativeLocal; |
227 | 227 |
228 // If the file is from a physical volume, actual file must be found. | 228 // If the file is from a physical volume, actual file must be found. |
229 if (is_native_file) { | 229 if (is_native_file) { |
230 if (!base::PathExists(local_path) || | 230 if (!base::PathExists(local_path) || |
231 base::IsLink(local_path) || | 231 base::IsLink(local_path) || |
232 !base::GetFileInfo(local_path, &file_info)) { | 232 !base::GetFileInfo(local_path, &file_info)) { |
233 continue; | 233 continue; |
234 } | 234 } |
235 } | 235 } |
236 | 236 |
(...skipping 26 matching lines...) Expand all Loading... |
263 FileBrowserHandlerExecutor::~FileBrowserHandlerExecutor() {} | 263 FileBrowserHandlerExecutor::~FileBrowserHandlerExecutor() {} |
264 | 264 |
265 void FileBrowserHandlerExecutor::Execute( | 265 void FileBrowserHandlerExecutor::Execute( |
266 const std::vector<FileSystemURL>& file_urls, | 266 const std::vector<FileSystemURL>& file_urls, |
267 const file_tasks::FileTaskFinishedCallback& done) { | 267 const file_tasks::FileTaskFinishedCallback& done) { |
268 done_ = done; | 268 done_ = done; |
269 | 269 |
270 // Get file system context for the extension to which onExecute event will be | 270 // Get file system context for the extension to which onExecute event will be |
271 // sent. The file access permissions will be granted to the extension in the | 271 // sent. The file access permissions will be granted to the extension in the |
272 // file system context for the files in |file_urls|. | 272 // file system context for the files in |file_urls|. |
273 scoped_refptr<fileapi::FileSystemContext> file_system_context( | 273 scoped_refptr<storage::FileSystemContext> file_system_context( |
274 util::GetFileSystemContextForExtensionId( | 274 util::GetFileSystemContextForExtensionId(profile_, extension_->id())); |
275 profile_, extension_->id())); | |
276 | 275 |
277 BrowserThread::PostTaskAndReplyWithResult( | 276 BrowserThread::PostTaskAndReplyWithResult( |
278 BrowserThread::FILE, | 277 BrowserThread::FILE, |
279 FROM_HERE, | 278 FROM_HERE, |
280 base::Bind(&SetupFileAccessPermissions, | 279 base::Bind(&SetupFileAccessPermissions, |
281 file_system_context, | 280 file_system_context, |
282 extension_, | 281 extension_, |
283 file_urls), | 282 file_urls), |
284 base::Bind(&FileBrowserHandlerExecutor::ExecuteAfterSetupFileAccess, | 283 base::Bind(&FileBrowserHandlerExecutor::ExecuteAfterSetupFileAccess, |
285 weak_ptr_factory_.GetWeakPtr())); | 284 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 if (common_handlers.empty()) | 516 if (common_handlers.empty()) |
518 return FileBrowserHandlerList(); | 517 return FileBrowserHandlerList(); |
519 } | 518 } |
520 } | 519 } |
521 | 520 |
522 return common_handlers; | 521 return common_handlers; |
523 } | 522 } |
524 | 523 |
525 } // namespace file_browser_handlers | 524 } // namespace file_browser_handlers |
526 } // namespace file_manager | 525 } // namespace file_manager |
OLD | NEW |