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 "apps/launcher.h" | 7 #include "apps/launcher.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 extension_misc::kQuickOfficeExtensionId, | 120 extension_misc::kQuickOfficeExtensionId, |
121 }; | 121 }; |
122 | 122 |
123 for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) { | 123 for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) { |
124 if (task.app_id == kBuiltInApps[i]) | 124 if (task.app_id == kBuiltInApps[i]) |
125 return true; | 125 return true; |
126 } | 126 } |
127 return false; | 127 return false; |
128 } | 128 } |
129 | 129 |
130 bool IsGenericFileHandler(const extensions::FileHandlerInfo& fileHandlerInfo) { | |
satorux1
2014/10/30 08:17:21
file_handler_info
http://google-styleguide.google
yawano
2014/10/31 01:26:30
Done.
| |
131 return fileHandlerInfo.extensions.count("*") > 0 || | |
132 fileHandlerInfo.types.count("*") > 0 || | |
133 fileHandlerInfo.types.count("*/*") > 0; | |
134 } | |
satorux1
2014/10/30 08:17:21
Please move this out of the anonymous namespace an
yawano
2014/10/31 01:26:29
Done.
| |
135 | |
130 } // namespace | 136 } // namespace |
131 | 137 |
132 FullTaskDescriptor::FullTaskDescriptor( | 138 FullTaskDescriptor::FullTaskDescriptor( |
133 const TaskDescriptor& task_descriptor, | 139 const TaskDescriptor& task_descriptor, |
134 const std::string& task_title, | 140 const std::string& task_title, |
135 const GURL& icon_url, | 141 const GURL& icon_url, |
136 bool is_default) | 142 bool is_default, |
143 bool is_generic_file_handler) | |
137 : task_descriptor_(task_descriptor), | 144 : task_descriptor_(task_descriptor), |
138 task_title_(task_title), | 145 task_title_(task_title), |
139 icon_url_(icon_url), | 146 icon_url_(icon_url), |
140 is_default_(is_default) { | 147 is_default_(is_default), |
148 is_generic_file_handler_(is_generic_file_handler) { | |
141 } | 149 } |
142 | 150 |
143 void UpdateDefaultTask(PrefService* pref_service, | 151 void UpdateDefaultTask(PrefService* pref_service, |
144 const std::string& task_id, | 152 const std::string& task_id, |
145 const std::set<std::string>& suffixes, | 153 const std::set<std::string>& suffixes, |
146 const std::set<std::string>& mime_types) { | 154 const std::set<std::string>& mime_types) { |
147 if (!pref_service) | 155 if (!pref_service) |
148 return; | 156 return; |
149 | 157 |
150 if (!mime_types.empty()) { | 158 if (!mime_types.empty()) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 TaskDescriptor descriptor(app_info.app_id, | 354 TaskDescriptor descriptor(app_info.app_id, |
347 TASK_TYPE_DRIVE_APP, | 355 TASK_TYPE_DRIVE_APP, |
348 kDriveAppActionID); | 356 kDriveAppActionID); |
349 GURL icon_url = drive::util::FindPreferredIcon( | 357 GURL icon_url = drive::util::FindPreferredIcon( |
350 app_info.app_icons, | 358 app_info.app_icons, |
351 drive::util::kPreferredIconSize); | 359 drive::util::kPreferredIconSize); |
352 result_list->push_back( | 360 result_list->push_back( |
353 FullTaskDescriptor(descriptor, | 361 FullTaskDescriptor(descriptor, |
354 app_info.app_name, | 362 app_info.app_name, |
355 icon_url, | 363 icon_url, |
356 false /* is_default */)); | 364 false /* is_default */, |
365 false /* is_generic_file_handler */)); | |
357 } | 366 } |
358 } | 367 } |
359 | 368 |
360 void FindFileHandlerTasks( | 369 void FindFileHandlerTasks( |
361 Profile* profile, | 370 Profile* profile, |
362 const PathAndMimeTypeSet& path_mime_set, | 371 const PathAndMimeTypeSet& path_mime_set, |
363 std::vector<FullTaskDescriptor>* result_list) { | 372 std::vector<FullTaskDescriptor>* result_list) { |
364 DCHECK(!path_mime_set.empty()); | 373 DCHECK(!path_mime_set.empty()); |
365 DCHECK(result_list); | 374 DCHECK(result_list); |
366 | 375 |
367 const extensions::ExtensionSet& enabled_extensions = | 376 const extensions::ExtensionSet& enabled_extensions = |
368 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 377 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
378 | |
369 for (extensions::ExtensionSet::const_iterator iter = | 379 for (extensions::ExtensionSet::const_iterator iter = |
370 enabled_extensions.begin(); | 380 enabled_extensions.begin(); |
371 iter != enabled_extensions.end(); | 381 iter != enabled_extensions.end(); |
372 ++iter) { | 382 ++iter) { |
373 const Extension* extension = iter->get(); | 383 const Extension* extension = iter->get(); |
374 | 384 |
375 // Check that the extension can be launched via an event. This includes all | 385 // Check that the extension can be launched via an event. This includes all |
376 // platform apps plus whitelisted extensions. | 386 // platform apps plus whitelisted extensions. |
377 if (!CanLaunchViaEvent(extension)) | 387 if (!CanLaunchViaEvent(extension)) |
378 continue; | 388 continue; |
379 | 389 |
380 // Ephemeral apps cannot be file handlers. | 390 // Ephemeral apps cannot be file handlers. |
381 if (extensions::util::IsEphemeralApp(extension->id(), profile)) | 391 if (extensions::util::IsEphemeralApp(extension->id(), profile)) |
382 continue; | 392 continue; |
383 | 393 |
384 if (profile->IsOffTheRecord() && | 394 if (profile->IsOffTheRecord() && |
385 !extensions::util::IsIncognitoEnabled(extension->id(), profile)) | 395 !extensions::util::IsIncognitoEnabled(extension->id(), profile)) |
386 continue; | 396 continue; |
387 | 397 |
388 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; | 398 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; |
389 FileHandlerList file_handlers = | 399 FileHandlerList file_handlers = |
390 FindFileHandlersForFiles(*extension, path_mime_set); | 400 FindFileHandlersForFiles(*extension, path_mime_set); |
391 if (file_handlers.empty()) | 401 if (file_handlers.empty()) |
392 continue; | 402 continue; |
393 | 403 |
394 // Only show the first matching handler from each app. | 404 // Show the first matching non-generic handler of each app. If there doesn't |
395 const extensions::FileHandlerInfo* file_handler = file_handlers.front(); | 405 // exist such handler, show the first matching handler of the app. |
406 const extensions::FileHandlerInfo* file_handler = nullptr; | |
407 for (auto handler : file_handlers) { | |
408 if (!IsGenericFileHandler(*handler)) { | |
409 file_handler = handler; | |
410 break; | |
411 } | |
412 } | |
413 if (file_handler == nullptr) { | |
414 file_handler = file_handlers.front(); | |
415 } | |
416 | |
396 std::string task_id = file_tasks::MakeTaskID( | 417 std::string task_id = file_tasks::MakeTaskID( |
397 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); | 418 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, file_handler->id); |
398 | 419 |
399 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( | 420 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( |
400 extension, | 421 extension, |
401 drive::util::kPreferredIconSize, | 422 drive::util::kPreferredIconSize, |
402 ExtensionIconSet::MATCH_BIGGER, | 423 ExtensionIconSet::MATCH_BIGGER, |
403 false, // grayscale | 424 false, // grayscale |
404 NULL); // exists | 425 NULL); // exists |
405 | 426 |
406 result_list->push_back( | 427 result_list->push_back( |
407 FullTaskDescriptor(TaskDescriptor(extension->id(), | 428 FullTaskDescriptor(TaskDescriptor(extension->id(), |
408 file_tasks::TASK_TYPE_FILE_HANDLER, | 429 file_tasks::TASK_TYPE_FILE_HANDLER, |
409 file_handler->id), | 430 file_handler->id), |
410 extension->name(), | 431 extension->name(), |
411 best_icon, | 432 best_icon, |
412 false /* is_default */)); | 433 false /* is_default */, |
434 IsGenericFileHandler(*file_handler))); | |
413 } | 435 } |
414 } | 436 } |
415 | 437 |
416 void FindFileBrowserHandlerTasks( | 438 void FindFileBrowserHandlerTasks( |
417 Profile* profile, | 439 Profile* profile, |
418 const std::vector<GURL>& file_urls, | 440 const std::vector<GURL>& file_urls, |
419 std::vector<FullTaskDescriptor>* result_list) { | 441 std::vector<FullTaskDescriptor>* result_list) { |
420 DCHECK(!file_urls.empty()); | 442 DCHECK(!file_urls.empty()); |
421 DCHECK(result_list); | 443 DCHECK(result_list); |
422 | 444 |
(...skipping 21 matching lines...) Expand all Loading... | |
444 ExtensionIconSet::MATCH_BIGGER, | 466 ExtensionIconSet::MATCH_BIGGER, |
445 false, // grayscale | 467 false, // grayscale |
446 NULL); // exists | 468 NULL); // exists |
447 | 469 |
448 result_list->push_back(FullTaskDescriptor( | 470 result_list->push_back(FullTaskDescriptor( |
449 TaskDescriptor(extension_id, | 471 TaskDescriptor(extension_id, |
450 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, | 472 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, |
451 handler->id()), | 473 handler->id()), |
452 handler->title(), | 474 handler->title(), |
453 icon_url, | 475 icon_url, |
454 false /* is_default */)); | 476 false /* is_default */, |
477 false /* is_generic_file_handler */)); | |
455 } | 478 } |
456 } | 479 } |
457 | 480 |
458 void FindAllTypesOfTasks( | 481 void FindAllTypesOfTasks( |
459 Profile* profile, | 482 Profile* profile, |
460 const drive::DriveAppRegistry* drive_app_registry, | 483 const drive::DriveAppRegistry* drive_app_registry, |
461 const PathAndMimeTypeSet& path_mime_set, | 484 const PathAndMimeTypeSet& path_mime_set, |
462 const std::vector<GURL>& file_urls, | 485 const std::vector<GURL>& file_urls, |
463 std::vector<FullTaskDescriptor>* result_list) { | 486 std::vector<FullTaskDescriptor>* result_list) { |
464 DCHECK(profile); | 487 DCHECK(profile); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 DCHECK(!task->is_default()); | 541 DCHECK(!task->is_default()); |
519 if (IsFallbackFileHandler(task->task_descriptor())) { | 542 if (IsFallbackFileHandler(task->task_descriptor())) { |
520 task->set_is_default(true); | 543 task->set_is_default(true); |
521 return; | 544 return; |
522 } | 545 } |
523 } | 546 } |
524 } | 547 } |
525 | 548 |
526 } // namespace file_tasks | 549 } // namespace file_tasks |
527 } // namespace file_manager | 550 } // namespace file_manager |
OLD | NEW |