| 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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 return false; | 127 return false; |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace | 130 } // namespace |
| 131 | 131 |
| 132 FullTaskDescriptor::FullTaskDescriptor( | 132 FullTaskDescriptor::FullTaskDescriptor( |
| 133 const TaskDescriptor& task_descriptor, | 133 const TaskDescriptor& task_descriptor, |
| 134 const std::string& task_title, | 134 const std::string& task_title, |
| 135 const GURL& icon_url, | 135 const GURL& icon_url, |
| 136 bool is_default) | 136 bool is_default, |
| 137 bool is_generic_file_handler) |
| 137 : task_descriptor_(task_descriptor), | 138 : task_descriptor_(task_descriptor), |
| 138 task_title_(task_title), | 139 task_title_(task_title), |
| 139 icon_url_(icon_url), | 140 icon_url_(icon_url), |
| 140 is_default_(is_default) { | 141 is_default_(is_default), |
| 142 is_generic_file_handler_(is_generic_file_handler) { |
| 141 } | 143 } |
| 142 | 144 |
| 143 void UpdateDefaultTask(PrefService* pref_service, | 145 void UpdateDefaultTask(PrefService* pref_service, |
| 144 const std::string& task_id, | 146 const std::string& task_id, |
| 145 const std::set<std::string>& suffixes, | 147 const std::set<std::string>& suffixes, |
| 146 const std::set<std::string>& mime_types) { | 148 const std::set<std::string>& mime_types) { |
| 147 if (!pref_service) | 149 if (!pref_service) |
| 148 return; | 150 return; |
| 149 | 151 |
| 150 if (!mime_types.empty()) { | 152 if (!mime_types.empty()) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 TaskDescriptor descriptor(app_info.app_id, | 348 TaskDescriptor descriptor(app_info.app_id, |
| 347 TASK_TYPE_DRIVE_APP, | 349 TASK_TYPE_DRIVE_APP, |
| 348 kDriveAppActionID); | 350 kDriveAppActionID); |
| 349 GURL icon_url = drive::util::FindPreferredIcon( | 351 GURL icon_url = drive::util::FindPreferredIcon( |
| 350 app_info.app_icons, | 352 app_info.app_icons, |
| 351 drive::util::kPreferredIconSize); | 353 drive::util::kPreferredIconSize); |
| 352 result_list->push_back( | 354 result_list->push_back( |
| 353 FullTaskDescriptor(descriptor, | 355 FullTaskDescriptor(descriptor, |
| 354 app_info.app_name, | 356 app_info.app_name, |
| 355 icon_url, | 357 icon_url, |
| 356 false /* is_default */)); | 358 false /* is_default */, |
| 359 false /* is_generic_file_handler */)); |
| 357 } | 360 } |
| 358 } | 361 } |
| 359 | 362 |
| 363 bool IsGenericFileHandler( |
| 364 const extensions::FileHandlerInfo& file_handler_info) { |
| 365 return file_handler_info.extensions.count("*") > 0 || |
| 366 file_handler_info.types.count("*") > 0 || |
| 367 file_handler_info.types.count("*/*") > 0; |
| 368 } |
| 369 |
| 360 void FindFileHandlerTasks( | 370 void FindFileHandlerTasks( |
| 361 Profile* profile, | 371 Profile* profile, |
| 362 const PathAndMimeTypeSet& path_mime_set, | 372 const PathAndMimeTypeSet& path_mime_set, |
| 363 std::vector<FullTaskDescriptor>* result_list) { | 373 std::vector<FullTaskDescriptor>* result_list) { |
| 364 DCHECK(!path_mime_set.empty()); | 374 DCHECK(!path_mime_set.empty()); |
| 365 DCHECK(result_list); | 375 DCHECK(result_list); |
| 366 | 376 |
| 367 const extensions::ExtensionSet& enabled_extensions = | 377 const extensions::ExtensionSet& enabled_extensions = |
| 368 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 378 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
| 379 |
| 369 for (extensions::ExtensionSet::const_iterator iter = | 380 for (extensions::ExtensionSet::const_iterator iter = |
| 370 enabled_extensions.begin(); | 381 enabled_extensions.begin(); |
| 371 iter != enabled_extensions.end(); | 382 iter != enabled_extensions.end(); |
| 372 ++iter) { | 383 ++iter) { |
| 373 const Extension* extension = iter->get(); | 384 const Extension* extension = iter->get(); |
| 374 | 385 |
| 375 // Check that the extension can be launched via an event. This includes all | 386 // Check that the extension can be launched via an event. This includes all |
| 376 // platform apps plus whitelisted extensions. | 387 // platform apps plus whitelisted extensions. |
| 377 if (!CanLaunchViaEvent(extension)) | 388 if (!CanLaunchViaEvent(extension)) |
| 378 continue; | 389 continue; |
| 379 | 390 |
| 380 // Ephemeral apps cannot be file handlers. | 391 // Ephemeral apps cannot be file handlers. |
| 381 if (extensions::util::IsEphemeralApp(extension->id(), profile)) | 392 if (extensions::util::IsEphemeralApp(extension->id(), profile)) |
| 382 continue; | 393 continue; |
| 383 | 394 |
| 384 if (profile->IsOffTheRecord() && | 395 if (profile->IsOffTheRecord() && |
| 385 !extensions::util::IsIncognitoEnabled(extension->id(), profile)) | 396 !extensions::util::IsIncognitoEnabled(extension->id(), profile)) |
| 386 continue; | 397 continue; |
| 387 | 398 |
| 388 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; | 399 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; |
| 389 FileHandlerList file_handlers = | 400 FileHandlerList file_handlers = |
| 390 FindFileHandlersForFiles(*extension, path_mime_set); | 401 FindFileHandlersForFiles(*extension, path_mime_set); |
| 391 if (file_handlers.empty()) | 402 if (file_handlers.empty()) |
| 392 continue; | 403 continue; |
| 393 | 404 |
| 394 // Only show the first matching handler from each app. | 405 // Show the first matching non-generic handler of each app. If there doesn't |
| 395 const extensions::FileHandlerInfo* file_handler = file_handlers.front(); | 406 // exist such handler, show the first matching handler of the app. |
| 407 const extensions::FileHandlerInfo* file_handler = nullptr; |
| 408 for (auto handler : file_handlers) { |
| 409 if (!IsGenericFileHandler(*handler)) { |
| 410 file_handler = handler; |
| 411 break; |
| 412 } |
| 413 } |
| 414 if (file_handler == nullptr) { |
| 415 file_handler = file_handlers.front(); |
| 416 } |
| 417 |
| 396 std::string task_id = file_tasks::MakeTaskID( | 418 std::string task_id = file_tasks::MakeTaskID( |
| 397 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); | 419 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); |
| 398 | 420 |
| 399 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( | 421 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( |
| 400 extension, | 422 extension, |
| 401 drive::util::kPreferredIconSize, | 423 drive::util::kPreferredIconSize, |
| 402 ExtensionIconSet::MATCH_BIGGER, | 424 ExtensionIconSet::MATCH_BIGGER, |
| 403 false, // grayscale | 425 false, // grayscale |
| 404 NULL); // exists | 426 NULL); // exists |
| 405 | 427 |
| 406 result_list->push_back( | 428 result_list->push_back( |
| 407 FullTaskDescriptor(TaskDescriptor(extension->id(), | 429 FullTaskDescriptor(TaskDescriptor(extension->id(), |
| 408 file_tasks::TASK_TYPE_FILE_HANDLER, | 430 file_tasks::TASK_TYPE_FILE_HANDLER, |
| 409 file_handler->id), | 431 file_handler->id), |
| 410 extension->name(), | 432 extension->name(), |
| 411 best_icon, | 433 best_icon, |
| 412 false /* is_default */)); | 434 false /* is_default */, |
| 435 IsGenericFileHandler(*file_handler))); |
| 413 } | 436 } |
| 414 } | 437 } |
| 415 | 438 |
| 416 void FindFileBrowserHandlerTasks( | 439 void FindFileBrowserHandlerTasks( |
| 417 Profile* profile, | 440 Profile* profile, |
| 418 const std::vector<GURL>& file_urls, | 441 const std::vector<GURL>& file_urls, |
| 419 std::vector<FullTaskDescriptor>* result_list) { | 442 std::vector<FullTaskDescriptor>* result_list) { |
| 420 DCHECK(!file_urls.empty()); | 443 DCHECK(!file_urls.empty()); |
| 421 DCHECK(result_list); | 444 DCHECK(result_list); |
| 422 | 445 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 444 ExtensionIconSet::MATCH_BIGGER, | 467 ExtensionIconSet::MATCH_BIGGER, |
| 445 false, // grayscale | 468 false, // grayscale |
| 446 NULL); // exists | 469 NULL); // exists |
| 447 | 470 |
| 448 result_list->push_back(FullTaskDescriptor( | 471 result_list->push_back(FullTaskDescriptor( |
| 449 TaskDescriptor(extension_id, | 472 TaskDescriptor(extension_id, |
| 450 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, | 473 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, |
| 451 handler->id()), | 474 handler->id()), |
| 452 handler->title(), | 475 handler->title(), |
| 453 icon_url, | 476 icon_url, |
| 454 false /* is_default */)); | 477 false /* is_default */, |
| 478 false /* is_generic_file_handler */)); |
| 455 } | 479 } |
| 456 } | 480 } |
| 457 | 481 |
| 458 void FindAllTypesOfTasks( | 482 void FindAllTypesOfTasks( |
| 459 Profile* profile, | 483 Profile* profile, |
| 460 const drive::DriveAppRegistry* drive_app_registry, | 484 const drive::DriveAppRegistry* drive_app_registry, |
| 461 const PathAndMimeTypeSet& path_mime_set, | 485 const PathAndMimeTypeSet& path_mime_set, |
| 462 const std::vector<GURL>& file_urls, | 486 const std::vector<GURL>& file_urls, |
| 463 std::vector<FullTaskDescriptor>* result_list) { | 487 std::vector<FullTaskDescriptor>* result_list) { |
| 464 DCHECK(profile); | 488 DCHECK(profile); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 DCHECK(!task->is_default()); | 542 DCHECK(!task->is_default()); |
| 519 if (IsFallbackFileHandler(task->task_descriptor())) { | 543 if (IsFallbackFileHandler(task->task_descriptor())) { |
| 520 task->set_is_default(true); | 544 task->set_is_default(true); |
| 521 return; | 545 return; |
| 522 } | 546 } |
| 523 } | 547 } |
| 524 } | 548 } |
| 525 | 549 |
| 526 } // namespace file_tasks | 550 } // namespace file_tasks |
| 527 } // namespace file_manager | 551 } // namespace file_manager |
| OLD | NEW |