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