Chromium Code Reviews| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 130 |
| 131 for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) { | 131 for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) { |
| 132 if (task.app_id == kBuiltInApps[i]) | 132 if (task.app_id == kBuiltInApps[i]) |
| 133 return true; | 133 return true; |
| 134 } | 134 } |
| 135 return false; | 135 return false; |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace | 138 } // namespace |
| 139 | 139 |
| 140 FullTaskDescriptor::FullTaskDescriptor( | 140 FullTaskDescriptor::FullTaskDescriptor(const TaskDescriptor& task_descriptor, |
| 141 const TaskDescriptor& task_descriptor, | 141 const base::string16& task_title, |
| 142 const std::string& task_title, | 142 const GURL& icon_url, |
| 143 const GURL& icon_url, | 143 bool is_default, |
| 144 bool is_default, | 144 bool is_generic_file_handler) |
| 145 bool is_generic_file_handler) | |
| 146 : task_descriptor_(task_descriptor), | 145 : task_descriptor_(task_descriptor), |
| 147 task_title_(task_title), | 146 task_title_(task_title), |
| 148 icon_url_(icon_url), | 147 icon_url_(icon_url), |
| 149 is_default_(is_default), | 148 is_default_(is_default), |
| 150 is_generic_file_handler_(is_generic_file_handler) { | 149 is_generic_file_handler_(is_generic_file_handler) {} |
| 151 } | 150 |
| 151 FullTaskDescriptor::~FullTaskDescriptor() {} | |
| 152 | 152 |
| 153 void UpdateDefaultTask(PrefService* pref_service, | 153 void UpdateDefaultTask(PrefService* pref_service, |
| 154 const std::string& task_id, | 154 const std::string& task_id, |
| 155 const std::set<std::string>& suffixes, | 155 const std::set<std::string>& suffixes, |
| 156 const std::set<std::string>& mime_types) { | 156 const std::set<std::string>& mime_types) { |
| 157 if (!pref_service) | 157 if (!pref_service) |
| 158 return; | 158 return; |
| 159 | 159 |
| 160 if (!mime_types.empty()) { | 160 if (!mime_types.empty()) { |
| 161 DictionaryPrefUpdate mime_type_pref(pref_service, | 161 DictionaryPrefUpdate mime_type_pref(pref_service, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 | 352 |
| 353 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin(); | 353 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin(); |
| 354 iter != drive_app_map.end(); ++iter) { | 354 iter != drive_app_map.end(); ++iter) { |
| 355 const drive::DriveAppInfo& app_info = iter->second; | 355 const drive::DriveAppInfo& app_info = iter->second; |
| 356 TaskDescriptor descriptor(app_info.app_id, | 356 TaskDescriptor descriptor(app_info.app_id, |
| 357 TASK_TYPE_DRIVE_APP, | 357 TASK_TYPE_DRIVE_APP, |
| 358 kDriveAppActionID); | 358 kDriveAppActionID); |
| 359 GURL icon_url = drive::util::FindPreferredIcon( | 359 GURL icon_url = drive::util::FindPreferredIcon( |
| 360 app_info.app_icons, | 360 app_info.app_icons, |
| 361 drive::util::kPreferredIconSize); | 361 drive::util::kPreferredIconSize); |
| 362 result_list->push_back( | 362 |
| 363 FullTaskDescriptor(descriptor, | 363 result_list->push_back(FullTaskDescriptor( |
| 364 app_info.app_name, | 364 descriptor, |
| 365 icon_url, | 365 extensions::file_handler_verbs::GetTitleForExtensionAndVerb( |
| 366 false /* is_default */, | 366 app_info.app_name, extensions::file_handler_verbs::kOpenWith), |
| 367 false /* is_generic_file_handler */)); | 367 icon_url, false /* is_default */, false /* is_generic_file_handler */)); |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 | 370 |
| 371 bool IsGoodMatchFileHandler( | 371 bool IsGoodMatchFileHandler( |
| 372 const extensions::FileHandlerInfo& file_handler_info, | 372 const extensions::FileHandlerInfo& file_handler_info, |
| 373 const std::vector<extensions::EntryInfo>& entries) { | 373 const std::vector<extensions::EntryInfo>& entries) { |
| 374 if (file_handler_info.extensions.count("*") > 0 || | 374 if (file_handler_info.extensions.count("*") > 0 || |
| 375 file_handler_info.types.count("*") > 0 || | 375 file_handler_info.types.count("*") > 0 || |
| 376 file_handler_info.types.count("*/*") > 0) | 376 file_handler_info.types.count("*/*") > 0) |
| 377 return false; | 377 return false; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 continue; | 424 continue; |
| 425 | 425 |
| 426 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't | 426 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't |
| 427 // show both the legacy one and the new one in Files app for ZIP files. | 427 // show both the legacy one and the new one in Files app for ZIP files. |
| 428 if (extension->id() == extension_misc::kZIPUnpackerExtensionId && | 428 if (extension->id() == extension_misc::kZIPUnpackerExtensionId && |
| 429 base::CommandLine::ForCurrentProcess()->HasSwitch( | 429 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 430 chromeos::switches::kDisableNewZIPUnpacker)) { | 430 chromeos::switches::kDisableNewZIPUnpacker)) { |
| 431 continue; | 431 continue; |
| 432 } | 432 } |
| 433 | 433 |
| 434 // Show the first good matching handler of each app. If there doesn't exist | 434 // A map which has as key a handler verb, and as value a pair of the |
| 435 // such handler, show the first matching handler of the app. | 435 // handler with which to open the given entries and a boolean marking |
| 436 const extensions::FileHandlerInfo* file_handler = file_handlers.front(); | 436 // if the handler is a good match. |
| 437 for (auto handler : file_handlers) { | 437 std::map<std::string, std::pair<const extensions::FileHandlerInfo*, bool>> |
| 438 if (IsGoodMatchFileHandler(*handler, entries)) { | 438 handlers_for_entries; |
| 439 file_handler = handler; | 439 // Show the first good matching handler of each verb supporting the given |
| 440 break; | 440 // entries that corresponds to the app. If there doesn't exist such handler, |
| 441 // show the first matching handler of the verb. | |
| 442 for (const auto handler : file_handlers) { | |
| 443 bool good_match = IsGoodMatchFileHandler(*handler, entries); | |
| 444 auto it = handlers_for_entries.find(handler->verb); | |
| 445 if (it == handlers_for_entries.end() || | |
| 446 (!it->second.second /* existing handler not a good match */ && | |
| 447 good_match)) { | |
| 448 handlers_for_entries[handler->verb] = | |
| 449 std::make_pair(handler, good_match); | |
| 441 } | 450 } |
| 442 } | 451 } |
| 443 | 452 |
| 444 std::string task_id = file_tasks::MakeTaskID( | 453 for (const auto entry : handlers_for_entries) { |
| 445 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); | 454 const extensions::FileHandlerInfo* handler = entry.second.first; |
| 455 std::string task_id = file_tasks::MakeTaskID( | |
| 456 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, handler->id); | |
| 446 | 457 |
| 447 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( | 458 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( |
| 448 extension, | 459 extension, drive::util::kPreferredIconSize, |
| 449 drive::util::kPreferredIconSize, | 460 ExtensionIconSet::MATCH_BIGGER, |
| 450 ExtensionIconSet::MATCH_BIGGER, | 461 false, // grayscale |
| 451 false, // grayscale | 462 NULL); // exists |
| 452 NULL); // exists | |
| 453 | 463 |
| 454 // If file handler doesn't match as good match, regards it as generic file | 464 // If file handler doesn't match as good match, regards it as generic file |
| 455 // handler. | 465 // handler. |
| 456 const bool is_generic_file_handler = | 466 const bool is_generic_file_handler = |
| 457 !IsGoodMatchFileHandler(*file_handler, entries); | 467 !IsGoodMatchFileHandler(*handler, entries); |
| 458 result_list->push_back(FullTaskDescriptor( | 468 result_list->push_back(FullTaskDescriptor( |
| 459 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, | 469 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, |
| 460 file_handler->id), | 470 handler->id), |
| 461 extension->name(), best_icon, false /* is_default */, | 471 extensions::file_handler_verbs::GetTitleForExtensionAndVerb( |
| 462 is_generic_file_handler)); | 472 extension->name(), handler->verb), |
| 473 best_icon, false /* is_default */, is_generic_file_handler)); | |
| 474 } | |
| 463 } | 475 } |
| 464 } | 476 } |
| 465 | 477 |
| 466 void FindFileBrowserHandlerTasks( | 478 void FindFileBrowserHandlerTasks( |
| 467 Profile* profile, | 479 Profile* profile, |
| 468 const std::vector<GURL>& file_urls, | 480 const std::vector<GURL>& file_urls, |
| 469 std::vector<FullTaskDescriptor>* result_list) { | 481 std::vector<FullTaskDescriptor>* result_list) { |
| 470 DCHECK(!file_urls.empty()); | 482 DCHECK(!file_urls.empty()); |
| 471 DCHECK(result_list); | 483 DCHECK(result_list); |
| 472 | 484 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 489 // TODO(zelidrag): Figure out how to expose icon URL that task defined in | 501 // TODO(zelidrag): Figure out how to expose icon URL that task defined in |
| 490 // manifest instead of the default extension icon. | 502 // manifest instead of the default extension icon. |
| 491 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL( | 503 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL( |
| 492 extension, | 504 extension, |
| 493 extension_misc::EXTENSION_ICON_BITTY, | 505 extension_misc::EXTENSION_ICON_BITTY, |
| 494 ExtensionIconSet::MATCH_BIGGER, | 506 ExtensionIconSet::MATCH_BIGGER, |
| 495 false, // grayscale | 507 false, // grayscale |
| 496 NULL); // exists | 508 NULL); // exists |
| 497 | 509 |
| 498 result_list->push_back(FullTaskDescriptor( | 510 result_list->push_back(FullTaskDescriptor( |
| 499 TaskDescriptor(extension_id, | 511 TaskDescriptor(extension_id, file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, |
| 500 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, | |
| 501 handler->id()), | 512 handler->id()), |
| 502 handler->title(), | 513 // TODO(cmihail): Should we support verbs also for FileBrowserHandler? |
|
fukino
2016/04/11 09:19:43
I think FileBrowserHandler already has the similar
cmihail
2016/04/13 07:36:46
Acknowledged.
| |
| 503 icon_url, | 514 extensions::file_handler_verbs::GetTitleForExtensionAndVerb( |
| 504 false /* is_default */, | 515 handler->title(), extensions::file_handler_verbs::kOpenWith), |
|
fukino
2016/04/11 09:19:43
We should not assume "Open with..." for FileBrowse
| |
| 505 false /* is_generic_file_handler */)); | 516 icon_url, false /* is_default */, false /* is_generic_file_handler */)); |
| 506 } | 517 } |
| 507 } | 518 } |
| 508 | 519 |
| 509 void FindAllTypesOfTasks(Profile* profile, | 520 void FindAllTypesOfTasks(Profile* profile, |
| 510 const drive::DriveAppRegistry* drive_app_registry, | 521 const drive::DriveAppRegistry* drive_app_registry, |
| 511 const std::vector<extensions::EntryInfo>& entries, | 522 const std::vector<extensions::EntryInfo>& entries, |
| 512 const std::vector<GURL>& file_urls, | 523 const std::vector<GURL>& file_urls, |
| 513 std::vector<FullTaskDescriptor>* result_list) { | 524 std::vector<FullTaskDescriptor>* result_list) { |
| 514 DCHECK(profile); | 525 DCHECK(profile); |
| 515 DCHECK(result_list); | 526 DCHECK(result_list); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 DCHECK(!task->is_default()); | 579 DCHECK(!task->is_default()); |
| 569 if (IsFallbackFileHandler(task->task_descriptor())) { | 580 if (IsFallbackFileHandler(task->task_descriptor())) { |
| 570 task->set_is_default(true); | 581 task->set_is_default(true); |
| 571 return; | 582 return; |
| 572 } | 583 } |
| 573 } | 584 } |
| 574 } | 585 } |
| 575 | 586 |
| 576 } // namespace file_tasks | 587 } // namespace file_tasks |
| 577 } // namespace file_manager | 588 } // namespace file_manager |
| OLD | NEW |