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 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 4 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
5 | 5 |
6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #include "webkit/plugins/webplugininfo.h" | 61 #include "webkit/plugins/webplugininfo.h" |
62 | 62 |
63 using base::DictionaryValue; | 63 using base::DictionaryValue; |
64 using base::ListValue; | 64 using base::ListValue; |
65 using content::BrowserContext; | 65 using content::BrowserContext; |
66 using content::BrowserThread; | 66 using content::BrowserThread; |
67 using content::PluginService; | 67 using content::PluginService; |
68 using content::UserMetricsAction; | 68 using content::UserMetricsAction; |
69 using extensions::Extension; | 69 using extensions::Extension; |
70 using file_handler_util::FileTaskExecutor; | 70 using file_handler_util::FileTaskExecutor; |
| 71 using fileapi::FileSystemURL; |
71 | 72 |
72 #define FILEBROWSER_EXTENSON_ID "hhaomjibdihmijegdhdafkllkbggdgoj" | 73 #define FILEBROWSER_EXTENSON_ID "hhaomjibdihmijegdhdafkllkbggdgoj" |
73 const char kFileBrowserDomain[] = FILEBROWSER_EXTENSON_ID; | 74 const char kFileBrowserDomain[] = FILEBROWSER_EXTENSON_ID; |
74 | 75 |
75 const char kFileBrowserGalleryTaskId[] = "gallery"; | 76 const char kFileBrowserGalleryTaskId[] = "gallery"; |
76 const char kFileBrowserMountArchiveTaskId[] = "mount-archive"; | 77 const char kFileBrowserMountArchiveTaskId[] = "mount-archive"; |
77 const char kFileBrowserWatchTaskId[] = "watch"; | 78 const char kFileBrowserWatchTaskId[] = "watch"; |
78 const char kFileBrowserPlayTaskId[] = "play"; | 79 const char kFileBrowserPlayTaskId[] = "play"; |
79 | 80 |
80 const char kVideoPlayerAppName[] = "videoplayer"; | 81 const char kVideoPlayerAppName[] = "videoplayer"; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 const GURL& url) { | 343 const GURL& url) { |
343 // We are executing the task on behalf of File Browser extension. | 344 // We are executing the task on behalf of File Browser extension. |
344 const GURL source_url(kBaseFileBrowserUrl); | 345 const GURL source_url(kBaseFileBrowserUrl); |
345 | 346 |
346 // If File Browser has not been open yet then it did not request access | 347 // If File Browser has not been open yet then it did not request access |
347 // to the file system. Do it now. | 348 // to the file system. Do it now. |
348 // File browser always runs in the site for its extension id, so that is the | 349 // File browser always runs in the site for its extension id, so that is the |
349 // site for which file access permissions should be granted. | 350 // site for which file access permissions should be granted. |
350 GURL site = extensions::ExtensionSystem::Get(profile)->extension_service()-> | 351 GURL site = extensions::ExtensionSystem::Get(profile)->extension_service()-> |
351 GetSiteForExtensionId(kFileBrowserDomain); | 352 GetSiteForExtensionId(kFileBrowserDomain); |
352 fileapi::ExternalFileSystemMountPointProvider* external_provider = | 353 fileapi::FileSystemContext* file_system_context = |
353 BrowserContext::GetStoragePartitionForSite(profile, site)-> | 354 BrowserContext::GetStoragePartitionForSite(profile, site)-> |
354 GetFileSystemContext()->external_provider(); | 355 GetFileSystemContext(); |
355 if (!external_provider) | 356 |
| 357 if (!file_system_context->external_provider()) |
356 return; | 358 return; |
357 external_provider->GrantFullAccessToExtension(source_url.host()); | 359 file_system_context->external_provider()->GrantFullAccessToExtension( |
| 360 source_url.host()); |
358 | 361 |
359 std::vector<GURL> urls; | 362 std::vector<FileSystemURL> urls; |
360 urls.push_back(url); | 363 urls.push_back(file_system_context->CrackURL(url)); |
361 scoped_refptr<FileTaskExecutor> executor = FileTaskExecutor::Create(profile, | 364 scoped_refptr<FileTaskExecutor> executor = FileTaskExecutor::Create(profile, |
362 source_url, kFileBrowserDomain, 0 /* no tab id */, extension_id, | 365 source_url, kFileBrowserDomain, 0 /* no tab id */, extension_id, |
363 file_handler_util::kTaskFile, action_id); | 366 file_handler_util::kTaskFile, action_id); |
364 executor->Execute(urls); | 367 executor->Execute(urls); |
365 } | 368 } |
366 | 369 |
367 void OpenFileBrowser(const FilePath& path, | 370 void OpenFileBrowser(const FilePath& path, |
368 TAB_REUSE_MODE mode, | 371 TAB_REUSE_MODE mode, |
369 const std::string& action_id) { | 372 const std::string& action_id) { |
370 content::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); | 373 content::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 435 } |
433 return NULL; | 436 return NULL; |
434 } | 437 } |
435 | 438 |
436 bool ExecuteDefaultHandler(Profile* profile, const FilePath& path) { | 439 bool ExecuteDefaultHandler(Profile* profile, const FilePath& path) { |
437 GURL url; | 440 GURL url; |
438 if (!ConvertFileToFileSystemUrl(profile, path, kFileBrowserDomain, &url)) | 441 if (!ConvertFileToFileSystemUrl(profile, path, kFileBrowserDomain, &url)) |
439 return false; | 442 return false; |
440 | 443 |
441 const FileBrowserHandler* handler; | 444 const FileBrowserHandler* handler; |
442 if (!file_handler_util::GetTaskForURL(profile, url, &handler)) | 445 if (!file_handler_util::GetTaskForURLAndPath(profile, url, path, &handler)) |
443 return false; | 446 return false; |
444 | 447 |
445 std::string extension_id = handler->extension_id(); | 448 std::string extension_id = handler->extension_id(); |
446 std::string action_id = handler->id(); | 449 std::string action_id = handler->id(); |
447 Browser* browser = chrome::FindLastActiveWithProfile(profile, | 450 Browser* browser = chrome::FindLastActiveWithProfile(profile, |
448 chrome::HOST_DESKTOP_TYPE_ASH); | 451 chrome::HOST_DESKTOP_TYPE_ASH); |
449 | 452 |
450 // If there is no browsers for the profile, bail out. Return true so warning | 453 // If there is no browsers for the profile, bail out. Return true so warning |
451 // about file type not being supported is not displayed. | 454 // about file type not being supported is not displayed. |
452 if (!browser) | 455 if (!browser) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 } | 543 } |
541 } | 544 } |
542 | 545 |
543 // Used to implement CheckIfDirectoryExists(). | 546 // Used to implement CheckIfDirectoryExists(). |
544 void CheckIfDirectoryExistsOnIOThread( | 547 void CheckIfDirectoryExistsOnIOThread( |
545 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 548 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
546 const GURL& url, | 549 const GURL& url, |
547 const fileapi::FileSystemOperation::StatusCallback& callback) { | 550 const fileapi::FileSystemOperation::StatusCallback& callback) { |
548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
549 | 552 |
550 fileapi::FileSystemURL file_system_url(url); | 553 fileapi::FileSystemURL file_system_url = file_system_context->CrackURL(url); |
551 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 554 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
552 fileapi::FileSystemOperation* operation = | 555 fileapi::FileSystemOperation* operation = |
553 file_system_context->CreateFileSystemOperation(file_system_url, &error); | 556 file_system_context->CreateFileSystemOperation(file_system_url, &error); |
554 if (error != base::PLATFORM_FILE_OK) { | 557 if (error != base::PLATFORM_FILE_OK) { |
555 callback.Run(error); | 558 callback.Run(error); |
556 return; | 559 return; |
557 } | 560 } |
558 operation->DirectoryExists(file_system_url, callback); | 561 operation->DirectoryExists(file_system_url, callback); |
559 } | 562 } |
560 | 563 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 for (google_apis::OperationProgressStatusList::const_iterator iter = | 933 for (google_apis::OperationProgressStatusList::const_iterator iter = |
931 list.begin(); | 934 list.begin(); |
932 iter != list.end(); ++iter) { | 935 iter != list.end(); ++iter) { |
933 result_list->Append( | 936 result_list->Append( |
934 ProgessStatusToDictionaryValue(profile, extension_id, *iter)); | 937 ProgessStatusToDictionaryValue(profile, extension_id, *iter)); |
935 } | 938 } |
936 return result_list.release(); | 939 return result_list.release(); |
937 } | 940 } |
938 | 941 |
939 } // namespace file_manager_util | 942 } // namespace file_manager_util |
OLD | NEW |