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 30 matching lines...) Expand all Loading... |
41 #include "chrome/browser/extensions/extension_function_registry.h" | 41 #include "chrome/browser/extensions/extension_function_registry.h" |
42 #include "chrome/browser/extensions/extension_process_manager.h" | 42 #include "chrome/browser/extensions/extension_process_manager.h" |
43 #include "chrome/browser/extensions/extension_service.h" | 43 #include "chrome/browser/extensions/extension_service.h" |
44 #include "chrome/browser/extensions/extension_system.h" | 44 #include "chrome/browser/extensions/extension_system.h" |
45 #include "chrome/browser/extensions/extension_tab_util.h" | 45 #include "chrome/browser/extensions/extension_tab_util.h" |
46 #include "chrome/browser/extensions/process_map.h" | 46 #include "chrome/browser/extensions/process_map.h" |
47 #include "chrome/browser/google_apis/drive_service_interface.h" | 47 #include "chrome/browser/google_apis/drive_service_interface.h" |
48 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 48 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
49 #include "chrome/browser/google_apis/operation_registry.h" | 49 #include "chrome/browser/google_apis/operation_registry.h" |
50 #include "chrome/browser/google_apis/time_util.h" | 50 #include "chrome/browser/google_apis/time_util.h" |
51 #include "chrome/browser/intents/web_intents_util.h" | |
52 #include "chrome/browser/profiles/profile.h" | 51 #include "chrome/browser/profiles/profile.h" |
53 #include "chrome/browser/ui/browser.h" | 52 #include "chrome/browser/ui/browser.h" |
54 #include "chrome/browser/ui/browser_window.h" | 53 #include "chrome/browser/ui/browser_window.h" |
55 #include "chrome/browser/ui/views/select_file_dialog_extension.h" | 54 #include "chrome/browser/ui/views/select_file_dialog_extension.h" |
56 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 55 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
57 #include "chrome/common/extensions/extension.h" | 56 #include "chrome/common/extensions/extension.h" |
58 #include "chrome/common/extensions/extension_constants.h" | 57 #include "chrome/common/extensions/extension_constants.h" |
59 #include "chrome/common/extensions/extension_icon_set.h" | 58 #include "chrome/common/extensions/extension_icon_set.h" |
60 #include "chrome/common/extensions/extension_manifest_constants.h" | 59 #include "chrome/common/extensions/extension_manifest_constants.h" |
61 #include "chrome/common/extensions/web_intents_handler.h" | |
62 #include "chrome/common/pref_names.h" | 60 #include "chrome/common/pref_names.h" |
63 #include "chromeos/disks/disk_mount_manager.h" | 61 #include "chromeos/disks/disk_mount_manager.h" |
64 #include "content/public/browser/child_process_security_policy.h" | 62 #include "content/public/browser/child_process_security_policy.h" |
65 #include "content/public/browser/render_process_host.h" | 63 #include "content/public/browser/render_process_host.h" |
66 #include "content/public/browser/render_view_host.h" | 64 #include "content/public/browser/render_view_host.h" |
67 #include "content/public/browser/storage_partition.h" | 65 #include "content/public/browser/storage_partition.h" |
68 #include "googleurl/src/gurl.h" | 66 #include "googleurl/src/gurl.h" |
69 #include "grit/app_locale_settings.h" | 67 #include "grit/app_locale_settings.h" |
70 #include "grit/generated_resources.h" | 68 #include "grit/generated_resources.h" |
71 #include "grit/platform_locale_settings.h" | 69 #include "grit/platform_locale_settings.h" |
72 #include "net/base/escape.h" | 70 #include "net/base/escape.h" |
73 #include "net/base/mime_util.h" | 71 #include "net/base/mime_util.h" |
74 #include "net/base/network_change_notifier.h" | 72 #include "net/base/network_change_notifier.h" |
75 #include "ui/base/l10n/l10n_util.h" | 73 #include "ui/base/l10n/l10n_util.h" |
76 #include "ui/shell_dialogs/selected_file_info.h" | 74 #include "ui/shell_dialogs/selected_file_info.h" |
77 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 75 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
78 #include "webkit/fileapi/file_system_context.h" | 76 #include "webkit/fileapi/file_system_context.h" |
79 #include "webkit/fileapi/file_system_file_util.h" | 77 #include "webkit/fileapi/file_system_file_util.h" |
80 #include "webkit/fileapi/file_system_operation_context.h" | 78 #include "webkit/fileapi/file_system_operation_context.h" |
81 #include "webkit/fileapi/file_system_types.h" | 79 #include "webkit/fileapi/file_system_types.h" |
82 #include "webkit/fileapi/file_system_url.h" | 80 #include "webkit/fileapi/file_system_url.h" |
83 #include "webkit/fileapi/file_system_util.h" | 81 #include "webkit/fileapi/file_system_util.h" |
84 #include "webkit/glue/web_intent_service_data.h" | |
85 #include "ui/webui/web_ui_util.h" | 82 #include "ui/webui/web_ui_util.h" |
86 | 83 |
87 using extensions::app_file_handler_util::FindFileHandlersForMimeTypes; | 84 using extensions::app_file_handler_util::FindFileHandlersForMimeTypes; |
88 using chromeos::disks::DiskMountManager; | 85 using chromeos::disks::DiskMountManager; |
89 using content::BrowserContext; | 86 using content::BrowserContext; |
90 using content::BrowserThread; | 87 using content::BrowserThread; |
91 using content::ChildProcessSecurityPolicy; | 88 using content::ChildProcessSecurityPolicy; |
92 using content::SiteInstance; | 89 using content::SiteInstance; |
93 using content::WebContents; | 90 using content::WebContents; |
94 using extensions::Extension; | 91 using extensions::Extension; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (icons.empty()) | 270 if (icons.empty()) |
274 return result; | 271 return result; |
275 result = icons.rbegin()->second; | 272 result = icons.rbegin()->second; |
276 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); | 273 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); |
277 iter != icons.rend() && iter->first >= preferred_size; ++iter) { | 274 iter != icons.rend() && iter->first >= preferred_size; ++iter) { |
278 result = iter->second; | 275 result = iter->second; |
279 } | 276 } |
280 return result; | 277 return result; |
281 } | 278 } |
282 | 279 |
283 #if defined(ENABLE_WEB_INTENTS) | |
284 // Finds the title of the given Web Intents |action|, if the passed extension | |
285 // supports this action for all specified |mime_types|. Returns true and | |
286 // provides the |title| as output on success. | |
287 bool FindTitleForActionWithTypes( | |
288 const Extension* extension, | |
289 const std::string& action, | |
290 const std::set<std::string>& mime_types, | |
291 std::string* title) { | |
292 DCHECK(!mime_types.empty()); | |
293 std::set<std::string> pending(mime_types.begin(), mime_types.end()); | |
294 std::string found_title; | |
295 | |
296 for (std::vector<webkit_glue::WebIntentServiceData>::const_iterator data = | |
297 extensions::WebIntentsInfo::GetIntentsServices(extension).begin(); | |
298 data != extensions::WebIntentsInfo::GetIntentsServices(extension).end(); | |
299 ++data) { | |
300 if (pending.empty()) | |
301 break; | |
302 | |
303 if (UTF16ToUTF8(data->action) != action) | |
304 continue; | |
305 | |
306 std::set<std::string>::iterator pending_iter = pending.begin(); | |
307 while (pending_iter != pending.end()) { | |
308 std::set<std::string>::iterator current = pending_iter++; | |
309 if (net::MatchesMimeType(UTF16ToUTF8(data->type), *current)) | |
310 pending.erase(current); | |
311 } | |
312 if (found_title.empty()) | |
313 found_title = UTF16ToUTF8(data->title); | |
314 } | |
315 | |
316 // Not all mime-types have been found. | |
317 if (!pending.empty()) | |
318 return false; | |
319 | |
320 *title = found_title; | |
321 return true; | |
322 } | |
323 #endif // defined(ENABLE_WEB_INTENTS) | |
324 | |
325 // Retrieves total and remaining available size on |mount_path|. | 280 // Retrieves total and remaining available size on |mount_path|. |
326 void GetSizeStatsOnFileThread(const std::string& mount_path, | 281 void GetSizeStatsOnFileThread(const std::string& mount_path, |
327 size_t* total_size_kb, | 282 size_t* total_size_kb, |
328 size_t* remaining_size_kb) { | 283 size_t* remaining_size_kb) { |
329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
330 | 285 |
331 uint64_t total_size_in_bytes = 0; | 286 uint64_t total_size_in_bytes = 0; |
332 uint64_t remaining_size_in_bytes = 0; | 287 uint64_t remaining_size_in_bytes = 0; |
333 | 288 |
334 struct statvfs stat = {}; // Zero-clear | 289 struct statvfs stat = {}; // Zero-clear |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 task->SetString("iconUrl", kDefaultIcon); | 944 task->SetString("iconUrl", kDefaultIcon); |
990 | 945 |
991 task->SetBoolean("driveApp", false); | 946 task->SetBoolean("driveApp", false); |
992 result_list->Append(task); | 947 result_list->Append(task); |
993 } | 948 } |
994 } | 949 } |
995 | 950 |
996 return true; | 951 return true; |
997 } | 952 } |
998 | 953 |
999 #if defined(ENABLE_WEB_INTENTS) | |
1000 // Find Web Intent platform apps that support the View task, and add them to | |
1001 // the |result_list|. These will be marked as kTaskWebIntent. | |
1002 bool GetFileTasksFileBrowserFunction::FindWebIntentTasks( | |
1003 const std::vector<FilePath>& file_paths, | |
1004 ListValue* result_list) { | |
1005 DCHECK(!file_paths.empty()); | |
1006 ExtensionService* service = profile_->GetExtensionService(); | |
1007 if (!service) | |
1008 return false; | |
1009 | |
1010 std::set<std::string> mime_types; | |
1011 GetMimeTypesForFileURLs(file_paths, &mime_types); | |
1012 | |
1013 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | |
1014 iter != service->extensions()->end(); | |
1015 ++iter) { | |
1016 const Extension* extension = *iter; | |
1017 | |
1018 // We don't support using hosted apps to open files. | |
1019 if (!extension->is_platform_app()) | |
1020 continue; | |
1021 | |
1022 if (profile_->IsOffTheRecord() && | |
1023 !service->IsIncognitoEnabled(extension->id())) | |
1024 continue; | |
1025 | |
1026 std::string title; | |
1027 if (!FindTitleForActionWithTypes( | |
1028 extension, web_intents::kActionView, mime_types, &title)) | |
1029 continue; | |
1030 | |
1031 DictionaryValue* task = new DictionaryValue; | |
1032 std::string task_id = file_handler_util::MakeTaskID(extension->id(), | |
1033 file_handler_util::kTaskWebIntent, web_intents::kActionView); | |
1034 task->SetString("taskId", task_id); | |
1035 task->SetString("title", title); | |
1036 task->SetBoolean("isDefault", false); | |
1037 | |
1038 GURL best_icon = extension->GetIconURL(kPreferredIconSize, | |
1039 ExtensionIconSet::MATCH_BIGGER); | |
1040 if (!best_icon.is_empty()) | |
1041 task->SetString("iconUrl", best_icon.spec()); | |
1042 else | |
1043 task->SetString("iconUrl", kDefaultIcon); | |
1044 | |
1045 task->SetBoolean("driveApp", false); | |
1046 result_list->Append(task); | |
1047 } | |
1048 | |
1049 return true; | |
1050 } | |
1051 #endif // defined(ENABLE_WEB_INTENTS) | |
1052 | |
1053 bool GetFileTasksFileBrowserFunction::RunImpl() { | 954 bool GetFileTasksFileBrowserFunction::RunImpl() { |
1054 // First argument is the list of files to get tasks for. | 955 // First argument is the list of files to get tasks for. |
1055 ListValue* files_list = NULL; | 956 ListValue* files_list = NULL; |
1056 if (!args_->GetList(0, &files_list)) | 957 if (!args_->GetList(0, &files_list)) |
1057 return false; | 958 return false; |
1058 | 959 |
1059 // Second argument is the list of mime types of each of the files in the list. | 960 // Second argument is the list of mime types of each of the files in the list. |
1060 ListValue* mime_types_list = NULL; | 961 ListValue* mime_types_list = NULL; |
1061 if (!args_->GetList(1, &mime_types_list)) | 962 if (!args_->GetList(1, &mime_types_list)) |
1062 return false; | 963 return false; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 default_tasks.find(*iter) != default_tasks.end()) { | 1052 default_tasks.find(*iter) != default_tasks.end()) { |
1152 task->SetBoolean("isDefault", true); | 1053 task->SetBoolean("isDefault", true); |
1153 default_already_set = true; | 1054 default_already_set = true; |
1154 } else { | 1055 } else { |
1155 task->SetBoolean("isDefault", false); | 1056 task->SetBoolean("isDefault", false); |
1156 } | 1057 } |
1157 | 1058 |
1158 result_list->Append(task); | 1059 result_list->Append(task); |
1159 } | 1060 } |
1160 | 1061 |
1161 // Take the union of platform app file handlers, Web Intents that platform | 1062 // Take the union of platform app file handlers, and all previous Drive |
1162 // apps may accept, and all previous Drive and extension tasks. As above, we | 1063 // and extension tasks. As above, we know there aren't duplicates because |
1163 // know there aren't duplicates because they're entirely different kinds of | 1064 // they're entirely different kinds of |
1164 // tasks. | 1065 // tasks. |
1165 if (!FindAppTasks(file_paths, result_list)) | 1066 if (!FindAppTasks(file_paths, result_list)) |
1166 return false; | 1067 return false; |
1167 | 1068 |
1168 #if defined(ENABLE_WEB_INTENTS) | |
1169 // TODO(benwells): remove the web intents tasks once we no longer support | |
1170 // them. | |
1171 if (!FindWebIntentTasks(file_paths, result_list)) | |
1172 return false; | |
1173 #endif | |
1174 | |
1175 if (VLOG_IS_ON(1)) { | 1069 if (VLOG_IS_ON(1)) { |
1176 std::string result_json; | 1070 std::string result_json; |
1177 base::JSONWriter::WriteWithOptions( | 1071 base::JSONWriter::WriteWithOptions( |
1178 result_list, | 1072 result_list, |
1179 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | | 1073 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | |
1180 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1074 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
1181 &result_json); | 1075 &result_json); |
1182 VLOG(1) << "GetFileTasks result:\n" << result_json; | 1076 VLOG(1) << "GetFileTasks result:\n" << result_json; |
1183 } | 1077 } |
1184 | 1078 |
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3231 this, name.size())); | 3125 this, name.size())); |
3232 return true; | 3126 return true; |
3233 } | 3127 } |
3234 | 3128 |
3235 void ValidatePathNameLengthFunction::OnFilePathLimitRetrieved( | 3129 void ValidatePathNameLengthFunction::OnFilePathLimitRetrieved( |
3236 size_t current_length, | 3130 size_t current_length, |
3237 size_t max_length) { | 3131 size_t max_length) { |
3238 SetResult(new base::FundamentalValue(current_length <= max_length)); | 3132 SetResult(new base::FundamentalValue(current_length <= max_length)); |
3239 SendResponse(true); | 3133 SendResponse(true); |
3240 } | 3134 } |
OLD | NEW |