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