Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/chromeos/file_manager/file_tasks.cc

Issue 1872223002: Add verbs API to file handlers. Modify the Chrome OS UI so that it displayes the internationalized … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove restriction to have uppercase verbs in manifest file. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) { 168 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) {
169 // Google documents can only be handled by internal handlers. 169 // Google documents can only be handled by internal handlers.
170 if (ContainsGoogleDocument(entries)) 170 if (ContainsGoogleDocument(entries))
171 KeepOnlyFileManagerInternalTasks(result_list.get()); 171 KeepOnlyFileManagerInternalTasks(result_list.get());
172 ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, result_list.get()); 172 ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, result_list.get());
173 callback.Run(std::move(result_list)); 173 callback.Run(std::move(result_list));
174 } 174 }
175 175
176 } // namespace 176 } // namespace
177 177
178 FullTaskDescriptor::FullTaskDescriptor( 178 FullTaskDescriptor::FullTaskDescriptor(const TaskDescriptor& task_descriptor,
179 const TaskDescriptor& task_descriptor, 179 const std::string& task_title,
180 const std::string& task_title, 180 const std::string& task_verb,
181 const GURL& icon_url, 181 const GURL& icon_url,
182 bool is_default, 182 bool is_default,
183 bool is_generic_file_handler) 183 bool is_generic_file_handler)
184 : task_descriptor_(task_descriptor), 184 : task_descriptor_(task_descriptor),
185 task_title_(task_title), 185 task_title_(task_title),
186 task_verb_(task_verb),
Devlin 2016/05/16 16:17:32 Should we DCHECK that task_verb_ is a valid verb?
cmihail 2016/05/18 02:35:31 Done. Thanks, I didn't really know about enum's su
186 icon_url_(icon_url), 187 icon_url_(icon_url),
187 is_default_(is_default), 188 is_default_(is_default),
188 is_generic_file_handler_(is_generic_file_handler) { 189 is_generic_file_handler_(is_generic_file_handler) {}
189 } 190
191 FullTaskDescriptor::~FullTaskDescriptor() {}
190 192
191 FullTaskDescriptor::FullTaskDescriptor(const FullTaskDescriptor& other) = 193 FullTaskDescriptor::FullTaskDescriptor(const FullTaskDescriptor& other) =
192 default; 194 default;
193 195
194 void UpdateDefaultTask(PrefService* pref_service, 196 void UpdateDefaultTask(PrefService* pref_service,
195 const std::string& task_id, 197 const std::string& task_id,
196 const std::set<std::string>& suffixes, 198 const std::set<std::string>& suffixes,
197 const std::set<std::string>& mime_types) { 199 const std::set<std::string>& mime_types) {
198 if (!pref_service) 200 if (!pref_service)
199 return; 201 return;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 406
405 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin(); 407 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin();
406 iter != drive_app_map.end(); ++iter) { 408 iter != drive_app_map.end(); ++iter) {
407 const drive::DriveAppInfo& app_info = iter->second; 409 const drive::DriveAppInfo& app_info = iter->second;
408 TaskDescriptor descriptor(app_info.app_id, 410 TaskDescriptor descriptor(app_info.app_id,
409 TASK_TYPE_DRIVE_APP, 411 TASK_TYPE_DRIVE_APP,
410 kDriveAppActionID); 412 kDriveAppActionID);
411 GURL icon_url = drive::util::FindPreferredIcon( 413 GURL icon_url = drive::util::FindPreferredIcon(
412 app_info.app_icons, 414 app_info.app_icons,
413 drive::util::kPreferredIconSize); 415 drive::util::kPreferredIconSize);
414 result_list->push_back( 416
415 FullTaskDescriptor(descriptor, 417 result_list->push_back(FullTaskDescriptor(
416 app_info.app_name, 418 descriptor, app_info.app_name,
417 icon_url, 419 extensions::file_handler_verbs::kOpenWith, icon_url,
418 false /* is_default */, 420 false /* is_default */, false /* is_generic_file_handler */));
419 false /* is_generic_file_handler */));
420 } 421 }
421 } 422 }
422 423
423 bool IsGoodMatchFileHandler( 424 bool IsGoodMatchFileHandler(
424 const extensions::FileHandlerInfo& file_handler_info, 425 const extensions::FileHandlerInfo& file_handler_info,
425 const std::vector<extensions::EntryInfo>& entries) { 426 const std::vector<extensions::EntryInfo>& entries) {
426 if (file_handler_info.extensions.count("*") > 0 || 427 if (file_handler_info.extensions.count("*") > 0 ||
427 file_handler_info.types.count("*") > 0 || 428 file_handler_info.types.count("*") > 0 ||
428 file_handler_info.types.count("*/*") > 0) 429 file_handler_info.types.count("*/*") > 0)
429 return false; 430 return false;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 continue; 477 continue;
477 478
478 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't 479 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't
479 // show both the legacy one and the new one in Files app for ZIP files. 480 // show both the legacy one and the new one in Files app for ZIP files.
480 if (extension->id() == extension_misc::kZIPUnpackerExtensionId && 481 if (extension->id() == extension_misc::kZIPUnpackerExtensionId &&
481 base::CommandLine::ForCurrentProcess()->HasSwitch( 482 base::CommandLine::ForCurrentProcess()->HasSwitch(
482 chromeos::switches::kDisableNewZIPUnpacker)) { 483 chromeos::switches::kDisableNewZIPUnpacker)) {
483 continue; 484 continue;
484 } 485 }
485 486
486 // Show the first good matching handler of each app. If there doesn't exist 487 // A map which has as key a handler verb, and as value a pair of the
487 // such handler, show the first matching handler of the app. 488 // handler with which to open the given entries and a boolean marking
488 const extensions::FileHandlerInfo* file_handler = file_handlers.front(); 489 // if the handler is a good match.
489 for (auto handler : file_handlers) { 490 std::map<std::string, std::pair<const extensions::FileHandlerInfo*, bool>>
490 if (IsGoodMatchFileHandler(*handler, entries)) { 491 handlers_for_entries;
491 file_handler = handler; 492 // Show the first good matching handler of each verb supporting the given
492 break; 493 // entries that corresponds to the app. If there doesn't exist such handler,
494 // show the first matching handler of the verb.
495 for (const auto handler : file_handlers) {
Devlin 2016/05/16 16:17:32 nit: I personally think auto here reduces readabil
cmihail 2016/05/18 02:35:31 Done.
496 bool good_match = IsGoodMatchFileHandler(*handler, entries);
497 auto it = handlers_for_entries.find(handler->verb);
498 if (it == handlers_for_entries.end() ||
499 (!it->second.second /* existing handler not a good match */ &&
500 good_match)) {
501 handlers_for_entries[handler->verb] =
502 std::make_pair(handler, good_match);
493 } 503 }
494 } 504 }
495 505
496 std::string task_id = file_tasks::MakeTaskID( 506 for (const auto entry : handlers_for_entries) {
Devlin 2016/05/16 16:17:32 this results in a copy - please make it const auto
cmihail 2016/05/18 02:35:31 Done.
497 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); 507 const extensions::FileHandlerInfo* handler = entry.second.first;
508 std::string task_id = file_tasks::MakeTaskID(
509 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, handler->id);
498 510
499 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( 511 GURL best_icon = extensions::ExtensionIconSource::GetIconURL(
500 extension, 512 extension, drive::util::kPreferredIconSize,
501 drive::util::kPreferredIconSize, 513 ExtensionIconSet::MATCH_BIGGER,
502 ExtensionIconSet::MATCH_BIGGER, 514 false, // grayscale
503 false, // grayscale 515 NULL); // exists
504 NULL); // exists
505 516
506 // If file handler doesn't match as good match, regards it as generic file 517 // If file handler doesn't match as good match, regards it as generic file
507 // handler. 518 // handler.
508 const bool is_generic_file_handler = 519 const bool is_generic_file_handler =
509 !IsGoodMatchFileHandler(*file_handler, entries); 520 !IsGoodMatchFileHandler(*handler, entries);
510 result_list->push_back(FullTaskDescriptor( 521 result_list->push_back(FullTaskDescriptor(
511 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, 522 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER,
512 file_handler->id), 523 handler->id),
513 extension->name(), best_icon, false /* is_default */, 524 extension->name(), handler->verb, best_icon, false /* is_default */,
514 is_generic_file_handler)); 525 is_generic_file_handler));
526 }
515 } 527 }
516 } 528 }
517 529
518 void FindFileBrowserHandlerTasks( 530 void FindFileBrowserHandlerTasks(
519 Profile* profile, 531 Profile* profile,
520 const std::vector<GURL>& file_urls, 532 const std::vector<GURL>& file_urls,
521 std::vector<FullTaskDescriptor>* result_list) { 533 std::vector<FullTaskDescriptor>* result_list) {
522 DCHECK(!file_urls.empty()); 534 DCHECK(!file_urls.empty());
523 DCHECK(result_list); 535 DCHECK(result_list);
524 536
(...skipping 16 matching lines...) Expand all
541 // TODO(zelidrag): Figure out how to expose icon URL that task defined in 553 // TODO(zelidrag): Figure out how to expose icon URL that task defined in
542 // manifest instead of the default extension icon. 554 // manifest instead of the default extension icon.
543 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL( 555 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL(
544 extension, 556 extension,
545 extension_misc::EXTENSION_ICON_BITTY, 557 extension_misc::EXTENSION_ICON_BITTY,
546 ExtensionIconSet::MATCH_BIGGER, 558 ExtensionIconSet::MATCH_BIGGER,
547 false, // grayscale 559 false, // grayscale
548 NULL); // exists 560 NULL); // exists
549 561
550 result_list->push_back(FullTaskDescriptor( 562 result_list->push_back(FullTaskDescriptor(
551 TaskDescriptor(extension_id, 563 TaskDescriptor(extension_id, file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER,
552 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER,
553 handler->id()), 564 handler->id()),
554 handler->title(), 565 handler->title(), "" /* no verb for FileBrowserHandler */, icon_url,
555 icon_url, 566 false /* is_default */, false /* is_generic_file_handler */));
556 false /* is_default */,
557 false /* is_generic_file_handler */));
558 } 567 }
559 } 568 }
560 569
561 void FindAllTypesOfTasks(Profile* profile, 570 void FindAllTypesOfTasks(Profile* profile,
562 const drive::DriveAppRegistry* drive_app_registry, 571 const drive::DriveAppRegistry* drive_app_registry,
563 const std::vector<extensions::EntryInfo>& entries, 572 const std::vector<extensions::EntryInfo>& entries,
564 const std::vector<GURL>& file_urls, 573 const std::vector<GURL>& file_urls,
565 const FindTasksCallback& callback) { 574 const FindTasksCallback& callback) {
566 DCHECK(profile); 575 DCHECK(profile);
567 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list( 576 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 DCHECK(!task->is_default()); 628 DCHECK(!task->is_default());
620 if (IsFallbackFileHandler(task->task_descriptor())) { 629 if (IsFallbackFileHandler(task->task_descriptor())) {
621 task->set_is_default(true); 630 task->set_is_default(true);
622 return; 631 return;
623 } 632 }
624 } 633 }
625 } 634 }
626 635
627 } // namespace file_tasks 636 } // namespace file_tasks
628 } // namespace file_manager 637 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698