| 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/file_manager/file_tasks.h" | 5 #include "chrome/browser/chromeos/file_manager/file_tasks.h" |
| 6 | 6 |
| 7 #include "apps/launcher.h" | 7 #include "apps/launcher.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | |
| 10 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 11 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| 12 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 12 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 14 #include "chrome/browser/chromeos/drive/file_task_executor.h" | 13 #include "chrome/browser/chromeos/drive/file_task_executor.h" |
| 15 #include "chrome/browser/chromeos/file_manager/app_id.h" | 14 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 16 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" | 15 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" |
| 17 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 16 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 18 #include "chrome/browser/chromeos/file_manager/open_util.h" | 17 #include "chrome/browser/chromeos/file_manager/open_util.h" |
| 19 #include "chrome/browser/drive/drive_api_util.h" | 18 #include "chrome/browser/drive/drive_api_util.h" |
| 20 #include "chrome/browser/drive/drive_app_registry.h" | 19 #include "chrome/browser/drive/drive_app_registry.h" |
| 21 #include "chrome/browser/extensions/extension_tab_util.h" | 20 #include "chrome/browser/extensions/extension_tab_util.h" |
| 22 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 23 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 25 #include "chrome/common/extensions/api/file_browser_handlers/file_browser_handle
r.h" | 24 #include "chrome/common/extensions/api/file_browser_handlers/file_browser_handle
r.h" |
| 26 #include "chrome/common/extensions/api/file_browser_private.h" | 25 #include "chrome/common/extensions/api/file_browser_private.h" |
| 27 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
| 28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 29 #include "chromeos/chromeos_switches.h" | |
| 30 #include "extensions/browser/extension_host.h" | 28 #include "extensions/browser/extension_host.h" |
| 31 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
| 32 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
| 33 #include "extensions/browser/extension_util.h" | 31 #include "extensions/browser/extension_util.h" |
| 34 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
| 35 #include "extensions/common/extension_set.h" | 33 #include "extensions/common/extension_set.h" |
| 36 #include "webkit/browser/fileapi/file_system_url.h" | 34 #include "webkit/browser/fileapi/file_system_url.h" |
| 37 | 35 |
| 38 using extensions::Extension; | 36 using extensions::Extension; |
| 39 using extensions::app_file_handler_util::FindFileHandlersForFiles; | 37 using extensions::app_file_handler_util::FindFileHandlersForFiles; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Leaves tasks handled by the file manger itself as is and removes all others. | 96 // Leaves tasks handled by the file manger itself as is and removes all others. |
| 99 void KeepOnlyFileManagerInternalTasks(std::vector<FullTaskDescriptor>* tasks) { | 97 void KeepOnlyFileManagerInternalTasks(std::vector<FullTaskDescriptor>* tasks) { |
| 100 std::vector<FullTaskDescriptor> filtered; | 98 std::vector<FullTaskDescriptor> filtered; |
| 101 for (size_t i = 0; i < tasks->size(); ++i) { | 99 for (size_t i = 0; i < tasks->size(); ++i) { |
| 102 if ((*tasks)[i].task_descriptor().app_id == kFileManagerAppId) | 100 if ((*tasks)[i].task_descriptor().app_id == kFileManagerAppId) |
| 103 filtered.push_back((*tasks)[i]); | 101 filtered.push_back((*tasks)[i]); |
| 104 } | 102 } |
| 105 tasks->swap(filtered); | 103 tasks->swap(filtered); |
| 106 } | 104 } |
| 107 | 105 |
| 108 void ChooseSuitableGalleryHandler(std::vector<FullTaskDescriptor>* task_list) { | |
| 109 const bool disable_new_gallery = | |
| 110 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 111 chromeos::switches::kFileManagerEnableNewGallery) == "false"; | |
| 112 std::vector<FullTaskDescriptor>::iterator it = task_list->begin(); | |
| 113 while (it != task_list->end()) { | |
| 114 if (disable_new_gallery) { | |
| 115 if (it->task_descriptor().app_id == kGalleryAppId) | |
| 116 it = task_list->erase(it); | |
| 117 else | |
| 118 ++it; | |
| 119 } else { | |
| 120 if (it->task_descriptor().app_id == kFileManagerAppId && | |
| 121 it->task_descriptor().action_id == "gallery") { | |
| 122 it = task_list->erase(it); | |
| 123 } else { | |
| 124 ++it; | |
| 125 } | |
| 126 } | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 // Returns true if the given task is a handler by built-in apps like Files.app | 106 // Returns true if the given task is a handler by built-in apps like Files.app |
| 131 // itself or QuickOffice etc. They are used as the initial default app. | 107 // itself or QuickOffice etc. They are used as the initial default app. |
| 132 bool IsFallbackFileHandler(const file_tasks::TaskDescriptor& task) { | 108 bool IsFallbackFileHandler(const file_tasks::TaskDescriptor& task) { |
| 133 if (task.task_type != file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER && | 109 if (task.task_type != file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER && |
| 134 task.task_type != file_tasks::TASK_TYPE_FILE_HANDLER) | 110 task.task_type != file_tasks::TASK_TYPE_FILE_HANDLER) |
| 135 return false; | 111 return false; |
| 136 | 112 |
| 137 const char* kBuiltInApps[] = { | 113 const char* kBuiltInApps[] = { |
| 138 kFileManagerAppId, | 114 kFileManagerAppId, |
| 139 kVideoPlayerAppId, | 115 kVideoPlayerAppId, |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 473 |
| 498 // Find and append file browser handler tasks. We know there aren't | 474 // Find and append file browser handler tasks. We know there aren't |
| 499 // duplicates because "file_browser_handlers" and "file_handlers" shouldn't | 475 // duplicates because "file_browser_handlers" and "file_handlers" shouldn't |
| 500 // be used in the same manifest.json. | 476 // be used in the same manifest.json. |
| 501 FindFileBrowserHandlerTasks(profile, file_urls, result_list); | 477 FindFileBrowserHandlerTasks(profile, file_urls, result_list); |
| 502 | 478 |
| 503 // Google documents can only be handled by internal handlers. | 479 // Google documents can only be handled by internal handlers. |
| 504 if (ContainsGoogleDocument(path_mime_set)) | 480 if (ContainsGoogleDocument(path_mime_set)) |
| 505 KeepOnlyFileManagerInternalTasks(result_list); | 481 KeepOnlyFileManagerInternalTasks(result_list); |
| 506 | 482 |
| 507 ChooseSuitableGalleryHandler(result_list); | |
| 508 ChooseAndSetDefaultTask(*profile->GetPrefs(), path_mime_set, result_list); | 483 ChooseAndSetDefaultTask(*profile->GetPrefs(), path_mime_set, result_list); |
| 509 } | 484 } |
| 510 | 485 |
| 511 void ChooseAndSetDefaultTask(const PrefService& pref_service, | 486 void ChooseAndSetDefaultTask(const PrefService& pref_service, |
| 512 const PathAndMimeTypeSet& path_mime_set, | 487 const PathAndMimeTypeSet& path_mime_set, |
| 513 std::vector<FullTaskDescriptor>* tasks) { | 488 std::vector<FullTaskDescriptor>* tasks) { |
| 514 // Collect the task IDs of default tasks from the preferences into a set. | 489 // Collect the task IDs of default tasks from the preferences into a set. |
| 515 std::set<std::string> default_task_ids; | 490 std::set<std::string> default_task_ids; |
| 516 for (PathAndMimeTypeSet::const_iterator it = path_mime_set.begin(); | 491 for (PathAndMimeTypeSet::const_iterator it = path_mime_set.begin(); |
| 517 it != path_mime_set.end(); ++it) { | 492 it != path_mime_set.end(); ++it) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 541 DCHECK(!task->is_default()); | 516 DCHECK(!task->is_default()); |
| 542 if (IsFallbackFileHandler(task->task_descriptor())) { | 517 if (IsFallbackFileHandler(task->task_descriptor())) { |
| 543 task->set_is_default(true); | 518 task->set_is_default(true); |
| 544 return; | 519 return; |
| 545 } | 520 } |
| 546 } | 521 } |
| 547 } | 522 } |
| 548 | 523 |
| 549 } // namespace file_tasks | 524 } // namespace file_tasks |
| 550 } // namespace file_manager | 525 } // namespace file_manager |
| OLD | NEW |