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

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: Fix comments mentioned by fukino@. 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 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 }
152 150
153 void UpdateDefaultTask(PrefService* pref_service, 151 void UpdateDefaultTask(PrefService* pref_service,
154 const std::string& task_id, 152 const std::string& task_id,
155 const std::set<std::string>& suffixes, 153 const std::set<std::string>& suffixes,
156 const std::set<std::string>& mime_types) { 154 const std::set<std::string>& mime_types) {
157 if (!pref_service) 155 if (!pref_service)
158 return; 156 return;
159 157
160 if (!mime_types.empty()) { 158 if (!mime_types.empty()) {
161 DictionaryPrefUpdate mime_type_pref(pref_service, 159 DictionaryPrefUpdate mime_type_pref(pref_service,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 350
353 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin(); 351 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin();
354 iter != drive_app_map.end(); ++iter) { 352 iter != drive_app_map.end(); ++iter) {
355 const drive::DriveAppInfo& app_info = iter->second; 353 const drive::DriveAppInfo& app_info = iter->second;
356 TaskDescriptor descriptor(app_info.app_id, 354 TaskDescriptor descriptor(app_info.app_id,
357 TASK_TYPE_DRIVE_APP, 355 TASK_TYPE_DRIVE_APP,
358 kDriveAppActionID); 356 kDriveAppActionID);
359 GURL icon_url = drive::util::FindPreferredIcon( 357 GURL icon_url = drive::util::FindPreferredIcon(
360 app_info.app_icons, 358 app_info.app_icons,
361 drive::util::kPreferredIconSize); 359 drive::util::kPreferredIconSize);
362 result_list->push_back( 360
363 FullTaskDescriptor(descriptor, 361 result_list->push_back(FullTaskDescriptor(
364 app_info.app_name, 362 descriptor,
365 icon_url, 363 extensions::file_handler_verbs::GetTitleForExtensionAndVerb(
366 false /* is_default */, 364 app_info.app_name, extensions::file_handler_verbs::kOpenWith),
367 false /* is_generic_file_handler */)); 365 icon_url, false /* is_default */, false /* is_generic_file_handler */));
368 } 366 }
369 } 367 }
370 368
371 bool IsGoodMatchFileHandler( 369 bool IsGoodMatchFileHandler(
372 const extensions::FileHandlerInfo& file_handler_info, 370 const extensions::FileHandlerInfo& file_handler_info,
373 const std::vector<extensions::EntryInfo>& entries) { 371 const std::vector<extensions::EntryInfo>& entries) {
374 if (file_handler_info.extensions.count("*") > 0 || 372 if (file_handler_info.extensions.count("*") > 0 ||
375 file_handler_info.types.count("*") > 0 || 373 file_handler_info.types.count("*") > 0 ||
376 file_handler_info.types.count("*/*") > 0) 374 file_handler_info.types.count("*/*") > 0)
377 return false; 375 return false;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 continue; 422 continue;
425 423
426 // If the new ZIP unpacker is disabled, then hide its handlers, so we don't 424 // 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. 425 // show both the legacy one and the new one in Files app for ZIP files.
428 if (extension->id() == extension_misc::kZIPUnpackerExtensionId && 426 if (extension->id() == extension_misc::kZIPUnpackerExtensionId &&
429 base::CommandLine::ForCurrentProcess()->HasSwitch( 427 base::CommandLine::ForCurrentProcess()->HasSwitch(
430 chromeos::switches::kDisableNewZIPUnpacker)) { 428 chromeos::switches::kDisableNewZIPUnpacker)) {
431 continue; 429 continue;
432 } 430 }
433 431
434 // Show the first good matching handler of each app. If there doesn't exist 432 // 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. 433 // handler with which to open the given entries and a boolean marking
436 const extensions::FileHandlerInfo* file_handler = file_handlers.front(); 434 // if the handler is a good match.
437 for (auto handler : file_handlers) { 435 std::map<std::string, std::pair<const extensions::FileHandlerInfo*, bool>>
438 if (IsGoodMatchFileHandler(*handler, entries)) { 436 handlers_for_entries;
439 file_handler = handler; 437 // Show the first good matching handler of each verb supporting the given
440 break; 438 // entries that corresponds to the app. If there doesn't exist such handler,
439 // show the first matching handler of the verb.
440 for (const auto handler : file_handlers) {
441 bool good_match = IsGoodMatchFileHandler(*handler, entries);
442 auto it = handlers_for_entries.find(handler->verb);
443 if (it == handlers_for_entries.end() ||
444 (!it->second.second /* existing handler not a good match */ &&
445 good_match)) {
446 handlers_for_entries[handler->verb] =
447 std::make_pair(handler, good_match);
441 } 448 }
442 } 449 }
443 450
444 std::string task_id = file_tasks::MakeTaskID( 451 for (const auto entry : handlers_for_entries) {
445 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); 452 const extensions::FileHandlerInfo* handler = entry.second.first;
453 std::string task_id = file_tasks::MakeTaskID(
454 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, handler->id);
446 455
447 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( 456 GURL best_icon = extensions::ExtensionIconSource::GetIconURL(
448 extension, 457 extension, drive::util::kPreferredIconSize,
449 drive::util::kPreferredIconSize, 458 ExtensionIconSet::MATCH_BIGGER,
450 ExtensionIconSet::MATCH_BIGGER, 459 false, // grayscale
451 false, // grayscale 460 NULL); // exists
452 NULL); // exists
453 461
454 // If file handler doesn't match as good match, regards it as generic file 462 // If file handler doesn't match as good match, regards it as generic file
455 // handler. 463 // handler.
456 const bool is_generic_file_handler = 464 const bool is_generic_file_handler =
457 !IsGoodMatchFileHandler(*file_handler, entries); 465 !IsGoodMatchFileHandler(*handler, entries);
458 result_list->push_back(FullTaskDescriptor( 466 result_list->push_back(FullTaskDescriptor(
459 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, 467 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER,
460 file_handler->id), 468 handler->id),
461 extension->name(), best_icon, false /* is_default */, 469 extensions::file_handler_verbs::GetTitleForExtensionAndVerb(
462 is_generic_file_handler)); 470 extension->name(), handler->verb),
471 best_icon, false /* is_default */, is_generic_file_handler));
472 }
463 } 473 }
464 } 474 }
465 475
466 void FindFileBrowserHandlerTasks( 476 void FindFileBrowserHandlerTasks(
467 Profile* profile, 477 Profile* profile,
468 const std::vector<GURL>& file_urls, 478 const std::vector<GURL>& file_urls,
469 std::vector<FullTaskDescriptor>* result_list) { 479 std::vector<FullTaskDescriptor>* result_list) {
470 DCHECK(!file_urls.empty()); 480 DCHECK(!file_urls.empty());
471 DCHECK(result_list); 481 DCHECK(result_list);
472 482
(...skipping 16 matching lines...) Expand all
489 // TODO(zelidrag): Figure out how to expose icon URL that task defined in 499 // TODO(zelidrag): Figure out how to expose icon URL that task defined in
490 // manifest instead of the default extension icon. 500 // manifest instead of the default extension icon.
491 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL( 501 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL(
492 extension, 502 extension,
493 extension_misc::EXTENSION_ICON_BITTY, 503 extension_misc::EXTENSION_ICON_BITTY,
494 ExtensionIconSet::MATCH_BIGGER, 504 ExtensionIconSet::MATCH_BIGGER,
495 false, // grayscale 505 false, // grayscale
496 NULL); // exists 506 NULL); // exists
497 507
498 result_list->push_back(FullTaskDescriptor( 508 result_list->push_back(FullTaskDescriptor(
499 TaskDescriptor(extension_id, 509 TaskDescriptor(extension_id, file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER,
500 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER,
501 handler->id()), 510 handler->id()),
502 handler->title(), 511 handler->title(), icon_url, false /* is_default */,
503 icon_url,
504 false /* is_default */,
505 false /* is_generic_file_handler */)); 512 false /* is_generic_file_handler */));
506 } 513 }
507 } 514 }
508 515
509 void FindAllTypesOfTasks(Profile* profile, 516 void FindAllTypesOfTasks(Profile* profile,
510 const drive::DriveAppRegistry* drive_app_registry, 517 const drive::DriveAppRegistry* drive_app_registry,
511 const std::vector<extensions::EntryInfo>& entries, 518 const std::vector<extensions::EntryInfo>& entries,
512 const std::vector<GURL>& file_urls, 519 const std::vector<GURL>& file_urls,
513 std::vector<FullTaskDescriptor>* result_list) { 520 std::vector<FullTaskDescriptor>* result_list) {
514 DCHECK(profile); 521 DCHECK(profile);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 DCHECK(!task->is_default()); 575 DCHECK(!task->is_default());
569 if (IsFallbackFileHandler(task->task_descriptor())) { 576 if (IsFallbackFileHandler(task->task_descriptor())) {
570 task->set_is_default(true); 577 task->set_is_default(true);
571 return; 578 return;
572 } 579 }
573 } 580 }
574 } 581 }
575 582
576 } // namespace file_tasks 583 } // namespace file_tasks
577 } // namespace file_manager 584 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698