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/extensions/file_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
6 | 6 |
7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
8 #include <sys/statvfs.h> | 8 #include <sys/statvfs.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <utime.h> | 10 #include <utime.h> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 using extensions::app_file_handler_util::FindFileHandlersForMimeTypes; | 88 using extensions::app_file_handler_util::FindFileHandlersForMimeTypes; |
89 using chromeos::disks::DiskMountManager; | 89 using chromeos::disks::DiskMountManager; |
90 using content::BrowserContext; | 90 using content::BrowserContext; |
91 using content::BrowserThread; | 91 using content::BrowserThread; |
92 using content::ChildProcessSecurityPolicy; | 92 using content::ChildProcessSecurityPolicy; |
93 using content::SiteInstance; | 93 using content::SiteInstance; |
94 using content::WebContents; | 94 using content::WebContents; |
95 using extensions::Extension; | 95 using extensions::Extension; |
96 using extensions::ZipFileCreator; | 96 using extensions::ZipFileCreator; |
97 using file_handler_util::FileTaskExecutor; | 97 using file_handler_util::FileTaskExecutor; |
| 98 using fileapi::FileSystemURL; |
98 using google_apis::InstalledApp; | 99 using google_apis::InstalledApp; |
99 | 100 |
100 namespace { | 101 namespace { |
101 | 102 |
102 // Default icon path for drive docs. | 103 // Default icon path for drive docs. |
103 const char kDefaultIcon[] = "images/filetype_generic.png"; | 104 const char kDefaultIcon[] = "images/filetype_generic.png"; |
104 const int kPreferredIconSize = 16; | 105 const int kPreferredIconSize = 16; |
105 | 106 |
106 // Error messages. | 107 // Error messages. |
107 const char kFileError[] = "File error %d"; | 108 const char kFileError[] = "File error %d"; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 static_cast<uint64_t>(stat.f_bfree) * stat.f_frsize; | 321 static_cast<uint64_t>(stat.f_bfree) * stat.f_frsize; |
321 } | 322 } |
322 *total_size_kb = static_cast<size_t>(total_size_in_bytes / 1024); | 323 *total_size_kb = static_cast<size_t>(total_size_in_bytes / 1024); |
323 *remaining_size_kb = static_cast<size_t>(remaining_size_in_bytes / 1024); | 324 *remaining_size_kb = static_cast<size_t>(remaining_size_in_bytes / 1024); |
324 } | 325 } |
325 | 326 |
326 // Given a |url|, return the virtual FilePath associated with it. If the file | 327 // Given a |url|, return the virtual FilePath associated with it. If the file |
327 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. | 328 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. |
328 // | 329 // |
329 // Virtual paths will look like "Downloads/foo/bar.txt" or "drive/foo/bar.txt". | 330 // Virtual paths will look like "Downloads/foo/bar.txt" or "drive/foo/bar.txt". |
330 FilePath GetVirtualPathFromURL(const GURL& url) { | 331 FilePath GetVirtualPathFromURL(fileapi::FileSystemContext* context, |
331 fileapi::FileSystemURL filesystem_url(url); | 332 const GURL& url) { |
| 333 fileapi::FileSystemURL filesystem_url(context->CrackURL(url)); |
332 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) | 334 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) |
333 return FilePath(); | 335 return FilePath(); |
334 return filesystem_url.virtual_path(); | 336 return filesystem_url.virtual_path(); |
335 } | 337 } |
336 | 338 |
337 // Given a |url|, return the local FilePath associated with it. If the file | 339 // Given a |url|, return the local FilePath associated with it. If the file |
338 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. | 340 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. |
339 // | 341 // |
340 // Local paths will look like "/home/chronos/user/Downloads/foo/bar.txt" or | 342 // Local paths will look like "/home/chronos/user/Downloads/foo/bar.txt" or |
341 // "/special/drive/foo/bar.txt". | 343 // "/special/drive/foo/bar.txt". |
342 FilePath GetLocalPathFromURL(const GURL& url) { | 344 FilePath GetLocalPathFromURL(fileapi::FileSystemContext* context, |
343 fileapi::FileSystemURL filesystem_url(url); | 345 const GURL& url) { |
| 346 fileapi::FileSystemURL filesystem_url(context->CrackURL(url)); |
344 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) | 347 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) |
345 return FilePath(); | 348 return FilePath(); |
346 return filesystem_url.path(); | 349 return filesystem_url.path(); |
347 } | 350 } |
348 | 351 |
349 // Make a set of unique filename suffixes out of the list of file URLs. | 352 // Make a set of unique filename suffixes out of the list of file URLs. |
350 std::set<std::string> GetUniqueSuffixes(base::ListValue* file_url_list) { | 353 std::set<std::string> GetUniqueSuffixes(base::ListValue* file_url_list, |
| 354 fileapi::FileSystemContext* context) { |
351 std::set<std::string> suffixes; | 355 std::set<std::string> suffixes; |
352 for (size_t i = 0; i < file_url_list->GetSize(); ++i) { | 356 for (size_t i = 0; i < file_url_list->GetSize(); ++i) { |
353 std::string url; | 357 std::string url_str; |
354 if (!file_url_list->GetString(i, &url)) | 358 if (!file_url_list->GetString(i, &url_str)) |
355 return std::set<std::string>(); | 359 return std::set<std::string>(); |
356 FilePath path = GetVirtualPathFromURL(GURL(url)); | 360 FileSystemURL url = context->CrackURL(GURL(url_str)); |
357 if (path.empty()) | 361 if (!url.is_valid() || url.path().empty()) |
358 return std::set<std::string>(); | 362 return std::set<std::string>(); |
359 // We'll skip empty suffixes. | 363 // We'll skip empty suffixes. |
360 if (!path.Extension().empty()) | 364 if (!url.path().Extension().empty()) |
361 suffixes.insert(path.Extension()); | 365 suffixes.insert(url.path().Extension()); |
362 } | 366 } |
363 return suffixes; | 367 return suffixes; |
364 } | 368 } |
365 | 369 |
366 // Make a set of unique MIME types out of the list of MIME types. | 370 // Make a set of unique MIME types out of the list of MIME types. |
367 std::set<std::string> GetUniqueMimeTypes(base::ListValue* mime_type_list) { | 371 std::set<std::string> GetUniqueMimeTypes(base::ListValue* mime_type_list) { |
368 std::set<std::string> mime_types; | 372 std::set<std::string> mime_types; |
369 for (size_t i = 0; i < mime_type_list->GetSize(); ++i) { | 373 for (size_t i = 0; i < mime_type_list->GetSize(); ++i) { |
370 std::string mime_type; | 374 std::string mime_type; |
371 if (!mime_type_list->GetString(i, &mime_type)) | 375 if (!mime_type_list->GetString(i, &mime_type)) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 if (!entry_proto.content_url().empty()) | 438 if (!entry_proto.content_url().empty()) |
435 property_dict->SetString("contentUrl", entry_proto.content_url()); | 439 property_dict->SetString("contentUrl", entry_proto.content_url()); |
436 | 440 |
437 property_dict->SetBoolean("isHosted", | 441 property_dict->SetBoolean("isHosted", |
438 file_specific_info.is_hosted_document()); | 442 file_specific_info.is_hosted_document()); |
439 | 443 |
440 property_dict->SetString("contentMimeType", | 444 property_dict->SetString("contentMimeType", |
441 file_specific_info.content_mime_type()); | 445 file_specific_info.content_mime_type()); |
442 } | 446 } |
443 | 447 |
| 448 void GetMimeTypesForFileURLs(const std::vector<FilePath>& file_paths, |
| 449 std::set<std::string>* mime_types) { |
| 450 for (std::vector<FilePath>::const_iterator iter = file_paths.begin(); |
| 451 iter != file_paths.end(); ++iter) { |
| 452 const FilePath::StringType file_extension = |
| 453 StringToLowerASCII(iter->Extension()); |
| 454 |
| 455 // TODO(thorogood): Rearchitect this call so it can run on the File thread; |
| 456 // GetMimeTypeFromFile requires this on Linux. Right now, we use |
| 457 // Chrome-level knowledge only. |
| 458 std::string mime_type; |
| 459 if (file_extension.empty() || |
| 460 !net::GetWellKnownMimeTypeFromExtension(file_extension.substr(1), |
| 461 &mime_type)) { |
| 462 // If the file doesn't have an extension or its mime-type cannot be |
| 463 // determined, then indicate that it has the empty mime-type. This will |
| 464 // only be matched if the Web Intents accepts "*" or "*/*". |
| 465 mime_types->insert(""); |
| 466 } else { |
| 467 mime_types->insert(mime_type); |
| 468 } |
| 469 } |
| 470 } |
| 471 |
444 } // namespace | 472 } // namespace |
445 | 473 |
446 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { | 474 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { |
447 public: | 475 public: |
448 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 476 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( |
449 RequestLocalFileSystemFunction* function, | 477 RequestLocalFileSystemFunction* function, |
450 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 478 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
451 int child_id, | 479 int child_id, |
452 scoped_refptr<const Extension> extension) { | 480 scoped_refptr<const Extension> extension) { |
453 return base::Bind( | 481 return base::Bind( |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 695 |
668 bool FileWatchBrowserFunctionBase::RunImpl() { | 696 bool FileWatchBrowserFunctionBase::RunImpl() { |
669 if (!render_view_host() || !render_view_host()->GetProcess()) | 697 if (!render_view_host() || !render_view_host()->GetProcess()) |
670 return false; | 698 return false; |
671 | 699 |
672 // First param is url of a file to watch. | 700 // First param is url of a file to watch. |
673 std::string url; | 701 std::string url; |
674 if (!args_->GetString(0, &url) || url.empty()) | 702 if (!args_->GetString(0, &url) || url.empty()) |
675 return false; | 703 return false; |
676 | 704 |
677 GURL file_watch_url(url); | 705 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 706 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 707 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 708 GetFileSystemContext(); |
| 709 |
| 710 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url)); |
678 BrowserThread::PostTask( | 711 BrowserThread::PostTask( |
679 BrowserThread::FILE, FROM_HERE, | 712 BrowserThread::FILE, FROM_HERE, |
680 base::Bind( | 713 base::Bind( |
681 &FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread, | 714 &FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread, |
682 this, | 715 this, |
683 FileBrowserPrivateAPI::Get(profile_)->event_router(), | 716 FileBrowserPrivateAPI::Get(profile_)->event_router(), |
684 file_watch_url, | 717 file_watch_url, |
685 extension_id())); | 718 extension_id())); |
686 | 719 |
687 return true; | 720 return true; |
688 } | 721 } |
689 | 722 |
690 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread( | 723 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread( |
691 scoped_refptr<FileBrowserEventRouter> event_router, | 724 scoped_refptr<FileBrowserEventRouter> event_router, |
692 const GURL& file_url, const std::string& extension_id) { | 725 const FileSystemURL& file_url, const std::string& extension_id) { |
693 FilePath local_path = GetLocalPathFromURL(file_url); | 726 FilePath local_path = file_url.path(); |
694 FilePath virtual_path = GetVirtualPathFromURL(file_url); | 727 FilePath virtual_path = file_url.virtual_path(); |
695 bool result = !local_path.empty() && PerformFileWatchOperation( | 728 bool result = !local_path.empty() && PerformFileWatchOperation( |
696 event_router, local_path, virtual_path, extension_id); | 729 event_router, local_path, virtual_path, extension_id); |
697 | 730 |
698 BrowserThread::PostTask( | 731 BrowserThread::PostTask( |
699 BrowserThread::UI, FROM_HERE, | 732 BrowserThread::UI, FROM_HERE, |
700 base::Bind( | 733 base::Bind( |
701 &FileWatchBrowserFunctionBase::RespondOnUIThread, this, result)); | 734 &FileWatchBrowserFunctionBase::RespondOnUIThread, this, result)); |
702 } | 735 } |
703 | 736 |
704 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( | 737 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 std::set<std::string> default_tasks; | 902 std::set<std::string> default_tasks; |
870 FindDefaultDriveTasks(file_info_list, available_tasks, &default_tasks); | 903 FindDefaultDriveTasks(file_info_list, available_tasks, &default_tasks); |
871 CreateDriveTasks(registry, app_info, available_tasks, default_tasks, | 904 CreateDriveTasks(registry, app_info, available_tasks, default_tasks, |
872 result_list, default_already_set); | 905 result_list, default_already_set); |
873 | 906 |
874 // We own the pointers in |app_info|, so we need to delete them. | 907 // We own the pointers in |app_info|, so we need to delete them. |
875 STLDeleteContainerPairSecondPointers(app_info.begin(), app_info.end()); | 908 STLDeleteContainerPairSecondPointers(app_info.begin(), app_info.end()); |
876 return true; | 909 return true; |
877 } | 910 } |
878 | 911 |
879 static void GetMimeTypesForFileURLs(const std::vector<GURL>& file_urls, | |
880 std::set<std::string>* mime_types) { | |
881 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); | |
882 iter != file_urls.end(); ++iter) { | |
883 const FilePath file = FilePath(GURL(iter->spec()).ExtractFileName()); | |
884 const FilePath::StringType file_extension = | |
885 StringToLowerASCII(file.Extension()); | |
886 | |
887 // TODO(thorogood): Rearchitect this call so it can run on the File thread; | |
888 // GetMimeTypeFromFile requires this on Linux. Right now, we use | |
889 // Chrome-level knowledge only. | |
890 std::string mime_type; | |
891 if (file_extension.empty() || !net::GetWellKnownMimeTypeFromExtension( | |
892 file_extension.substr(1), &mime_type)) { | |
893 // If the file doesn't have an extension or its mime-type cannot be | |
894 // determined, then indicate that it has the empty mime-type. This will | |
895 // only be matched if the Web Intents accepts "*" or "*/*". | |
896 mime_types->insert(""); | |
897 } else { | |
898 mime_types->insert(mime_type); | |
899 } | |
900 } | |
901 } | |
902 | |
903 bool GetFileTasksFileBrowserFunction::FindAppTasks( | 912 bool GetFileTasksFileBrowserFunction::FindAppTasks( |
904 const std::vector<GURL>& file_urls, | 913 const std::vector<FilePath>& file_paths, |
905 ListValue* result_list) { | 914 ListValue* result_list) { |
906 DCHECK(!file_urls.empty()); | 915 DCHECK(!file_paths.empty()); |
907 ExtensionService* service = profile_->GetExtensionService(); | 916 ExtensionService* service = profile_->GetExtensionService(); |
908 if (!service) | 917 if (!service) |
909 return false; | 918 return false; |
910 | 919 |
911 std::set<std::string> mime_types; | 920 std::set<std::string> mime_types; |
912 GetMimeTypesForFileURLs(file_urls, &mime_types); | 921 GetMimeTypesForFileURLs(file_paths, &mime_types); |
913 | 922 |
914 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | 923 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); |
915 iter != service->extensions()->end(); | 924 iter != service->extensions()->end(); |
916 ++iter) { | 925 ++iter) { |
917 const Extension* extension = *iter; | 926 const Extension* extension = *iter; |
918 | 927 |
919 // We don't support using hosted apps to open files. | 928 // We don't support using hosted apps to open files. |
920 if (!extension->is_platform_app()) | 929 if (!extension->is_platform_app()) |
921 continue; | 930 continue; |
922 | 931 |
(...skipping 28 matching lines...) Expand all Loading... |
951 result_list->Append(task); | 960 result_list->Append(task); |
952 } | 961 } |
953 } | 962 } |
954 | 963 |
955 return true; | 964 return true; |
956 } | 965 } |
957 | 966 |
958 // Find Web Intent platform apps that support the View task, and add them to | 967 // Find Web Intent platform apps that support the View task, and add them to |
959 // the |result_list|. These will be marked as kTaskWebIntent. | 968 // the |result_list|. These will be marked as kTaskWebIntent. |
960 bool GetFileTasksFileBrowserFunction::FindWebIntentTasks( | 969 bool GetFileTasksFileBrowserFunction::FindWebIntentTasks( |
961 const std::vector<GURL>& file_urls, | 970 const std::vector<FilePath>& file_paths, |
962 ListValue* result_list) { | 971 ListValue* result_list) { |
963 DCHECK(!file_urls.empty()); | 972 DCHECK(!file_paths.empty()); |
964 ExtensionService* service = profile_->GetExtensionService(); | 973 ExtensionService* service = profile_->GetExtensionService(); |
965 if (!service) | 974 if (!service) |
966 return false; | 975 return false; |
967 | 976 |
968 std::set<std::string> mime_types; | 977 std::set<std::string> mime_types; |
969 GetMimeTypesForFileURLs(file_urls, &mime_types); | 978 GetMimeTypesForFileURLs(file_paths, &mime_types); |
970 | 979 |
971 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | 980 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); |
972 iter != service->extensions()->end(); | 981 iter != service->extensions()->end(); |
973 ++iter) { | 982 ++iter) { |
974 const Extension* extension = *iter; | 983 const Extension* extension = *iter; |
975 | 984 |
976 // We don't support using hosted apps to open files. | 985 // We don't support using hosted apps to open files. |
977 if (!extension->is_platform_app()) | 986 if (!extension->is_platform_app()) |
978 continue; | 987 continue; |
979 | 988 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 // Second argument is the list of mime types of each of the files in the list. | 1025 // Second argument is the list of mime types of each of the files in the list. |
1017 ListValue* mime_types_list = NULL; | 1026 ListValue* mime_types_list = NULL; |
1018 if (!args_->GetList(1, &mime_types_list)) | 1027 if (!args_->GetList(1, &mime_types_list)) |
1019 return false; | 1028 return false; |
1020 | 1029 |
1021 // MIME types can either be empty, or there needs to be one for each file. | 1030 // MIME types can either be empty, or there needs to be one for each file. |
1022 if (mime_types_list->GetSize() != files_list->GetSize() && | 1031 if (mime_types_list->GetSize() != files_list->GetSize() && |
1023 mime_types_list->GetSize() != 0) | 1032 mime_types_list->GetSize() != 0) |
1024 return false; | 1033 return false; |
1025 | 1034 |
| 1035 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1036 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1037 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1038 GetFileSystemContext(); |
| 1039 |
1026 // Collect all the URLs, convert them to GURLs, and crack all the urls into | 1040 // Collect all the URLs, convert them to GURLs, and crack all the urls into |
1027 // file paths. | 1041 // file paths. |
1028 FileInfoList info_list; | 1042 FileInfoList info_list; |
1029 std::vector<GURL> file_urls; | 1043 std::vector<GURL> file_urls; |
| 1044 std::vector<FilePath> file_paths; |
1030 for (size_t i = 0; i < files_list->GetSize(); ++i) { | 1045 for (size_t i = 0; i < files_list->GetSize(); ++i) { |
1031 FileInfo info; | 1046 FileInfo info; |
1032 std::string file_url; | 1047 std::string file_url_str; |
1033 if (!files_list->GetString(i, &file_url)) | 1048 if (!files_list->GetString(i, &file_url_str)) |
1034 return false; | 1049 return false; |
1035 info.file_url = GURL(file_url); | 1050 |
1036 file_urls.push_back(info.file_url); | |
1037 if (mime_types_list->GetSize() != 0 && | 1051 if (mime_types_list->GetSize() != 0 && |
1038 !mime_types_list->GetString(i, &info.mime_type)) | 1052 !mime_types_list->GetString(i, &info.mime_type)) |
1039 return false; | 1053 return false; |
1040 fileapi::FileSystemURL file_system_url(info.file_url); | 1054 |
1041 if (chromeos::CrosMountPointProvider::CanHandleURL(file_system_url)) { | 1055 GURL file_url(file_url_str); |
1042 info.file_path = file_system_url.path(); | 1056 fileapi::FileSystemURL file_system_url( |
1043 } | 1057 file_system_context->CrackURL(file_url)); |
| 1058 if (!chromeos::CrosMountPointProvider::CanHandleURL(file_system_url)) |
| 1059 continue; |
| 1060 |
| 1061 file_urls.push_back(file_url); |
| 1062 file_paths.push_back(file_system_url.path()); |
| 1063 |
| 1064 info.file_url = file_url; |
| 1065 info.file_path = file_system_url.path(); |
1044 info_list.push_back(info); | 1066 info_list.push_back(info); |
1045 } | 1067 } |
1046 | 1068 |
1047 ListValue* result_list = new ListValue(); | 1069 ListValue* result_list = new ListValue(); |
1048 SetResult(result_list); | 1070 SetResult(result_list); |
1049 | 1071 |
1050 // Find the Drive apps first, because we want them to take precedence | 1072 // Find the Drive apps first, because we want them to take precedence |
1051 // when setting the default app. | 1073 // when setting the default app. |
1052 bool default_already_set = false; | 1074 bool default_already_set = false; |
1053 if (!FindDriveAppTasks(info_list, result_list, &default_already_set)) | 1075 if (!FindDriveAppTasks(info_list, result_list, &default_already_set)) |
1054 return false; | 1076 return false; |
1055 | 1077 |
1056 // Take the union of Drive and extension tasks: Because any Drive tasks we | 1078 // Take the union of Drive and extension tasks: Because any Drive tasks we |
1057 // found must apply to all of the files (intersection), and because the same | 1079 // found must apply to all of the files (intersection), and because the same |
1058 // is true of the extensions, we simply take the union of two lists by adding | 1080 // is true of the extensions, we simply take the union of two lists by adding |
1059 // the extension tasks to the Drive task list. We know there aren't duplicates | 1081 // the extension tasks to the Drive task list. We know there aren't duplicates |
1060 // because they're entirely different kinds of tasks, but there could be both | 1082 // because they're entirely different kinds of tasks, but there could be both |
1061 // kinds of tasks for a file type (an image file, for instance). | 1083 // kinds of tasks for a file type (an image file, for instance). |
1062 std::set<const FileBrowserHandler*> common_tasks; | 1084 std::set<const FileBrowserHandler*> common_tasks; |
1063 std::set<const FileBrowserHandler*> default_tasks; | 1085 std::set<const FileBrowserHandler*> default_tasks; |
1064 if (!file_handler_util::FindCommonTasks(profile_, file_urls, &common_tasks)) | 1086 if (!file_handler_util::FindCommonTasks(profile_, file_urls, &common_tasks)) |
1065 return false; | 1087 return false; |
1066 file_handler_util::FindDefaultTasks(profile_, file_urls, | 1088 file_handler_util::FindDefaultTasks(profile_, file_paths, |
1067 common_tasks, &default_tasks); | 1089 common_tasks, &default_tasks); |
1068 | 1090 |
1069 ExtensionService* service = | 1091 ExtensionService* service = |
1070 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 1092 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
1071 for (std::set<const FileBrowserHandler*>::const_iterator iter = | 1093 for (std::set<const FileBrowserHandler*>::const_iterator iter = |
1072 common_tasks.begin(); | 1094 common_tasks.begin(); |
1073 iter != common_tasks.end(); | 1095 iter != common_tasks.end(); |
1074 ++iter) { | 1096 ++iter) { |
1075 const FileBrowserHandler* handler = *iter; | 1097 const FileBrowserHandler* handler = *iter; |
1076 const std::string extension_id = handler->extension_id(); | 1098 const std::string extension_id = handler->extension_id(); |
(...skipping 22 matching lines...) Expand all Loading... |
1099 task->SetBoolean("isDefault", false); | 1121 task->SetBoolean("isDefault", false); |
1100 } | 1122 } |
1101 | 1123 |
1102 result_list->Append(task); | 1124 result_list->Append(task); |
1103 } | 1125 } |
1104 | 1126 |
1105 // Take the union of platform app file handlers, Web Intents that platform | 1127 // Take the union of platform app file handlers, Web Intents that platform |
1106 // apps may accept, and all previous Drive and extension tasks. As above, we | 1128 // apps may accept, and all previous Drive and extension tasks. As above, we |
1107 // know there aren't duplicates because they're entirely different kinds of | 1129 // know there aren't duplicates because they're entirely different kinds of |
1108 // tasks. | 1130 // tasks. |
1109 if (!FindAppTasks(file_urls, result_list)) | 1131 if (!FindAppTasks(file_paths, result_list)) |
1110 return false; | 1132 return false; |
1111 | 1133 |
1112 // TODO(benwells): remove the web intents tasks once we no longer support | 1134 // TODO(benwells): remove the web intents tasks once we no longer support |
1113 // them. | 1135 // them. |
1114 if (!FindWebIntentTasks(file_urls, result_list)) | 1136 if (!FindWebIntentTasks(file_paths, result_list)) |
1115 return false; | 1137 return false; |
1116 | 1138 |
1117 if (VLOG_IS_ON(1)) { | 1139 if (VLOG_IS_ON(1)) { |
1118 std::string result_json; | 1140 std::string result_json; |
1119 base::JSONWriter::WriteWithOptions( | 1141 base::JSONWriter::WriteWithOptions( |
1120 result_list, | 1142 result_list, |
1121 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | | 1143 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | |
1122 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1144 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
1123 &result_json); | 1145 &result_json); |
1124 VLOG(1) << "GetFileTasks result:\n" << result_json; | 1146 VLOG(1) << "GetFileTasks result:\n" << result_json; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 std::string action_id; | 1178 std::string action_id; |
1157 if (!file_handler_util::CrackTaskID( | 1179 if (!file_handler_util::CrackTaskID( |
1158 task_id, &extension_id, &task_type, &action_id)) { | 1180 task_id, &extension_id, &task_type, &action_id)) { |
1159 LOG(WARNING) << "Invalid task " << task_id; | 1181 LOG(WARNING) << "Invalid task " << task_id; |
1160 return false; | 1182 return false; |
1161 } | 1183 } |
1162 | 1184 |
1163 if (!files_list->GetSize()) | 1185 if (!files_list->GetSize()) |
1164 return true; | 1186 return true; |
1165 | 1187 |
1166 std::vector<GURL> file_urls; | 1188 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1189 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1190 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1191 GetFileSystemContext(); |
| 1192 |
| 1193 std::vector<FileSystemURL> file_urls; |
1167 for (size_t i = 0; i < files_list->GetSize(); i++) { | 1194 for (size_t i = 0; i < files_list->GetSize(); i++) { |
1168 std::string origin_file_url; | 1195 std::string file_url_str; |
1169 if (!files_list->GetString(i, &origin_file_url)) { | 1196 if (!files_list->GetString(i, &file_url_str)) { |
1170 error_ = kInvalidFileUrl; | 1197 error_ = kInvalidFileUrl; |
1171 return false; | 1198 return false; |
1172 } | 1199 } |
1173 file_urls.push_back(GURL(origin_file_url)); | 1200 FileSystemURL url = file_system_context->CrackURL(GURL(file_url_str)); |
| 1201 if (!chromeos::CrosMountPointProvider::CanHandleURL(url)) { |
| 1202 error_ = kInvalidFileUrl; |
| 1203 return false; |
| 1204 } |
| 1205 file_urls.push_back(url); |
1174 } | 1206 } |
1175 | 1207 |
1176 WebContents* web_contents = | 1208 WebContents* web_contents = |
1177 dispatcher()->delegate()->GetAssociatedWebContents(); | 1209 dispatcher()->delegate()->GetAssociatedWebContents(); |
1178 int32 tab_id = 0; | 1210 int32 tab_id = 0; |
1179 if (web_contents) | 1211 if (web_contents) |
1180 tab_id = ExtensionTabUtil::GetTabId(web_contents); | 1212 tab_id = ExtensionTabUtil::GetTabId(web_contents); |
1181 | 1213 |
1182 scoped_refptr<FileTaskExecutor> executor( | 1214 scoped_refptr<FileTaskExecutor> executor( |
1183 FileTaskExecutor::Create(profile(), | 1215 FileTaskExecutor::Create(profile(), |
(...skipping 19 matching lines...) Expand all Loading... |
1203 | 1235 |
1204 bool SetDefaultTaskFileBrowserFunction::RunImpl() { | 1236 bool SetDefaultTaskFileBrowserFunction::RunImpl() { |
1205 // First param is task id that was to the extension with setDefaultTask call. | 1237 // First param is task id that was to the extension with setDefaultTask call. |
1206 std::string task_id; | 1238 std::string task_id; |
1207 if (!args_->GetString(0, &task_id) || !task_id.size()) | 1239 if (!args_->GetString(0, &task_id) || !task_id.size()) |
1208 return false; | 1240 return false; |
1209 | 1241 |
1210 base::ListValue* file_url_list; | 1242 base::ListValue* file_url_list; |
1211 if (!args_->GetList(1, &file_url_list)) | 1243 if (!args_->GetList(1, &file_url_list)) |
1212 return false; | 1244 return false; |
1213 std::set<std::string> suffixes = GetUniqueSuffixes(file_url_list); | 1245 |
| 1246 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1247 scoped_refptr<fileapi::FileSystemContext> context = |
| 1248 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1249 GetFileSystemContext(); |
| 1250 |
| 1251 std::set<std::string> suffixes = GetUniqueSuffixes(file_url_list, context); |
1214 | 1252 |
1215 // MIME types are an optional parameter. | 1253 // MIME types are an optional parameter. |
1216 base::ListValue* mime_type_list; | 1254 base::ListValue* mime_type_list; |
1217 std::set<std::string> mime_types; | 1255 std::set<std::string> mime_types; |
1218 if (args_->GetList(2, &mime_type_list) && !mime_type_list->empty()) { | 1256 if (args_->GetList(2, &mime_type_list) && !mime_type_list->empty()) { |
1219 if (mime_type_list->GetSize() != file_url_list->GetSize()) | 1257 if (mime_type_list->GetSize() != file_url_list->GetSize()) |
1220 return false; | 1258 return false; |
1221 mime_types = GetUniqueMimeTypes(mime_type_list); | 1259 mime_types = GetUniqueMimeTypes(mime_type_list); |
1222 } | 1260 } |
1223 | 1261 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 net::UnescapeURLComponent(parameters[i].second, | 1362 net::UnescapeURLComponent(parameters[i].second, |
1325 kUnescapeRuleForQueryParameters); | 1363 kUnescapeRuleForQueryParameters); |
1326 local_path = FilePath::FromUTF8Unsafe(unescaped_value); | 1364 local_path = FilePath::FromUTF8Unsafe(unescaped_value); |
1327 break; | 1365 break; |
1328 } | 1366 } |
1329 } | 1367 } |
1330 } | 1368 } |
1331 } | 1369 } |
1332 | 1370 |
1333 // Extract the path from |file_url|. | 1371 // Extract the path from |file_url|. |
1334 fileapi::FileSystemURL url(file_url); | 1372 fileapi::FileSystemURL url(file_system_context->CrackURL(file_url)); |
1335 if (!chromeos::CrosMountPointProvider::CanHandleURL(url)) | 1373 if (!chromeos::CrosMountPointProvider::CanHandleURL(url)) |
1336 continue; | 1374 continue; |
1337 | 1375 |
1338 if (!url.path().empty()) { | 1376 if (!url.path().empty()) { |
1339 DVLOG(1) << "Selected: file path: " << url.path().value() | 1377 DVLOG(1) << "Selected: file path: " << url.path().value() |
1340 << " local path: " << local_path.value(); | 1378 << " local path: " << local_path.value(); |
1341 selected_files.push_back( | 1379 selected_files.push_back( |
1342 ui::SelectedFileInfo(url.path(), local_path)); | 1380 ui::SelectedFileInfo(url.path(), local_path)); |
1343 } | 1381 } |
1344 } | 1382 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 return false; | 1426 return false; |
1389 } | 1427 } |
1390 | 1428 |
1391 ListValue* path_list = NULL; | 1429 ListValue* path_list = NULL; |
1392 args_->GetList(0, &path_list); | 1430 args_->GetList(0, &path_list); |
1393 DCHECK(path_list); | 1431 DCHECK(path_list); |
1394 | 1432 |
1395 std::string internal_task_id; | 1433 std::string internal_task_id; |
1396 args_->GetString(1, &internal_task_id); | 1434 args_->GetString(1, &internal_task_id); |
1397 | 1435 |
| 1436 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1437 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1438 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1439 GetFileSystemContext(); |
| 1440 |
1398 std::vector<FilePath> files; | 1441 std::vector<FilePath> files; |
1399 for (size_t i = 0; i < path_list->GetSize(); ++i) { | 1442 for (size_t i = 0; i < path_list->GetSize(); ++i) { |
1400 std::string url_as_string; | 1443 std::string url_as_string; |
1401 path_list->GetString(i, &url_as_string); | 1444 path_list->GetString(i, &url_as_string); |
1402 FilePath path = GetLocalPathFromURL(GURL(url_as_string)); | 1445 FilePath path = GetLocalPathFromURL(file_system_context, |
| 1446 GURL(url_as_string)); |
1403 if (path.empty()) | 1447 if (path.empty()) |
1404 return false; | 1448 return false; |
1405 files.push_back(path); | 1449 files.push_back(path); |
1406 } | 1450 } |
1407 | 1451 |
1408 Browser* browser = GetCurrentBrowser(); | 1452 Browser* browser = GetCurrentBrowser(); |
1409 bool success = browser; | 1453 bool success = browser; |
1410 | 1454 |
1411 if (browser) { | 1455 if (browser) { |
1412 for (size_t i = 0; i < files.size(); ++i) { | 1456 for (size_t i = 0; i < files.size(); ++i) { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 file_url, | 1709 file_url, |
1666 strtoul(timestamp.c_str(), NULL, 0))); | 1710 strtoul(timestamp.c_str(), NULL, 0))); |
1667 | 1711 |
1668 return true; | 1712 return true; |
1669 } | 1713 } |
1670 | 1714 |
1671 void SetLastModifiedFunction::RunOperationOnFileThread(std::string file_url, | 1715 void SetLastModifiedFunction::RunOperationOnFileThread(std::string file_url, |
1672 time_t timestamp) { | 1716 time_t timestamp) { |
1673 bool succeeded = false; | 1717 bool succeeded = false; |
1674 | 1718 |
1675 FilePath local_path = GetLocalPathFromURL(GURL(file_url)); | 1719 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1720 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1721 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1722 GetFileSystemContext(); |
| 1723 |
| 1724 FilePath local_path = GetLocalPathFromURL(file_system_context, |
| 1725 GURL(file_url)); |
1676 if (!local_path.empty()) { | 1726 if (!local_path.empty()) { |
1677 struct stat sb; | 1727 struct stat sb; |
1678 if (stat(local_path.value().c_str(), &sb) == 0) { | 1728 if (stat(local_path.value().c_str(), &sb) == 0) { |
1679 struct utimbuf times; | 1729 struct utimbuf times; |
1680 times.actime = sb.st_atime; | 1730 times.actime = sb.st_atime; |
1681 times.modtime = timestamp; | 1731 times.modtime = timestamp; |
1682 | 1732 |
1683 if (utime(local_path.value().c_str(), ×) == 0) | 1733 if (utime(local_path.value().c_str(), ×) == 0) |
1684 succeeded = true; | 1734 succeeded = true; |
1685 } | 1735 } |
(...skipping 15 matching lines...) Expand all Loading... |
1701 | 1751 |
1702 bool GetSizeStatsFunction::RunImpl() { | 1752 bool GetSizeStatsFunction::RunImpl() { |
1703 if (args_->GetSize() != 1) { | 1753 if (args_->GetSize() != 1) { |
1704 return false; | 1754 return false; |
1705 } | 1755 } |
1706 | 1756 |
1707 std::string mount_url; | 1757 std::string mount_url; |
1708 if (!args_->GetString(0, &mount_url)) | 1758 if (!args_->GetString(0, &mount_url)) |
1709 return false; | 1759 return false; |
1710 | 1760 |
1711 FilePath file_path = GetLocalPathFromURL(GURL(mount_url)); | 1761 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1762 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1763 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1764 GetFileSystemContext(); |
| 1765 |
| 1766 FilePath file_path = GetLocalPathFromURL(file_system_context, |
| 1767 GURL(mount_url)); |
1712 if (file_path.empty()) | 1768 if (file_path.empty()) |
1713 return false; | 1769 return false; |
1714 | 1770 |
1715 if (file_path == drive::util::GetDriveMountPointPath()) { | 1771 if (file_path == drive::util::GetDriveMountPointPath()) { |
1716 drive::DriveSystemService* system_service = | 1772 drive::DriveSystemService* system_service = |
1717 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 1773 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
1718 // |system_service| is NULL if Drive is disabled. | 1774 // |system_service| is NULL if Drive is disabled. |
1719 if (!system_service) { | 1775 if (!system_service) { |
1720 // If stats couldn't be gotten for drive, result should be left | 1776 // If stats couldn't be gotten for drive, result should be left |
1721 // undefined. See comments in GetDriveAvailableSpaceCallback(). | 1777 // undefined. See comments in GetDriveAvailableSpaceCallback(). |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 if (args_->GetSize() != 1) { | 1853 if (args_->GetSize() != 1) { |
1798 return false; | 1854 return false; |
1799 } | 1855 } |
1800 | 1856 |
1801 std::string volume_file_url; | 1857 std::string volume_file_url; |
1802 if (!args_->GetString(0, &volume_file_url)) { | 1858 if (!args_->GetString(0, &volume_file_url)) { |
1803 NOTREACHED(); | 1859 NOTREACHED(); |
1804 return false; | 1860 return false; |
1805 } | 1861 } |
1806 | 1862 |
1807 FilePath file_path = GetLocalPathFromURL(GURL(volume_file_url)); | 1863 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1864 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1865 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1866 GetFileSystemContext(); |
| 1867 |
| 1868 FilePath file_path = GetLocalPathFromURL(file_system_context, |
| 1869 GURL(volume_file_url)); |
1808 if (file_path.empty()) | 1870 if (file_path.empty()) |
1809 return false; | 1871 return false; |
1810 | 1872 |
1811 DiskMountManager::GetInstance()->FormatMountedDevice(file_path.value()); | 1873 DiskMountManager::GetInstance()->FormatMountedDevice(file_path.value()); |
1812 SendResponse(true); | 1874 SendResponse(true); |
1813 return true; | 1875 return true; |
1814 } | 1876 } |
1815 | 1877 |
1816 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { | 1878 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { |
1817 } | 1879 } |
1818 | 1880 |
1819 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { | 1881 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { |
1820 } | 1882 } |
1821 | 1883 |
1822 bool GetVolumeMetadataFunction::RunImpl() { | 1884 bool GetVolumeMetadataFunction::RunImpl() { |
1823 if (args_->GetSize() != 1) { | 1885 if (args_->GetSize() != 1) { |
1824 error_ = "Invalid argument count"; | 1886 error_ = "Invalid argument count"; |
1825 return false; | 1887 return false; |
1826 } | 1888 } |
1827 | 1889 |
1828 std::string volume_mount_url; | 1890 std::string volume_mount_url; |
1829 if (!args_->GetString(0, &volume_mount_url)) { | 1891 if (!args_->GetString(0, &volume_mount_url)) { |
1830 NOTREACHED(); | 1892 NOTREACHED(); |
1831 return false; | 1893 return false; |
1832 } | 1894 } |
1833 | 1895 |
1834 FilePath file_path = GetLocalPathFromURL(GURL(volume_mount_url)); | 1896 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1897 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1898 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1899 GetFileSystemContext(); |
| 1900 |
| 1901 FilePath file_path = GetLocalPathFromURL(file_system_context, |
| 1902 GURL(volume_mount_url)); |
1835 if (file_path.empty()) { | 1903 if (file_path.empty()) { |
1836 error_ = "Invalid mount path."; | 1904 error_ = "Invalid mount path."; |
1837 return false; | 1905 return false; |
1838 } | 1906 } |
1839 | 1907 |
1840 results_.reset(); | 1908 results_.reset(); |
1841 | 1909 |
1842 const DiskMountManager::Disk* volume = GetVolumeAsDisk(file_path.value()); | 1910 const DiskMountManager::Disk* volume = GetVolumeAsDisk(file_path.value()); |
1843 if (volume) { | 1911 if (volume) { |
1844 DictionaryValue* volume_info = | 1912 DictionaryValue* volume_info = |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2273 } | 2341 } |
2274 | 2342 |
2275 void GetDriveFilePropertiesFunction::GetNextFileProperties() { | 2343 void GetDriveFilePropertiesFunction::GetNextFileProperties() { |
2276 if (current_index_ >= path_list_->GetSize()) { | 2344 if (current_index_ >= path_list_->GetSize()) { |
2277 // Exit of asynchronous look and return the result. | 2345 // Exit of asynchronous look and return the result. |
2278 SetResult(file_properties_.release()); | 2346 SetResult(file_properties_.release()); |
2279 SendResponse(true); | 2347 SendResponse(true); |
2280 return; | 2348 return; |
2281 } | 2349 } |
2282 | 2350 |
| 2351 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 2352 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 2353 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 2354 GetFileSystemContext(); |
| 2355 |
2283 std::string file_str; | 2356 std::string file_str; |
2284 path_list_->GetString(current_index_, &file_str); | 2357 path_list_->GetString(current_index_, &file_str); |
2285 GURL file_url = GURL(file_str); | 2358 GURL file_url = GURL(file_str); |
2286 FilePath file_path = GetVirtualPathFromURL(file_url); | 2359 FilePath file_path = GetVirtualPathFromURL(file_system_context, |
| 2360 file_url); |
2287 | 2361 |
2288 base::DictionaryValue* property_dict = new base::DictionaryValue; | 2362 base::DictionaryValue* property_dict = new base::DictionaryValue; |
2289 property_dict->SetString("fileUrl", file_url.spec()); | 2363 property_dict->SetString("fileUrl", file_url.spec()); |
2290 file_properties_->Append(property_dict); | 2364 file_properties_->Append(property_dict); |
2291 | 2365 |
2292 // Start getting the file info. | 2366 // Start getting the file info. |
2293 drive::DriveSystemService* system_service = | 2367 drive::DriveSystemService* system_service = |
2294 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2368 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
2295 // |system_service| is NULL if Drive is disabled. | 2369 // |system_service| is NULL if Drive is disabled. |
2296 if (!system_service) { | 2370 if (!system_service) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2494 } | 2568 } |
2495 | 2569 |
2496 GetFileLocationsFunction::~GetFileLocationsFunction() { | 2570 GetFileLocationsFunction::~GetFileLocationsFunction() { |
2497 } | 2571 } |
2498 | 2572 |
2499 bool GetFileLocationsFunction::RunImpl() { | 2573 bool GetFileLocationsFunction::RunImpl() { |
2500 ListValue* file_urls_as_strings = NULL; | 2574 ListValue* file_urls_as_strings = NULL; |
2501 if (!args_->GetList(0, &file_urls_as_strings)) | 2575 if (!args_->GetList(0, &file_urls_as_strings)) |
2502 return false; | 2576 return false; |
2503 | 2577 |
| 2578 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 2579 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 2580 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 2581 GetFileSystemContext(); |
| 2582 |
2504 // Convert the list of strings to a list of GURLs. | 2583 // Convert the list of strings to a list of GURLs. |
2505 scoped_ptr<ListValue> locations(new ListValue); | 2584 scoped_ptr<ListValue> locations(new ListValue); |
2506 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { | 2585 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { |
2507 std::string file_url_as_string; | 2586 std::string file_url_as_string; |
2508 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) | 2587 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) |
2509 return false; | 2588 return false; |
2510 | 2589 |
2511 fileapi::FileSystemURL url((GURL(file_url_as_string))); | 2590 fileapi::FileSystemURL url( |
| 2591 file_system_context->CrackURL(GURL(file_url_as_string))); |
2512 if (url.type() == fileapi::kFileSystemTypeDrive) | 2592 if (url.type() == fileapi::kFileSystemTypeDrive) |
2513 locations->Append(new base::StringValue("drive")); | 2593 locations->Append(new base::StringValue("drive")); |
2514 else | 2594 else |
2515 locations->Append(new base::StringValue("local")); | 2595 locations->Append(new base::StringValue("local")); |
2516 } | 2596 } |
2517 | 2597 |
2518 SetResult(locations.release()); | 2598 SetResult(locations.release()); |
2519 SendResponse(true); | 2599 SendResponse(true); |
2520 return true; | 2600 return true; |
2521 } | 2601 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2657 ListValue* url_list = NULL; | 2737 ListValue* url_list = NULL; |
2658 if (!args_->GetList(0, &url_list)) | 2738 if (!args_->GetList(0, &url_list)) |
2659 return false; | 2739 return false; |
2660 | 2740 |
2661 drive::DriveSystemService* system_service = | 2741 drive::DriveSystemService* system_service = |
2662 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2742 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
2663 // |system_service| is NULL if Drive is disabled. | 2743 // |system_service| is NULL if Drive is disabled. |
2664 if (!system_service) | 2744 if (!system_service) |
2665 return false; | 2745 return false; |
2666 | 2746 |
| 2747 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 2748 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 2749 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 2750 GetFileSystemContext(); |
| 2751 |
2667 scoped_ptr<ListValue> responses(new ListValue()); | 2752 scoped_ptr<ListValue> responses(new ListValue()); |
2668 for (size_t i = 0; i < url_list->GetSize(); ++i) { | 2753 for (size_t i = 0; i < url_list->GetSize(); ++i) { |
2669 std::string url_as_string; | 2754 std::string url_as_string; |
2670 url_list->GetString(i, &url_as_string); | 2755 url_list->GetString(i, &url_as_string); |
2671 | 2756 |
2672 FilePath file_path = GetLocalPathFromURL(GURL(url_as_string)); | 2757 FilePath file_path = GetLocalPathFromURL(file_system_context, |
| 2758 GURL(url_as_string)); |
2673 if (file_path.empty()) | 2759 if (file_path.empty()) |
2674 continue; | 2760 continue; |
2675 | 2761 |
2676 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); | 2762 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); |
2677 file_path = drive::util::ExtractDrivePath(file_path); | 2763 file_path = drive::util::ExtractDrivePath(file_path); |
2678 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 2764 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
2679 result->SetBoolean( | 2765 result->SetBoolean( |
2680 "canceled", | 2766 "canceled", |
2681 system_service->drive_service()->CancelForFilePath(file_path)); | 2767 system_service->drive_service()->CancelForFilePath(file_path)); |
2682 GURL file_url; | 2768 GURL file_url; |
(...skipping 21 matching lines...) Expand all Loading... |
2704 !args_->GetString(1, &destination_file_url)) { | 2790 !args_->GetString(1, &destination_file_url)) { |
2705 return false; | 2791 return false; |
2706 } | 2792 } |
2707 | 2793 |
2708 drive::DriveSystemService* system_service = | 2794 drive::DriveSystemService* system_service = |
2709 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2795 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
2710 // |system_service| is NULL if Drive is disabled. | 2796 // |system_service| is NULL if Drive is disabled. |
2711 if (!system_service) | 2797 if (!system_service) |
2712 return false; | 2798 return false; |
2713 | 2799 |
2714 FilePath source_file = GetLocalPathFromURL(GURL(source_file_url)); | 2800 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
2715 FilePath destination_file = GetLocalPathFromURL(GURL(destination_file_url)); | 2801 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 2802 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 2803 GetFileSystemContext(); |
| 2804 |
| 2805 FilePath source_file = GetLocalPathFromURL(file_system_context, |
| 2806 GURL(source_file_url)); |
| 2807 FilePath destination_file = GetLocalPathFromURL(file_system_context, |
| 2808 GURL(destination_file_url)); |
2716 if (source_file.empty() || destination_file.empty()) | 2809 if (source_file.empty() || destination_file.empty()) |
2717 return false; | 2810 return false; |
2718 | 2811 |
2719 bool source_file_under_drive = | 2812 bool source_file_under_drive = |
2720 drive::util::IsUnderDriveMountPoint(source_file); | 2813 drive::util::IsUnderDriveMountPoint(source_file); |
2721 bool destination_file_under_drive = | 2814 bool destination_file_under_drive = |
2722 drive::util::IsUnderDriveMountPoint(destination_file); | 2815 drive::util::IsUnderDriveMountPoint(destination_file); |
2723 | 2816 |
2724 if (source_file_under_drive && !destination_file_under_drive) { | 2817 if (source_file_under_drive && !destination_file_under_drive) { |
2725 // Transfer a file from gdata to local file system. | 2818 // Transfer a file from gdata to local file system. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2953 std::string file_url_as_string; | 3046 std::string file_url_as_string; |
2954 if (!args_->GetString(0, &file_url_as_string)) | 3047 if (!args_->GetString(0, &file_url_as_string)) |
2955 return false; | 3048 return false; |
2956 | 3049 |
2957 drive::DriveSystemService* system_service = | 3050 drive::DriveSystemService* system_service = |
2958 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 3051 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
2959 // |system_service| is NULL if Drive is disabled. | 3052 // |system_service| is NULL if Drive is disabled. |
2960 if (!system_service || !system_service->file_system()) | 3053 if (!system_service || !system_service->file_system()) |
2961 return false; | 3054 return false; |
2962 | 3055 |
2963 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 3056 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 3057 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 3058 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 3059 GetFileSystemContext(); |
| 3060 |
| 3061 FilePath directory_path = GetVirtualPathFromURL(file_system_context, |
| 3062 GURL(file_url_as_string)); |
2964 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 3063 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
2965 | 3064 |
2966 return true; | 3065 return true; |
2967 } | 3066 } |
2968 | 3067 |
2969 ZipSelectionFunction::ZipSelectionFunction() { | 3068 ZipSelectionFunction::ZipSelectionFunction() { |
2970 } | 3069 } |
2971 | 3070 |
2972 ZipSelectionFunction::~ZipSelectionFunction() { | 3071 ZipSelectionFunction::~ZipSelectionFunction() { |
2973 } | 3072 } |
2974 | 3073 |
2975 bool ZipSelectionFunction::RunImpl() { | 3074 bool ZipSelectionFunction::RunImpl() { |
2976 if (args_->GetSize() < 3) { | 3075 if (args_->GetSize() < 3) { |
2977 return false; | 3076 return false; |
2978 } | 3077 } |
2979 | 3078 |
2980 // First param is the source directory URL. | 3079 // First param is the source directory URL. |
2981 std::string dir_url; | 3080 std::string dir_url; |
2982 if (!args_->GetString(0, &dir_url) || dir_url.empty()) | 3081 if (!args_->GetString(0, &dir_url) || dir_url.empty()) |
2983 return false; | 3082 return false; |
2984 | 3083 |
2985 FilePath src_dir = GetLocalPathFromURL(GURL(dir_url)); | 3084 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 3085 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 3086 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 3087 GetFileSystemContext(); |
| 3088 |
| 3089 FilePath src_dir = GetLocalPathFromURL(file_system_context, |
| 3090 GURL(dir_url)); |
2986 if (src_dir.empty()) | 3091 if (src_dir.empty()) |
2987 return false; | 3092 return false; |
2988 | 3093 |
2989 // Second param is the list of selected file URLs. | 3094 // Second param is the list of selected file URLs. |
2990 ListValue* selection_urls = NULL; | 3095 ListValue* selection_urls = NULL; |
2991 args_->GetList(1, &selection_urls); | 3096 args_->GetList(1, &selection_urls); |
2992 if (!selection_urls || !selection_urls->GetSize()) | 3097 if (!selection_urls || !selection_urls->GetSize()) |
2993 return false; | 3098 return false; |
2994 | 3099 |
2995 std::vector<FilePath> files; | 3100 std::vector<FilePath> files; |
2996 for (size_t i = 0; i < selection_urls->GetSize(); ++i) { | 3101 for (size_t i = 0; i < selection_urls->GetSize(); ++i) { |
2997 std::string file_url; | 3102 std::string file_url; |
2998 selection_urls->GetString(i, &file_url); | 3103 selection_urls->GetString(i, &file_url); |
2999 FilePath path = GetLocalPathFromURL(GURL(file_url)); | 3104 FilePath path = GetLocalPathFromURL(file_system_context, GURL(file_url)); |
3000 if (path.empty()) | 3105 if (path.empty()) |
3001 return false; | 3106 return false; |
3002 files.push_back(path); | 3107 files.push_back(path); |
3003 } | 3108 } |
3004 | 3109 |
3005 // Third param is the name of the output zip file. | 3110 // Third param is the name of the output zip file. |
3006 std::string dest_name; | 3111 std::string dest_name; |
3007 if (!args_->GetString(2, &dest_name) || dest_name.empty()) | 3112 if (!args_->GetString(2, &dest_name) || dest_name.empty()) |
3008 return false; | 3113 return false; |
3009 | 3114 |
(...skipping 24 matching lines...) Expand all Loading... |
3034 // Keep the refcount until the zipping is complete on utility process. | 3139 // Keep the refcount until the zipping is complete on utility process. |
3035 AddRef(); | 3140 AddRef(); |
3036 return true; | 3141 return true; |
3037 } | 3142 } |
3038 | 3143 |
3039 void ZipSelectionFunction::OnZipDone(bool success) { | 3144 void ZipSelectionFunction::OnZipDone(bool success) { |
3040 SetResult(new base::FundamentalValue(success)); | 3145 SetResult(new base::FundamentalValue(success)); |
3041 SendResponse(true); | 3146 SendResponse(true); |
3042 Release(); | 3147 Release(); |
3043 } | 3148 } |
OLD | NEW |