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/statvfs.h> | 7 #include <sys/statvfs.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.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_util.h" | 44 #include "chrome/browser/google_apis/gdata_util.h" |
44 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 45 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
45 #include "chrome/browser/google_apis/operation_registry.h" | 46 #include "chrome/browser/google_apis/operation_registry.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 1821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 SET_STRING(IDS_FILE_BROWSER, RENAME_PROMPT); | 1918 SET_STRING(IDS_FILE_BROWSER, RENAME_PROMPT); |
1917 SET_STRING(IDS_FILE_BROWSER, RENAME_BUTTON_LABEL); | 1919 SET_STRING(IDS_FILE_BROWSER, RENAME_BUTTON_LABEL); |
1918 | 1920 |
1919 SET_STRING(IDS_FILE_BROWSER, ERROR_DELETING); | 1921 SET_STRING(IDS_FILE_BROWSER, ERROR_DELETING); |
1920 SET_STRING(IDS_FILE_BROWSER, DELETE_BUTTON_LABEL); | 1922 SET_STRING(IDS_FILE_BROWSER, DELETE_BUTTON_LABEL); |
1921 | 1923 |
1922 SET_STRING(IDS_FILE_BROWSER, PASTE_BUTTON_LABEL); | 1924 SET_STRING(IDS_FILE_BROWSER, PASTE_BUTTON_LABEL); |
1923 | 1925 |
1924 SET_STRING(IDS_FILE_BROWSER, COPY_BUTTON_LABEL); | 1926 SET_STRING(IDS_FILE_BROWSER, COPY_BUTTON_LABEL); |
1925 SET_STRING(IDS_FILE_BROWSER, CUT_BUTTON_LABEL); | 1927 SET_STRING(IDS_FILE_BROWSER, CUT_BUTTON_LABEL); |
| 1928 SET_STRING(IDS_FILE_BROWSER, ZIP_SELECTION_BUTTON_LABEL); |
1926 | 1929 |
1927 SET_STRING(IDS_FILE_BROWSER, OPEN_WITH_BUTTON_LABEL); | 1930 SET_STRING(IDS_FILE_BROWSER, OPEN_WITH_BUTTON_LABEL); |
1928 | 1931 |
1929 SET_STRING(IDS_FILE_BROWSER, TRANSFER_ITEMS_REMAINING); | 1932 SET_STRING(IDS_FILE_BROWSER, TRANSFER_ITEMS_REMAINING); |
1930 SET_STRING(IDS_FILE_BROWSER, TRANSFER_CANCELLED); | 1933 SET_STRING(IDS_FILE_BROWSER, TRANSFER_CANCELLED); |
1931 SET_STRING(IDS_FILE_BROWSER, TRANSFER_TARGET_EXISTS_ERROR); | 1934 SET_STRING(IDS_FILE_BROWSER, TRANSFER_TARGET_EXISTS_ERROR); |
1932 SET_STRING(IDS_FILE_BROWSER, TRANSFER_FILESYSTEM_ERROR); | 1935 SET_STRING(IDS_FILE_BROWSER, TRANSFER_FILESYSTEM_ERROR); |
1933 SET_STRING(IDS_FILE_BROWSER, TRANSFER_UNEXPECTED_ERROR); | 1936 SET_STRING(IDS_FILE_BROWSER, TRANSFER_UNEXPECTED_ERROR); |
1934 SET_STRING(IDS_FILE_BROWSER, COPY_FILE_NAME); | 1937 SET_STRING(IDS_FILE_BROWSER, COPY_FILE_NAME); |
1935 SET_STRING(IDS_FILE_BROWSER, COPY_ITEMS_REMAINING); | 1938 SET_STRING(IDS_FILE_BROWSER, COPY_ITEMS_REMAINING); |
1936 SET_STRING(IDS_FILE_BROWSER, COPY_CANCELLED); | 1939 SET_STRING(IDS_FILE_BROWSER, COPY_CANCELLED); |
1937 SET_STRING(IDS_FILE_BROWSER, COPY_TARGET_EXISTS_ERROR); | 1940 SET_STRING(IDS_FILE_BROWSER, COPY_TARGET_EXISTS_ERROR); |
1938 SET_STRING(IDS_FILE_BROWSER, COPY_FILESYSTEM_ERROR); | 1941 SET_STRING(IDS_FILE_BROWSER, COPY_FILESYSTEM_ERROR); |
1939 SET_STRING(IDS_FILE_BROWSER, COPY_UNEXPECTED_ERROR); | 1942 SET_STRING(IDS_FILE_BROWSER, COPY_UNEXPECTED_ERROR); |
1940 SET_STRING(IDS_FILE_BROWSER, MOVE_FILE_NAME); | 1943 SET_STRING(IDS_FILE_BROWSER, MOVE_FILE_NAME); |
1941 SET_STRING(IDS_FILE_BROWSER, MOVE_ITEMS_REMAINING); | 1944 SET_STRING(IDS_FILE_BROWSER, MOVE_ITEMS_REMAINING); |
1942 SET_STRING(IDS_FILE_BROWSER, MOVE_CANCELLED); | 1945 SET_STRING(IDS_FILE_BROWSER, MOVE_CANCELLED); |
1943 SET_STRING(IDS_FILE_BROWSER, MOVE_TARGET_EXISTS_ERROR); | 1946 SET_STRING(IDS_FILE_BROWSER, MOVE_TARGET_EXISTS_ERROR); |
1944 SET_STRING(IDS_FILE_BROWSER, MOVE_FILESYSTEM_ERROR); | 1947 SET_STRING(IDS_FILE_BROWSER, MOVE_FILESYSTEM_ERROR); |
1945 SET_STRING(IDS_FILE_BROWSER, MOVE_UNEXPECTED_ERROR); | 1948 SET_STRING(IDS_FILE_BROWSER, MOVE_UNEXPECTED_ERROR); |
| 1949 SET_STRING(IDS_FILE_BROWSER, ZIP_FILE_NAME); |
| 1950 SET_STRING(IDS_FILE_BROWSER, ZIP_ITEMS_REMAINING); |
| 1951 SET_STRING(IDS_FILE_BROWSER, ZIP_CANCELLED); |
| 1952 SET_STRING(IDS_FILE_BROWSER, ZIP_TARGET_EXISTS_ERROR); |
| 1953 SET_STRING(IDS_FILE_BROWSER, ZIP_FILESYSTEM_ERROR); |
| 1954 SET_STRING(IDS_FILE_BROWSER, ZIP_UNEXPECTED_ERROR); |
1946 | 1955 |
1947 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE_PLURAL); | 1956 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE_PLURAL); |
1948 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE); | 1957 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE); |
1949 SET_STRING(IDS_FILE_BROWSER, UNDO_DELETE); | 1958 SET_STRING(IDS_FILE_BROWSER, UNDO_DELETE); |
1950 | 1959 |
1951 SET_STRING(IDS_FILE_BROWSER, CANCEL_LABEL); | 1960 SET_STRING(IDS_FILE_BROWSER, CANCEL_LABEL); |
1952 SET_STRING(IDS_FILE_BROWSER, OPEN_LABEL); | 1961 SET_STRING(IDS_FILE_BROWSER, OPEN_LABEL); |
1953 SET_STRING(IDS_FILE_BROWSER, SAVE_LABEL); | 1962 SET_STRING(IDS_FILE_BROWSER, SAVE_LABEL); |
1954 SET_STRING(IDS_FILE_BROWSER, OK_LABEL); | 1963 SET_STRING(IDS_FILE_BROWSER, OK_LABEL); |
1955 | 1964 |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2889 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2898 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
2890 // |system_service| is NULL if Drive is disabled. | 2899 // |system_service| is NULL if Drive is disabled. |
2891 if (!system_service || !system_service->file_system()) | 2900 if (!system_service || !system_service->file_system()) |
2892 return false; | 2901 return false; |
2893 | 2902 |
2894 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 2903 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); |
2895 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 2904 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
2896 | 2905 |
2897 return true; | 2906 return true; |
2898 } | 2907 } |
| 2908 |
| 2909 ZipSelectionFunction::ZipSelectionFunction() { |
| 2910 } |
| 2911 |
| 2912 ZipSelectionFunction::~ZipSelectionFunction() { |
| 2913 } |
| 2914 |
| 2915 bool ZipSelectionFunction::RunImpl() { |
| 2916 if (args_->GetSize() < 3) { |
| 2917 return false; |
| 2918 } |
| 2919 |
| 2920 // First param is the source directory URL. |
| 2921 std::string dir_url; |
| 2922 if (!args_->GetString(0, &dir_url) || dir_url.empty()) |
| 2923 return false; |
| 2924 |
| 2925 // Second param is the list of selected file URLs. |
| 2926 ListValue* selection_urls = NULL; |
| 2927 args_->GetList(1, &selection_urls); |
| 2928 if (!selection_urls || !selection_urls->GetSize()) |
| 2929 return false; |
| 2930 |
| 2931 // Third param is the name of the output zip file. |
| 2932 std::string dest_name; |
| 2933 if (!args_->GetString(2, &dest_name) || dest_name.empty()) |
| 2934 return false; |
| 2935 |
| 2936 UrlList file_urls; |
| 2937 size_t len = selection_urls->GetSize(); |
| 2938 file_urls.reserve(len + 1); |
| 2939 file_urls.push_back(GURL(dir_url)); |
| 2940 for (size_t i = 0; i < len; ++i) { |
| 2941 std::string file_url; |
| 2942 selection_urls->GetString(i, &file_url); |
| 2943 file_urls.push_back(GURL(file_url)); |
| 2944 } |
| 2945 |
| 2946 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( |
| 2947 file_urls, |
| 2948 base::Bind(&ZipSelectionFunction::GetLocalPathsResponseOnUIThread, |
| 2949 this, |
| 2950 dest_name)); |
| 2951 return true; |
| 2952 } |
| 2953 |
| 2954 void ZipSelectionFunction::GetLocalPathsResponseOnUIThread( |
| 2955 const std::string dest_name, |
| 2956 const SelectedFileInfoList& files) { |
| 2957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2958 if (files.size() <= 1) { |
| 2959 NOTREACHED(); |
| 2960 SendResponse(false); |
| 2961 return; |
| 2962 } |
| 2963 |
| 2964 SelectedFileInfoList::const_iterator iter = files.begin(); |
| 2965 FilePath src_dir = iter->file_path; |
| 2966 |
| 2967 // Check if the dir path is under Drive cache directory. |
| 2968 // TODO(hshi): support create zip file on Drive (crbug.com/158690). |
| 2969 drive::DriveSystemService* system_service = |
| 2970 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2971 drive::DriveCache* cache = system_service ? system_service->cache() : NULL; |
| 2972 if (cache && cache->IsUnderDriveCacheDirectory(src_dir)) { |
| 2973 SendResponse(false); |
| 2974 return; |
| 2975 } |
| 2976 |
| 2977 FilePath dest_file = src_dir.Append(dest_name); |
| 2978 std::vector<FilePath> src_relative_paths; |
| 2979 for (++iter; iter != files.end(); ++iter) { |
| 2980 const FilePath& file_path = iter->file_path; |
| 2981 |
| 2982 // Obtain the relative path of |file_path| under |src_dir|. |
| 2983 FilePath relative_path; |
| 2984 if (!src_dir.AppendRelativePath(file_path, &relative_path)) { |
| 2985 // All files must be under |src_dir| or there is a bug in extension code. |
| 2986 SendResponse(false); |
| 2987 return; |
| 2988 } |
| 2989 src_relative_paths.push_back(relative_path); |
| 2990 } |
| 2991 |
| 2992 zip_file_creator_ = new ZipFileCreator(this, src_dir, src_relative_paths, |
| 2993 dest_file); |
| 2994 zip_file_creator_->Start(); |
| 2995 |
| 2996 // Keep the refcount until the zipping is complete on utility process. |
| 2997 AddRef(); |
| 2998 } |
| 2999 |
| 3000 void ZipSelectionFunction::OnZipDone(bool success) { |
| 3001 SetResult(new base::FundamentalValue(success)); |
| 3002 SendResponse(true); |
| 3003 Release(); |
| 3004 } |
OLD | NEW |