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

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 unused internationalization function on C++ code. Created 4 years, 8 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 std::string& task_title,
142 const std::string& task_title, 142 const std::string& task_verb,
143 const GURL& icon_url, 143 const GURL& icon_url,
144 bool is_default, 144 bool is_default,
145 bool is_generic_file_handler) 145 bool is_generic_file_handler)
146 : task_descriptor_(task_descriptor), 146 : task_descriptor_(task_descriptor),
147 task_title_(task_title), 147 task_title_(task_title),
148 task_verb_(task_verb),
148 icon_url_(icon_url), 149 icon_url_(icon_url),
149 is_default_(is_default), 150 is_default_(is_default),
150 is_generic_file_handler_(is_generic_file_handler) { 151 is_generic_file_handler_(is_generic_file_handler) {}
151 } 152
153 FullTaskDescriptor::~FullTaskDescriptor() {}
fukino 2016/04/18 08:06:05 Looks unnecessary :)
cmihail 2016/04/21 09:36:43 See header comment.
152 154
153 void UpdateDefaultTask(PrefService* pref_service, 155 void UpdateDefaultTask(PrefService* pref_service,
154 const std::string& task_id, 156 const std::string& task_id,
155 const std::set<std::string>& suffixes, 157 const std::set<std::string>& suffixes,
156 const std::set<std::string>& mime_types) { 158 const std::set<std::string>& mime_types) {
157 if (!pref_service) 159 if (!pref_service)
158 return; 160 return;
159 161
160 if (!mime_types.empty()) { 162 if (!mime_types.empty()) {
161 DictionaryPrefUpdate mime_type_pref(pref_service, 163 DictionaryPrefUpdate mime_type_pref(pref_service,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 354
353 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin(); 355 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin();
354 iter != drive_app_map.end(); ++iter) { 356 iter != drive_app_map.end(); ++iter) {
355 const drive::DriveAppInfo& app_info = iter->second; 357 const drive::DriveAppInfo& app_info = iter->second;
356 TaskDescriptor descriptor(app_info.app_id, 358 TaskDescriptor descriptor(app_info.app_id,
357 TASK_TYPE_DRIVE_APP, 359 TASK_TYPE_DRIVE_APP,
358 kDriveAppActionID); 360 kDriveAppActionID);
359 GURL icon_url = drive::util::FindPreferredIcon( 361 GURL icon_url = drive::util::FindPreferredIcon(
360 app_info.app_icons, 362 app_info.app_icons,
361 drive::util::kPreferredIconSize); 363 drive::util::kPreferredIconSize);
362 result_list->push_back( 364
363 FullTaskDescriptor(descriptor, 365 result_list->push_back(FullTaskDescriptor(
364 app_info.app_name, 366 descriptor, app_info.app_name,
365 icon_url, 367 extensions::file_handler_verbs::kOpenWith, icon_url,
366 false /* is_default */, 368 false /* is_default */, false /* is_generic_file_handler */));
367 false /* is_generic_file_handler */));
368 } 369 }
369 } 370 }
370 371
371 bool IsGoodMatchFileHandler( 372 bool IsGoodMatchFileHandler(
372 const extensions::FileHandlerInfo& file_handler_info, 373 const extensions::FileHandlerInfo& file_handler_info,
373 const std::vector<extensions::EntryInfo>& entries) { 374 const std::vector<extensions::EntryInfo>& entries) {
374 if (file_handler_info.extensions.count("*") > 0 || 375 if (file_handler_info.extensions.count("*") > 0 ||
375 file_handler_info.types.count("*") > 0 || 376 file_handler_info.types.count("*") > 0 ||
376 file_handler_info.types.count("*/*") > 0) 377 file_handler_info.types.count("*/*") > 0)
377 return false; 378 return false;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 continue; 425 continue;
425 426
426 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't 427 // 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. 428 // show both the legacy one and the new one in Files app for ZIP files.
428 if (extension->id() == extension_misc::kZIPUnpackerExtensionId && 429 if (extension->id() == extension_misc::kZIPUnpackerExtensionId &&
429 base::CommandLine::ForCurrentProcess()->HasSwitch( 430 base::CommandLine::ForCurrentProcess()->HasSwitch(
430 chromeos::switches::kDisableNewZIPUnpacker)) { 431 chromeos::switches::kDisableNewZIPUnpacker)) {
431 continue; 432 continue;
432 } 433 }
433 434
434 // Show the first good matching handler of each app. If there doesn't exist 435 // 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. 436 // handler with which to open the given entries and a boolean marking
436 const extensions::FileHandlerInfo* file_handler = file_handlers.front(); 437 // if the handler is a good match.
437 for (auto handler : file_handlers) { 438 std::map<std::string, std::pair<const extensions::FileHandlerInfo*, bool>>
438 if (IsGoodMatchFileHandler(*handler, entries)) { 439 handlers_for_entries;
439 file_handler = handler; 440 // Show the first good matching handler of each verb supporting the given
440 break; 441 // entries that corresponds to the app. If there doesn't exist such handler,
442 // show the first matching handler of the verb.
443 for (const auto handler : file_handlers) {
444 bool good_match = IsGoodMatchFileHandler(*handler, entries);
445 auto it = handlers_for_entries.find(handler->verb);
446 if (it == handlers_for_entries.end() ||
447 (!it->second.second /* existing handler not a good match */ &&
448 good_match)) {
449 handlers_for_entries[handler->verb] =
450 std::make_pair(handler, good_match);
441 } 451 }
442 } 452 }
443 453
444 std::string task_id = file_tasks::MakeTaskID( 454 for (const auto entry : handlers_for_entries) {
445 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); 455 const extensions::FileHandlerInfo* handler = entry.second.first;
456 std::string task_id = file_tasks::MakeTaskID(
457 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, handler->id);
446 458
447 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( 459 GURL best_icon = extensions::ExtensionIconSource::GetIconURL(
448 extension, 460 extension, drive::util::kPreferredIconSize,
449 drive::util::kPreferredIconSize, 461 ExtensionIconSet::MATCH_BIGGER,
450 ExtensionIconSet::MATCH_BIGGER, 462 false, // grayscale
451 false, // grayscale 463 NULL); // exists
452 NULL); // exists
453 464
454 // If file handler doesn't match as good match, regards it as generic file 465 // If file handler doesn't match as good match, regards it as generic file
455 // handler. 466 // handler.
456 const bool is_generic_file_handler = 467 const bool is_generic_file_handler =
457 !IsGoodMatchFileHandler(*file_handler, entries); 468 !IsGoodMatchFileHandler(*handler, entries);
458 result_list->push_back(FullTaskDescriptor( 469 result_list->push_back(FullTaskDescriptor(
459 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, 470 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER,
460 file_handler->id), 471 handler->id),
461 extension->name(), best_icon, false /* is_default */, 472 extension->name(), handler->verb, best_icon, false /* is_default */,
462 is_generic_file_handler)); 473 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
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 handler->title(), "" /* no verb for FileBrowserHandler */, icon_url,
503 icon_url, 514 false /* is_default */, false /* is_generic_file_handler */));
504 false /* is_default */,
505 false /* is_generic_file_handler */));
506 } 515 }
507 } 516 }
508 517
509 void FindAllTypesOfTasks(Profile* profile, 518 void FindAllTypesOfTasks(Profile* profile,
510 const drive::DriveAppRegistry* drive_app_registry, 519 const drive::DriveAppRegistry* drive_app_registry,
511 const std::vector<extensions::EntryInfo>& entries, 520 const std::vector<extensions::EntryInfo>& entries,
512 const std::vector<GURL>& file_urls, 521 const std::vector<GURL>& file_urls,
513 std::vector<FullTaskDescriptor>* result_list) { 522 std::vector<FullTaskDescriptor>* result_list) {
514 DCHECK(profile); 523 DCHECK(profile);
515 DCHECK(result_list); 524 DCHECK(result_list);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 DCHECK(!task->is_default()); 577 DCHECK(!task->is_default());
569 if (IsFallbackFileHandler(task->task_descriptor())) { 578 if (IsFallbackFileHandler(task->task_descriptor())) {
570 task->set_is_default(true); 579 task->set_is_default(true);
571 return; 580 return;
572 } 581 }
573 } 582 }
574 } 583 }
575 584
576 } // namespace file_tasks 585 } // namespace file_tasks
577 } // namespace file_manager 586 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698