| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "extensions/browser/entry_info.h" | 39 #include "extensions/browser/entry_info.h" |
| 40 #include "extensions/browser/extension_host.h" | 40 #include "extensions/browser/extension_host.h" |
| 41 #include "extensions/browser/extension_registry.h" | 41 #include "extensions/browser/extension_registry.h" |
| 42 #include "extensions/browser/extension_system.h" | 42 #include "extensions/browser/extension_system.h" |
| 43 #include "extensions/browser/extension_util.h" | 43 #include "extensions/browser/extension_util.h" |
| 44 #include "extensions/common/constants.h" | 44 #include "extensions/common/constants.h" |
| 45 #include "extensions/common/extension_set.h" | 45 #include "extensions/common/extension_set.h" |
| 46 #include "storage/browser/fileapi/file_system_url.h" | 46 #include "storage/browser/fileapi/file_system_url.h" |
| 47 | 47 |
| 48 using extensions::Extension; | 48 using extensions::Extension; |
| 49 using extensions::api::file_manager_private::Verb; |
| 49 using extensions::app_file_handler_util::FindFileHandlersForEntries; | 50 using extensions::app_file_handler_util::FindFileHandlersForEntries; |
| 50 using storage::FileSystemURL; | 51 using storage::FileSystemURL; |
| 51 | 52 |
| 52 namespace file_manager { | 53 namespace file_manager { |
| 53 namespace file_tasks { | 54 namespace file_tasks { |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| 56 | 57 |
| 57 // The values "file" and "app" are confusing, but cannot be changed easily as | 58 // The values "file" and "app" are confusing, but cannot be changed easily as |
| 58 // these are used in default task IDs stored in preferences. | 59 // these are used in default task IDs stored in preferences. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) { | 161 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) { |
| 161 // Google documents can only be handled by internal handlers. | 162 // Google documents can only be handled by internal handlers. |
| 162 if (ContainsGoogleDocument(entries)) | 163 if (ContainsGoogleDocument(entries)) |
| 163 KeepOnlyFileManagerInternalTasks(result_list.get()); | 164 KeepOnlyFileManagerInternalTasks(result_list.get()); |
| 164 ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, result_list.get()); | 165 ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, result_list.get()); |
| 165 callback.Run(std::move(result_list)); | 166 callback.Run(std::move(result_list)); |
| 166 } | 167 } |
| 167 | 168 |
| 168 } // namespace | 169 } // namespace |
| 169 | 170 |
| 170 FullTaskDescriptor::FullTaskDescriptor( | 171 FullTaskDescriptor::FullTaskDescriptor(const TaskDescriptor& task_descriptor, |
| 171 const TaskDescriptor& task_descriptor, | 172 const std::string& task_title, |
| 172 const std::string& task_title, | 173 const Verb task_verb, |
| 173 const GURL& icon_url, | 174 const GURL& icon_url, |
| 174 bool is_default, | 175 bool is_default, |
| 175 bool is_generic_file_handler) | 176 bool is_generic_file_handler) |
| 176 : task_descriptor_(task_descriptor), | 177 : task_descriptor_(task_descriptor), |
| 177 task_title_(task_title), | 178 task_title_(task_title), |
| 179 task_verb_(task_verb), |
| 178 icon_url_(icon_url), | 180 icon_url_(icon_url), |
| 179 is_default_(is_default), | 181 is_default_(is_default), |
| 180 is_generic_file_handler_(is_generic_file_handler) { | 182 is_generic_file_handler_(is_generic_file_handler) {} |
| 181 } | 183 |
| 184 FullTaskDescriptor::~FullTaskDescriptor() {} |
| 182 | 185 |
| 183 FullTaskDescriptor::FullTaskDescriptor(const FullTaskDescriptor& other) = | 186 FullTaskDescriptor::FullTaskDescriptor(const FullTaskDescriptor& other) = |
| 184 default; | 187 default; |
| 185 | 188 |
| 186 void UpdateDefaultTask(PrefService* pref_service, | 189 void UpdateDefaultTask(PrefService* pref_service, |
| 187 const std::string& task_id, | 190 const std::string& task_id, |
| 188 const std::set<std::string>& suffixes, | 191 const std::set<std::string>& suffixes, |
| 189 const std::set<std::string>& mime_types) { | 192 const std::set<std::string>& mime_types) { |
| 190 if (!pref_service) | 193 if (!pref_service) |
| 191 return; | 194 return; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 399 |
| 397 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin(); | 400 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin(); |
| 398 iter != drive_app_map.end(); ++iter) { | 401 iter != drive_app_map.end(); ++iter) { |
| 399 const drive::DriveAppInfo& app_info = iter->second; | 402 const drive::DriveAppInfo& app_info = iter->second; |
| 400 TaskDescriptor descriptor(app_info.app_id, | 403 TaskDescriptor descriptor(app_info.app_id, |
| 401 TASK_TYPE_DRIVE_APP, | 404 TASK_TYPE_DRIVE_APP, |
| 402 kDriveAppActionID); | 405 kDriveAppActionID); |
| 403 GURL icon_url = drive::util::FindPreferredIcon( | 406 GURL icon_url = drive::util::FindPreferredIcon( |
| 404 app_info.app_icons, | 407 app_info.app_icons, |
| 405 drive::util::kPreferredIconSize); | 408 drive::util::kPreferredIconSize); |
| 406 result_list->push_back( | 409 |
| 407 FullTaskDescriptor(descriptor, | 410 result_list->push_back(FullTaskDescriptor( |
| 408 app_info.app_name, | 411 descriptor, app_info.app_name, Verb::VERB_OPEN_WITH, icon_url, |
| 409 icon_url, | 412 false /* is_default */, false /* is_generic_file_handler */)); |
| 410 false /* is_default */, | |
| 411 false /* is_generic_file_handler */)); | |
| 412 } | 413 } |
| 413 } | 414 } |
| 414 | 415 |
| 415 bool IsGoodMatchFileHandler( | 416 bool IsGoodMatchFileHandler( |
| 416 const extensions::FileHandlerInfo& file_handler_info, | 417 const extensions::FileHandlerInfo& file_handler_info, |
| 417 const std::vector<extensions::EntryInfo>& entries) { | 418 const std::vector<extensions::EntryInfo>& entries) { |
| 418 if (file_handler_info.extensions.count("*") > 0 || | 419 if (file_handler_info.extensions.count("*") > 0 || |
| 419 file_handler_info.types.count("*") > 0 || | 420 file_handler_info.types.count("*") > 0 || |
| 420 file_handler_info.types.count("*/*") > 0) | 421 file_handler_info.types.count("*/*") > 0) |
| 421 return false; | 422 return false; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 continue; | 469 continue; |
| 469 | 470 |
| 470 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't | 471 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't |
| 471 // show both the legacy one and the new one in Files app for ZIP files. | 472 // show both the legacy one and the new one in Files app for ZIP files. |
| 472 if (extension->id() == extension_misc::kZIPUnpackerExtensionId && | 473 if (extension->id() == extension_misc::kZIPUnpackerExtensionId && |
| 473 base::CommandLine::ForCurrentProcess()->HasSwitch( | 474 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 474 chromeos::switches::kDisableNewZIPUnpacker)) { | 475 chromeos::switches::kDisableNewZIPUnpacker)) { |
| 475 continue; | 476 continue; |
| 476 } | 477 } |
| 477 | 478 |
| 478 // Show the first good matching handler of each app. If there doesn't exist | 479 // A map which has as key a handler verb, and as value a pair of the |
| 479 // such handler, show the first matching handler of the app. | 480 // handler with which to open the given entries and a boolean marking |
| 480 const extensions::FileHandlerInfo* file_handler = file_handlers.front(); | 481 // if the handler is a good match. |
| 481 for (auto handler : file_handlers) { | 482 std::map<std::string, std::pair<const extensions::FileHandlerInfo*, bool>> |
| 482 if (IsGoodMatchFileHandler(*handler, entries)) { | 483 handlers_for_entries; |
| 483 file_handler = handler; | 484 // Show the first good matching handler of each verb supporting the given |
| 484 break; | 485 // entries that corresponds to the app. If there doesn't exist such handler, |
| 486 // show the first matching handler of the verb. |
| 487 for (const extensions::FileHandlerInfo* handler : file_handlers) { |
| 488 bool good_match = IsGoodMatchFileHandler(*handler, entries); |
| 489 auto it = handlers_for_entries.find(handler->verb); |
| 490 if (it == handlers_for_entries.end() || |
| 491 (!it->second.second /* existing handler not a good match */ && |
| 492 good_match)) { |
| 493 handlers_for_entries[handler->verb] = |
| 494 std::make_pair(handler, good_match); |
| 485 } | 495 } |
| 486 } | 496 } |
| 487 | 497 |
| 488 std::string task_id = file_tasks::MakeTaskID( | 498 for (const auto& entry : handlers_for_entries) { |
| 489 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); | 499 const extensions::FileHandlerInfo* handler = entry.second.first; |
| 500 std::string task_id = file_tasks::MakeTaskID( |
| 501 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, handler->id); |
| 490 | 502 |
| 491 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( | 503 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( |
| 492 extension, | 504 extension, drive::util::kPreferredIconSize, |
| 493 drive::util::kPreferredIconSize, | 505 ExtensionIconSet::MATCH_BIGGER, |
| 494 ExtensionIconSet::MATCH_BIGGER, | 506 false, // grayscale |
| 495 false, // grayscale | 507 NULL); // exists |
| 496 NULL); // exists | |
| 497 | 508 |
| 498 // If file handler doesn't match as good match, regards it as generic file | 509 // If file handler doesn't match as good match, regards it as generic file |
| 499 // handler. | 510 // handler. |
| 500 const bool is_generic_file_handler = | 511 const bool is_generic_file_handler = |
| 501 !IsGoodMatchFileHandler(*file_handler, entries); | 512 !IsGoodMatchFileHandler(*handler, entries); |
| 502 result_list->push_back(FullTaskDescriptor( | 513 Verb verb; |
| 503 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, | 514 if (handler->verb == extensions::file_handler_verbs::kAddTo) { |
| 504 file_handler->id), | 515 verb = Verb::VERB_ADD_TO; |
| 505 extension->name(), best_icon, false /* is_default */, | 516 } else if (handler->verb == extensions::file_handler_verbs::kPackWith) { |
| 506 is_generic_file_handler)); | 517 verb = Verb::VERB_PACK_WITH; |
| 518 } else if (handler->verb == extensions::file_handler_verbs::kShareWith) { |
| 519 verb = Verb::VERB_SHARE_WITH; |
| 520 } else { |
| 521 // Only kOpenWith is a valid remaining verb. Invalid verbs should fall |
| 522 // back to it. |
| 523 DCHECK(handler->verb == extensions::file_handler_verbs::kOpenWith); |
| 524 verb = Verb::VERB_OPEN_WITH; |
| 525 } |
| 526 |
| 527 result_list->push_back(FullTaskDescriptor( |
| 528 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, |
| 529 handler->id), |
| 530 extension->name(), verb, best_icon, false /* is_default */, |
| 531 is_generic_file_handler)); |
| 532 } |
| 507 } | 533 } |
| 508 } | 534 } |
| 509 | 535 |
| 510 void FindFileBrowserHandlerTasks( | 536 void FindFileBrowserHandlerTasks( |
| 511 Profile* profile, | 537 Profile* profile, |
| 512 const std::vector<GURL>& file_urls, | 538 const std::vector<GURL>& file_urls, |
| 513 std::vector<FullTaskDescriptor>* result_list) { | 539 std::vector<FullTaskDescriptor>* result_list) { |
| 514 DCHECK(!file_urls.empty()); | 540 DCHECK(!file_urls.empty()); |
| 515 DCHECK(result_list); | 541 DCHECK(result_list); |
| 516 | 542 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 533 // TODO(zelidrag): Figure out how to expose icon URL that task defined in | 559 // TODO(zelidrag): Figure out how to expose icon URL that task defined in |
| 534 // manifest instead of the default extension icon. | 560 // manifest instead of the default extension icon. |
| 535 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL( | 561 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL( |
| 536 extension, | 562 extension, |
| 537 extension_misc::EXTENSION_ICON_BITTY, | 563 extension_misc::EXTENSION_ICON_BITTY, |
| 538 ExtensionIconSet::MATCH_BIGGER, | 564 ExtensionIconSet::MATCH_BIGGER, |
| 539 false, // grayscale | 565 false, // grayscale |
| 540 NULL); // exists | 566 NULL); // exists |
| 541 | 567 |
| 542 result_list->push_back(FullTaskDescriptor( | 568 result_list->push_back(FullTaskDescriptor( |
| 543 TaskDescriptor(extension_id, | 569 TaskDescriptor(extension_id, file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, |
| 544 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, | |
| 545 handler->id()), | 570 handler->id()), |
| 546 handler->title(), | 571 handler->title(), Verb::VERB_NONE /* no verb for FileBrowserHandler */, |
| 547 icon_url, | 572 icon_url, false /* is_default */, false /* is_generic_file_handler */)); |
| 548 false /* is_default */, | |
| 549 false /* is_generic_file_handler */)); | |
| 550 } | 573 } |
| 551 } | 574 } |
| 552 | 575 |
| 553 void FindExtensionAndAppTasks( | 576 void FindExtensionAndAppTasks( |
| 554 Profile* profile, | 577 Profile* profile, |
| 555 const std::vector<extensions::EntryInfo>& entries, | 578 const std::vector<extensions::EntryInfo>& entries, |
| 556 const std::vector<GURL>& file_urls, | 579 const std::vector<GURL>& file_urls, |
| 557 const FindTasksCallback& callback, | 580 const FindTasksCallback& callback, |
| 558 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) { | 581 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) { |
| 559 // 3. Continues from FindAllTypesOfTasks. Find and append file handler tasks. | 582 // 3. Continues from FindAllTypesOfTasks. Find and append file handler tasks. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 DCHECK(!task->is_default()); | 643 DCHECK(!task->is_default()); |
| 621 if (IsFallbackFileHandler(task->task_descriptor())) { | 644 if (IsFallbackFileHandler(task->task_descriptor())) { |
| 622 task->set_is_default(true); | 645 task->set_is_default(true); |
| 623 return; | 646 return; |
| 624 } | 647 } |
| 625 } | 648 } |
| 626 } | 649 } |
| 627 | 650 |
| 628 } // namespace file_tasks | 651 } // namespace file_tasks |
| 629 } // namespace file_manager | 652 } // namespace file_manager |
| OLD | NEW |