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 15 matching lines...) Expand all Loading... |
26 #include "base/values.h" | 26 #include "base/values.h" |
27 #include "chrome/browser/chromeos/cros/cros_library.h" | 27 #include "chrome/browser/chromeos/cros/cros_library.h" |
28 #include "chrome/browser/chromeos/cros/network_library.h" | 28 #include "chrome/browser/chromeos/cros/network_library.h" |
29 #include "chrome/browser/chromeos/drive/drive.pb.h" | 29 #include "chrome/browser/chromeos/drive/drive.pb.h" |
30 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" | 30 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" |
31 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 31 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
32 #include "chrome/browser/chromeos/drive/drive_system_service.h" | 32 #include "chrome/browser/chromeos/drive/drive_system_service.h" |
33 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" | 33 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" |
34 #include "chrome/browser/chromeos/extensions/file_handler_util.h" | 34 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
35 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 35 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 36 #include "chrome/browser/chromeos/extensions/zip_file_creator.h" |
36 #include "chrome/browser/chromeos/system/statistics_provider.h" | 37 #include "chrome/browser/chromeos/system/statistics_provider.h" |
37 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 38 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
38 #include "chrome/browser/extensions/extension_process_manager.h" | 39 #include "chrome/browser/extensions/extension_process_manager.h" |
39 #include "chrome/browser/extensions/extension_service.h" | 40 #include "chrome/browser/extensions/extension_service.h" |
40 #include "chrome/browser/extensions/extension_tab_util.h" | 41 #include "chrome/browser/extensions/extension_tab_util.h" |
41 #include "chrome/browser/extensions/process_map.h" | 42 #include "chrome/browser/extensions/process_map.h" |
42 #include "chrome/browser/google_apis/drive_service_interface.h" | 43 #include "chrome/browser/google_apis/drive_service_interface.h" |
43 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 44 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
44 #include "chrome/browser/google_apis/operation_registry.h" | 45 #include "chrome/browser/google_apis/operation_registry.h" |
45 #include "chrome/browser/google_apis/time_util.h" | 46 #include "chrome/browser/google_apis/time_util.h" |
(...skipping 29 matching lines...) Expand all Loading... |
75 #include "webkit/fileapi/file_system_util.h" | 76 #include "webkit/fileapi/file_system_util.h" |
76 #include "webkit/glue/web_intent_service_data.h" | 77 #include "webkit/glue/web_intent_service_data.h" |
77 | 78 |
78 using chromeos::disks::DiskMountManager; | 79 using chromeos::disks::DiskMountManager; |
79 using content::BrowserContext; | 80 using content::BrowserContext; |
80 using content::BrowserThread; | 81 using content::BrowserThread; |
81 using content::ChildProcessSecurityPolicy; | 82 using content::ChildProcessSecurityPolicy; |
82 using content::SiteInstance; | 83 using content::SiteInstance; |
83 using content::WebContents; | 84 using content::WebContents; |
84 using extensions::Extension; | 85 using extensions::Extension; |
| 86 using extensions::ZipFileCreator; |
85 using file_handler_util::FileTaskExecutor; | 87 using file_handler_util::FileTaskExecutor; |
86 using google_apis::InstalledApp; | 88 using google_apis::InstalledApp; |
87 | 89 |
88 namespace { | 90 namespace { |
89 | 91 |
90 // Default icon path for drive docs. | 92 // Default icon path for drive docs. |
91 const char kDefaultIcon[] = "images/filetype_generic.png"; | 93 const char kDefaultIcon[] = "images/filetype_generic.png"; |
92 const int kPreferredIconSize = 16; | 94 const int kPreferredIconSize = 16; |
93 | 95 |
94 // Error messages. | 96 // Error messages. |
(...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1918 SET_STRING(IDS_FILE_BROWSER, RENAME_PROMPT); | 1920 SET_STRING(IDS_FILE_BROWSER, RENAME_PROMPT); |
1919 SET_STRING(IDS_FILE_BROWSER, RENAME_BUTTON_LABEL); | 1921 SET_STRING(IDS_FILE_BROWSER, RENAME_BUTTON_LABEL); |
1920 | 1922 |
1921 SET_STRING(IDS_FILE_BROWSER, ERROR_DELETING); | 1923 SET_STRING(IDS_FILE_BROWSER, ERROR_DELETING); |
1922 SET_STRING(IDS_FILE_BROWSER, DELETE_BUTTON_LABEL); | 1924 SET_STRING(IDS_FILE_BROWSER, DELETE_BUTTON_LABEL); |
1923 | 1925 |
1924 SET_STRING(IDS_FILE_BROWSER, PASTE_BUTTON_LABEL); | 1926 SET_STRING(IDS_FILE_BROWSER, PASTE_BUTTON_LABEL); |
1925 | 1927 |
1926 SET_STRING(IDS_FILE_BROWSER, COPY_BUTTON_LABEL); | 1928 SET_STRING(IDS_FILE_BROWSER, COPY_BUTTON_LABEL); |
1927 SET_STRING(IDS_FILE_BROWSER, CUT_BUTTON_LABEL); | 1929 SET_STRING(IDS_FILE_BROWSER, CUT_BUTTON_LABEL); |
| 1930 SET_STRING(IDS_FILE_BROWSER, ZIP_SELECTION_BUTTON_LABEL); |
1928 | 1931 |
1929 SET_STRING(IDS_FILE_BROWSER, OPEN_WITH_BUTTON_LABEL); | 1932 SET_STRING(IDS_FILE_BROWSER, OPEN_WITH_BUTTON_LABEL); |
1930 | 1933 |
1931 SET_STRING(IDS_FILE_BROWSER, TRANSFER_ITEMS_REMAINING); | 1934 SET_STRING(IDS_FILE_BROWSER, TRANSFER_ITEMS_REMAINING); |
1932 SET_STRING(IDS_FILE_BROWSER, TRANSFER_CANCELLED); | 1935 SET_STRING(IDS_FILE_BROWSER, TRANSFER_CANCELLED); |
1933 SET_STRING(IDS_FILE_BROWSER, TRANSFER_TARGET_EXISTS_ERROR); | 1936 SET_STRING(IDS_FILE_BROWSER, TRANSFER_TARGET_EXISTS_ERROR); |
1934 SET_STRING(IDS_FILE_BROWSER, TRANSFER_FILESYSTEM_ERROR); | 1937 SET_STRING(IDS_FILE_BROWSER, TRANSFER_FILESYSTEM_ERROR); |
1935 SET_STRING(IDS_FILE_BROWSER, TRANSFER_UNEXPECTED_ERROR); | 1938 SET_STRING(IDS_FILE_BROWSER, TRANSFER_UNEXPECTED_ERROR); |
1936 SET_STRING(IDS_FILE_BROWSER, COPY_FILE_NAME); | 1939 SET_STRING(IDS_FILE_BROWSER, COPY_FILE_NAME); |
1937 SET_STRING(IDS_FILE_BROWSER, COPY_ITEMS_REMAINING); | 1940 SET_STRING(IDS_FILE_BROWSER, COPY_ITEMS_REMAINING); |
1938 SET_STRING(IDS_FILE_BROWSER, COPY_CANCELLED); | 1941 SET_STRING(IDS_FILE_BROWSER, COPY_CANCELLED); |
1939 SET_STRING(IDS_FILE_BROWSER, COPY_TARGET_EXISTS_ERROR); | 1942 SET_STRING(IDS_FILE_BROWSER, COPY_TARGET_EXISTS_ERROR); |
1940 SET_STRING(IDS_FILE_BROWSER, COPY_FILESYSTEM_ERROR); | 1943 SET_STRING(IDS_FILE_BROWSER, COPY_FILESYSTEM_ERROR); |
1941 SET_STRING(IDS_FILE_BROWSER, COPY_UNEXPECTED_ERROR); | 1944 SET_STRING(IDS_FILE_BROWSER, COPY_UNEXPECTED_ERROR); |
1942 SET_STRING(IDS_FILE_BROWSER, MOVE_FILE_NAME); | 1945 SET_STRING(IDS_FILE_BROWSER, MOVE_FILE_NAME); |
1943 SET_STRING(IDS_FILE_BROWSER, MOVE_ITEMS_REMAINING); | 1946 SET_STRING(IDS_FILE_BROWSER, MOVE_ITEMS_REMAINING); |
1944 SET_STRING(IDS_FILE_BROWSER, MOVE_CANCELLED); | 1947 SET_STRING(IDS_FILE_BROWSER, MOVE_CANCELLED); |
1945 SET_STRING(IDS_FILE_BROWSER, MOVE_TARGET_EXISTS_ERROR); | 1948 SET_STRING(IDS_FILE_BROWSER, MOVE_TARGET_EXISTS_ERROR); |
1946 SET_STRING(IDS_FILE_BROWSER, MOVE_FILESYSTEM_ERROR); | 1949 SET_STRING(IDS_FILE_BROWSER, MOVE_FILESYSTEM_ERROR); |
1947 SET_STRING(IDS_FILE_BROWSER, MOVE_UNEXPECTED_ERROR); | 1950 SET_STRING(IDS_FILE_BROWSER, MOVE_UNEXPECTED_ERROR); |
| 1951 SET_STRING(IDS_FILE_BROWSER, ZIP_FILE_NAME); |
| 1952 SET_STRING(IDS_FILE_BROWSER, ZIP_ITEMS_REMAINING); |
| 1953 SET_STRING(IDS_FILE_BROWSER, ZIP_CANCELLED); |
| 1954 SET_STRING(IDS_FILE_BROWSER, ZIP_TARGET_EXISTS_ERROR); |
| 1955 SET_STRING(IDS_FILE_BROWSER, ZIP_FILESYSTEM_ERROR); |
| 1956 SET_STRING(IDS_FILE_BROWSER, ZIP_UNEXPECTED_ERROR); |
1948 | 1957 |
1949 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE_PLURAL); | 1958 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE_PLURAL); |
1950 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE); | 1959 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE); |
1951 SET_STRING(IDS_FILE_BROWSER, UNDO_DELETE); | 1960 SET_STRING(IDS_FILE_BROWSER, UNDO_DELETE); |
1952 | 1961 |
1953 SET_STRING(IDS_FILE_BROWSER, CANCEL_LABEL); | 1962 SET_STRING(IDS_FILE_BROWSER, CANCEL_LABEL); |
1954 SET_STRING(IDS_FILE_BROWSER, OPEN_LABEL); | 1963 SET_STRING(IDS_FILE_BROWSER, OPEN_LABEL); |
1955 SET_STRING(IDS_FILE_BROWSER, SAVE_LABEL); | 1964 SET_STRING(IDS_FILE_BROWSER, SAVE_LABEL); |
1956 SET_STRING(IDS_FILE_BROWSER, OK_LABEL); | 1965 SET_STRING(IDS_FILE_BROWSER, OK_LABEL); |
1957 | 1966 |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2891 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2900 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
2892 // |system_service| is NULL if Drive is disabled. | 2901 // |system_service| is NULL if Drive is disabled. |
2893 if (!system_service || !system_service->file_system()) | 2902 if (!system_service || !system_service->file_system()) |
2894 return false; | 2903 return false; |
2895 | 2904 |
2896 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 2905 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); |
2897 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 2906 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
2898 | 2907 |
2899 return true; | 2908 return true; |
2900 } | 2909 } |
| 2910 |
| 2911 ZipSelectionFunction::ZipSelectionFunction() { |
| 2912 } |
| 2913 |
| 2914 ZipSelectionFunction::~ZipSelectionFunction() { |
| 2915 } |
| 2916 |
| 2917 bool ZipSelectionFunction::RunImpl() { |
| 2918 if (args_->GetSize() < 3) { |
| 2919 return false; |
| 2920 } |
| 2921 |
| 2922 // First param is the source directory URL. |
| 2923 std::string dir_url; |
| 2924 if (!args_->GetString(0, &dir_url) || dir_url.empty()) |
| 2925 return false; |
| 2926 |
| 2927 // Second param is the list of selected file URLs. |
| 2928 ListValue* selection_urls = NULL; |
| 2929 args_->GetList(1, &selection_urls); |
| 2930 if (!selection_urls || !selection_urls->GetSize()) |
| 2931 return false; |
| 2932 |
| 2933 // Third param is the name of the output zip file. |
| 2934 std::string dest_name; |
| 2935 if (!args_->GetString(2, &dest_name) || dest_name.empty()) |
| 2936 return false; |
| 2937 |
| 2938 UrlList file_urls; |
| 2939 size_t len = selection_urls->GetSize(); |
| 2940 file_urls.reserve(len + 1); |
| 2941 file_urls.push_back(GURL(dir_url)); |
| 2942 for (size_t i = 0; i < len; ++i) { |
| 2943 std::string file_url; |
| 2944 selection_urls->GetString(i, &file_url); |
| 2945 file_urls.push_back(GURL(file_url)); |
| 2946 } |
| 2947 |
| 2948 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( |
| 2949 file_urls, |
| 2950 base::Bind(&ZipSelectionFunction::GetLocalPathsResponseOnUIThread, |
| 2951 this, |
| 2952 dest_name)); |
| 2953 return true; |
| 2954 } |
| 2955 |
| 2956 void ZipSelectionFunction::GetLocalPathsResponseOnUIThread( |
| 2957 const std::string dest_name, |
| 2958 const SelectedFileInfoList& files) { |
| 2959 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2960 if (files.size() <= 1) { |
| 2961 NOTREACHED(); |
| 2962 SendResponse(false); |
| 2963 return; |
| 2964 } |
| 2965 |
| 2966 SelectedFileInfoList::const_iterator iter = files.begin(); |
| 2967 FilePath src_dir = iter->file_path; |
| 2968 |
| 2969 // Check if the dir path is under Drive cache directory. |
| 2970 // TODO(hshi): support create zip file on Drive (crbug.com/158690). |
| 2971 drive::DriveSystemService* system_service = |
| 2972 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2973 drive::DriveCache* cache = system_service ? system_service->cache() : NULL; |
| 2974 if (cache && cache->IsUnderDriveCacheDirectory(src_dir)) { |
| 2975 SendResponse(false); |
| 2976 return; |
| 2977 } |
| 2978 |
| 2979 FilePath dest_file = src_dir.Append(dest_name); |
| 2980 std::vector<FilePath> src_relative_paths; |
| 2981 for (++iter; iter != files.end(); ++iter) { |
| 2982 const FilePath& file_path = iter->file_path; |
| 2983 |
| 2984 // Obtain the relative path of |file_path| under |src_dir|. |
| 2985 FilePath relative_path; |
| 2986 if (!src_dir.AppendRelativePath(file_path, &relative_path)) { |
| 2987 // All files must be under |src_dir| or there is a bug in extension code. |
| 2988 SendResponse(false); |
| 2989 return; |
| 2990 } |
| 2991 src_relative_paths.push_back(relative_path); |
| 2992 } |
| 2993 |
| 2994 zip_file_creator_ = new ZipFileCreator(this, src_dir, src_relative_paths, |
| 2995 dest_file); |
| 2996 zip_file_creator_->Start(); |
| 2997 |
| 2998 // Keep the refcount until the zipping is complete on utility process. |
| 2999 AddRef(); |
| 3000 } |
| 3001 |
| 3002 void ZipSelectionFunction::OnZipDone(bool success) { |
| 3003 SetResult(new base::FundamentalValue(success)); |
| 3004 SendResponse(true); |
| 3005 Release(); |
| 3006 } |
OLD | NEW |