Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc

Issue 14790018: ChromeOS: Use file extensions in Files app to decide which apps to use. (Closed) Base URL: http://git.chromium.org/chromium/src.git@file-handler-extensions2
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::FindFileHandlers;
87 using extensions::app_file_handler_util::MimeTypeAndPathSet;
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (!entry_proto.download_url().empty()) 386 if (!entry_proto.download_url().empty())
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 GetMimeTypeAndPathsForFileURLs(
Matt Giuca 2013/05/07 05:39:59 I wouldn't change the name here, because it isn't
Sam McNally 2013/05/07 06:15:27 Done.
396 std::set<std::string>* mime_types) { 397 const std::vector<base::FilePath>& file_paths,
398 MimeTypeAndPathSet* files) {
397 for (std::vector<base::FilePath>::const_iterator iter = file_paths.begin(); 399 for (std::vector<base::FilePath>::const_iterator iter = file_paths.begin();
398 iter != file_paths.end(); ++iter) { 400 iter != file_paths.end(); ++iter) {
399 const base::FilePath::StringType file_extension = 401 const base::FilePath::StringType file_extension =
400 StringToLowerASCII(iter->Extension()); 402 StringToLowerASCII(iter->Extension());
401 403
402 // TODO(thorogood): Rearchitect this call so it can run on the File thread; 404 // TODO(thorogood): Rearchitect this call so it can run on the File thread;
403 // GetMimeTypeFromFile requires this on Linux. Right now, we use 405 // GetMimeTypeFromFile requires this on Linux. Right now, we use
404 // Chrome-level knowledge only. 406 // Chrome-level knowledge only.
405 std::string mime_type; 407 std::string mime_type;
406 if (file_extension.empty() || 408 if (file_extension.empty() ||
407 !net::GetWellKnownMimeTypeFromExtension(file_extension.substr(1), 409 !net::GetWellKnownMimeTypeFromExtension(file_extension.substr(1),
408 &mime_type)) { 410 &mime_type)) {
409 // If the file doesn't have an extension or its mime-type cannot be 411 // 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 412 // determined, then indicate that it has the empty mime-type. This will
411 // only be matched if the Web Intents accepts "*" or "*/*". 413 // only be matched if the Web Intents accepts "*" or "*/*".
412 mime_types->insert(""); 414 files->insert(std::make_pair("", *iter));
413 } else { 415 } else {
414 mime_types->insert(mime_type); 416 files->insert(std::make_pair(mime_type, *iter));
415 } 417 }
416 } 418 }
417 } 419 }
418 420
419 // Retrieves the maximum file name length of the file system of |path|. 421 // Retrieves the maximum file name length of the file system of |path|.
420 // Returns 0 if it could not be queried. 422 // Returns 0 if it could not be queried.
421 size_t GetFileNameMaxLengthOnBlockingPool(const std::string& path) { 423 size_t GetFileNameMaxLengthOnBlockingPool(const std::string& path) {
422 struct statvfs stat = {}; 424 struct statvfs stat = {};
423 if (statvfs(path.c_str(), &stat) != 0) { 425 if (statvfs(path.c_str(), &stat) != 0) {
424 // The filesystem seems not supporting statvfs(). Assume it to be a commonly 426 // The filesystem seems not supporting statvfs(). Assume it to be a commonly
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 } 893 }
892 894
893 bool GetFileTasksFileBrowserFunction::FindAppTasks( 895 bool GetFileTasksFileBrowserFunction::FindAppTasks(
894 const std::vector<base::FilePath>& file_paths, 896 const std::vector<base::FilePath>& file_paths,
895 ListValue* result_list) { 897 ListValue* result_list) {
896 DCHECK(!file_paths.empty()); 898 DCHECK(!file_paths.empty());
897 ExtensionService* service = profile_->GetExtensionService(); 899 ExtensionService* service = profile_->GetExtensionService();
898 if (!service) 900 if (!service)
899 return false; 901 return false;
900 902
901 std::set<std::string> mime_types; 903 MimeTypeAndPathSet files;
902 GetMimeTypesForFileURLs(file_paths, &mime_types); 904 GetMimeTypeAndPathsForFileURLs(file_paths, &files);
903 905
904 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); 906 for (ExtensionSet::const_iterator iter = service->extensions()->begin();
905 iter != service->extensions()->end(); 907 iter != service->extensions()->end();
906 ++iter) { 908 ++iter) {
907 const Extension* extension = *iter; 909 const Extension* extension = *iter;
908 910
909 // We don't support using hosted apps to open files. 911 // We don't support using hosted apps to open files.
910 if (!extension->is_platform_app()) 912 if (!extension->is_platform_app())
911 continue; 913 continue;
912 914
913 if (profile_->IsOffTheRecord() && 915 if (profile_->IsOffTheRecord() &&
914 !service->IsIncognitoEnabled(extension->id())) 916 !service->IsIncognitoEnabled(extension->id()))
915 continue; 917 continue;
916 918
917 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; 919 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList;
918 FileHandlerList file_handlers = 920 FileHandlerList file_handlers = FindFileHandlers(*extension, files);
919 FindFileHandlersForMimeTypes(*extension, mime_types);
920 // TODO(benwells): also support matching by file extension.
921 if (file_handlers.empty()) 921 if (file_handlers.empty())
922 continue; 922 continue;
923 923
924 for (FileHandlerList::iterator i = file_handlers.begin(); 924 for (FileHandlerList::iterator i = file_handlers.begin();
925 i != file_handlers.end(); ++i) { 925 i != file_handlers.end(); ++i) {
926 DictionaryValue* task = new DictionaryValue; 926 DictionaryValue* task = new DictionaryValue;
927 std::string task_id = file_handler_util::MakeTaskID(extension->id(), 927 std::string task_id = file_handler_util::MakeTaskID(extension->id(),
928 file_handler_util::kTaskApp, (*i)->id); 928 file_handler_util::kTaskApp, (*i)->id);
929 task->SetString("taskId", task_id); 929 task->SetString("taskId", task_id);
930 task->SetString("title", (*i)->title); 930 task->SetString("title", (*i)->title);
(...skipping 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after
3159 OpenNewWindowFunction::OpenNewWindowFunction() {} 3159 OpenNewWindowFunction::OpenNewWindowFunction() {}
3160 3160
3161 OpenNewWindowFunction::~OpenNewWindowFunction() {} 3161 OpenNewWindowFunction::~OpenNewWindowFunction() {}
3162 3162
3163 bool OpenNewWindowFunction::RunImpl() { 3163 bool OpenNewWindowFunction::RunImpl() {
3164 std::string url; 3164 std::string url;
3165 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); 3165 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url));
3166 file_manager_util::OpenNewWindow(profile_, GURL(url)); 3166 file_manager_util::OpenNewWindow(profile_, GURL(url));
3167 return true; 3167 return true;
3168 } 3168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698