Chromium Code Reviews| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 if (icons.empty()) | 271 if (icons.empty()) |
| 275 return result; | 272 return result; |
| 276 result = icons.rbegin()->second; | 273 result = icons.rbegin()->second; |
| 277 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); | 274 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); |
| 278 iter != icons.rend() && iter->first >= preferred_size; ++iter) { | 275 iter != icons.rend() && iter->first >= preferred_size; ++iter) { |
| 279 result = iter->second; | 276 result = iter->second; |
| 280 } | 277 } |
| 281 return result; | 278 return result; |
| 282 } | 279 } |
| 283 | 280 |
| 284 #if defined(ENABLE_WEB_INTENTS) | |
| 285 // Finds the title of the given Web Intents |action|, if the passed extension | |
| 286 // supports this action for all specified |mime_types|. Returns true and | |
| 287 // provides the |title| as output on success. | |
| 288 bool FindTitleForActionWithTypes( | |
| 289 const Extension* extension, | |
| 290 const std::string& action, | |
| 291 const std::set<std::string>& mime_types, | |
| 292 std::string* title) { | |
| 293 DCHECK(!mime_types.empty()); | |
| 294 std::set<std::string> pending(mime_types.begin(), mime_types.end()); | |
| 295 std::string found_title; | |
| 296 | |
| 297 for (std::vector<webkit_glue::WebIntentServiceData>::const_iterator data = | |
| 298 extensions::WebIntentsInfo::GetIntentsServices(extension).begin(); | |
| 299 data != extensions::WebIntentsInfo::GetIntentsServices(extension).end(); | |
| 300 ++data) { | |
| 301 if (pending.empty()) | |
| 302 break; | |
| 303 | |
| 304 if (UTF16ToUTF8(data->action) != action) | |
| 305 continue; | |
| 306 | |
| 307 std::set<std::string>::iterator pending_iter = pending.begin(); | |
| 308 while (pending_iter != pending.end()) { | |
| 309 std::set<std::string>::iterator current = pending_iter++; | |
| 310 if (net::MatchesMimeType(UTF16ToUTF8(data->type), *current)) | |
| 311 pending.erase(current); | |
| 312 } | |
| 313 if (found_title.empty()) | |
| 314 found_title = UTF16ToUTF8(data->title); | |
| 315 } | |
| 316 | |
| 317 // Not all mime-types have been found. | |
| 318 if (!pending.empty()) | |
| 319 return false; | |
| 320 | |
| 321 *title = found_title; | |
| 322 return true; | |
| 323 } | |
| 324 #endif // defined(ENABLE_WEB_INTENTS) | |
| 325 | |
| 326 // Retrieves total and remaining available size on |mount_path|. | 281 // Retrieves total and remaining available size on |mount_path|. |
| 327 void GetSizeStatsOnFileThread(const std::string& mount_path, | 282 void GetSizeStatsOnFileThread(const std::string& mount_path, |
| 328 size_t* total_size_kb, | 283 size_t* total_size_kb, |
| 329 size_t* remaining_size_kb) { | 284 size_t* remaining_size_kb) { |
| 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 331 | 286 |
| 332 uint64_t total_size_in_bytes = 0; | 287 uint64_t total_size_in_bytes = 0; |
| 333 uint64_t remaining_size_in_bytes = 0; | 288 uint64_t remaining_size_in_bytes = 0; |
| 334 | 289 |
| 335 struct statvfs stat = {}; // Zero-clear | 290 struct statvfs stat = {}; // Zero-clear |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 991 task->SetString("iconUrl", kDefaultIcon); | 946 task->SetString("iconUrl", kDefaultIcon); |
| 992 | 947 |
| 993 task->SetBoolean("driveApp", false); | 948 task->SetBoolean("driveApp", false); |
| 994 result_list->Append(task); | 949 result_list->Append(task); |
| 995 } | 950 } |
| 996 } | 951 } |
| 997 | 952 |
| 998 return true; | 953 return true; |
| 999 } | 954 } |
| 1000 | 955 |
| 1001 #if defined(ENABLE_WEB_INTENTS) | |
| 1002 // Find Web Intent platform apps that support the View task, and add them to | |
| 1003 // the |result_list|. These will be marked as kTaskWebIntent. | |
| 1004 bool GetFileTasksFileBrowserFunction::FindWebIntentTasks( | |
| 1005 const std::vector<FilePath>& file_paths, | |
| 1006 ListValue* result_list) { | |
| 1007 DCHECK(!file_paths.empty()); | |
| 1008 ExtensionService* service = profile_->GetExtensionService(); | |
| 1009 if (!service) | |
| 1010 return false; | |
| 1011 | |
| 1012 std::set<std::string> mime_types; | |
| 1013 GetMimeTypesForFileURLs(file_paths, &mime_types); | |
| 1014 | |
| 1015 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | |
| 1016 iter != service->extensions()->end(); | |
| 1017 ++iter) { | |
| 1018 const Extension* extension = *iter; | |
| 1019 | |
| 1020 // We don't support using hosted apps to open files. | |
| 1021 if (!extension->is_platform_app()) | |
| 1022 continue; | |
| 1023 | |
| 1024 if (profile_->IsOffTheRecord() && | |
| 1025 !service->IsIncognitoEnabled(extension->id())) | |
| 1026 continue; | |
| 1027 | |
| 1028 std::string title; | |
| 1029 if (!FindTitleForActionWithTypes( | |
| 1030 extension, web_intents::kActionView, mime_types, &title)) | |
| 1031 continue; | |
| 1032 | |
| 1033 DictionaryValue* task = new DictionaryValue; | |
| 1034 std::string task_id = file_handler_util::MakeTaskID(extension->id(), | |
| 1035 file_handler_util::kTaskWebIntent, web_intents::kActionView); | |
| 1036 task->SetString("taskId", task_id); | |
| 1037 task->SetString("title", title); | |
| 1038 task->SetBoolean("isDefault", false); | |
| 1039 | |
| 1040 GURL best_icon = extension->GetIconURL(kPreferredIconSize, | |
| 1041 ExtensionIconSet::MATCH_BIGGER); | |
| 1042 if (!best_icon.is_empty()) | |
| 1043 task->SetString("iconUrl", best_icon.spec()); | |
| 1044 else | |
| 1045 task->SetString("iconUrl", kDefaultIcon); | |
| 1046 | |
| 1047 task->SetBoolean("driveApp", false); | |
| 1048 result_list->Append(task); | |
| 1049 } | |
| 1050 | |
| 1051 return true; | |
| 1052 } | |
| 1053 #endif // defined(ENABLE_WEB_INTENTS) | |
| 1054 | |
| 1055 bool GetFileTasksFileBrowserFunction::RunImpl() { | 956 bool GetFileTasksFileBrowserFunction::RunImpl() { |
| 1056 // First argument is the list of files to get tasks for. | 957 // First argument is the list of files to get tasks for. |
| 1057 ListValue* files_list = NULL; | 958 ListValue* files_list = NULL; |
| 1058 if (!args_->GetList(0, &files_list)) | 959 if (!args_->GetList(0, &files_list)) |
| 1059 return false; | 960 return false; |
| 1060 | 961 |
| 1061 // Second argument is the list of mime types of each of the files in the list. | 962 // Second argument is the list of mime types of each of the files in the list. |
| 1062 ListValue* mime_types_list = NULL; | 963 ListValue* mime_types_list = NULL; |
| 1063 if (!args_->GetList(1, &mime_types_list)) | 964 if (!args_->GetList(1, &mime_types_list)) |
| 1064 return false; | 965 return false; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 default_tasks.find(*iter) != default_tasks.end()) { | 1054 default_tasks.find(*iter) != default_tasks.end()) { |
| 1154 task->SetBoolean("isDefault", true); | 1055 task->SetBoolean("isDefault", true); |
| 1155 default_already_set = true; | 1056 default_already_set = true; |
| 1156 } else { | 1057 } else { |
| 1157 task->SetBoolean("isDefault", false); | 1058 task->SetBoolean("isDefault", false); |
| 1158 } | 1059 } |
| 1159 | 1060 |
| 1160 result_list->Append(task); | 1061 result_list->Append(task); |
| 1161 } | 1062 } |
| 1162 | 1063 |
| 1163 // Take the union of platform app file handlers, Web Intents that platform | 1064 // Take the union of platform app file handlers, and all previous Drive |
|
benwells
2013/02/11 08:04:44
Tiny nit: double space.
Nico
2013/02/11 15:16:12
Done.
| |
| 1164 // apps may accept, and all previous Drive and extension tasks. As above, we | 1065 // and extension tasks. As above, we know there aren't duplicates because |
| 1165 // know there aren't duplicates because they're entirely different kinds of | 1066 // they're entirely different kinds of |
| 1166 // tasks. | 1067 // tasks. |
| 1167 if (!FindAppTasks(file_paths, result_list)) | 1068 if (!FindAppTasks(file_paths, result_list)) |
| 1168 return false; | 1069 return false; |
| 1169 | 1070 |
| 1170 #if defined(ENABLE_WEB_INTENTS) | |
| 1171 // TODO(benwells): remove the web intents tasks once we no longer support | |
| 1172 // them. | |
| 1173 if (!FindWebIntentTasks(file_paths, result_list)) | |
| 1174 return false; | |
| 1175 #endif | |
| 1176 | |
| 1177 if (VLOG_IS_ON(1)) { | 1071 if (VLOG_IS_ON(1)) { |
| 1178 std::string result_json; | 1072 std::string result_json; |
| 1179 base::JSONWriter::WriteWithOptions( | 1073 base::JSONWriter::WriteWithOptions( |
| 1180 result_list, | 1074 result_list, |
| 1181 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | | 1075 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | |
| 1182 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1076 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 1183 &result_json); | 1077 &result_json); |
| 1184 VLOG(1) << "GetFileTasks result:\n" << result_json; | 1078 VLOG(1) << "GetFileTasks result:\n" << result_json; |
| 1185 } | 1079 } |
| 1186 | 1080 |
| (...skipping 2168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3355 this, name.size())); | 3249 this, name.size())); |
| 3356 return true; | 3250 return true; |
| 3357 } | 3251 } |
| 3358 | 3252 |
| 3359 void ValidatePathNameLengthFunction::OnFilePathLimitRetrieved( | 3253 void ValidatePathNameLengthFunction::OnFilePathLimitRetrieved( |
| 3360 size_t current_length, | 3254 size_t current_length, |
| 3361 size_t max_length) { | 3255 size_t max_length) { |
| 3362 SetResult(new base::FundamentalValue(current_length <= max_length)); | 3256 SetResult(new base::FundamentalValue(current_length <= max_length)); |
| 3363 SendResponse(true); | 3257 SendResponse(true); |
| 3364 } | 3258 } |
| OLD | NEW |