| 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_manager/file_browser_private_a
pi.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a
pi.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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 #include "ui/shell_dialogs/selected_file_info.h" | 76 #include "ui/shell_dialogs/selected_file_info.h" |
| 77 #include "ui/webui/web_ui_util.h" | 77 #include "ui/webui/web_ui_util.h" |
| 78 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 78 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
| 79 #include "webkit/fileapi/file_system_context.h" | 79 #include "webkit/fileapi/file_system_context.h" |
| 80 #include "webkit/fileapi/file_system_file_util.h" | 80 #include "webkit/fileapi/file_system_file_util.h" |
| 81 #include "webkit/fileapi/file_system_operation_context.h" | 81 #include "webkit/fileapi/file_system_operation_context.h" |
| 82 #include "webkit/fileapi/file_system_types.h" | 82 #include "webkit/fileapi/file_system_types.h" |
| 83 #include "webkit/fileapi/file_system_url.h" | 83 #include "webkit/fileapi/file_system_url.h" |
| 84 #include "webkit/fileapi/file_system_util.h" | 84 #include "webkit/fileapi/file_system_util.h" |
| 85 | 85 |
| 86 using extensions::app_file_handler_util::FindFileHandlersForMimeTypes; | 86 using extensions::app_file_handler_util::FindFileHandlersForFiles; |
| 87 using extensions::app_file_handler_util::PathAndMimeTypeSet; |
| 87 using chromeos::disks::DiskMountManager; | 88 using chromeos::disks::DiskMountManager; |
| 88 using content::BrowserContext; | 89 using content::BrowserContext; |
| 89 using content::BrowserThread; | 90 using content::BrowserThread; |
| 90 using content::ChildProcessSecurityPolicy; | 91 using content::ChildProcessSecurityPolicy; |
| 91 using content::SiteInstance; | 92 using content::SiteInstance; |
| 92 using content::WebContents; | 93 using content::WebContents; |
| 93 using extensions::Extension; | 94 using extensions::Extension; |
| 94 using extensions::ZipFileCreator; | 95 using extensions::ZipFileCreator; |
| 95 using file_handler_util::FileTaskExecutor; | 96 using file_handler_util::FileTaskExecutor; |
| 96 using fileapi::FileSystemURL; | 97 using fileapi::FileSystemURL; |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 property_dict->SetString("contentUrl", entry_proto.download_url()); | 387 property_dict->SetString("contentUrl", entry_proto.download_url()); |
| 387 | 388 |
| 388 property_dict->SetBoolean("isHosted", | 389 property_dict->SetBoolean("isHosted", |
| 389 file_specific_info.is_hosted_document()); | 390 file_specific_info.is_hosted_document()); |
| 390 | 391 |
| 391 property_dict->SetString("contentMimeType", | 392 property_dict->SetString("contentMimeType", |
| 392 file_specific_info.content_mime_type()); | 393 file_specific_info.content_mime_type()); |
| 393 } | 394 } |
| 394 | 395 |
| 395 void GetMimeTypesForFileURLs(const std::vector<base::FilePath>& file_paths, | 396 void GetMimeTypesForFileURLs(const std::vector<base::FilePath>& file_paths, |
| 396 std::set<std::string>* mime_types) { | 397 PathAndMimeTypeSet* files) { |
| 397 for (std::vector<base::FilePath>::const_iterator iter = file_paths.begin(); | 398 for (std::vector<base::FilePath>::const_iterator iter = file_paths.begin(); |
| 398 iter != file_paths.end(); ++iter) { | 399 iter != file_paths.end(); ++iter) { |
| 399 const base::FilePath::StringType file_extension = | 400 const base::FilePath::StringType file_extension = |
| 400 StringToLowerASCII(iter->Extension()); | 401 StringToLowerASCII(iter->Extension()); |
| 401 | 402 |
| 402 // TODO(thorogood): Rearchitect this call so it can run on the File thread; | 403 // TODO(thorogood): Rearchitect this call so it can run on the File thread; |
| 403 // GetMimeTypeFromFile requires this on Linux. Right now, we use | 404 // GetMimeTypeFromFile requires this on Linux. Right now, we use |
| 404 // Chrome-level knowledge only. | 405 // Chrome-level knowledge only. |
| 405 std::string mime_type; | 406 std::string mime_type; |
| 406 if (file_extension.empty() || | 407 if (file_extension.empty() || |
| 407 !net::GetWellKnownMimeTypeFromExtension(file_extension.substr(1), | 408 !net::GetWellKnownMimeTypeFromExtension(file_extension.substr(1), |
| 408 &mime_type)) { | 409 &mime_type)) { |
| 409 // If the file doesn't have an extension or its mime-type cannot be | 410 // If the file doesn't have an extension or its mime-type cannot be |
| 410 // determined, then indicate that it has the empty mime-type. This will | 411 // determined, then indicate that it has the empty mime-type. This will |
| 411 // only be matched if the Web Intents accepts "*" or "*/*". | 412 // only be matched if the Web Intents accepts "*" or "*/*". |
| 412 mime_types->insert(""); | 413 files->insert(std::make_pair(*iter, "")); |
| 413 } else { | 414 } else { |
| 414 mime_types->insert(mime_type); | 415 files->insert(std::make_pair(*iter, mime_type)); |
| 415 } | 416 } |
| 416 } | 417 } |
| 417 } | 418 } |
| 418 | 419 |
| 419 // Retrieves the maximum file name length of the file system of |path|. | 420 // Retrieves the maximum file name length of the file system of |path|. |
| 420 // Returns 0 if it could not be queried. | 421 // Returns 0 if it could not be queried. |
| 421 size_t GetFileNameMaxLengthOnBlockingPool(const std::string& path) { | 422 size_t GetFileNameMaxLengthOnBlockingPool(const std::string& path) { |
| 422 struct statvfs stat = {}; | 423 struct statvfs stat = {}; |
| 423 if (statvfs(path.c_str(), &stat) != 0) { | 424 if (statvfs(path.c_str(), &stat) != 0) { |
| 424 // The filesystem seems not supporting statvfs(). Assume it to be a commonly | 425 // The filesystem seems not supporting statvfs(). Assume it to be a commonly |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 } | 892 } |
| 892 | 893 |
| 893 bool GetFileTasksFileBrowserFunction::FindAppTasks( | 894 bool GetFileTasksFileBrowserFunction::FindAppTasks( |
| 894 const std::vector<base::FilePath>& file_paths, | 895 const std::vector<base::FilePath>& file_paths, |
| 895 ListValue* result_list) { | 896 ListValue* result_list) { |
| 896 DCHECK(!file_paths.empty()); | 897 DCHECK(!file_paths.empty()); |
| 897 ExtensionService* service = profile_->GetExtensionService(); | 898 ExtensionService* service = profile_->GetExtensionService(); |
| 898 if (!service) | 899 if (!service) |
| 899 return false; | 900 return false; |
| 900 | 901 |
| 901 std::set<std::string> mime_types; | 902 PathAndMimeTypeSet files; |
| 902 GetMimeTypesForFileURLs(file_paths, &mime_types); | 903 GetMimeTypesForFileURLs(file_paths, &files); |
| 903 | 904 |
| 904 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | 905 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); |
| 905 iter != service->extensions()->end(); | 906 iter != service->extensions()->end(); |
| 906 ++iter) { | 907 ++iter) { |
| 907 const Extension* extension = *iter; | 908 const Extension* extension = *iter; |
| 908 | 909 |
| 909 // We don't support using hosted apps to open files. | 910 // We don't support using hosted apps to open files. |
| 910 if (!extension->is_platform_app()) | 911 if (!extension->is_platform_app()) |
| 911 continue; | 912 continue; |
| 912 | 913 |
| 913 if (profile_->IsOffTheRecord() && | 914 if (profile_->IsOffTheRecord() && |
| 914 !service->IsIncognitoEnabled(extension->id())) | 915 !service->IsIncognitoEnabled(extension->id())) |
| 915 continue; | 916 continue; |
| 916 | 917 |
| 917 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; | 918 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; |
| 918 FileHandlerList file_handlers = | 919 FileHandlerList file_handlers = FindFileHandlersForFiles(*extension, files); |
| 919 FindFileHandlersForMimeTypes(*extension, mime_types); | |
| 920 // TODO(benwells): also support matching by file extension. | |
| 921 if (file_handlers.empty()) | 920 if (file_handlers.empty()) |
| 922 continue; | 921 continue; |
| 923 | 922 |
| 924 for (FileHandlerList::iterator i = file_handlers.begin(); | 923 for (FileHandlerList::iterator i = file_handlers.begin(); |
| 925 i != file_handlers.end(); ++i) { | 924 i != file_handlers.end(); ++i) { |
| 926 DictionaryValue* task = new DictionaryValue; | 925 DictionaryValue* task = new DictionaryValue; |
| 927 std::string task_id = file_handler_util::MakeTaskID(extension->id(), | 926 std::string task_id = file_handler_util::MakeTaskID(extension->id(), |
| 928 file_handler_util::kTaskApp, (*i)->id); | 927 file_handler_util::kTaskApp, (*i)->id); |
| 929 task->SetString("taskId", task_id); | 928 task->SetString("taskId", task_id); |
| 930 task->SetString("title", (*i)->title); | 929 task->SetString("title", (*i)->title); |
| (...skipping 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3159 OpenNewWindowFunction::OpenNewWindowFunction() {} | 3158 OpenNewWindowFunction::OpenNewWindowFunction() {} |
| 3160 | 3159 |
| 3161 OpenNewWindowFunction::~OpenNewWindowFunction() {} | 3160 OpenNewWindowFunction::~OpenNewWindowFunction() {} |
| 3162 | 3161 |
| 3163 bool OpenNewWindowFunction::RunImpl() { | 3162 bool OpenNewWindowFunction::RunImpl() { |
| 3164 std::string url; | 3163 std::string url; |
| 3165 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 3164 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
| 3166 file_manager_util::OpenNewWindow(profile_, GURL(url)); | 3165 file_manager_util::OpenNewWindow(profile_, GURL(url)); |
| 3167 return true; | 3166 return true; |
| 3168 } | 3167 } |
| OLD | NEW |