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

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: Add an enum for verbs in idl 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 27 matching lines...) Expand all
38 #include "extensions/browser/entry_info.h" 38 #include "extensions/browser/entry_info.h"
39 #include "extensions/browser/extension_host.h" 39 #include "extensions/browser/extension_host.h"
40 #include "extensions/browser/extension_registry.h" 40 #include "extensions/browser/extension_registry.h"
41 #include "extensions/browser/extension_system.h" 41 #include "extensions/browser/extension_system.h"
42 #include "extensions/browser/extension_util.h" 42 #include "extensions/browser/extension_util.h"
43 #include "extensions/common/constants.h" 43 #include "extensions/common/constants.h"
44 #include "extensions/common/extension_set.h" 44 #include "extensions/common/extension_set.h"
45 #include "storage/browser/fileapi/file_system_url.h" 45 #include "storage/browser/fileapi/file_system_url.h"
46 46
47 using extensions::Extension; 47 using extensions::Extension;
48 using extensions::api::file_manager_private::Verb;
48 using extensions::app_file_handler_util::FindFileHandlersForEntries; 49 using extensions::app_file_handler_util::FindFileHandlersForEntries;
49 using storage::FileSystemURL; 50 using storage::FileSystemURL;
50 51
51 namespace file_manager { 52 namespace file_manager {
52 namespace file_tasks { 53 namespace file_tasks {
53 54
54 namespace { 55 namespace {
55 56
56 // The values "file" and "app" are confusing, but cannot be changed easily as 57 // The values "file" and "app" are confusing, but cannot be changed easily as
57 // these are used in default task IDs stored in preferences. 58 // these are used in default task IDs stored in preferences.
58 const char kFileBrowserHandlerTaskType[] = "file"; 59 const char kFileBrowserHandlerTaskType[] = "file";
59 const char kFileHandlerTaskType[] = "app"; 60 const char kFileHandlerTaskType[] = "app";
60 const char kDriveAppTaskType[] = "drive"; 61 const char kDriveAppTaskType[] = "drive";
61 const char kArcAppTaskType[] = "arc"; 62 const char kArcAppTaskType[] = "arc";
62 63
63 // Drive apps always use the action ID. 64 // Drive apps always use the action ID.
64 const char kDriveAppActionID[] = "open-with"; 65 const char kDriveAppActionID[] = "more-actions";
65 66
66 // Converts a TaskType to a string. 67 // Converts a TaskType to a string.
67 std::string TaskTypeToString(TaskType task_type) { 68 std::string TaskTypeToString(TaskType task_type) {
68 switch (task_type) { 69 switch (task_type) {
69 case TASK_TYPE_FILE_BROWSER_HANDLER: 70 case TASK_TYPE_FILE_BROWSER_HANDLER:
70 return kFileBrowserHandlerTaskType; 71 return kFileBrowserHandlerTaskType;
71 case TASK_TYPE_FILE_HANDLER: 72 case TASK_TYPE_FILE_HANDLER:
72 return kFileHandlerTaskType; 73 return kFileHandlerTaskType;
73 case TASK_TYPE_DRIVE_APP: 74 case TASK_TYPE_DRIVE_APP:
74 return kDriveAppTaskType; 75 return kDriveAppTaskType;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) { 169 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list) {
169 // Google documents can only be handled by internal handlers. 170 // Google documents can only be handled by internal handlers.
170 if (ContainsGoogleDocument(entries)) 171 if (ContainsGoogleDocument(entries))
171 KeepOnlyFileManagerInternalTasks(result_list.get()); 172 KeepOnlyFileManagerInternalTasks(result_list.get());
172 ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, result_list.get()); 173 ChooseAndSetDefaultTask(*profile->GetPrefs(), entries, result_list.get());
173 callback.Run(std::move(result_list)); 174 callback.Run(std::move(result_list));
174 } 175 }
175 176
176 } // namespace 177 } // namespace
177 178
178 FullTaskDescriptor::FullTaskDescriptor( 179 FullTaskDescriptor::FullTaskDescriptor(const TaskDescriptor& task_descriptor,
179 const TaskDescriptor& task_descriptor, 180 const std::string& task_title,
180 const std::string& task_title, 181 const Verb& task_verb,
181 const GURL& icon_url, 182 const GURL& icon_url,
182 bool is_default, 183 bool is_default,
183 bool is_generic_file_handler) 184 bool is_generic_file_handler)
184 : task_descriptor_(task_descriptor), 185 : task_descriptor_(task_descriptor),
185 task_title_(task_title), 186 task_title_(task_title),
187 task_verb_(task_verb),
186 icon_url_(icon_url), 188 icon_url_(icon_url),
187 is_default_(is_default), 189 is_default_(is_default),
188 is_generic_file_handler_(is_generic_file_handler) { 190 is_generic_file_handler_(is_generic_file_handler) {}
189 } 191
192 FullTaskDescriptor::~FullTaskDescriptor() {}
190 193
191 FullTaskDescriptor::FullTaskDescriptor(const FullTaskDescriptor& other) = 194 FullTaskDescriptor::FullTaskDescriptor(const FullTaskDescriptor& other) =
192 default; 195 default;
193 196
194 void UpdateDefaultTask(PrefService* pref_service, 197 void UpdateDefaultTask(PrefService* pref_service,
195 const std::string& task_id, 198 const std::string& task_id,
196 const std::set<std::string>& suffixes, 199 const std::set<std::string>& suffixes,
197 const std::set<std::string>& mime_types) { 200 const std::set<std::string>& mime_types) {
198 if (!pref_service) 201 if (!pref_service)
199 return; 202 return;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 407
405 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin(); 408 for (DriveAppInfoMap::const_iterator iter = drive_app_map.begin();
406 iter != drive_app_map.end(); ++iter) { 409 iter != drive_app_map.end(); ++iter) {
407 const drive::DriveAppInfo& app_info = iter->second; 410 const drive::DriveAppInfo& app_info = iter->second;
408 TaskDescriptor descriptor(app_info.app_id, 411 TaskDescriptor descriptor(app_info.app_id,
409 TASK_TYPE_DRIVE_APP, 412 TASK_TYPE_DRIVE_APP,
410 kDriveAppActionID); 413 kDriveAppActionID);
411 GURL icon_url = drive::util::FindPreferredIcon( 414 GURL icon_url = drive::util::FindPreferredIcon(
412 app_info.app_icons, 415 app_info.app_icons,
413 drive::util::kPreferredIconSize); 416 drive::util::kPreferredIconSize);
414 result_list->push_back( 417
415 FullTaskDescriptor(descriptor, 418 result_list->push_back(FullTaskDescriptor(
416 app_info.app_name, 419 descriptor, app_info.app_name, Verb::VERB_OPEN_WITH, icon_url,
417 icon_url, 420 false /* is_default */, false /* is_generic_file_handler */));
418 false /* is_default */,
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 extensions::FileHandlerInfo* handler : file_handlers) {
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) {
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 Verb verb;
511 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, 522 if (handler->verb == extensions::file_handler_verbs::kAddTo) {
512 file_handler->id), 523 verb = Verb::VERB_ADD_TO;
513 extension->name(), best_icon, false /* is_default */, 524 } else if (handler->verb == extensions::file_handler_verbs::kPackWith) {
514 is_generic_file_handler)); 525 verb = Verb::VERB_PACK_WITH;
526 } else {
527 // Only kOpenWith is a valid remaining verb. Invalid verbs should fall
528 // back to it.
529 DCHECK(handler->verb == extensions::file_handler_verbs::kOpenWith);
530 verb = Verb::VERB_OPEN_WITH;
531 }
532
533 result_list->push_back(FullTaskDescriptor(
534 TaskDescriptor(extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER,
535 handler->id),
536 extension->name(), verb, best_icon, false /* is_default */,
537 is_generic_file_handler));
538 }
515 } 539 }
516 } 540 }
517 541
518 void FindFileBrowserHandlerTasks( 542 void FindFileBrowserHandlerTasks(
519 Profile* profile, 543 Profile* profile,
520 const std::vector<GURL>& file_urls, 544 const std::vector<GURL>& file_urls,
521 std::vector<FullTaskDescriptor>* result_list) { 545 std::vector<FullTaskDescriptor>* result_list) {
522 DCHECK(!file_urls.empty()); 546 DCHECK(!file_urls.empty());
523 DCHECK(result_list); 547 DCHECK(result_list);
524 548
(...skipping 16 matching lines...) Expand all
541 // TODO(zelidrag): Figure out how to expose icon URL that task defined in 565 // TODO(zelidrag): Figure out how to expose icon URL that task defined in
542 // manifest instead of the default extension icon. 566 // manifest instead of the default extension icon.
543 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL( 567 const GURL icon_url = extensions::ExtensionIconSource::GetIconURL(
544 extension, 568 extension,
545 extension_misc::EXTENSION_ICON_BITTY, 569 extension_misc::EXTENSION_ICON_BITTY,
546 ExtensionIconSet::MATCH_BIGGER, 570 ExtensionIconSet::MATCH_BIGGER,
547 false, // grayscale 571 false, // grayscale
548 NULL); // exists 572 NULL); // exists
549 573
550 result_list->push_back(FullTaskDescriptor( 574 result_list->push_back(FullTaskDescriptor(
551 TaskDescriptor(extension_id, 575 TaskDescriptor(extension_id, file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER,
552 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER,
553 handler->id()), 576 handler->id()),
554 handler->title(), 577 handler->title(), Verb::VERB_NONE /* no verb for FileBrowserHandler */,
555 icon_url, 578 icon_url, false /* is_default */, false /* is_generic_file_handler */));
556 false /* is_default */,
557 false /* is_generic_file_handler */));
558 } 579 }
559 } 580 }
560 581
561 void FindAllTypesOfTasks(Profile* profile, 582 void FindAllTypesOfTasks(Profile* profile,
562 const drive::DriveAppRegistry* drive_app_registry, 583 const drive::DriveAppRegistry* drive_app_registry,
563 const std::vector<extensions::EntryInfo>& entries, 584 const std::vector<extensions::EntryInfo>& entries,
564 const std::vector<GURL>& file_urls, 585 const std::vector<GURL>& file_urls,
565 const FindTasksCallback& callback) { 586 const FindTasksCallback& callback) {
566 DCHECK(profile); 587 DCHECK(profile);
567 std::unique_ptr<std::vector<FullTaskDescriptor>> result_list( 588 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()); 640 DCHECK(!task->is_default());
620 if (IsFallbackFileHandler(task->task_descriptor())) { 641 if (IsFallbackFileHandler(task->task_descriptor())) {
621 task->set_is_default(true); 642 task->set_is_default(true);
622 return; 643 return;
623 } 644 }
624 } 645 }
625 } 646 }
626 647
627 } // namespace file_tasks 648 } // namespace file_tasks
628 } // namespace file_manager 649 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698