Chromium Code Reviews| 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/extensions/file_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
| 6 | 6 |
| 7 #include <sys/statvfs.h> | 7 #include <sys/statvfs.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/file_path.h" | |
| 13 #include "base/file_util.h" | |
| 14 #include "base/i18n/case_conversion.h" | |
| 12 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 13 #include "base/logging.h" | 16 #include "base/logging.h" |
| 14 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
| 15 #include "base/memory/singleton.h" | 18 #include "base/memory/singleton.h" |
| 16 #include "base/string_split.h" | 19 #include "base/string_split.h" |
| 17 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
| 18 #include "base/time.h" | 21 #include "base/time.h" |
| 19 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "base/utf_string_conversions.h" | |
| 20 #include "chrome/browser/chromeos/cros/cros_library.h" | 24 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 21 #include "chrome/browser/chromeos/cros/network_library.h" | 25 #include "chrome/browser/chromeos/cros/network_library.h" |
| 22 #include "chrome/browser/chromeos/extensions/file_handler_util.h" | 26 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
| 23 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 27 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 24 #include "chrome/browser/chromeos/gdata/drive.pb.h" | 28 #include "chrome/browser/chromeos/gdata/drive.pb.h" |
| 25 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" | 29 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
| 26 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 30 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
| 27 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 31 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| 28 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 32 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 29 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" | 33 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 46 #include "chrome/common/extensions/file_browser_handler.h" | 50 #include "chrome/common/extensions/file_browser_handler.h" |
| 47 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
| 48 #include "chromeos/disks/disk_mount_manager.h" | 52 #include "chromeos/disks/disk_mount_manager.h" |
| 49 #include "content/public/browser/child_process_security_policy.h" | 53 #include "content/public/browser/child_process_security_policy.h" |
| 50 #include "content/public/browser/render_process_host.h" | 54 #include "content/public/browser/render_process_host.h" |
| 51 #include "content/public/browser/render_view_host.h" | 55 #include "content/public/browser/render_view_host.h" |
| 52 #include "googleurl/src/gurl.h" | 56 #include "googleurl/src/gurl.h" |
| 53 #include "grit/generated_resources.h" | 57 #include "grit/generated_resources.h" |
| 54 #include "grit/platform_locale_settings.h" | 58 #include "grit/platform_locale_settings.h" |
| 55 #include "net/base/escape.h" | 59 #include "net/base/escape.h" |
| 60 #include "net/base/mime_util.h" | |
| 56 #include "ui/base/dialogs/selected_file_info.h" | 61 #include "ui/base/dialogs/selected_file_info.h" |
| 57 #include "ui/base/l10n/l10n_util.h" | 62 #include "ui/base/l10n/l10n_util.h" |
| 58 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 63 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
| 59 #include "webkit/fileapi/file_system_context.h" | 64 #include "webkit/fileapi/file_system_context.h" |
| 60 #include "webkit/fileapi/file_system_file_util.h" | 65 #include "webkit/fileapi/file_system_file_util.h" |
| 61 #include "webkit/fileapi/file_system_operation_context.h" | 66 #include "webkit/fileapi/file_system_operation_context.h" |
| 62 #include "webkit/fileapi/file_system_types.h" | 67 #include "webkit/fileapi/file_system_types.h" |
| 63 #include "webkit/fileapi/file_system_url.h" | 68 #include "webkit/fileapi/file_system_url.h" |
| 64 #include "webkit/fileapi/file_system_util.h" | 69 #include "webkit/fileapi/file_system_util.h" |
| 70 #include "webkit/glue/web_intent_service_data.h" | |
| 65 | 71 |
| 66 using chromeos::disks::DiskMountManager; | 72 using chromeos::disks::DiskMountManager; |
| 67 using content::BrowserContext; | 73 using content::BrowserContext; |
| 68 using content::BrowserThread; | 74 using content::BrowserThread; |
| 69 using content::ChildProcessSecurityPolicy; | 75 using content::ChildProcessSecurityPolicy; |
| 70 using content::SiteInstance; | 76 using content::SiteInstance; |
| 71 using content::WebContents; | 77 using content::WebContents; |
| 72 using extensions::Extension; | 78 using extensions::Extension; |
| 73 using file_handler_util::FileTaskExecutor; | 79 using file_handler_util::FileTaskExecutor; |
| 74 using gdata::InstalledApp; | 80 using gdata::InstalledApp; |
| 75 using gdata::OperationRegistry; | 81 using gdata::OperationRegistry; |
| 76 | 82 |
| 77 namespace { | 83 namespace { |
| 78 | 84 |
| 85 // The default View action for Web Intents. | |
| 86 const char kWebIntentViewAction[] = "http://webintents.org/view"; | |
| 87 | |
| 79 // Default icon path for drive docs. | 88 // Default icon path for drive docs. |
| 80 const char kDefaultDriveIcon[] = "images/filetype_generic.png"; | 89 const char kDefaultIcon[] = "images/filetype_generic.png"; |
| 81 const int kPreferredIconSize = 16; | 90 const int kPreferredIconSize = 16; |
| 82 | 91 |
| 83 // Error messages. | 92 // Error messages. |
| 84 const char kFileError[] = "File error %d"; | 93 const char kFileError[] = "File error %d"; |
| 85 const char kInvalidFileUrl[] = "Invalid file URL"; | 94 const char kInvalidFileUrl[] = "Invalid file URL"; |
| 86 const char kVolumeDevicePathNotFound[] = "Device path not found"; | 95 const char kVolumeDevicePathNotFound[] = "Device path not found"; |
| 87 | 96 |
| 88 // Unescape rules used for parsing query parameters. | 97 // Unescape rules used for parsing query parameters. |
| 89 const net::UnescapeRule::Type kUnescapeRuleForQueryParameters = | 98 const net::UnescapeRule::Type kUnescapeRuleForQueryParameters = |
| 90 net::UnescapeRule::SPACES | | 99 net::UnescapeRule::SPACES | |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 if (icons.empty()) | 256 if (icons.empty()) |
| 248 return result; | 257 return result; |
| 249 result = icons.rbegin()->second; | 258 result = icons.rbegin()->second; |
| 250 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); | 259 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); |
| 251 iter != icons.rend() && iter->first >= preferred_size; ++iter) { | 260 iter != icons.rend() && iter->first >= preferred_size; ++iter) { |
| 252 result = iter->second; | 261 result = iter->second; |
| 253 } | 262 } |
| 254 return result; | 263 return result; |
| 255 } | 264 } |
| 256 | 265 |
| 266 // Given an extension, a Web Intents |action|, and a set of |mime_types|, | |
| 267 // determines whether this extension supports this action for all specified | |
| 268 // mime-types. | |
| 269 bool ExtensionSupportsAction(const Extension* extension, | |
| 270 const std::string& action, | |
| 271 const std::set<std::string>& mime_types) { | |
| 272 DCHECK(!mime_types.empty()); | |
| 273 std::set<std::string> pending(mime_types.begin(), mime_types.end()); | |
| 274 | |
| 275 for (std::vector<webkit_glue::WebIntentServiceData>::const_iterator i = | |
| 276 extension->intents_services().begin(); | |
| 277 i != extension->intents_services().end(); ++i) { | |
| 278 if (pending.empty()) | |
| 279 break; | |
| 280 | |
| 281 if (UTF16ToUTF8(i->action) != action) | |
| 282 continue; | |
| 283 | |
| 284 std::set<std::string>::iterator pi = pending.begin(); | |
| 285 while (pi != pending.end()) { | |
| 286 if (net::MatchesMimeType(UTF16ToUTF8(i->type), *pi)) | |
| 287 pending.erase(pi++); | |
| 288 else | |
| 289 ++pi; | |
| 290 } | |
| 291 } | |
| 292 | |
| 293 return pending.empty(); // if empty, we've found all mime-types | |
| 294 } | |
| 295 | |
| 296 // Retrieves the title for the given Extension and |action| pair, returning | |
| 297 // true if it could be found. | |
| 298 bool TitleForExtensionAction(const Extension* extension, | |
| 299 const std::string& action, std::string* title) { | |
|
benwells
2012/08/30 08:09:03
I think you should pass in the mime types here and
thorogood
2012/09/01 03:02:11
Sounds good. My original methods made more sense w
| |
| 300 for (std::vector<webkit_glue::WebIntentServiceData>::const_iterator i = | |
| 301 extension->intents_services().begin(); | |
| 302 i != extension->intents_services().end(); ++i) { | |
| 303 if (action == UTF16ToUTF8(i->action)) { | |
| 304 *title = UTF16ToUTF8(i->title); | |
| 305 return true; | |
| 306 } | |
| 307 } | |
| 308 return false; | |
| 309 } | |
| 310 | |
| 257 // Retrieves total and remaining available size on |mount_path|. | 311 // Retrieves total and remaining available size on |mount_path|. |
| 258 void GetSizeStatsOnFileThread(const std::string& mount_path, | 312 void GetSizeStatsOnFileThread(const std::string& mount_path, |
| 259 size_t* total_size_kb, | 313 size_t* total_size_kb, |
| 260 size_t* remaining_size_kb) { | 314 size_t* remaining_size_kb) { |
| 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 262 | 316 |
| 263 uint64_t total_size_in_bytes = 0; | 317 uint64_t total_size_in_bytes = 0; |
| 264 uint64_t remaining_size_in_bytes = 0; | 318 uint64_t remaining_size_in_bytes = 0; |
| 265 | 319 |
| 266 struct statvfs stat = {}; // Zero-clear | 320 struct statvfs stat = {}; // Zero-clear |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 // OK, now we traverse the intersection of available applications for this | 623 // OK, now we traverse the intersection of available applications for this |
| 570 // list of files, adding a task for each one that is found. | 624 // list of files, adding a task for each one that is found. |
| 571 for (std::set<std::string>::iterator app_iter = available_apps.begin(); | 625 for (std::set<std::string>::iterator app_iter = available_apps.begin(); |
| 572 app_iter != available_apps.end(); ++app_iter) { | 626 app_iter != available_apps.end(); ++app_iter) { |
| 573 WebAppInfoMap::const_iterator info_iter = app_info.find(*app_iter); | 627 WebAppInfoMap::const_iterator info_iter = app_info.find(*app_iter); |
| 574 DCHECK(info_iter != app_info.end()); | 628 DCHECK(info_iter != app_info.end()); |
| 575 gdata::DriveWebAppInfo* info = info_iter->second; | 629 gdata::DriveWebAppInfo* info = info_iter->second; |
| 576 DictionaryValue* task = new DictionaryValue; | 630 DictionaryValue* task = new DictionaryValue; |
| 577 // TODO(gspencer): For now, the action id is always "open-with", but we | 631 // TODO(gspencer): For now, the action id is always "open-with", but we |
| 578 // could add any actions that the drive app supports. | 632 // could add any actions that the drive app supports. |
| 579 std::string task_id = | 633 std::string task_id = file_handler_util::MakeTaskID( |
| 580 file_handler_util::MakeDriveTaskID(*app_iter, "open-with"); | 634 *app_iter, file_handler_util::TASK_DRIVE, "open-with"); |
| 581 task->SetString("taskId", task_id); | 635 task->SetString("taskId", task_id); |
| 582 task->SetString("title", info->app_name); | 636 task->SetString("title", info->app_name); |
| 583 | 637 |
| 584 // Create the list of extensions as patterns registered for this | 638 // Create the list of extensions as patterns registered for this |
| 585 // application. (Extensions here refers to filename suffixes (extensions), | 639 // application. (Extensions here refers to filename suffixes (extensions), |
| 586 // not Chrome or Drive extensions.) | 640 // not Chrome or Drive extensions.) |
| 587 ListValue* pattern_list = new ListValue; | 641 ListValue* pattern_list = new ListValue; |
| 588 std::set<std::string> extensions = | 642 std::set<std::string> extensions = |
| 589 registry->GetExtensionsForWebStoreApp(*app_iter); | 643 registry->GetExtensionsForWebStoreApp(*app_iter); |
| 590 for (std::set<std::string>::iterator ext_iter = extensions.begin(); | 644 for (std::set<std::string>::iterator ext_iter = extensions.begin(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 614 return true; | 668 return true; |
| 615 | 669 |
| 616 gdata::GDataSystemService* system_service = | 670 gdata::GDataSystemService* system_service = |
| 617 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 671 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
| 618 // |system_service| is NULL if incognito window / guest login. We return true | 672 // |system_service| is NULL if incognito window / guest login. We return true |
| 619 // in this case because there might be other extension tasks, even if we don't | 673 // in this case because there might be other extension tasks, even if we don't |
| 620 // have any to add. | 674 // have any to add. |
| 621 if (!system_service || !system_service->webapps_registry()) | 675 if (!system_service || !system_service->webapps_registry()) |
| 622 return true; | 676 return true; |
| 623 | 677 |
| 624 | |
| 625 gdata::DriveWebAppsRegistry* registry = system_service->webapps_registry(); | 678 gdata::DriveWebAppsRegistry* registry = system_service->webapps_registry(); |
| 626 | 679 |
| 627 // Map of app_id to DriveWebAppInfo so we can look up the apps we've found | 680 // Map of app_id to DriveWebAppInfo so we can look up the apps we've found |
| 628 // after taking the intersection of available apps. | 681 // after taking the intersection of available apps. |
| 629 std::map<std::string, gdata::DriveWebAppInfo*> app_info; | 682 std::map<std::string, gdata::DriveWebAppInfo*> app_info; |
| 630 // Set of application IDs. This will end up with the intersection of the | 683 // Set of application IDs. This will end up with the intersection of the |
| 631 // application IDs that apply to the paths in |file_paths|. | 684 // application IDs that apply to the paths in |file_paths|. |
| 632 std::set<std::string> available_apps; | 685 std::set<std::string> available_apps; |
| 633 | 686 |
| 634 IntersectAvailableDriveTasks(registry, file_info_list, | 687 IntersectAvailableDriveTasks(registry, file_info_list, |
| 635 &app_info, &available_apps); | 688 &app_info, &available_apps); |
| 636 CreateDriveTasks(registry, app_info, available_apps, result_list); | 689 CreateDriveTasks(registry, app_info, available_apps, result_list); |
| 637 | 690 |
| 638 // We own the pointers in |app_info|, so we need to delete them. | 691 // We own the pointers in |app_info|, so we need to delete them. |
| 639 STLDeleteContainerPairSecondPointers(app_info.begin(), app_info.end()); | 692 STLDeleteContainerPairSecondPointers(app_info.begin(), app_info.end()); |
| 640 return true; | 693 return true; |
| 641 } | 694 } |
| 642 | 695 |
| 696 // Find special tasks here for Web Intent platform apps. Iterate through | |
| 697 // matching apps and add them. These tasks will be identified by the "http" | |
|
benwells
2012/08/30 08:09:03
Is this comment still correct?
thorogood
2012/09/01 03:02:11
Nope, clarified.
| |
| 698 // prefix found on the task action. | |
| 699 bool GetFileTasksFileBrowserFunction::FindWebIntentTasks( | |
| 700 const std::vector<GURL>& file_urls, | |
| 701 ListValue* result_list) { | |
| 702 DCHECK(!file_urls.empty()); | |
| 703 ExtensionService* service = profile_->GetExtensionService(); | |
| 704 if (!service) | |
| 705 return false; | |
| 706 | |
| 707 std::set<std::string> mime_types; | |
| 708 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); | |
| 709 iter != file_urls.end(); ++iter) { | |
| 710 const FilePath file = FilePath(GURL(iter->spec()).ExtractFileName()); | |
| 711 const FilePath::StringType file_extension = | |
| 712 StringToLowerASCII(file.Extension()); | |
| 713 | |
| 714 // TODO(thorogood): Rearchitect this call so it can run on the File thread; | |
| 715 // GetMimeTypeFromFile requires this on Linux. Right now, we use | |
| 716 // Chrome-level knowledge only. | |
| 717 std::string mime_type; | |
| 718 if (!file_extension.empty() && !net::GetWellKnownMimeTypeFromExtension( | |
| 719 file_extension.substr(1), &mime_type)) | |
|
benwells
2012/08/30 08:09:03
Should this be if (file_extension.empty || !net::.
thorogood
2012/09/01 03:02:11
Well, the second command should only run if the fi
| |
| 720 mime_type = std::string(); // There was no mime-type available from this | |
| 721 // file, but we'll still match "*". | |
| 722 mime_types.insert(mime_type); | |
| 723 } | |
| 724 | |
| 725 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | |
| 726 iter != service->extensions()->end(); | |
| 727 ++iter) { | |
| 728 const Extension* extension = *iter; | |
| 729 | |
| 730 // We can't use hosted apps to open files. | |
|
benwells
2012/08/30 08:09:03
Hmm ... apart from it not being implemented, is th
thorogood
2012/09/01 03:02:11
I've now said "We don't support using hosted apps
| |
| 731 if (!extension->is_platform_app()) | |
| 732 continue; | |
| 733 | |
| 734 if (profile_->IsOffTheRecord() && | |
| 735 !service->IsIncognitoEnabled(extension->id())) | |
| 736 continue; | |
| 737 | |
| 738 if (!ExtensionSupportsAction(extension, kWebIntentViewAction, mime_types)) | |
| 739 continue; | |
| 740 | |
| 741 std::string title; | |
| 742 DCHECK(TitleForExtensionAction(extension, kWebIntentViewAction, &title)); | |
| 743 | |
| 744 DictionaryValue* task = new DictionaryValue; | |
| 745 std::string task_id = file_handler_util::MakeTaskID(extension->id(), | |
| 746 file_handler_util::TASK_WEBINTENT, kWebIntentViewAction); | |
| 747 task->SetString("taskId", task_id); | |
| 748 task->SetString("title", title); | |
| 749 task->Set("patterns", new ListValue); | |
| 750 | |
| 751 GURL best_icon = extension->GetIconURL(kPreferredIconSize, | |
| 752 ExtensionIconSet::MATCH_BIGGER); | |
| 753 if (!best_icon.is_empty()) | |
| 754 task->SetString("iconUrl", best_icon.spec()); | |
| 755 else | |
| 756 task->SetString("iconUrl", kDefaultIcon); | |
| 757 | |
| 758 task->SetBoolean("driveApp", false); | |
| 759 result_list->Append(task); | |
| 760 } | |
| 761 | |
| 762 return true; | |
| 763 } | |
| 764 | |
| 643 bool GetFileTasksFileBrowserFunction::RunImpl() { | 765 bool GetFileTasksFileBrowserFunction::RunImpl() { |
| 644 // First argument is the list of files to get tasks for. | 766 // First argument is the list of files to get tasks for. |
| 645 ListValue* files_list = NULL; | 767 ListValue* files_list = NULL; |
| 646 if (!args_->GetList(0, &files_list)) | 768 if (!args_->GetList(0, &files_list)) |
| 647 return false; | 769 return false; |
| 648 | 770 |
| 649 // Second argument is the list of mime types of each of the files in the list. | 771 // Second argument is the list of mime types of each of the files in the list. |
| 650 ListValue* mime_types_list = NULL; | 772 ListValue* mime_types_list = NULL; |
| 651 if (!args_->GetList(1, &mime_types_list)) | 773 if (!args_->GetList(1, &mime_types_list)) |
| 652 return false; | 774 return false; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 ExtensionService* service = profile_->GetExtensionService(); | 811 ExtensionService* service = profile_->GetExtensionService(); |
| 690 for (file_handler_util::LastUsedHandlerList::const_iterator iter = | 812 for (file_handler_util::LastUsedHandlerList::const_iterator iter = |
| 691 common_tasks.begin(); | 813 common_tasks.begin(); |
| 692 iter != common_tasks.end(); | 814 iter != common_tasks.end(); |
| 693 ++iter) { | 815 ++iter) { |
| 694 const FileBrowserHandler* handler = iter->handler; | 816 const FileBrowserHandler* handler = iter->handler; |
| 695 const std::string extension_id = handler->extension_id(); | 817 const std::string extension_id = handler->extension_id(); |
| 696 const Extension* extension = service->GetExtensionById(extension_id, false); | 818 const Extension* extension = service->GetExtensionById(extension_id, false); |
| 697 CHECK(extension); | 819 CHECK(extension); |
| 698 DictionaryValue* task = new DictionaryValue; | 820 DictionaryValue* task = new DictionaryValue; |
| 699 task->SetString("taskId", | 821 task->SetString("taskId", file_handler_util::MakeTaskID( |
| 700 file_handler_util::MakeTaskID(extension_id, handler->id())); | 822 extension_id, file_handler_util::TASK_FILE, handler->id())); |
| 701 task->SetString("title", handler->title()); | 823 task->SetString("title", handler->title()); |
| 702 task->Set("patterns", URLPatternSetToStringList(iter->patterns)); | 824 task->Set("patterns", URLPatternSetToStringList(iter->patterns)); |
| 703 // TODO(zelidrag): Figure out how to expose icon URL that task defined in | 825 // TODO(zelidrag): Figure out how to expose icon URL that task defined in |
| 704 // manifest instead of the default extension icon. | 826 // manifest instead of the default extension icon. |
| 705 GURL icon = | 827 GURL icon = |
| 706 ExtensionIconSource::GetIconURL(extension, | 828 ExtensionIconSource::GetIconURL(extension, |
| 707 extension_misc::EXTENSION_ICON_BITTY, | 829 extension_misc::EXTENSION_ICON_BITTY, |
| 708 ExtensionIconSet::MATCH_BIGGER, | 830 ExtensionIconSet::MATCH_BIGGER, |
| 709 false, NULL); // grayscale | 831 false, NULL); // grayscale |
| 710 task->SetString("iconUrl", icon.spec()); | 832 task->SetString("iconUrl", icon.spec()); |
| 711 task->SetBoolean("driveApp", false); | 833 task->SetBoolean("driveApp", false); |
| 712 result_list->Append(task); | 834 result_list->Append(task); |
| 713 } | 835 } |
| 714 | 836 |
| 715 // Take the union of Drive and extension tasks: Because any extension tasks we | 837 // Take the union of Drive and extension tasks: Because any extension tasks we |
| 716 // found must apply to all of the files (intersection), and because the same | 838 // found must apply to all of the files (intersection), and because the same |
| 717 // is true of the drive apps, we simply take the union of two lists by adding | 839 // is true of the drive apps, we simply take the union of two lists by adding |
| 718 // the drive tasks to the extension task list. We know there aren't duplicates | 840 // the drive tasks to the extension task list. We know there aren't duplicates |
| 719 // because they're entirely different kinds of tasks, but there could be both | 841 // because they're entirely different kinds of tasks, but there could be both |
| 720 // kinds of tasks for a file type (an image file, for instance). | 842 // kinds of tasks for a file type (an image file, for instance). |
| 721 if (!FindDriveAppTasks(info_list, result_list)) | 843 if (!FindDriveAppTasks(info_list, result_list)) |
| 722 return false; | 844 return false; |
| 723 | 845 |
| 846 // Take the union of Web Intents (that platform apps may accept) and all | |
| 847 // previous Drive and extension tasks. As above, we know there aren't | |
| 848 // duplicates because they're entirely different kinds of tasks. | |
| 849 if (!FindWebIntentTasks(file_urls, result_list)) | |
| 850 return false; | |
| 851 | |
| 724 if (VLOG_IS_ON(1)) { | 852 if (VLOG_IS_ON(1)) { |
| 725 std::string result_json; | 853 std::string result_json; |
| 726 base::JSONWriter::WriteWithOptions( | 854 base::JSONWriter::WriteWithOptions( |
| 727 result_list, | 855 result_list, |
| 728 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | | 856 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | |
| 729 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 857 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 730 &result_json); | 858 &result_json); |
| 731 VLOG(1) << "GetFileTasks result:\n" << result_json; | 859 VLOG(1) << "GetFileTasks result:\n" << result_json; |
| 732 } | 860 } |
| 733 | 861 |
| 734 // TODO(zelidrag, serya): Add intent content tasks to result_list once we | |
| 735 // implement that API. | |
| 736 SendResponse(true); | 862 SendResponse(true); |
| 737 return true; | 863 return true; |
| 738 } | 864 } |
| 739 | 865 |
| 740 ExecuteTasksFileBrowserFunction::ExecuteTasksFileBrowserFunction() {} | 866 ExecuteTasksFileBrowserFunction::ExecuteTasksFileBrowserFunction() {} |
| 741 | 867 |
| 742 void ExecuteTasksFileBrowserFunction::OnTaskExecuted(bool success) { | 868 void ExecuteTasksFileBrowserFunction::OnTaskExecuted(bool success) { |
| 743 SendResponse(success); | 869 SendResponse(success); |
| 744 } | 870 } |
| 745 | 871 |
| 746 ExecuteTasksFileBrowserFunction::~ExecuteTasksFileBrowserFunction() {} | 872 ExecuteTasksFileBrowserFunction::~ExecuteTasksFileBrowserFunction() {} |
| 747 | 873 |
| 748 bool ExecuteTasksFileBrowserFunction::RunImpl() { | 874 bool ExecuteTasksFileBrowserFunction::RunImpl() { |
| 749 // First param is task id that was to the extension with getFileTasks call. | 875 // First param is task id that was to the extension with getFileTasks call. |
| 750 std::string task_id; | 876 std::string task_id; |
| 751 if (!args_->GetString(0, &task_id) || !task_id.size()) | 877 if (!args_->GetString(0, &task_id) || !task_id.size()) |
| 752 return false; | 878 return false; |
| 753 | 879 |
| 754 // TODO(kaznacheev): Crack the task_id here, store it in the Executor | 880 // TODO(kaznacheev): Crack the task_id here, store it in the Executor |
| 755 // and avoid passing it around. | 881 // and avoid passing it around. |
| 756 | 882 |
| 757 // The second param is the list of files that need to be executed with this | 883 // The second param is the list of files that need to be executed with this |
| 758 // task. | 884 // task. |
| 759 ListValue* files_list = NULL; | 885 ListValue* files_list = NULL; |
| 760 if (!args_->GetList(1, &files_list)) | 886 if (!args_->GetList(1, &files_list)) |
| 761 return false; | 887 return false; |
| 762 | 888 |
| 763 std::string extension_id; | 889 std::string extension_id; |
| 890 file_handler_util::TaskType task_type; | |
| 764 std::string action_id; | 891 std::string action_id; |
| 765 if (!file_handler_util::CrackTaskID(task_id, &extension_id, &action_id)) { | 892 if (!file_handler_util::CrackTaskID( |
| 893 task_id, &extension_id, &task_type, &action_id)) { | |
| 766 LOG(WARNING) << "Invalid task " << task_id; | 894 LOG(WARNING) << "Invalid task " << task_id; |
| 767 return false; | 895 return false; |
| 768 } | 896 } |
| 769 | 897 |
| 770 if (!files_list->GetSize()) | 898 if (!files_list->GetSize()) |
| 771 return true; | 899 return true; |
| 772 | 900 |
| 773 std::vector<GURL> file_urls; | 901 std::vector<GURL> file_urls; |
| 774 for (size_t i = 0; i < files_list->GetSize(); i++) { | 902 for (size_t i = 0; i < files_list->GetSize(); i++) { |
| 775 std::string origin_file_url; | 903 std::string origin_file_url; |
| 776 if (!files_list->GetString(i, &origin_file_url)) { | 904 if (!files_list->GetString(i, &origin_file_url)) { |
| 777 error_ = kInvalidFileUrl; | 905 error_ = kInvalidFileUrl; |
| 778 return false; | 906 return false; |
| 779 } | 907 } |
| 780 file_urls.push_back(GURL(origin_file_url)); | 908 file_urls.push_back(GURL(origin_file_url)); |
| 781 } | 909 } |
| 782 | 910 |
| 783 scoped_refptr<FileTaskExecutor> executor( | 911 scoped_refptr<FileTaskExecutor> executor( |
| 784 FileTaskExecutor::Create(profile(), | 912 FileTaskExecutor::Create(profile(), |
| 785 source_url(), | 913 source_url(), |
| 786 extension_id, | 914 extension_id, |
| 915 task_type, | |
| 787 action_id)); | 916 action_id)); |
| 788 | 917 |
| 789 if (!executor->ExecuteAndNotify( | 918 if (!executor->ExecuteAndNotify( |
| 790 file_urls, | 919 file_urls, |
| 791 base::Bind(&ExecuteTasksFileBrowserFunction::OnTaskExecuted, this))) | 920 base::Bind(&ExecuteTasksFileBrowserFunction::OnTaskExecuted, this))) |
| 792 return false; | 921 return false; |
| 793 | 922 |
| 794 SetResult(new base::FundamentalValue(true)); | 923 SetResult(new base::FundamentalValue(true)); |
| 795 return true; | 924 return true; |
| 796 } | 925 } |
| (...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2440 gdata::GDataSystemService* system_service = | 2569 gdata::GDataSystemService* system_service = |
| 2441 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 2570 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
| 2442 if (!system_service || !system_service->file_system()) | 2571 if (!system_service || !system_service->file_system()) |
| 2443 return false; | 2572 return false; |
| 2444 | 2573 |
| 2445 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 2574 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); |
| 2446 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 2575 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
| 2447 | 2576 |
| 2448 return true; | 2577 return true; |
| 2449 } | 2578 } |
| OLD | NEW |