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" | 9 #include "base/command_line.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
14 #include "chrome/browser/chromeos/drive/file_task_executor.h" | 14 #include "chrome/browser/chromeos/drive/file_task_executor.h" |
15 #include "chrome/browser/chromeos/file_manager/app_id.h" | 15 #include "chrome/browser/chromeos/file_manager/app_id.h" |
16 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" | 16 #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" |
17 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 17 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
18 #include "chrome/browser/chromeos/file_manager/open_util.h" | 18 #include "chrome/browser/chromeos/file_manager/open_util.h" |
19 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" | |
20 #include "chrome/browser/drive/drive_api_util.h" | 19 #include "chrome/browser/drive/drive_api_util.h" |
21 #include "chrome/browser/drive/drive_app_registry.h" | 20 #include "chrome/browser/drive/drive_app_registry.h" |
22 #include "chrome/browser/extensions/extension_tab_util.h" | 21 #include "chrome/browser/extensions/extension_tab_util.h" |
23 #include "chrome/browser/extensions/extension_util.h" | 22 #include "chrome/browser/extensions/extension_util.h" |
24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 24 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
26 #include "chrome/common/extensions/api/file_browser_handlers/file_browser_handle
r.h" | 25 #include "chrome/common/extensions/api/file_browser_handlers/file_browser_handle
r.h" |
27 #include "chrome/common/extensions/api/file_browser_private.h" | 26 #include "chrome/common/extensions/api/file_browser_private.h" |
| 27 #include "chrome/common/extensions/extension_constants.h" |
28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
29 #include "chromeos/chromeos_switches.h" | 29 #include "chromeos/chromeos_switches.h" |
30 #include "extensions/browser/extension_host.h" | 30 #include "extensions/browser/extension_host.h" |
31 #include "extensions/browser/extension_registry.h" | 31 #include "extensions/browser/extension_registry.h" |
32 #include "extensions/browser/extension_system.h" | 32 #include "extensions/browser/extension_system.h" |
33 #include "extensions/browser/extension_util.h" | 33 #include "extensions/browser/extension_util.h" |
34 #include "extensions/common/constants.h" | 34 #include "extensions/common/constants.h" |
35 #include "extensions/common/extension_set.h" | 35 #include "extensions/common/extension_set.h" |
36 #include "webkit/browser/fileapi/file_system_context.h" | |
37 #include "webkit/browser/fileapi/file_system_url.h" | 36 #include "webkit/browser/fileapi/file_system_url.h" |
38 | 37 |
39 using extensions::Extension; | 38 using extensions::Extension; |
40 using extensions::app_file_handler_util::FindFileHandlersForFiles; | 39 using extensions::app_file_handler_util::FindFileHandlersForFiles; |
41 using fileapi::FileSystemURL; | 40 using fileapi::FileSystemURL; |
42 | 41 |
43 namespace file_manager { | 42 namespace file_manager { |
44 namespace file_tasks { | 43 namespace file_tasks { |
45 | 44 |
46 namespace { | 45 namespace { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 if (it->task_descriptor().app_id == kFileManagerAppId && | 122 if (it->task_descriptor().app_id == kFileManagerAppId && |
124 it->task_descriptor().action_id == "gallery") { | 123 it->task_descriptor().action_id == "gallery") { |
125 it = task_list->erase(it); | 124 it = task_list->erase(it); |
126 } else { | 125 } else { |
127 ++it; | 126 ++it; |
128 } | 127 } |
129 } | 128 } |
130 } | 129 } |
131 } | 130 } |
132 | 131 |
| 132 // Returns true if the given task is a handler by built-in apps like Files.app |
| 133 // itself or QuickOffice etc. They are used as the initial default app. |
| 134 bool IsFallbackFileHandler(const file_tasks::TaskDescriptor& task) { |
| 135 if (task.task_type != file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER && |
| 136 task.task_type != file_tasks::TASK_TYPE_FILE_HANDLER) |
| 137 return false; |
| 138 |
| 139 const char* kBuiltInApps[] = { |
| 140 kFileManagerAppId, |
| 141 kVideoPlayerAppId, |
| 142 kGalleryAppId, |
| 143 extension_misc::kQuickOfficeComponentExtensionId, |
| 144 extension_misc::kQuickOfficeInternalExtensionId, |
| 145 extension_misc::kQuickOfficeExtensionId, |
| 146 }; |
| 147 |
| 148 for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) { |
| 149 if (task.app_id == kBuiltInApps[i]) |
| 150 return true; |
| 151 } |
| 152 return false; |
| 153 } |
| 154 |
133 } // namespace | 155 } // namespace |
134 | 156 |
135 FullTaskDescriptor::FullTaskDescriptor( | 157 FullTaskDescriptor::FullTaskDescriptor( |
136 const TaskDescriptor& task_descriptor, | 158 const TaskDescriptor& task_descriptor, |
137 const std::string& task_title, | 159 const std::string& task_title, |
138 const GURL& icon_url, | 160 const GURL& icon_url, |
139 bool is_default) | 161 bool is_default) |
140 : task_descriptor_(task_descriptor), | 162 : task_descriptor_(task_descriptor), |
141 task_title_(task_title), | 163 task_title_(task_title), |
142 icon_url_(icon_url), | 164 icon_url_(icon_url), |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 226 |
205 std::string MakeTaskID(const std::string& app_id, | 227 std::string MakeTaskID(const std::string& app_id, |
206 TaskType task_type, | 228 TaskType task_type, |
207 const std::string& action_id) { | 229 const std::string& action_id) { |
208 return base::StringPrintf("%s|%s|%s", | 230 return base::StringPrintf("%s|%s|%s", |
209 app_id.c_str(), | 231 app_id.c_str(), |
210 TaskTypeToString(task_type).c_str(), | 232 TaskTypeToString(task_type).c_str(), |
211 action_id.c_str()); | 233 action_id.c_str()); |
212 } | 234 } |
213 | 235 |
214 std::string MakeDriveAppTaskId(const std::string& app_id) { | |
215 return MakeTaskID(app_id, TASK_TYPE_DRIVE_APP, kDriveAppActionID); | |
216 } | |
217 | |
218 std::string TaskDescriptorToId(const TaskDescriptor& task_descriptor) { | 236 std::string TaskDescriptorToId(const TaskDescriptor& task_descriptor) { |
219 return MakeTaskID(task_descriptor.app_id, | 237 return MakeTaskID(task_descriptor.app_id, |
220 task_descriptor.task_type, | 238 task_descriptor.task_type, |
221 task_descriptor.action_id); | 239 task_descriptor.action_id); |
222 } | 240 } |
223 | 241 |
224 bool ParseTaskID(const std::string& task_id, TaskDescriptor* task) { | 242 bool ParseTaskID(const std::string& task_id, TaskDescriptor* task) { |
225 DCHECK(task); | 243 DCHECK(task); |
226 | 244 |
227 std::vector<std::string> result; | 245 std::vector<std::string> result; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 // Execute the task. | 299 // Execute the task. |
282 if (task.task_type == TASK_TYPE_FILE_BROWSER_HANDLER) { | 300 if (task.task_type == TASK_TYPE_FILE_BROWSER_HANDLER) { |
283 return file_browser_handlers::ExecuteFileBrowserHandler( | 301 return file_browser_handlers::ExecuteFileBrowserHandler( |
284 profile, | 302 profile, |
285 extension, | 303 extension, |
286 task.action_id, | 304 task.action_id, |
287 file_urls, | 305 file_urls, |
288 done); | 306 done); |
289 } else if (task.task_type == TASK_TYPE_FILE_HANDLER) { | 307 } else if (task.task_type == TASK_TYPE_FILE_HANDLER) { |
290 std::vector<base::FilePath> paths; | 308 std::vector<base::FilePath> paths; |
291 for (size_t i = 0; i != file_urls.size(); ++i) { | 309 for (size_t i = 0; i != file_urls.size(); ++i) |
292 paths.push_back(file_urls[i].path()); | 310 paths.push_back(file_urls[i].path()); |
293 } | |
294 apps::LaunchPlatformAppWithFileHandler( | 311 apps::LaunchPlatformAppWithFileHandler( |
295 profile, extension, task.action_id, paths); | 312 profile, extension, task.action_id, paths); |
296 if (!done.is_null()) | 313 if (!done.is_null()) |
297 done.Run(extensions::api::file_browser_private::TASK_RESULT_MESSAGE_SENT); | 314 done.Run(extensions::api::file_browser_private::TASK_RESULT_MESSAGE_SENT); |
298 return true; | 315 return true; |
299 } | 316 } |
300 NOTREACHED(); | 317 NOTREACHED(); |
301 return false; | 318 return false; |
302 } | 319 } |
303 | 320 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 task->set_is_default(true); | 534 task->set_is_default(true); |
518 return; | 535 return; |
519 } | 536 } |
520 } | 537 } |
521 | 538 |
522 // No default tasks found. If there is any fallback file browser handler, | 539 // No default tasks found. If there is any fallback file browser handler, |
523 // make it as default task, so it's selected by default. | 540 // make it as default task, so it's selected by default. |
524 for (size_t i = 0; i < tasks->size(); ++i) { | 541 for (size_t i = 0; i < tasks->size(); ++i) { |
525 FullTaskDescriptor* task = &tasks->at(i); | 542 FullTaskDescriptor* task = &tasks->at(i); |
526 DCHECK(!task->is_default()); | 543 DCHECK(!task->is_default()); |
527 if (file_browser_handlers::IsFallbackFileBrowserHandler( | 544 if (IsFallbackFileHandler(task->task_descriptor())) { |
528 task->task_descriptor())) { | |
529 task->set_is_default(true); | 545 task->set_is_default(true); |
530 return; | 546 return; |
531 } | 547 } |
532 } | 548 } |
533 } | 549 } |
534 | 550 |
535 } // namespace file_tasks | 551 } // namespace file_tasks |
536 } // namespace file_manager | 552 } // namespace file_manager |
OLD | NEW |