| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 using extensions::app_file_handler_util::FindFileHandlersForMimeTypes; | 86 using extensions::app_file_handler_util::FindFileHandlersForMimeTypes; |
| 87 using chromeos::disks::DiskMountManager; | 87 using chromeos::disks::DiskMountManager; |
| 88 using content::BrowserContext; | 88 using content::BrowserContext; |
| 89 using content::BrowserThread; | 89 using content::BrowserThread; |
| 90 using content::ChildProcessSecurityPolicy; | 90 using content::ChildProcessSecurityPolicy; |
| 91 using content::SiteInstance; | 91 using content::SiteInstance; |
| 92 using content::WebContents; | 92 using content::WebContents; |
| 93 using extensions::Extension; | 93 using extensions::Extension; |
| 94 using extensions::ZipFileCreator; | 94 using extensions::ZipFileCreator; |
| 95 using file_handler_util::FileTaskExecutor; | 95 using file_handler_util::FileTaskExecutor; |
| 96 using fileapi::FileSystemURL; |
| 96 using google_apis::InstalledApp; | 97 using google_apis::InstalledApp; |
| 97 | 98 |
| 98 namespace { | 99 namespace { |
| 99 | 100 |
| 100 // Default icon path for drive docs. | 101 // Default icon path for drive docs. |
| 101 const char kDefaultIcon[] = "images/filetype_generic.png"; | 102 const char kDefaultIcon[] = "images/filetype_generic.png"; |
| 102 const int kPreferredIconSize = 16; | 103 const int kPreferredIconSize = 16; |
| 103 | 104 |
| 104 // Error messages. | 105 // Error messages. |
| 105 const char kFileError[] = "File error %d"; | 106 const char kFileError[] = "File error %d"; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 static_cast<uint64_t>(stat.f_bfree) * stat.f_frsize; | 319 static_cast<uint64_t>(stat.f_bfree) * stat.f_frsize; |
| 319 } | 320 } |
| 320 *total_size_kb = static_cast<size_t>(total_size_in_bytes / 1024); | 321 *total_size_kb = static_cast<size_t>(total_size_in_bytes / 1024); |
| 321 *remaining_size_kb = static_cast<size_t>(remaining_size_in_bytes / 1024); | 322 *remaining_size_kb = static_cast<size_t>(remaining_size_in_bytes / 1024); |
| 322 } | 323 } |
| 323 | 324 |
| 324 // Given a |url|, return the virtual FilePath associated with it. If the file | 325 // Given a |url|, return the virtual FilePath associated with it. If the file |
| 325 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. | 326 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. |
| 326 // | 327 // |
| 327 // Virtual paths will look like "Downloads/foo/bar.txt" or "drive/foo/bar.txt". | 328 // Virtual paths will look like "Downloads/foo/bar.txt" or "drive/foo/bar.txt". |
| 328 FilePath GetVirtualPathFromURL(const GURL& url) { | 329 FilePath GetVirtualPathFromURL(fileapi::FileSystemContext* context, |
| 329 fileapi::FileSystemURL filesystem_url(url); | 330 const GURL& url) { |
| 331 fileapi::FileSystemURL filesystem_url(context->CrackURL(url)); |
| 330 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) | 332 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) |
| 331 return FilePath(); | 333 return FilePath(); |
| 332 return filesystem_url.virtual_path(); | 334 return filesystem_url.virtual_path(); |
| 333 } | 335 } |
| 334 | 336 |
| 335 // Given a |url|, return the local FilePath associated with it. If the file | 337 // Given a |url|, return the local FilePath associated with it. If the file |
| 336 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. | 338 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. |
| 337 // | 339 // |
| 338 // Local paths will look like "/home/chronos/user/Downloads/foo/bar.txt" or | 340 // Local paths will look like "/home/chronos/user/Downloads/foo/bar.txt" or |
| 339 // "/special/drive/foo/bar.txt". | 341 // "/special/drive/foo/bar.txt". |
| 340 FilePath GetLocalPathFromURL(const GURL& url) { | 342 FilePath GetLocalPathFromURL(fileapi::FileSystemContext* context, |
| 341 fileapi::FileSystemURL filesystem_url(url); | 343 const GURL& url) { |
| 344 fileapi::FileSystemURL filesystem_url(context->CrackURL(url)); |
| 342 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) | 345 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) |
| 343 return FilePath(); | 346 return FilePath(); |
| 344 return filesystem_url.path(); | 347 return filesystem_url.path(); |
| 345 } | 348 } |
| 346 | 349 |
| 347 // Make a set of unique filename suffixes out of the list of file URLs. | 350 // Make a set of unique filename suffixes out of the list of file URLs. |
| 348 std::set<std::string> GetUniqueSuffixes(base::ListValue* file_url_list) { | 351 std::set<std::string> GetUniqueSuffixes(base::ListValue* file_url_list) { |
| 349 std::set<std::string> suffixes; | 352 std::set<std::string> suffixes; |
| 350 for (size_t i = 0; i < file_url_list->GetSize(); ++i) { | 353 for (size_t i = 0; i < file_url_list->GetSize(); ++i) { |
| 351 std::string url; | 354 std::string url; |
| 352 if (!file_url_list->GetString(i, &url)) | 355 if (!file_url_list->GetString(i, &url)) |
| 353 return std::set<std::string>(); | 356 return std::set<std::string>(); |
| 354 FilePath path = GetVirtualPathFromURL(GURL(url)); | 357 FileSystemURL non_cracked = FileSystemURL(GURL(url)); |
| 358 FilePath path = non_cracked.path(); |
| 355 if (path.empty()) | 359 if (path.empty()) |
| 356 return std::set<std::string>(); | 360 return std::set<std::string>(); |
| 357 // We'll skip empty suffixes. | 361 // We'll skip empty suffixes. |
| 358 if (!path.Extension().empty()) | 362 if (!path.Extension().empty()) |
| 359 suffixes.insert(path.Extension()); | 363 suffixes.insert(path.Extension()); |
| 360 } | 364 } |
| 361 return suffixes; | 365 return suffixes; |
| 362 } | 366 } |
| 363 | 367 |
| 364 // Make a set of unique MIME types out of the list of MIME types. | 368 // Make a set of unique MIME types out of the list of MIME types. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 if (!entry_proto.content_url().empty()) | 436 if (!entry_proto.content_url().empty()) |
| 433 property_dict->SetString("contentUrl", entry_proto.content_url()); | 437 property_dict->SetString("contentUrl", entry_proto.content_url()); |
| 434 | 438 |
| 435 property_dict->SetBoolean("isHosted", | 439 property_dict->SetBoolean("isHosted", |
| 436 file_specific_info.is_hosted_document()); | 440 file_specific_info.is_hosted_document()); |
| 437 | 441 |
| 438 property_dict->SetString("contentMimeType", | 442 property_dict->SetString("contentMimeType", |
| 439 file_specific_info.content_mime_type()); | 443 file_specific_info.content_mime_type()); |
| 440 } | 444 } |
| 441 | 445 |
| 446 // TODO(tbarzic): Pass set of file extensions instead of file urls to the |
| 447 // function. |
| 448 void GetMimeTypesForFileURLs(const std::vector<GURL>& file_urls, |
| 449 std::set<std::string>* mime_types) { |
| 450 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); |
| 451 iter != file_urls.end(); ++iter) { |
| 452 FileSystemURL non_cracked_url(*iter); |
| 453 if (!non_cracked_url.is_valid()) |
| 454 continue; |
| 455 |
| 456 const FilePath::StringType file_extension = |
| 457 StringToLowerASCII(non_cracked_url.path().Extension()); |
| 458 |
| 459 // TODO(thorogood): Rearchitect this call so it can run on the File thread; |
| 460 // GetMimeTypeFromFile requires this on Linux. Right now, we use |
| 461 // Chrome-level knowledge only. |
| 462 std::string mime_type; |
| 463 if (file_extension.empty() || |
| 464 !net::GetWellKnownMimeTypeFromExtension(file_extension.substr(1), |
| 465 &mime_type)) { |
| 466 // If the file doesn't have an extension or its mime-type cannot be |
| 467 // determined, then indicate that it has the empty mime-type. This will |
| 468 // only be matched if the Web Intents accepts "*" or "*/*". |
| 469 mime_types->insert(""); |
| 470 } else { |
| 471 mime_types->insert(mime_type); |
| 472 } |
| 473 } |
| 474 } |
| 475 |
| 442 } // namespace | 476 } // namespace |
| 443 | 477 |
| 444 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { | 478 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { |
| 445 public: | 479 public: |
| 446 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 480 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( |
| 447 RequestLocalFileSystemFunction* function, | 481 RequestLocalFileSystemFunction* function, |
| 448 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 482 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
| 449 int child_id, | 483 int child_id, |
| 450 scoped_refptr<const Extension> extension) { | 484 scoped_refptr<const Extension> extension) { |
| 451 return base::Bind( | 485 return base::Bind( |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 | 699 |
| 666 bool FileWatchBrowserFunctionBase::RunImpl() { | 700 bool FileWatchBrowserFunctionBase::RunImpl() { |
| 667 if (!render_view_host() || !render_view_host()->GetProcess()) | 701 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 668 return false; | 702 return false; |
| 669 | 703 |
| 670 // First param is url of a file to watch. | 704 // First param is url of a file to watch. |
| 671 std::string url; | 705 std::string url; |
| 672 if (!args_->GetString(0, &url) || url.empty()) | 706 if (!args_->GetString(0, &url) || url.empty()) |
| 673 return false; | 707 return false; |
| 674 | 708 |
| 675 GURL file_watch_url(url); | 709 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 710 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 711 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 712 GetFileSystemContext(); |
| 713 |
| 714 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url)); |
| 676 BrowserThread::PostTask( | 715 BrowserThread::PostTask( |
| 677 BrowserThread::FILE, FROM_HERE, | 716 BrowserThread::FILE, FROM_HERE, |
| 678 base::Bind( | 717 base::Bind( |
| 679 &FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread, | 718 &FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread, |
| 680 this, | 719 this, |
| 681 FileBrowserPrivateAPI::Get(profile_)->event_router(), | 720 FileBrowserPrivateAPI::Get(profile_)->event_router(), |
| 682 file_watch_url, | 721 file_watch_url, |
| 683 extension_id())); | 722 extension_id())); |
| 684 | 723 |
| 685 return true; | 724 return true; |
| 686 } | 725 } |
| 687 | 726 |
| 688 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread( | 727 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread( |
| 689 scoped_refptr<FileBrowserEventRouter> event_router, | 728 scoped_refptr<FileBrowserEventRouter> event_router, |
| 690 const GURL& file_url, const std::string& extension_id) { | 729 const FileSystemURL& file_url, const std::string& extension_id) { |
| 691 FilePath local_path = GetLocalPathFromURL(file_url); | 730 FilePath local_path = file_url.path(); |
| 692 FilePath virtual_path = GetVirtualPathFromURL(file_url); | 731 FilePath virtual_path = file_url.virtual_path(); |
| 693 bool result = !local_path.empty() && PerformFileWatchOperation( | 732 bool result = !local_path.empty() && PerformFileWatchOperation( |
| 694 event_router, local_path, virtual_path, extension_id); | 733 event_router, local_path, virtual_path, extension_id); |
| 695 | 734 |
| 696 BrowserThread::PostTask( | 735 BrowserThread::PostTask( |
| 697 BrowserThread::UI, FROM_HERE, | 736 BrowserThread::UI, FROM_HERE, |
| 698 base::Bind( | 737 base::Bind( |
| 699 &FileWatchBrowserFunctionBase::RespondOnUIThread, this, result)); | 738 &FileWatchBrowserFunctionBase::RespondOnUIThread, this, result)); |
| 700 } | 739 } |
| 701 | 740 |
| 702 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( | 741 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 std::set<std::string> default_tasks; | 906 std::set<std::string> default_tasks; |
| 868 FindDefaultDriveTasks(file_info_list, available_tasks, &default_tasks); | 907 FindDefaultDriveTasks(file_info_list, available_tasks, &default_tasks); |
| 869 CreateDriveTasks(registry, app_info, available_tasks, default_tasks, | 908 CreateDriveTasks(registry, app_info, available_tasks, default_tasks, |
| 870 result_list, default_already_set); | 909 result_list, default_already_set); |
| 871 | 910 |
| 872 // We own the pointers in |app_info|, so we need to delete them. | 911 // We own the pointers in |app_info|, so we need to delete them. |
| 873 STLDeleteContainerPairSecondPointers(app_info.begin(), app_info.end()); | 912 STLDeleteContainerPairSecondPointers(app_info.begin(), app_info.end()); |
| 874 return true; | 913 return true; |
| 875 } | 914 } |
| 876 | 915 |
| 877 static void GetMimeTypesForFileURLs(const std::vector<GURL>& file_urls, | |
| 878 std::set<std::string>* mime_types) { | |
| 879 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); | |
| 880 iter != file_urls.end(); ++iter) { | |
| 881 const FilePath file = FilePath(GURL(iter->spec()).ExtractFileName()); | |
| 882 const FilePath::StringType file_extension = | |
| 883 StringToLowerASCII(file.Extension()); | |
| 884 | |
| 885 // TODO(thorogood): Rearchitect this call so it can run on the File thread; | |
| 886 // GetMimeTypeFromFile requires this on Linux. Right now, we use | |
| 887 // Chrome-level knowledge only. | |
| 888 std::string mime_type; | |
| 889 if (file_extension.empty() || !net::GetWellKnownMimeTypeFromExtension( | |
| 890 file_extension.substr(1), &mime_type)) { | |
| 891 // If the file doesn't have an extension or its mime-type cannot be | |
| 892 // determined, then indicate that it has the empty mime-type. This will | |
| 893 // only be matched if the Web Intents accepts "*" or "*/*". | |
| 894 mime_types->insert(""); | |
| 895 } else { | |
| 896 mime_types->insert(mime_type); | |
| 897 } | |
| 898 } | |
| 899 } | |
| 900 | |
| 901 bool GetFileTasksFileBrowserFunction::FindAppTasks( | 916 bool GetFileTasksFileBrowserFunction::FindAppTasks( |
| 902 const std::vector<GURL>& file_urls, | 917 const std::vector<GURL>& file_urls, |
| 903 ListValue* result_list) { | 918 ListValue* result_list) { |
| 904 DCHECK(!file_urls.empty()); | 919 DCHECK(!file_urls.empty()); |
| 905 ExtensionService* service = profile_->GetExtensionService(); | 920 ExtensionService* service = profile_->GetExtensionService(); |
| 906 if (!service) | 921 if (!service) |
| 907 return false; | 922 return false; |
| 908 | 923 |
| 909 std::set<std::string> mime_types; | 924 std::set<std::string> mime_types; |
| 910 GetMimeTypesForFileURLs(file_urls, &mime_types); | 925 GetMimeTypesForFileURLs(file_urls, &mime_types); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 // Second argument is the list of mime types of each of the files in the list. | 1029 // Second argument is the list of mime types of each of the files in the list. |
| 1015 ListValue* mime_types_list = NULL; | 1030 ListValue* mime_types_list = NULL; |
| 1016 if (!args_->GetList(1, &mime_types_list)) | 1031 if (!args_->GetList(1, &mime_types_list)) |
| 1017 return false; | 1032 return false; |
| 1018 | 1033 |
| 1019 // MIME types can either be empty, or there needs to be one for each file. | 1034 // MIME types can either be empty, or there needs to be one for each file. |
| 1020 if (mime_types_list->GetSize() != files_list->GetSize() && | 1035 if (mime_types_list->GetSize() != files_list->GetSize() && |
| 1021 mime_types_list->GetSize() != 0) | 1036 mime_types_list->GetSize() != 0) |
| 1022 return false; | 1037 return false; |
| 1023 | 1038 |
| 1039 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1040 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1041 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1042 GetFileSystemContext(); |
| 1043 |
| 1024 // Collect all the URLs, convert them to GURLs, and crack all the urls into | 1044 // Collect all the URLs, convert them to GURLs, and crack all the urls into |
| 1025 // file paths. | 1045 // file paths. |
| 1026 FileInfoList info_list; | 1046 FileInfoList info_list; |
| 1027 std::vector<GURL> file_urls; | 1047 std::vector<GURL> file_urls; |
| 1028 for (size_t i = 0; i < files_list->GetSize(); ++i) { | 1048 for (size_t i = 0; i < files_list->GetSize(); ++i) { |
| 1029 FileInfo info; | 1049 FileInfo info; |
| 1030 std::string file_url; | 1050 std::string file_url_str; |
| 1031 if (!files_list->GetString(i, &file_url)) | 1051 if (!files_list->GetString(i, &file_url_str)) |
| 1032 return false; | 1052 return false; |
| 1033 info.file_url = GURL(file_url); | 1053 |
| 1034 file_urls.push_back(info.file_url); | |
| 1035 if (mime_types_list->GetSize() != 0 && | 1054 if (mime_types_list->GetSize() != 0 && |
| 1036 !mime_types_list->GetString(i, &info.mime_type)) | 1055 !mime_types_list->GetString(i, &info.mime_type)) |
| 1037 return false; | 1056 return false; |
| 1038 fileapi::FileSystemURL file_system_url(info.file_url); | 1057 |
| 1039 if (chromeos::CrosMountPointProvider::CanHandleURL(file_system_url)) { | 1058 GURL file_url(file_url_str); |
| 1040 info.file_path = file_system_url.path(); | 1059 fileapi::FileSystemURL file_system_url( |
| 1041 } | 1060 file_system_context->CrackURL(file_url)); |
| 1061 if (!chromeos::CrosMountPointProvider::CanHandleURL(file_system_url)) |
| 1062 continue; |
| 1063 |
| 1064 file_urls.push_back(file_url); |
| 1065 |
| 1066 info.file_url = file_url; |
| 1067 info.file_path = file_system_url.path(); |
| 1042 info_list.push_back(info); | 1068 info_list.push_back(info); |
| 1043 } | 1069 } |
| 1044 | 1070 |
| 1045 ListValue* result_list = new ListValue(); | 1071 ListValue* result_list = new ListValue(); |
| 1046 SetResult(result_list); | 1072 SetResult(result_list); |
| 1047 | 1073 |
| 1048 // Find the Drive apps first, because we want them to take precedence | 1074 // Find the Drive apps first, because we want them to take precedence |
| 1049 // when setting the default app. | 1075 // when setting the default app. |
| 1050 bool default_already_set = false; | 1076 bool default_already_set = false; |
| 1051 if (!FindDriveAppTasks(info_list, result_list, &default_already_set)) | 1077 if (!FindDriveAppTasks(info_list, result_list, &default_already_set)) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 std::string action_id; | 1180 std::string action_id; |
| 1155 if (!file_handler_util::CrackTaskID( | 1181 if (!file_handler_util::CrackTaskID( |
| 1156 task_id, &extension_id, &task_type, &action_id)) { | 1182 task_id, &extension_id, &task_type, &action_id)) { |
| 1157 LOG(WARNING) << "Invalid task " << task_id; | 1183 LOG(WARNING) << "Invalid task " << task_id; |
| 1158 return false; | 1184 return false; |
| 1159 } | 1185 } |
| 1160 | 1186 |
| 1161 if (!files_list->GetSize()) | 1187 if (!files_list->GetSize()) |
| 1162 return true; | 1188 return true; |
| 1163 | 1189 |
| 1164 std::vector<GURL> file_urls; | 1190 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1191 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1192 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1193 GetFileSystemContext(); |
| 1194 |
| 1195 std::vector<FileSystemURL> file_urls; |
| 1165 for (size_t i = 0; i < files_list->GetSize(); i++) { | 1196 for (size_t i = 0; i < files_list->GetSize(); i++) { |
| 1166 std::string origin_file_url; | 1197 std::string file_url_str; |
| 1167 if (!files_list->GetString(i, &origin_file_url)) { | 1198 if (!files_list->GetString(i, &file_url_str)) { |
| 1168 error_ = kInvalidFileUrl; | 1199 error_ = kInvalidFileUrl; |
| 1169 return false; | 1200 return false; |
| 1170 } | 1201 } |
| 1171 file_urls.push_back(GURL(origin_file_url)); | 1202 FileSystemURL url = file_system_context->CrackURL(GURL(file_url_str)); |
| 1203 if (!chromeos::CrosMountPointProvider::CanHandleURL(url)) { |
| 1204 error_ = kInvalidFileUrl; |
| 1205 return false; |
| 1206 } |
| 1207 file_urls.push_back(url); |
| 1172 } | 1208 } |
| 1173 | 1209 |
| 1174 WebContents* web_contents = | 1210 WebContents* web_contents = |
| 1175 dispatcher()->delegate()->GetAssociatedWebContents(); | 1211 dispatcher()->delegate()->GetAssociatedWebContents(); |
| 1176 int32 tab_id = 0; | 1212 int32 tab_id = 0; |
| 1177 if (web_contents) | 1213 if (web_contents) |
| 1178 tab_id = ExtensionTabUtil::GetTabId(web_contents); | 1214 tab_id = ExtensionTabUtil::GetTabId(web_contents); |
| 1179 | 1215 |
| 1180 scoped_refptr<FileTaskExecutor> executor( | 1216 scoped_refptr<FileTaskExecutor> executor( |
| 1181 FileTaskExecutor::Create(profile(), | 1217 FileTaskExecutor::Create(profile(), |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 net::UnescapeURLComponent(parameters[i].second, | 1358 net::UnescapeURLComponent(parameters[i].second, |
| 1323 kUnescapeRuleForQueryParameters); | 1359 kUnescapeRuleForQueryParameters); |
| 1324 local_path = FilePath::FromUTF8Unsafe(unescaped_value); | 1360 local_path = FilePath::FromUTF8Unsafe(unescaped_value); |
| 1325 break; | 1361 break; |
| 1326 } | 1362 } |
| 1327 } | 1363 } |
| 1328 } | 1364 } |
| 1329 } | 1365 } |
| 1330 | 1366 |
| 1331 // Extract the path from |file_url|. | 1367 // Extract the path from |file_url|. |
| 1332 fileapi::FileSystemURL url(file_url); | 1368 fileapi::FileSystemURL url(file_system_context->CrackURL(file_url)); |
| 1333 if (!chromeos::CrosMountPointProvider::CanHandleURL(url)) | 1369 if (!chromeos::CrosMountPointProvider::CanHandleURL(url)) |
| 1334 continue; | 1370 continue; |
| 1335 | 1371 |
| 1336 if (!url.path().empty()) { | 1372 if (!url.path().empty()) { |
| 1337 DVLOG(1) << "Selected: file path: " << url.path().value() | 1373 DVLOG(1) << "Selected: file path: " << url.path().value() |
| 1338 << " local path: " << local_path.value(); | 1374 << " local path: " << local_path.value(); |
| 1339 selected_files.push_back( | 1375 selected_files.push_back( |
| 1340 ui::SelectedFileInfo(url.path(), local_path)); | 1376 ui::SelectedFileInfo(url.path(), local_path)); |
| 1341 } | 1377 } |
| 1342 } | 1378 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 return false; | 1422 return false; |
| 1387 } | 1423 } |
| 1388 | 1424 |
| 1389 ListValue* path_list = NULL; | 1425 ListValue* path_list = NULL; |
| 1390 args_->GetList(0, &path_list); | 1426 args_->GetList(0, &path_list); |
| 1391 DCHECK(path_list); | 1427 DCHECK(path_list); |
| 1392 | 1428 |
| 1393 std::string internal_task_id; | 1429 std::string internal_task_id; |
| 1394 args_->GetString(1, &internal_task_id); | 1430 args_->GetString(1, &internal_task_id); |
| 1395 | 1431 |
| 1432 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1433 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1434 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1435 GetFileSystemContext(); |
| 1436 |
| 1396 std::vector<FilePath> files; | 1437 std::vector<FilePath> files; |
| 1397 for (size_t i = 0; i < path_list->GetSize(); ++i) { | 1438 for (size_t i = 0; i < path_list->GetSize(); ++i) { |
| 1398 std::string url_as_string; | 1439 std::string url_as_string; |
| 1399 path_list->GetString(i, &url_as_string); | 1440 path_list->GetString(i, &url_as_string); |
| 1400 FilePath path = GetLocalPathFromURL(GURL(url_as_string)); | 1441 FilePath path = GetLocalPathFromURL(file_system_context, |
| 1442 GURL(url_as_string)); |
| 1401 if (path.empty()) | 1443 if (path.empty()) |
| 1402 return false; | 1444 return false; |
| 1403 files.push_back(path); | 1445 files.push_back(path); |
| 1404 } | 1446 } |
| 1405 | 1447 |
| 1406 Browser* browser = GetCurrentBrowser(); | 1448 Browser* browser = GetCurrentBrowser(); |
| 1407 bool success = browser; | 1449 bool success = browser; |
| 1408 | 1450 |
| 1409 if (browser) { | 1451 if (browser) { |
| 1410 for (size_t i = 0; i < files.size(); ++i) { | 1452 for (size_t i = 0; i < files.size(); ++i) { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 file_url, | 1705 file_url, |
| 1664 strtoul(timestamp.c_str(), NULL, 0))); | 1706 strtoul(timestamp.c_str(), NULL, 0))); |
| 1665 | 1707 |
| 1666 return true; | 1708 return true; |
| 1667 } | 1709 } |
| 1668 | 1710 |
| 1669 void SetLastModifiedFunction::RunOperationOnFileThread(std::string file_url, | 1711 void SetLastModifiedFunction::RunOperationOnFileThread(std::string file_url, |
| 1670 time_t timestamp) { | 1712 time_t timestamp) { |
| 1671 bool succeeded = false; | 1713 bool succeeded = false; |
| 1672 | 1714 |
| 1673 FilePath local_path = GetLocalPathFromURL(GURL(file_url)); | 1715 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1716 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1717 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1718 GetFileSystemContext(); |
| 1719 |
| 1720 FilePath local_path = GetLocalPathFromURL(file_system_context, |
| 1721 GURL(file_url)); |
| 1674 if (!local_path.empty()) { | 1722 if (!local_path.empty()) { |
| 1675 struct stat sb; | 1723 struct stat sb; |
| 1676 if (stat(local_path.value().c_str(), &sb) == 0) { | 1724 if (stat(local_path.value().c_str(), &sb) == 0) { |
| 1677 struct utimbuf times; | 1725 struct utimbuf times; |
| 1678 times.actime = sb.st_atime; | 1726 times.actime = sb.st_atime; |
| 1679 times.modtime = timestamp; | 1727 times.modtime = timestamp; |
| 1680 | 1728 |
| 1681 if (utime(local_path.value().c_str(), ×) == 0) | 1729 if (utime(local_path.value().c_str(), ×) == 0) |
| 1682 succeeded = true; | 1730 succeeded = true; |
| 1683 } | 1731 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1699 | 1747 |
| 1700 bool GetSizeStatsFunction::RunImpl() { | 1748 bool GetSizeStatsFunction::RunImpl() { |
| 1701 if (args_->GetSize() != 1) { | 1749 if (args_->GetSize() != 1) { |
| 1702 return false; | 1750 return false; |
| 1703 } | 1751 } |
| 1704 | 1752 |
| 1705 std::string mount_url; | 1753 std::string mount_url; |
| 1706 if (!args_->GetString(0, &mount_url)) | 1754 if (!args_->GetString(0, &mount_url)) |
| 1707 return false; | 1755 return false; |
| 1708 | 1756 |
| 1709 FilePath file_path = GetLocalPathFromURL(GURL(mount_url)); | 1757 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1758 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1759 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1760 GetFileSystemContext(); |
| 1761 |
| 1762 FilePath file_path = GetLocalPathFromURL(file_system_context, |
| 1763 GURL(mount_url)); |
| 1710 if (file_path.empty()) | 1764 if (file_path.empty()) |
| 1711 return false; | 1765 return false; |
| 1712 | 1766 |
| 1713 if (file_path == drive::util::GetDriveMountPointPath()) { | 1767 if (file_path == drive::util::GetDriveMountPointPath()) { |
| 1714 drive::DriveSystemService* system_service = | 1768 drive::DriveSystemService* system_service = |
| 1715 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 1769 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 1716 // |system_service| is NULL if Drive is disabled. | 1770 // |system_service| is NULL if Drive is disabled. |
| 1717 if (!system_service) { | 1771 if (!system_service) { |
| 1718 // If stats couldn't be gotten for drive, result should be left | 1772 // If stats couldn't be gotten for drive, result should be left |
| 1719 // undefined. See comments in GetDriveAvailableSpaceCallback(). | 1773 // undefined. See comments in GetDriveAvailableSpaceCallback(). |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1795 if (args_->GetSize() != 1) { | 1849 if (args_->GetSize() != 1) { |
| 1796 return false; | 1850 return false; |
| 1797 } | 1851 } |
| 1798 | 1852 |
| 1799 std::string volume_file_url; | 1853 std::string volume_file_url; |
| 1800 if (!args_->GetString(0, &volume_file_url)) { | 1854 if (!args_->GetString(0, &volume_file_url)) { |
| 1801 NOTREACHED(); | 1855 NOTREACHED(); |
| 1802 return false; | 1856 return false; |
| 1803 } | 1857 } |
| 1804 | 1858 |
| 1805 FilePath file_path = GetLocalPathFromURL(GURL(volume_file_url)); | 1859 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1860 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1861 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1862 GetFileSystemContext(); |
| 1863 |
| 1864 FilePath file_path = GetLocalPathFromURL(file_system_context, |
| 1865 GURL(volume_file_url)); |
| 1806 if (file_path.empty()) | 1866 if (file_path.empty()) |
| 1807 return false; | 1867 return false; |
| 1808 | 1868 |
| 1809 DiskMountManager::GetInstance()->FormatMountedDevice(file_path.value()); | 1869 DiskMountManager::GetInstance()->FormatMountedDevice(file_path.value()); |
| 1810 SendResponse(true); | 1870 SendResponse(true); |
| 1811 return true; | 1871 return true; |
| 1812 } | 1872 } |
| 1813 | 1873 |
| 1814 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { | 1874 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { |
| 1815 } | 1875 } |
| 1816 | 1876 |
| 1817 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { | 1877 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { |
| 1818 } | 1878 } |
| 1819 | 1879 |
| 1820 bool GetVolumeMetadataFunction::RunImpl() { | 1880 bool GetVolumeMetadataFunction::RunImpl() { |
| 1821 if (args_->GetSize() != 1) { | 1881 if (args_->GetSize() != 1) { |
| 1822 error_ = "Invalid argument count"; | 1882 error_ = "Invalid argument count"; |
| 1823 return false; | 1883 return false; |
| 1824 } | 1884 } |
| 1825 | 1885 |
| 1826 std::string volume_mount_url; | 1886 std::string volume_mount_url; |
| 1827 if (!args_->GetString(0, &volume_mount_url)) { | 1887 if (!args_->GetString(0, &volume_mount_url)) { |
| 1828 NOTREACHED(); | 1888 NOTREACHED(); |
| 1829 return false; | 1889 return false; |
| 1830 } | 1890 } |
| 1831 | 1891 |
| 1832 FilePath file_path = GetLocalPathFromURL(GURL(volume_mount_url)); | 1892 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 1893 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 1894 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 1895 GetFileSystemContext(); |
| 1896 |
| 1897 FilePath file_path = GetLocalPathFromURL(file_system_context, |
| 1898 GURL(volume_mount_url)); |
| 1833 if (file_path.empty()) { | 1899 if (file_path.empty()) { |
| 1834 error_ = "Invalid mount path."; | 1900 error_ = "Invalid mount path."; |
| 1835 return false; | 1901 return false; |
| 1836 } | 1902 } |
| 1837 | 1903 |
| 1838 results_.reset(); | 1904 results_.reset(); |
| 1839 | 1905 |
| 1840 const DiskMountManager::Disk* volume = GetVolumeAsDisk(file_path.value()); | 1906 const DiskMountManager::Disk* volume = GetVolumeAsDisk(file_path.value()); |
| 1841 if (volume) { | 1907 if (volume) { |
| 1842 DictionaryValue* volume_info = | 1908 DictionaryValue* volume_info = |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2269 } | 2335 } |
| 2270 | 2336 |
| 2271 void GetDriveFilePropertiesFunction::GetNextFileProperties() { | 2337 void GetDriveFilePropertiesFunction::GetNextFileProperties() { |
| 2272 if (current_index_ >= path_list_->GetSize()) { | 2338 if (current_index_ >= path_list_->GetSize()) { |
| 2273 // Exit of asynchronous look and return the result. | 2339 // Exit of asynchronous look and return the result. |
| 2274 SetResult(file_properties_.release()); | 2340 SetResult(file_properties_.release()); |
| 2275 SendResponse(true); | 2341 SendResponse(true); |
| 2276 return; | 2342 return; |
| 2277 } | 2343 } |
| 2278 | 2344 |
| 2345 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 2346 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 2347 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 2348 GetFileSystemContext(); |
| 2349 |
| 2279 std::string file_str; | 2350 std::string file_str; |
| 2280 path_list_->GetString(current_index_, &file_str); | 2351 path_list_->GetString(current_index_, &file_str); |
| 2281 GURL file_url = GURL(file_str); | 2352 GURL file_url = GURL(file_str); |
| 2282 FilePath file_path = GetVirtualPathFromURL(file_url); | 2353 FilePath file_path = GetVirtualPathFromURL(file_system_context, |
| 2354 file_url); |
| 2283 | 2355 |
| 2284 base::DictionaryValue* property_dict = new base::DictionaryValue; | 2356 base::DictionaryValue* property_dict = new base::DictionaryValue; |
| 2285 property_dict->SetString("fileUrl", file_url.spec()); | 2357 property_dict->SetString("fileUrl", file_url.spec()); |
| 2286 file_properties_->Append(property_dict); | 2358 file_properties_->Append(property_dict); |
| 2287 | 2359 |
| 2288 // Start getting the file info. | 2360 // Start getting the file info. |
| 2289 drive::DriveSystemService* system_service = | 2361 drive::DriveSystemService* system_service = |
| 2290 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2362 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2291 // |system_service| is NULL if Drive is disabled. | 2363 // |system_service| is NULL if Drive is disabled. |
| 2292 if (!system_service) { | 2364 if (!system_service) { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2490 } | 2562 } |
| 2491 | 2563 |
| 2492 GetFileLocationsFunction::~GetFileLocationsFunction() { | 2564 GetFileLocationsFunction::~GetFileLocationsFunction() { |
| 2493 } | 2565 } |
| 2494 | 2566 |
| 2495 bool GetFileLocationsFunction::RunImpl() { | 2567 bool GetFileLocationsFunction::RunImpl() { |
| 2496 ListValue* file_urls_as_strings = NULL; | 2568 ListValue* file_urls_as_strings = NULL; |
| 2497 if (!args_->GetList(0, &file_urls_as_strings)) | 2569 if (!args_->GetList(0, &file_urls_as_strings)) |
| 2498 return false; | 2570 return false; |
| 2499 | 2571 |
| 2572 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 2573 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 2574 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 2575 GetFileSystemContext(); |
| 2576 |
| 2500 // Convert the list of strings to a list of GURLs. | 2577 // Convert the list of strings to a list of GURLs. |
| 2501 scoped_ptr<ListValue> locations(new ListValue); | 2578 scoped_ptr<ListValue> locations(new ListValue); |
| 2502 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { | 2579 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { |
| 2503 std::string file_url_as_string; | 2580 std::string file_url_as_string; |
| 2504 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) | 2581 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) |
| 2505 return false; | 2582 return false; |
| 2506 | 2583 |
| 2507 fileapi::FileSystemURL url((GURL(file_url_as_string))); | 2584 fileapi::FileSystemURL url( |
| 2585 file_system_context->CrackURL(GURL(file_url_as_string))); |
| 2508 if (url.type() == fileapi::kFileSystemTypeDrive) | 2586 if (url.type() == fileapi::kFileSystemTypeDrive) |
| 2509 locations->Append(new base::StringValue("drive")); | 2587 locations->Append(new base::StringValue("drive")); |
| 2510 else | 2588 else |
| 2511 locations->Append(new base::StringValue("local")); | 2589 locations->Append(new base::StringValue("local")); |
| 2512 } | 2590 } |
| 2513 | 2591 |
| 2514 SetResult(locations.release()); | 2592 SetResult(locations.release()); |
| 2515 SendResponse(true); | 2593 SendResponse(true); |
| 2516 return true; | 2594 return true; |
| 2517 } | 2595 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2653 ListValue* url_list = NULL; | 2731 ListValue* url_list = NULL; |
| 2654 if (!args_->GetList(0, &url_list)) | 2732 if (!args_->GetList(0, &url_list)) |
| 2655 return false; | 2733 return false; |
| 2656 | 2734 |
| 2657 drive::DriveSystemService* system_service = | 2735 drive::DriveSystemService* system_service = |
| 2658 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2736 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2659 // |system_service| is NULL if Drive is disabled. | 2737 // |system_service| is NULL if Drive is disabled. |
| 2660 if (!system_service) | 2738 if (!system_service) |
| 2661 return false; | 2739 return false; |
| 2662 | 2740 |
| 2741 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 2742 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 2743 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 2744 GetFileSystemContext(); |
| 2745 |
| 2663 scoped_ptr<ListValue> responses(new ListValue()); | 2746 scoped_ptr<ListValue> responses(new ListValue()); |
| 2664 for (size_t i = 0; i < url_list->GetSize(); ++i) { | 2747 for (size_t i = 0; i < url_list->GetSize(); ++i) { |
| 2665 std::string url_as_string; | 2748 std::string url_as_string; |
| 2666 url_list->GetString(i, &url_as_string); | 2749 url_list->GetString(i, &url_as_string); |
| 2667 | 2750 |
| 2668 FilePath file_path = GetLocalPathFromURL(GURL(url_as_string)); | 2751 FilePath file_path = GetLocalPathFromURL(file_system_context, |
| 2752 GURL(url_as_string)); |
| 2669 if (file_path.empty()) | 2753 if (file_path.empty()) |
| 2670 continue; | 2754 continue; |
| 2671 | 2755 |
| 2672 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); | 2756 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); |
| 2673 file_path = drive::util::ExtractDrivePath(file_path); | 2757 file_path = drive::util::ExtractDrivePath(file_path); |
| 2674 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 2758 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
| 2675 result->SetBoolean( | 2759 result->SetBoolean( |
| 2676 "canceled", | 2760 "canceled", |
| 2677 system_service->drive_service()->CancelForFilePath(file_path)); | 2761 system_service->drive_service()->CancelForFilePath(file_path)); |
| 2678 GURL file_url; | 2762 GURL file_url; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2700 !args_->GetString(1, &destination_file_url)) { | 2784 !args_->GetString(1, &destination_file_url)) { |
| 2701 return false; | 2785 return false; |
| 2702 } | 2786 } |
| 2703 | 2787 |
| 2704 drive::DriveSystemService* system_service = | 2788 drive::DriveSystemService* system_service = |
| 2705 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2789 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2706 // |system_service| is NULL if Drive is disabled. | 2790 // |system_service| is NULL if Drive is disabled. |
| 2707 if (!system_service) | 2791 if (!system_service) |
| 2708 return false; | 2792 return false; |
| 2709 | 2793 |
| 2710 FilePath source_file = GetLocalPathFromURL(GURL(source_file_url)); | 2794 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 2711 FilePath destination_file = GetLocalPathFromURL(GURL(destination_file_url)); | 2795 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 2796 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 2797 GetFileSystemContext(); |
| 2798 |
| 2799 FilePath source_file = GetLocalPathFromURL(file_system_context, |
| 2800 GURL(source_file_url)); |
| 2801 FilePath destination_file = GetLocalPathFromURL(file_system_context, |
| 2802 GURL(destination_file_url)); |
| 2712 if (source_file.empty() || destination_file.empty()) | 2803 if (source_file.empty() || destination_file.empty()) |
| 2713 return false; | 2804 return false; |
| 2714 | 2805 |
| 2715 bool source_file_under_drive = | 2806 bool source_file_under_drive = |
| 2716 drive::util::IsUnderDriveMountPoint(source_file); | 2807 drive::util::IsUnderDriveMountPoint(source_file); |
| 2717 bool destination_file_under_drive = | 2808 bool destination_file_under_drive = |
| 2718 drive::util::IsUnderDriveMountPoint(destination_file); | 2809 drive::util::IsUnderDriveMountPoint(destination_file); |
| 2719 | 2810 |
| 2720 if (source_file_under_drive && !destination_file_under_drive) { | 2811 if (source_file_under_drive && !destination_file_under_drive) { |
| 2721 // Transfer a file from gdata to local file system. | 2812 // Transfer a file from gdata to local file system. |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2949 std::string file_url_as_string; | 3040 std::string file_url_as_string; |
| 2950 if (!args_->GetString(0, &file_url_as_string)) | 3041 if (!args_->GetString(0, &file_url_as_string)) |
| 2951 return false; | 3042 return false; |
| 2952 | 3043 |
| 2953 drive::DriveSystemService* system_service = | 3044 drive::DriveSystemService* system_service = |
| 2954 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 3045 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2955 // |system_service| is NULL if Drive is disabled. | 3046 // |system_service| is NULL if Drive is disabled. |
| 2956 if (!system_service || !system_service->file_system()) | 3047 if (!system_service || !system_service->file_system()) |
| 2957 return false; | 3048 return false; |
| 2958 | 3049 |
| 2959 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 3050 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 3051 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 3052 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 3053 GetFileSystemContext(); |
| 3054 |
| 3055 FilePath directory_path = GetVirtualPathFromURL(file_system_context, |
| 3056 GURL(file_url_as_string)); |
| 2960 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 3057 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
| 2961 | 3058 |
| 2962 return true; | 3059 return true; |
| 2963 } | 3060 } |
| 2964 | 3061 |
| 2965 ZipSelectionFunction::ZipSelectionFunction() { | 3062 ZipSelectionFunction::ZipSelectionFunction() { |
| 2966 } | 3063 } |
| 2967 | 3064 |
| 2968 ZipSelectionFunction::~ZipSelectionFunction() { | 3065 ZipSelectionFunction::~ZipSelectionFunction() { |
| 2969 } | 3066 } |
| 2970 | 3067 |
| 2971 bool ZipSelectionFunction::RunImpl() { | 3068 bool ZipSelectionFunction::RunImpl() { |
| 2972 if (args_->GetSize() < 3) { | 3069 if (args_->GetSize() < 3) { |
| 2973 return false; | 3070 return false; |
| 2974 } | 3071 } |
| 2975 | 3072 |
| 2976 // First param is the source directory URL. | 3073 // First param is the source directory URL. |
| 2977 std::string dir_url; | 3074 std::string dir_url; |
| 2978 if (!args_->GetString(0, &dir_url) || dir_url.empty()) | 3075 if (!args_->GetString(0, &dir_url) || dir_url.empty()) |
| 2979 return false; | 3076 return false; |
| 2980 | 3077 |
| 2981 FilePath src_dir = GetLocalPathFromURL(GURL(dir_url)); | 3078 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 3079 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 3080 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 3081 GetFileSystemContext(); |
| 3082 |
| 3083 FilePath src_dir = GetLocalPathFromURL(file_system_context, |
| 3084 GURL(dir_url)); |
| 2982 if (src_dir.empty()) | 3085 if (src_dir.empty()) |
| 2983 return false; | 3086 return false; |
| 2984 | 3087 |
| 2985 // Second param is the list of selected file URLs. | 3088 // Second param is the list of selected file URLs. |
| 2986 ListValue* selection_urls = NULL; | 3089 ListValue* selection_urls = NULL; |
| 2987 args_->GetList(1, &selection_urls); | 3090 args_->GetList(1, &selection_urls); |
| 2988 if (!selection_urls || !selection_urls->GetSize()) | 3091 if (!selection_urls || !selection_urls->GetSize()) |
| 2989 return false; | 3092 return false; |
| 2990 | 3093 |
| 2991 std::vector<FilePath> files; | 3094 std::vector<FilePath> files; |
| 2992 for (size_t i = 0; i < selection_urls->GetSize(); ++i) { | 3095 for (size_t i = 0; i < selection_urls->GetSize(); ++i) { |
| 2993 std::string file_url; | 3096 std::string file_url; |
| 2994 selection_urls->GetString(i, &file_url); | 3097 selection_urls->GetString(i, &file_url); |
| 2995 FilePath path = GetLocalPathFromURL(GURL(file_url)); | 3098 FilePath path = GetLocalPathFromURL(file_system_context, GURL(file_url)); |
| 2996 if (path.empty()) | 3099 if (path.empty()) |
| 2997 return false; | 3100 return false; |
| 2998 files.push_back(path); | 3101 files.push_back(path); |
| 2999 } | 3102 } |
| 3000 | 3103 |
| 3001 // Third param is the name of the output zip file. | 3104 // Third param is the name of the output zip file. |
| 3002 std::string dest_name; | 3105 std::string dest_name; |
| 3003 if (!args_->GetString(2, &dest_name) || dest_name.empty()) | 3106 if (!args_->GetString(2, &dest_name) || dest_name.empty()) |
| 3004 return false; | 3107 return false; |
| 3005 | 3108 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3030 // Keep the refcount until the zipping is complete on utility process. | 3133 // Keep the refcount until the zipping is complete on utility process. |
| 3031 AddRef(); | 3134 AddRef(); |
| 3032 return true; | 3135 return true; |
| 3033 } | 3136 } |
| 3034 | 3137 |
| 3035 void ZipSelectionFunction::OnZipDone(bool success) { | 3138 void ZipSelectionFunction::OnZipDone(bool success) { |
| 3036 SetResult(new base::FundamentalValue(success)); | 3139 SetResult(new base::FundamentalValue(success)); |
| 3037 SendResponse(true); | 3140 SendResponse(true); |
| 3038 Release(); | 3141 Release(); |
| 3039 } | 3142 } |
| OLD | NEW |