| 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" | 19 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
| 20 #include "chrome/browser/drive/drive_app_registry.h" | 20 #include "chrome/browser/drive/drive_app_registry.h" |
| 21 #include "chrome/browser/extensions/extension_service.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" |
| 28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 29 #include "chromeos/chromeos_switches.h" | 28 #include "chromeos/chromeos_switches.h" |
| 30 #include "extensions/browser/extension_host.h" | 29 #include "extensions/browser/extension_host.h" |
| 30 #include "extensions/browser/extension_registry.h" |
| 31 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
| 32 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
| 33 #include "extensions/common/extension_set.h" | 33 #include "extensions/common/extension_set.h" |
| 34 #include "google_apis/drive/gdata_wapi_parser.h" | 34 #include "google_apis/drive/gdata_wapi_parser.h" |
| 35 #include "webkit/browser/fileapi/file_system_context.h" | 35 #include "webkit/browser/fileapi/file_system_context.h" |
| 36 #include "webkit/browser/fileapi/file_system_url.h" | 36 #include "webkit/browser/fileapi/file_system_url.h" |
| 37 | 37 |
| 38 using extensions::Extension; | 38 using extensions::Extension; |
| 39 using extensions::app_file_handler_util::FindFileHandlersForFiles; | 39 using extensions::app_file_handler_util::FindFileHandlersForFiles; |
| 40 using fileapi::FileSystemURL; | 40 using fileapi::FileSystemURL; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } // namespace | 133 } // namespace |
| 134 | 134 |
| 135 FullTaskDescriptor::FullTaskDescriptor( | 135 FullTaskDescriptor::FullTaskDescriptor( |
| 136 const TaskDescriptor& task_descriptor, | 136 const TaskDescriptor& task_descriptor, |
| 137 const std::string& task_title, | 137 const std::string& task_title, |
| 138 const GURL& icon_url, | 138 const GURL& icon_url, |
| 139 bool is_default) | 139 bool is_default) |
| 140 : task_descriptor_(task_descriptor), | 140 : task_descriptor_(task_descriptor), |
| 141 task_title_(task_title), | 141 task_title_(task_title), |
| 142 icon_url_(icon_url), | 142 icon_url_(icon_url), |
| 143 is_default_(is_default){ | 143 is_default_(is_default) { |
| 144 } | 144 } |
| 145 | 145 |
| 146 void UpdateDefaultTask(PrefService* pref_service, | 146 void UpdateDefaultTask(PrefService* pref_service, |
| 147 const std::string& task_id, | 147 const std::string& task_id, |
| 148 const std::set<std::string>& suffixes, | 148 const std::set<std::string>& suffixes, |
| 149 const std::set<std::string>& mime_types) { | 149 const std::set<std::string>& mime_types) { |
| 150 if (!pref_service) | 150 if (!pref_service) |
| 151 return; | 151 return; |
| 152 | 152 |
| 153 if (!mime_types.empty()) { | 153 if (!mime_types.empty()) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // drive::FileTaskExecutor is responsible to handle drive tasks. | 266 // drive::FileTaskExecutor is responsible to handle drive tasks. |
| 267 if (task.task_type == TASK_TYPE_DRIVE_APP) { | 267 if (task.task_type == TASK_TYPE_DRIVE_APP) { |
| 268 DCHECK_EQ(kDriveAppActionID, task.action_id); | 268 DCHECK_EQ(kDriveAppActionID, task.action_id); |
| 269 drive::FileTaskExecutor* executor = | 269 drive::FileTaskExecutor* executor = |
| 270 new drive::FileTaskExecutor(profile, task.app_id); | 270 new drive::FileTaskExecutor(profile, task.app_id); |
| 271 executor->Execute(file_urls, done); | 271 executor->Execute(file_urls, done); |
| 272 return true; | 272 return true; |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Get the extension. | 275 // Get the extension. |
| 276 ExtensionService* service = | 276 const Extension* extension = extensions::ExtensionRegistry::Get( |
| 277 extensions::ExtensionSystem::Get(profile)->extension_service(); | 277 profile)->enabled_extensions().GetByID(task.app_id); |
| 278 const Extension* extension = service ? | |
| 279 service->GetExtensionById(task.app_id, false) : NULL; | |
| 280 if (!extension) | 278 if (!extension) |
| 281 return false; | 279 return false; |
| 282 | 280 |
| 283 // Execute the task. | 281 // Execute the task. |
| 284 if (task.task_type == TASK_TYPE_FILE_BROWSER_HANDLER) { | 282 if (task.task_type == TASK_TYPE_FILE_BROWSER_HANDLER) { |
| 285 return file_browser_handlers::ExecuteFileBrowserHandler( | 283 return file_browser_handlers::ExecuteFileBrowserHandler( |
| 286 profile, | 284 profile, |
| 287 extension, | 285 extension, |
| 288 task.action_id, | 286 task.action_id, |
| 289 file_urls, | 287 file_urls, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 365 } |
| 368 } | 366 } |
| 369 | 367 |
| 370 void FindFileHandlerTasks( | 368 void FindFileHandlerTasks( |
| 371 Profile* profile, | 369 Profile* profile, |
| 372 const PathAndMimeTypeSet& path_mime_set, | 370 const PathAndMimeTypeSet& path_mime_set, |
| 373 std::vector<FullTaskDescriptor>* result_list) { | 371 std::vector<FullTaskDescriptor>* result_list) { |
| 374 DCHECK(!path_mime_set.empty()); | 372 DCHECK(!path_mime_set.empty()); |
| 375 DCHECK(result_list); | 373 DCHECK(result_list); |
| 376 | 374 |
| 377 ExtensionService* service = profile->GetExtensionService(); | 375 const extensions::ExtensionSet& enabled_extensions = |
| 378 if (!service) | 376 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
| 379 return; | |
| 380 | |
| 381 for (extensions::ExtensionSet::const_iterator iter = | 377 for (extensions::ExtensionSet::const_iterator iter = |
| 382 service->extensions()->begin(); | 378 enabled_extensions.begin(); |
| 383 iter != service->extensions()->end(); | 379 iter != enabled_extensions.end(); |
| 384 ++iter) { | 380 ++iter) { |
| 385 const Extension* extension = iter->get(); | 381 const Extension* extension = iter->get(); |
| 386 | 382 |
| 387 // We don't support using hosted apps to open files. | 383 // We don't support using hosted apps to open files. |
| 388 if (!extension->is_platform_app()) | 384 if (!extension->is_platform_app()) |
| 389 continue; | 385 continue; |
| 390 | 386 |
| 391 if (profile->IsOffTheRecord() && | 387 if (profile->IsOffTheRecord() && |
| 392 !extensions::util::IsIncognitoEnabled(extension->id(), profile)) | 388 !extensions::util::IsIncognitoEnabled(extension->id(), profile)) |
| 393 continue; | 389 continue; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 const std::vector<GURL>& file_urls, | 421 const std::vector<GURL>& file_urls, |
| 426 std::vector<FullTaskDescriptor>* result_list) { | 422 std::vector<FullTaskDescriptor>* result_list) { |
| 427 DCHECK(!file_urls.empty()); | 423 DCHECK(!file_urls.empty()); |
| 428 DCHECK(result_list); | 424 DCHECK(result_list); |
| 429 | 425 |
| 430 file_browser_handlers::FileBrowserHandlerList common_tasks = | 426 file_browser_handlers::FileBrowserHandlerList common_tasks = |
| 431 file_browser_handlers::FindFileBrowserHandlers(profile, file_urls); | 427 file_browser_handlers::FindFileBrowserHandlers(profile, file_urls); |
| 432 if (common_tasks.empty()) | 428 if (common_tasks.empty()) |
| 433 return; | 429 return; |
| 434 | 430 |
| 435 ExtensionService* service = | 431 const extensions::ExtensionSet& enabled_extensions = |
| 436 extensions::ExtensionSystem::Get(profile)->extension_service(); | 432 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
| 437 for (file_browser_handlers::FileBrowserHandlerList::const_iterator iter = | 433 for (file_browser_handlers::FileBrowserHandlerList::const_iterator iter = |
| 438 common_tasks.begin(); | 434 common_tasks.begin(); |
| 439 iter != common_tasks.end(); | 435 iter != common_tasks.end(); |
| 440 ++iter) { | 436 ++iter) { |
| 441 const FileBrowserHandler* handler = *iter; | 437 const FileBrowserHandler* handler = *iter; |
| 442 const std::string extension_id = handler->extension_id(); | 438 const std::string extension_id = handler->extension_id(); |
| 443 const Extension* extension = service->GetExtensionById(extension_id, false); | 439 const Extension* extension = enabled_extensions.GetByID(extension_id); |
| 444 DCHECK(extension); | 440 DCHECK(extension); |
| 445 | 441 |
| 446 // TODO(zelidrag): Figure out how to expose icon URL that task defined in | 442 // TODO(zelidrag): Figure out how to expose icon URL that task defined in |
| 447 // manifest instead of the default extension icon. | 443 // manifest instead of the default extension icon. |
| 448 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL( | 444 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL( |
| 449 extension, | 445 extension, |
| 450 extension_misc::EXTENSION_ICON_BITTY, | 446 extension_misc::EXTENSION_ICON_BITTY, |
| 451 ExtensionIconSet::MATCH_BIGGER, | 447 ExtensionIconSet::MATCH_BIGGER, |
| 452 false, // grayscale | 448 false, // grayscale |
| 453 NULL); // exists | 449 NULL); // exists |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 if (file_browser_handlers::IsFallbackFileBrowserHandler( | 523 if (file_browser_handlers::IsFallbackFileBrowserHandler( |
| 528 task->task_descriptor())) { | 524 task->task_descriptor())) { |
| 529 task->set_is_default(true); | 525 task->set_is_default(true); |
| 530 return; | 526 return; |
| 531 } | 527 } |
| 532 } | 528 } |
| 533 } | 529 } |
| 534 | 530 |
| 535 } // namespace file_tasks | 531 } // namespace file_tasks |
| 536 } // namespace file_manager | 532 } // namespace file_manager |
| OLD | NEW |