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_file_system_util.h" | 29 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" |
| 26 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" | 30 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
| 27 #include "chrome/browser/chromeos/gdata/drive_system_service.h" | 31 #include "chrome/browser/chromeos/gdata/drive_system_service.h" |
| 28 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 32 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
| 29 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 33 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 30 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" | 34 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
| 31 #include "chrome/browser/chromeos/system/statistics_provider.h" | 35 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 32 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 36 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 33 #include "chrome/browser/extensions/extension_process_manager.h" | 37 #include "chrome/browser/extensions/extension_process_manager.h" |
| 34 #include "chrome/browser/extensions/extension_service.h" | 38 #include "chrome/browser/extensions/extension_service.h" |
| 35 #include "chrome/browser/extensions/extension_tab_util.h" | 39 #include "chrome/browser/extensions/extension_tab_util.h" |
| 36 #include "chrome/browser/extensions/process_map.h" | 40 #include "chrome/browser/extensions/process_map.h" |
| 41 #include "chrome/browser/intents/web_intents_util.h" | |
| 37 #include "chrome/browser/google_apis/operation_registry.h" | 42 #include "chrome/browser/google_apis/operation_registry.h" |
| 38 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
| 39 #include "chrome/browser/ui/browser.h" | 44 #include "chrome/browser/ui/browser.h" |
| 40 #include "chrome/browser/ui/browser_window.h" | 45 #include "chrome/browser/ui/browser_window.h" |
| 41 #include "chrome/browser/ui/views/select_file_dialog_extension.h" | 46 #include "chrome/browser/ui/views/select_file_dialog_extension.h" |
| 42 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 47 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 43 #include "chrome/common/chrome_version_info.h" | 48 #include "chrome/common/chrome_version_info.h" |
| 44 #include "chrome/common/extensions/extension.h" | 49 #include "chrome/common/extensions/extension.h" |
| 45 #include "chrome/common/extensions/extension_constants.h" | 50 #include "chrome/common/extensions/extension_constants.h" |
| 46 #include "chrome/common/extensions/extension_icon_set.h" | 51 #include "chrome/common/extensions/extension_icon_set.h" |
| 47 #include "chrome/common/extensions/file_browser_handler.h" | 52 #include "chrome/common/extensions/file_browser_handler.h" |
| 48 #include "chrome/common/pref_names.h" | 53 #include "chrome/common/pref_names.h" |
| 49 #include "chromeos/disks/disk_mount_manager.h" | 54 #include "chromeos/disks/disk_mount_manager.h" |
| 50 #include "content/public/browser/child_process_security_policy.h" | 55 #include "content/public/browser/child_process_security_policy.h" |
| 51 #include "content/public/browser/render_process_host.h" | 56 #include "content/public/browser/render_process_host.h" |
| 52 #include "content/public/browser/render_view_host.h" | 57 #include "content/public/browser/render_view_host.h" |
| 53 #include "googleurl/src/gurl.h" | 58 #include "googleurl/src/gurl.h" |
| 54 #include "grit/generated_resources.h" | 59 #include "grit/generated_resources.h" |
| 55 #include "grit/platform_locale_settings.h" | 60 #include "grit/platform_locale_settings.h" |
| 56 #include "net/base/escape.h" | 61 #include "net/base/escape.h" |
| 62 #include "net/base/mime_util.h" | |
| 57 #include "ui/base/dialogs/selected_file_info.h" | 63 #include "ui/base/dialogs/selected_file_info.h" |
| 58 #include "ui/base/l10n/l10n_util.h" | 64 #include "ui/base/l10n/l10n_util.h" |
| 59 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 65 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
| 60 #include "webkit/fileapi/file_system_context.h" | 66 #include "webkit/fileapi/file_system_context.h" |
| 61 #include "webkit/fileapi/file_system_file_util.h" | 67 #include "webkit/fileapi/file_system_file_util.h" |
| 62 #include "webkit/fileapi/file_system_operation_context.h" | 68 #include "webkit/fileapi/file_system_operation_context.h" |
| 63 #include "webkit/fileapi/file_system_types.h" | 69 #include "webkit/fileapi/file_system_types.h" |
| 64 #include "webkit/fileapi/file_system_url.h" | 70 #include "webkit/fileapi/file_system_url.h" |
| 65 #include "webkit/fileapi/file_system_util.h" | 71 #include "webkit/fileapi/file_system_util.h" |
| 72 #include "webkit/glue/web_intent_service_data.h" | |
| 66 | 73 |
| 67 using chromeos::disks::DiskMountManager; | 74 using chromeos::disks::DiskMountManager; |
| 68 using content::BrowserContext; | 75 using content::BrowserContext; |
| 69 using content::BrowserThread; | 76 using content::BrowserThread; |
| 70 using content::ChildProcessSecurityPolicy; | 77 using content::ChildProcessSecurityPolicy; |
| 71 using content::SiteInstance; | 78 using content::SiteInstance; |
| 72 using content::WebContents; | 79 using content::WebContents; |
| 73 using extensions::Extension; | 80 using extensions::Extension; |
| 74 using file_handler_util::FileTaskExecutor; | 81 using file_handler_util::FileTaskExecutor; |
| 75 using gdata::InstalledApp; | 82 using gdata::InstalledApp; |
| 76 using gdata::OperationRegistry; | 83 using gdata::OperationRegistry; |
| 77 | 84 |
| 78 namespace { | 85 namespace { |
| 79 | 86 |
| 80 // Default icon path for drive docs. | 87 // Default icon path for drive docs. |
| 81 const char kDefaultDriveIcon[] = "images/filetype_generic.png"; | 88 const char kDefaultIcon[] = "images/filetype_generic.png"; |
| 82 const int kPreferredIconSize = 16; | 89 const int kPreferredIconSize = 16; |
| 83 | 90 |
| 84 // Error messages. | 91 // Error messages. |
| 85 const char kFileError[] = "File error %d"; | 92 const char kFileError[] = "File error %d"; |
| 86 const char kInvalidFileUrl[] = "Invalid file URL"; | 93 const char kInvalidFileUrl[] = "Invalid file URL"; |
| 87 const char kVolumeDevicePathNotFound[] = "Device path not found"; | 94 const char kVolumeDevicePathNotFound[] = "Device path not found"; |
| 88 | 95 |
| 89 // Unescape rules used for parsing query parameters. | 96 // Unescape rules used for parsing query parameters. |
| 90 const net::UnescapeRule::Type kUnescapeRuleForQueryParameters = | 97 const net::UnescapeRule::Type kUnescapeRuleForQueryParameters = |
| 91 net::UnescapeRule::SPACES | | 98 net::UnescapeRule::SPACES | |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 if (icons.empty()) | 235 if (icons.empty()) |
| 229 return result; | 236 return result; |
| 230 result = icons.rbegin()->second; | 237 result = icons.rbegin()->second; |
| 231 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); | 238 for (InstalledApp::IconList::const_reverse_iterator iter = icons.rbegin(); |
| 232 iter != icons.rend() && iter->first >= preferred_size; ++iter) { | 239 iter != icons.rend() && iter->first >= preferred_size; ++iter) { |
| 233 result = iter->second; | 240 result = iter->second; |
| 234 } | 241 } |
| 235 return result; | 242 return result; |
| 236 } | 243 } |
| 237 | 244 |
| 245 // Given an extension, a Web Intents |action|, and a set of |mime_types|, | |
| 246 // determines whether this extension supports this action for all specified | |
| 247 // mime-types. | |
| 248 // If this method returns true, also returns the |title| of this action. | |
| 249 bool ExtensionSupportsAction(const Extension* extension, | |
|
tbarzic
2012/09/13 18:44:45
nit:
const Extension* extension should got to the
thorogood
2012/09/16 03:41:19
Done.
| |
| 250 const std::string& action, | |
| 251 const std::set<std::string>& mime_types, | |
| 252 std::string* title) { | |
| 253 DCHECK(!mime_types.empty()); | |
| 254 std::set<std::string> pending(mime_types.begin(), mime_types.end()); | |
| 255 std::string found_title; | |
| 256 | |
| 257 for (std::vector<webkit_glue::WebIntentServiceData>::const_iterator data = | |
| 258 extension->intents_services().begin(); | |
| 259 data != extension->intents_services().end(); ++data) { | |
| 260 if (pending.empty()) | |
| 261 break; | |
| 262 | |
| 263 if (UTF16ToUTF8(data->action) != action) | |
| 264 continue; | |
| 265 | |
| 266 std::set<std::string>::iterator pending_iter = pending.begin(); | |
| 267 while (pending_iter != pending.end()) { | |
| 268 std::set<std::string>::iterator current = pending_iter++; | |
| 269 if (net::MatchesMimeType(UTF16ToUTF8(data->type), *pending_iter)) | |
| 270 pending.erase(current); | |
| 271 } | |
| 272 if (found_title.empty()) | |
| 273 found_title = UTF16ToUTF8(data->title); | |
| 274 } | |
| 275 | |
| 276 if (!pending.empty()) | |
| 277 return false; // we haven't found all mime-types | |
| 278 | |
| 279 *title = found_title; | |
| 280 return true; | |
| 281 } | |
| 282 | |
| 238 // Retrieves total and remaining available size on |mount_path|. | 283 // Retrieves total and remaining available size on |mount_path|. |
| 239 void GetSizeStatsOnFileThread(const std::string& mount_path, | 284 void GetSizeStatsOnFileThread(const std::string& mount_path, |
| 240 size_t* total_size_kb, | 285 size_t* total_size_kb, |
| 241 size_t* remaining_size_kb) { | 286 size_t* remaining_size_kb) { |
| 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 243 | 288 |
| 244 uint64_t total_size_in_bytes = 0; | 289 uint64_t total_size_in_bytes = 0; |
| 245 uint64_t remaining_size_in_bytes = 0; | 290 uint64_t remaining_size_in_bytes = 0; |
| 246 | 291 |
| 247 struct statvfs stat = {}; // Zero-clear | 292 struct statvfs stat = {}; // Zero-clear |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 file_iter->mime_type, &info); | 639 file_iter->mime_type, &info); |
| 595 std::vector<gdata::DriveWebAppInfo*> info_ptrs; | 640 std::vector<gdata::DriveWebAppInfo*> info_ptrs; |
| 596 info.release(&info_ptrs); // so they don't go away prematurely. | 641 info.release(&info_ptrs); // so they don't go away prematurely. |
| 597 std::set<std::string> tasks_for_this_file; | 642 std::set<std::string> tasks_for_this_file; |
| 598 for (std::vector<gdata::DriveWebAppInfo*>::iterator | 643 for (std::vector<gdata::DriveWebAppInfo*>::iterator |
| 599 apps = info_ptrs.begin(); apps != info_ptrs.end(); ++apps) { | 644 apps = info_ptrs.begin(); apps != info_ptrs.end(); ++apps) { |
| 600 std::pair<WebAppInfoMap::iterator, bool> insert_result = | 645 std::pair<WebAppInfoMap::iterator, bool> insert_result = |
| 601 app_info->insert(std::make_pair((*apps)->app_id, *apps)); | 646 app_info->insert(std::make_pair((*apps)->app_id, *apps)); |
| 602 // TODO(gspencer): For now, the action id is always "open-with", but we | 647 // TODO(gspencer): For now, the action id is always "open-with", but we |
| 603 // could add any actions that the drive app supports. | 648 // could add any actions that the drive app supports. |
| 604 std::string task_id = | 649 std::string task_id = file_handler_util::MakeTaskID( |
| 605 file_handler_util::MakeDriveTaskID((*apps)->app_id, "open-with"); | 650 (*apps)->app_id, file_handler_util::TASK_DRIVE, "open-with"); |
| 606 tasks_for_this_file.insert(task_id); | 651 tasks_for_this_file.insert(task_id); |
| 607 // If we failed to insert a task_id because there was a duplicate, then we | 652 // If we failed to insert a task_id because there was a duplicate, then we |
| 608 // must delete it (since we own it). | 653 // must delete it (since we own it). |
| 609 if (!insert_result.second) | 654 if (!insert_result.second) |
| 610 delete *apps; | 655 delete *apps; |
| 611 } | 656 } |
| 612 if (file_iter == file_info_list.begin()) { | 657 if (file_iter == file_info_list.begin()) { |
| 613 *available_tasks = tasks_for_this_file; | 658 *available_tasks = tasks_for_this_file; |
| 614 } else { | 659 } else { |
| 615 std::set<std::string> intersection; | 660 std::set<std::string> intersection; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 const std::set<std::string>& available_tasks, | 693 const std::set<std::string>& available_tasks, |
| 649 const std::set<std::string>& default_tasks, | 694 const std::set<std::string>& default_tasks, |
| 650 ListValue* result_list, | 695 ListValue* result_list, |
| 651 bool* default_already_set) { | 696 bool* default_already_set) { |
| 652 *default_already_set = false; | 697 *default_already_set = false; |
| 653 // OK, now we traverse the intersection of available applications for this | 698 // OK, now we traverse the intersection of available applications for this |
| 654 // list of files, adding a task for each one that is found. | 699 // list of files, adding a task for each one that is found. |
| 655 for (std::set<std::string>::const_iterator app_iter = available_tasks.begin(); | 700 for (std::set<std::string>::const_iterator app_iter = available_tasks.begin(); |
| 656 app_iter != available_tasks.end(); ++app_iter) { | 701 app_iter != available_tasks.end(); ++app_iter) { |
| 657 std::string app_id; | 702 std::string app_id; |
| 658 bool result = file_handler_util::CrackDriveTaskID(*app_iter, &app_id, NULL); | 703 file_handler_util::TaskType task_type; |
| 704 bool result = file_handler_util::CrackTaskID( | |
| 705 *app_iter, &app_id, &task_type, NULL); | |
| 659 DCHECK(result) << "Unable to parse Drive task id: " << *app_iter; | 706 DCHECK(result) << "Unable to parse Drive task id: " << *app_iter; |
| 660 if (!result) | 707 DCHECK_EQ(task_type, file_handler_util::TASK_DRIVE); |
| 708 if (!result || task_type != file_handler_util::TASK_DRIVE) | |
| 661 continue; | 709 continue; |
| 662 WebAppInfoMap::const_iterator info_iter = app_info.find(app_id); | 710 WebAppInfoMap::const_iterator info_iter = app_info.find(app_id); |
| 663 DCHECK(info_iter != app_info.end()); | 711 DCHECK(info_iter != app_info.end()); |
| 664 gdata::DriveWebAppInfo* info = info_iter->second; | 712 gdata::DriveWebAppInfo* info = info_iter->second; |
| 665 DictionaryValue* task = new DictionaryValue; | 713 DictionaryValue* task = new DictionaryValue; |
| 666 | 714 |
| 667 task->SetString("taskId", *app_iter); | 715 task->SetString("taskId", *app_iter); |
| 668 task->SetString("title", info->app_name); | 716 task->SetString("title", info->app_name); |
| 669 | 717 |
| 670 GURL best_icon = FindPreferredIcon(info->app_icons, | 718 GURL best_icon = FindPreferredIcon(info->app_icons, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 699 return true; | 747 return true; |
| 700 | 748 |
| 701 gdata::DriveSystemService* system_service = | 749 gdata::DriveSystemService* system_service = |
| 702 gdata::DriveSystemServiceFactory::GetForProfile(profile_); | 750 gdata::DriveSystemServiceFactory::GetForProfile(profile_); |
| 703 // |system_service| is NULL if incognito window / guest login. We return true | 751 // |system_service| is NULL if incognito window / guest login. We return true |
| 704 // in this case because there might be other extension tasks, even if we don't | 752 // in this case because there might be other extension tasks, even if we don't |
| 705 // have any to add. | 753 // have any to add. |
| 706 if (!system_service || !system_service->webapps_registry()) | 754 if (!system_service || !system_service->webapps_registry()) |
| 707 return true; | 755 return true; |
| 708 | 756 |
| 709 | |
| 710 gdata::DriveWebAppsRegistry* registry = system_service->webapps_registry(); | 757 gdata::DriveWebAppsRegistry* registry = system_service->webapps_registry(); |
| 711 | 758 |
| 712 // Map of app_id to DriveWebAppInfo so we can look up the apps we've found | 759 // Map of app_id to DriveWebAppInfo so we can look up the apps we've found |
| 713 // after taking the intersection of available apps. | 760 // after taking the intersection of available apps. |
| 714 std::map<std::string, gdata::DriveWebAppInfo*> app_info; | 761 std::map<std::string, gdata::DriveWebAppInfo*> app_info; |
| 715 // Set of application IDs. This will end up with the intersection of the | 762 // Set of application IDs. This will end up with the intersection of the |
| 716 // application IDs that apply to the paths in |file_paths|. | 763 // application IDs that apply to the paths in |file_paths|. |
| 717 std::set<std::string> available_tasks; | 764 std::set<std::string> available_tasks; |
| 718 | 765 |
| 719 IntersectAvailableDriveTasks(registry, file_info_list, | 766 IntersectAvailableDriveTasks(registry, file_info_list, |
| 720 &app_info, &available_tasks); | 767 &app_info, &available_tasks); |
| 721 std::set<std::string> default_tasks; | 768 std::set<std::string> default_tasks; |
| 722 FindDefaultDriveTasks(file_info_list, available_tasks, &default_tasks); | 769 FindDefaultDriveTasks(file_info_list, available_tasks, &default_tasks); |
| 723 CreateDriveTasks(registry, app_info, available_tasks, default_tasks, | 770 CreateDriveTasks(registry, app_info, available_tasks, default_tasks, |
| 724 result_list, default_already_set); | 771 result_list, default_already_set); |
| 725 | 772 |
| 726 // We own the pointers in |app_info|, so we need to delete them. | 773 // We own the pointers in |app_info|, so we need to delete them. |
| 727 STLDeleteContainerPairSecondPointers(app_info.begin(), app_info.end()); | 774 STLDeleteContainerPairSecondPointers(app_info.begin(), app_info.end()); |
| 728 return true; | 775 return true; |
| 729 } | 776 } |
| 730 | 777 |
| 778 // Find Web Intent platform apps that support the View task, and add them to | |
| 779 // the |result_list|. These will be marked as TASK_WEBINTENT. | |
| 780 bool GetFileTasksFileBrowserFunction::FindWebIntentTasks( | |
| 781 const std::vector<GURL>& file_urls, | |
| 782 ListValue* result_list) { | |
| 783 DCHECK(!file_urls.empty()); | |
| 784 ExtensionService* service = profile_->GetExtensionService(); | |
| 785 if (!service) | |
| 786 return false; | |
| 787 | |
| 788 std::set<std::string> mime_types; | |
| 789 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); | |
| 790 iter != file_urls.end(); ++iter) { | |
| 791 const FilePath file = FilePath(GURL(iter->spec()).ExtractFileName()); | |
| 792 const FilePath::StringType file_extension = | |
| 793 StringToLowerASCII(file.Extension()); | |
| 794 | |
| 795 // TODO(thorogood): Rearchitect this call so it can run on the File thread; | |
| 796 // GetMimeTypeFromFile requires this on Linux. Right now, we use | |
| 797 // Chrome-level knowledge only. | |
| 798 std::string mime_type; | |
| 799 if (!file_extension.empty() && !net::GetWellKnownMimeTypeFromExtension( | |
| 800 file_extension.substr(1), &mime_type)) | |
| 801 mime_type = std::string(); // There was no mime-type available from this | |
| 802 // file, but we'll still match "*". | |
| 803 mime_types.insert(mime_type); | |
| 804 } | |
| 805 | |
| 806 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | |
| 807 iter != service->extensions()->end(); | |
| 808 ++iter) { | |
| 809 const Extension* extension = *iter; | |
| 810 std::string title; | |
| 811 | |
| 812 // We don't support using hosted apps to open files. | |
| 813 if (!extension->is_platform_app()) | |
| 814 continue; | |
| 815 | |
| 816 if (profile_->IsOffTheRecord() && | |
| 817 !service->IsIncognitoEnabled(extension->id())) | |
| 818 continue; | |
| 819 | |
| 820 if (!ExtensionSupportsAction( | |
| 821 extension, web_intents::kActionView, mime_types, &title)) | |
| 822 continue; | |
| 823 | |
| 824 DictionaryValue* task = new DictionaryValue; | |
| 825 std::string task_id = file_handler_util::MakeTaskID(extension->id(), | |
| 826 file_handler_util::TASK_WEBINTENT, web_intents::kActionView); | |
| 827 task->SetString("taskId", task_id); | |
| 828 task->SetString("title", title); | |
| 829 task->SetBoolean("isDefault", false); | |
| 830 | |
| 831 GURL best_icon = extension->GetIconURL(kPreferredIconSize, | |
| 832 ExtensionIconSet::MATCH_BIGGER); | |
| 833 if (!best_icon.is_empty()) | |
| 834 task->SetString("iconUrl", best_icon.spec()); | |
| 835 else | |
| 836 task->SetString("iconUrl", kDefaultIcon); | |
| 837 | |
| 838 task->SetBoolean("driveApp", false); | |
| 839 result_list->Append(task); | |
| 840 } | |
| 841 | |
| 842 return true; | |
| 843 } | |
| 844 | |
| 731 bool GetFileTasksFileBrowserFunction::RunImpl() { | 845 bool GetFileTasksFileBrowserFunction::RunImpl() { |
| 732 // First argument is the list of files to get tasks for. | 846 // First argument is the list of files to get tasks for. |
| 733 ListValue* files_list = NULL; | 847 ListValue* files_list = NULL; |
| 734 if (!args_->GetList(0, &files_list)) | 848 if (!args_->GetList(0, &files_list)) |
| 735 return false; | 849 return false; |
| 736 | 850 |
| 737 // Second argument is the list of mime types of each of the files in the list. | 851 // Second argument is the list of mime types of each of the files in the list. |
| 738 ListValue* mime_types_list = NULL; | 852 ListValue* mime_types_list = NULL; |
| 739 if (!args_->GetList(1, &mime_types_list)) | 853 if (!args_->GetList(1, &mime_types_list)) |
| 740 return false; | 854 return false; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 ExtensionService* service = profile_->GetExtensionService(); | 904 ExtensionService* service = profile_->GetExtensionService(); |
| 791 for (std::set<const FileBrowserHandler*>::const_iterator iter = | 905 for (std::set<const FileBrowserHandler*>::const_iterator iter = |
| 792 common_tasks.begin(); | 906 common_tasks.begin(); |
| 793 iter != common_tasks.end(); | 907 iter != common_tasks.end(); |
| 794 ++iter) { | 908 ++iter) { |
| 795 const FileBrowserHandler* handler = *iter; | 909 const FileBrowserHandler* handler = *iter; |
| 796 const std::string extension_id = handler->extension_id(); | 910 const std::string extension_id = handler->extension_id(); |
| 797 const Extension* extension = service->GetExtensionById(extension_id, false); | 911 const Extension* extension = service->GetExtensionById(extension_id, false); |
| 798 CHECK(extension); | 912 CHECK(extension); |
| 799 DictionaryValue* task = new DictionaryValue; | 913 DictionaryValue* task = new DictionaryValue; |
| 800 task->SetString("taskId", | 914 task->SetString("taskId", file_handler_util::MakeTaskID( |
| 801 file_handler_util::MakeTaskID(extension_id, handler->id())); | 915 extension_id, file_handler_util::TASK_FILE, handler->id())); |
| 802 task->SetString("title", handler->title()); | 916 task->SetString("title", handler->title()); |
| 803 // TODO(zelidrag): Figure out how to expose icon URL that task defined in | 917 // TODO(zelidrag): Figure out how to expose icon URL that task defined in |
| 804 // manifest instead of the default extension icon. | 918 // manifest instead of the default extension icon. |
| 805 GURL icon = | 919 GURL icon = |
| 806 ExtensionIconSource::GetIconURL(extension, | 920 ExtensionIconSource::GetIconURL(extension, |
| 807 extension_misc::EXTENSION_ICON_BITTY, | 921 extension_misc::EXTENSION_ICON_BITTY, |
| 808 ExtensionIconSet::MATCH_BIGGER, | 922 ExtensionIconSet::MATCH_BIGGER, |
| 809 false, NULL); // grayscale | 923 false, NULL); // grayscale |
| 810 task->SetString("iconUrl", icon.spec()); | 924 task->SetString("iconUrl", icon.spec()); |
| 811 task->SetBoolean("driveApp", false); | 925 task->SetBoolean("driveApp", false); |
| 812 | 926 |
| 813 // Only set the default if there isn't already a default set. | 927 // Only set the default if there isn't already a default set. |
| 814 if (!default_already_set && | 928 if (!default_already_set && |
| 815 default_tasks.find(*iter) != default_tasks.end()) { | 929 default_tasks.find(*iter) != default_tasks.end()) { |
| 816 task->SetBoolean("isDefault", true); | 930 task->SetBoolean("isDefault", true); |
| 817 default_already_set = true; | 931 default_already_set = true; |
| 818 } else { | 932 } else { |
| 819 task->SetBoolean("isDefault", false); | 933 task->SetBoolean("isDefault", false); |
| 820 } | 934 } |
| 821 | 935 |
| 822 result_list->Append(task); | 936 result_list->Append(task); |
| 823 } | 937 } |
| 824 | 938 |
| 939 // Take the union of Web Intents (that platform apps may accept) and all | |
| 940 // previous Drive and extension tasks. As above, we know there aren't | |
| 941 // duplicates because they're entirely different kinds of tasks. | |
| 942 if (!FindWebIntentTasks(file_urls, result_list)) | |
| 943 return false; | |
| 944 | |
| 825 if (VLOG_IS_ON(1)) { | 945 if (VLOG_IS_ON(1)) { |
| 826 std::string result_json; | 946 std::string result_json; |
| 827 base::JSONWriter::WriteWithOptions( | 947 base::JSONWriter::WriteWithOptions( |
| 828 result_list, | 948 result_list, |
| 829 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | | 949 base::JSONWriter::OPTIONS_DO_NOT_ESCAPE | |
| 830 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 950 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 831 &result_json); | 951 &result_json); |
| 832 VLOG(1) << "GetFileTasks result:\n" << result_json; | 952 VLOG(1) << "GetFileTasks result:\n" << result_json; |
| 833 } | 953 } |
| 834 | 954 |
| 835 // TODO(zelidrag, serya): Add intent content tasks to result_list once we | |
| 836 // implement that API. | |
| 837 SendResponse(true); | 955 SendResponse(true); |
| 838 return true; | 956 return true; |
| 839 } | 957 } |
| 840 | 958 |
| 841 ExecuteTasksFileBrowserFunction::ExecuteTasksFileBrowserFunction() {} | 959 ExecuteTasksFileBrowserFunction::ExecuteTasksFileBrowserFunction() {} |
| 842 | 960 |
| 843 void ExecuteTasksFileBrowserFunction::OnTaskExecuted(bool success) { | 961 void ExecuteTasksFileBrowserFunction::OnTaskExecuted(bool success) { |
| 844 SendResponse(success); | 962 SendResponse(success); |
| 845 } | 963 } |
| 846 | 964 |
| 847 ExecuteTasksFileBrowserFunction::~ExecuteTasksFileBrowserFunction() {} | 965 ExecuteTasksFileBrowserFunction::~ExecuteTasksFileBrowserFunction() {} |
| 848 | 966 |
| 849 bool ExecuteTasksFileBrowserFunction::RunImpl() { | 967 bool ExecuteTasksFileBrowserFunction::RunImpl() { |
| 850 // First param is task id that was to the extension with getFileTasks call. | 968 // First param is task id that was to the extension with getFileTasks call. |
| 851 std::string task_id; | 969 std::string task_id; |
| 852 if (!args_->GetString(0, &task_id) || !task_id.size()) | 970 if (!args_->GetString(0, &task_id) || !task_id.size()) |
| 853 return false; | 971 return false; |
| 854 | 972 |
| 855 // TODO(kaznacheev): Crack the task_id here, store it in the Executor | 973 // TODO(kaznacheev): Crack the task_id here, store it in the Executor |
| 856 // and avoid passing it around. | 974 // and avoid passing it around. |
| 857 | 975 |
| 858 // The second param is the list of files that need to be executed with this | 976 // The second param is the list of files that need to be executed with this |
| 859 // task. | 977 // task. |
| 860 ListValue* files_list = NULL; | 978 ListValue* files_list = NULL; |
| 861 if (!args_->GetList(1, &files_list)) | 979 if (!args_->GetList(1, &files_list)) |
| 862 return false; | 980 return false; |
| 863 | 981 |
| 864 std::string extension_id; | 982 std::string extension_id; |
| 983 file_handler_util::TaskType task_type; | |
| 865 std::string action_id; | 984 std::string action_id; |
| 866 if (!file_handler_util::CrackTaskID(task_id, &extension_id, &action_id)) { | 985 if (!file_handler_util::CrackTaskID( |
| 986 task_id, &extension_id, &task_type, &action_id)) { | |
| 867 LOG(WARNING) << "Invalid task " << task_id; | 987 LOG(WARNING) << "Invalid task " << task_id; |
| 868 return false; | 988 return false; |
| 869 } | 989 } |
| 870 | 990 |
| 871 if (!files_list->GetSize()) | 991 if (!files_list->GetSize()) |
| 872 return true; | 992 return true; |
| 873 | 993 |
| 874 std::vector<GURL> file_urls; | 994 std::vector<GURL> file_urls; |
| 875 for (size_t i = 0; i < files_list->GetSize(); i++) { | 995 for (size_t i = 0; i < files_list->GetSize(); i++) { |
| 876 std::string origin_file_url; | 996 std::string origin_file_url; |
| 877 if (!files_list->GetString(i, &origin_file_url)) { | 997 if (!files_list->GetString(i, &origin_file_url)) { |
| 878 error_ = kInvalidFileUrl; | 998 error_ = kInvalidFileUrl; |
| 879 return false; | 999 return false; |
| 880 } | 1000 } |
| 881 file_urls.push_back(GURL(origin_file_url)); | 1001 file_urls.push_back(GURL(origin_file_url)); |
| 882 } | 1002 } |
| 883 | 1003 |
| 884 scoped_refptr<FileTaskExecutor> executor( | 1004 scoped_refptr<FileTaskExecutor> executor( |
| 885 FileTaskExecutor::Create(profile(), | 1005 FileTaskExecutor::Create(profile(), |
| 886 source_url(), | 1006 source_url(), |
| 887 extension_id, | 1007 extension_id, |
| 1008 task_type, | |
| 888 action_id)); | 1009 action_id)); |
| 889 | 1010 |
| 890 if (!executor->ExecuteAndNotify( | 1011 if (!executor->ExecuteAndNotify( |
| 891 file_urls, | 1012 file_urls, |
| 892 base::Bind(&ExecuteTasksFileBrowserFunction::OnTaskExecuted, this))) | 1013 base::Bind(&ExecuteTasksFileBrowserFunction::OnTaskExecuted, this))) |
| 893 return false; | 1014 return false; |
| 894 | 1015 |
| 895 SetResult(new base::FundamentalValue(true)); | 1016 SetResult(new base::FundamentalValue(true)); |
| 896 return true; | 1017 return true; |
| 897 } | 1018 } |
| (...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2010 // Get drive WebApps that can accept this file. | 2131 // Get drive WebApps that can accept this file. |
| 2011 ScopedVector<gdata::DriveWebAppInfo> web_apps; | 2132 ScopedVector<gdata::DriveWebAppInfo> web_apps; |
| 2012 system_service->webapps_registry()->GetWebAppsForFile( | 2133 system_service->webapps_registry()->GetWebAppsForFile( |
| 2013 file_path, file_specific_info.content_mime_type(), &web_apps); | 2134 file_path, file_specific_info.content_mime_type(), &web_apps); |
| 2014 if (!web_apps.empty()) { | 2135 if (!web_apps.empty()) { |
| 2015 std::string default_task_id = file_handler_util::GetDefaultTaskIdFromPrefs( | 2136 std::string default_task_id = file_handler_util::GetDefaultTaskIdFromPrefs( |
| 2016 profile_, | 2137 profile_, |
| 2017 file_specific_info.content_mime_type(), | 2138 file_specific_info.content_mime_type(), |
| 2018 file_path.Extension()); | 2139 file_path.Extension()); |
| 2019 std::string default_app_id; | 2140 std::string default_app_id; |
| 2020 file_handler_util::CrackDriveTaskID(default_task_id, &default_app_id, NULL); | 2141 file_handler_util::CrackTaskID( |
| 2142 default_task_id, &default_app_id, NULL, NULL); | |
| 2021 | 2143 |
| 2022 ListValue* apps = new ListValue(); | 2144 ListValue* apps = new ListValue(); |
| 2023 property_dict->Set("driveApps", apps); | 2145 property_dict->Set("driveApps", apps); |
| 2024 for (ScopedVector<gdata::DriveWebAppInfo>::const_iterator it = | 2146 for (ScopedVector<gdata::DriveWebAppInfo>::const_iterator it = |
| 2025 web_apps.begin(); | 2147 web_apps.begin(); |
| 2026 it != web_apps.end(); ++it) { | 2148 it != web_apps.end(); ++it) { |
| 2027 const gdata::DriveWebAppInfo* webapp_info = *it; | 2149 const gdata::DriveWebAppInfo* webapp_info = *it; |
| 2028 DictionaryValue* app = new DictionaryValue(); | 2150 DictionaryValue* app = new DictionaryValue(); |
| 2029 app->SetString("appId", webapp_info->app_id); | 2151 app->SetString("appId", webapp_info->app_id); |
| 2030 app->SetString("appName", webapp_info->app_name); | 2152 app->SetString("appName", webapp_info->app_name); |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2598 gdata::DriveSystemService* system_service = | 2720 gdata::DriveSystemService* system_service = |
| 2599 gdata::DriveSystemServiceFactory::GetForProfile(profile_); | 2721 gdata::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2600 if (!system_service || !system_service->file_system()) | 2722 if (!system_service || !system_service->file_system()) |
| 2601 return false; | 2723 return false; |
| 2602 | 2724 |
| 2603 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 2725 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); |
| 2604 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 2726 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
| 2605 | 2727 |
| 2606 return true; | 2728 return true; |
| 2607 } | 2729 } |
| OLD | NEW |