| 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_manager/file_browser_private_a
pi.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a
pi.h" |
| 6 | 6 |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/statvfs.h> | 8 #include <sys/statvfs.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <utime.h> | 10 #include <utime.h> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/memory/singleton.h" | 22 #include "base/memory/singleton.h" |
| 23 #include "base/posix/eintr_wrapper.h" | 23 #include "base/posix/eintr_wrapper.h" |
| 24 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
| 25 #include "base/stringprintf.h" | 25 #include "base/stringprintf.h" |
| 26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
| 28 #include "base/time.h" | 28 #include "base/time.h" |
| 29 #include "base/utf_string_conversions.h" | 29 #include "base/utf_string_conversions.h" |
| 30 #include "base/values.h" | 30 #include "base/values.h" |
| 31 #include "chrome/browser/chromeos/drive/drive.pb.h" | 31 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 32 #include "chrome/browser/chromeos/drive/drive_app_registry.h" |
| 32 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 33 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 33 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" | |
| 34 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 34 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 35 #include "chrome/browser/chromeos/drive/file_system_util.h" | 35 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 36 #include "chrome/browser/chromeos/drive/logging.h" | 36 #include "chrome/browser/chromeos/drive/logging.h" |
| 37 #include "chrome/browser/chromeos/drive/search_metadata.h" | 37 #include "chrome/browser/chromeos/drive/search_metadata.h" |
| 38 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_handler.h
" | 38 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_handler.h
" |
| 39 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a
pi_factory.h" | 39 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a
pi_factory.h" |
| 40 #include "chrome/browser/chromeos/extensions/file_manager/file_handler_util.h" | 40 #include "chrome/browser/chromeos/extensions/file_manager/file_handler_util.h" |
| 41 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" | 41 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" |
| 42 #include "chrome/browser/chromeos/extensions/file_manager/zip_file_creator.h" | 42 #include "chrome/browser/chromeos/extensions/file_manager/zip_file_creator.h" |
| 43 #include "chrome/browser/chromeos/settings/cros_settings.h" | 43 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 TaskInfo(const string16& app_name, const GURL& icon_url) | 748 TaskInfo(const string16& app_name, const GURL& icon_url) |
| 749 : app_name(app_name), icon_url(icon_url) { | 749 : app_name(app_name), icon_url(icon_url) { |
| 750 } | 750 } |
| 751 | 751 |
| 752 string16 app_name; | 752 string16 app_name; |
| 753 GURL icon_url; | 753 GURL icon_url; |
| 754 }; | 754 }; |
| 755 | 755 |
| 756 // static | 756 // static |
| 757 void GetFileTasksFileBrowserFunction::GetAvailableDriveTasks( | 757 void GetFileTasksFileBrowserFunction::GetAvailableDriveTasks( |
| 758 drive::DriveWebAppsRegistry* registry, | 758 drive::DriveAppRegistry* registry, |
| 759 const FileInfoList& file_info_list, | 759 const FileInfoList& file_info_list, |
| 760 TaskInfoMap* task_info_map) { | 760 TaskInfoMap* task_info_map) { |
| 761 DCHECK(registry); | 761 DCHECK(registry); |
| 762 DCHECK(task_info_map); | 762 DCHECK(task_info_map); |
| 763 DCHECK(task_info_map->empty()); | 763 DCHECK(task_info_map->empty()); |
| 764 | 764 |
| 765 bool is_first = true; | 765 bool is_first = true; |
| 766 for (size_t i = 0; i < file_info_list.size(); ++i) { | 766 for (size_t i = 0; i < file_info_list.size(); ++i) { |
| 767 const FileInfo& file_info = file_info_list[i]; | 767 const FileInfo& file_info = file_info_list[i]; |
| 768 if (file_info.file_path.empty()) | 768 if (file_info.file_path.empty()) |
| 769 continue; | 769 continue; |
| 770 | 770 |
| 771 ScopedVector<drive::DriveWebAppInfo> app_info_list; | 771 ScopedVector<drive::DriveAppInfo> app_info_list; |
| 772 registry->GetWebAppsForFile( | 772 registry->GetAppsForFile( |
| 773 file_info.file_path, file_info.mime_type, &app_info_list); | 773 file_info.file_path, file_info.mime_type, &app_info_list); |
| 774 | 774 |
| 775 if (is_first) { | 775 if (is_first) { |
| 776 // For the first file, we store all the info. | 776 // For the first file, we store all the info. |
| 777 for (size_t j = 0; j < app_info_list.size(); ++j) { | 777 for (size_t j = 0; j < app_info_list.size(); ++j) { |
| 778 const drive::DriveWebAppInfo& app_info = *app_info_list[j]; | 778 const drive::DriveAppInfo& app_info = *app_info_list[j]; |
| 779 GURL icon_url = | 779 GURL icon_url = |
| 780 FindPreferredIcon(app_info.app_icons, kPreferredIconSize); | 780 FindPreferredIcon(app_info.app_icons, kPreferredIconSize); |
| 781 task_info_map->insert(std::pair<std::string, TaskInfo>( | 781 task_info_map->insert(std::pair<std::string, TaskInfo>( |
| 782 MakeWebAppTaskId(app_info.app_id), | 782 MakeWebAppTaskId(app_info.app_id), |
| 783 TaskInfo(app_info.app_name, icon_url))); | 783 TaskInfo(app_info.app_name, icon_url))); |
| 784 } | 784 } |
| 785 } else { | 785 } else { |
| 786 // For remaining files, take the intersection with the current result, | 786 // For remaining files, take the intersection with the current result, |
| 787 // based on the task id. | 787 // based on the task id. |
| 788 std::set<std::string> task_id_set; | 788 std::set<std::string> task_id_set; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 DCHECK(default_already_set); | 863 DCHECK(default_already_set); |
| 864 | 864 |
| 865 if (file_info_list.empty()) | 865 if (file_info_list.empty()) |
| 866 return true; | 866 return true; |
| 867 | 867 |
| 868 drive::DriveIntegrationService* integration_service = | 868 drive::DriveIntegrationService* integration_service = |
| 869 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 869 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
| 870 // |integration_service| is NULL if Drive is disabled. We return true in this | 870 // |integration_service| is NULL if Drive is disabled. We return true in this |
| 871 // case because there might be other extension tasks, even if we don't have | 871 // case because there might be other extension tasks, even if we don't have |
| 872 // any to add. | 872 // any to add. |
| 873 if (!integration_service || !integration_service->webapps_registry()) | 873 if (!integration_service || !integration_service->drive_app_registry()) |
| 874 return true; | 874 return true; |
| 875 | 875 |
| 876 drive::DriveWebAppsRegistry* registry = | 876 drive::DriveAppRegistry* registry = |
| 877 integration_service->webapps_registry(); | 877 integration_service->drive_app_registry(); |
| 878 DCHECK(registry); | 878 DCHECK(registry); |
| 879 | 879 |
| 880 // Map of task_id to TaskInfo of available tasks. | 880 // Map of task_id to TaskInfo of available tasks. |
| 881 TaskInfoMap task_info_map; | 881 TaskInfoMap task_info_map; |
| 882 GetAvailableDriveTasks(registry, file_info_list, &task_info_map); | 882 GetAvailableDriveTasks(registry, file_info_list, &task_info_map); |
| 883 std::set<std::string> default_tasks; | 883 std::set<std::string> default_tasks; |
| 884 FindDefaultDriveTasks(file_info_list, task_info_map, &default_tasks); | 884 FindDefaultDriveTasks(file_info_list, task_info_map, &default_tasks); |
| 885 CreateDriveTasks( | 885 CreateDriveTasks( |
| 886 task_info_map, default_tasks, result_list, default_already_set); | 886 task_info_map, default_tasks, result_list, default_already_set); |
| 887 return true; | 887 return true; |
| (...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2429 // FillDriveEntryPropertiesValue(). | 2429 // FillDriveEntryPropertiesValue(). |
| 2430 if (entry.get() && !entry->has_file_specific_info()) { | 2430 if (entry.get() && !entry->has_file_specific_info()) { |
| 2431 CompleteGetFileProperties(error); | 2431 CompleteGetFileProperties(error); |
| 2432 return; | 2432 return; |
| 2433 } | 2433 } |
| 2434 | 2434 |
| 2435 const drive::FileSpecificInfo& file_specific_info = | 2435 const drive::FileSpecificInfo& file_specific_info = |
| 2436 entry->file_specific_info(); | 2436 entry->file_specific_info(); |
| 2437 | 2437 |
| 2438 // Get drive WebApps that can accept this file. | 2438 // Get drive WebApps that can accept this file. |
| 2439 ScopedVector<drive::DriveWebAppInfo> web_apps; | 2439 ScopedVector<drive::DriveAppInfo> drive_apps; |
| 2440 integration_service->webapps_registry()->GetWebAppsForFile( | 2440 integration_service->drive_app_registry()->GetAppsForFile( |
| 2441 file_path_, file_specific_info.content_mime_type(), &web_apps); | 2441 file_path_, file_specific_info.content_mime_type(), &drive_apps); |
| 2442 if (!web_apps.empty()) { | 2442 if (!drive_apps.empty()) { |
| 2443 std::string default_task_id = file_handler_util::GetDefaultTaskIdFromPrefs( | 2443 std::string default_task_id = file_handler_util::GetDefaultTaskIdFromPrefs( |
| 2444 profile_, | 2444 profile_, |
| 2445 file_specific_info.content_mime_type(), | 2445 file_specific_info.content_mime_type(), |
| 2446 file_path_.Extension()); | 2446 file_path_.Extension()); |
| 2447 std::string default_app_id; | 2447 std::string default_app_id; |
| 2448 file_handler_util::CrackTaskID( | 2448 file_handler_util::CrackTaskID( |
| 2449 default_task_id, &default_app_id, NULL, NULL); | 2449 default_task_id, &default_app_id, NULL, NULL); |
| 2450 | 2450 |
| 2451 ListValue* apps = new ListValue(); | 2451 ListValue* apps = new ListValue(); |
| 2452 properties_->Set("driveApps", apps); | 2452 properties_->Set("driveApps", apps); |
| 2453 for (ScopedVector<drive::DriveWebAppInfo>::const_iterator it = | 2453 for (ScopedVector<drive::DriveAppInfo>::const_iterator it = |
| 2454 web_apps.begin(); | 2454 drive_apps.begin(); |
| 2455 it != web_apps.end(); ++it) { | 2455 it != drive_apps.end(); ++it) { |
| 2456 const drive::DriveWebAppInfo* webapp_info = *it; | 2456 const drive::DriveAppInfo* app_info = *it; |
| 2457 DictionaryValue* app = new DictionaryValue(); | 2457 DictionaryValue* app = new DictionaryValue(); |
| 2458 app->SetString("appId", webapp_info->app_id); | 2458 app->SetString("appId", app_info->app_id); |
| 2459 app->SetString("appName", webapp_info->app_name); | 2459 app->SetString("appName", app_info->app_name); |
| 2460 GURL app_icon = FindPreferredIcon(webapp_info->app_icons, | 2460 GURL app_icon = FindPreferredIcon(app_info->app_icons, |
| 2461 kPreferredIconSize); | 2461 kPreferredIconSize); |
| 2462 if (!app_icon.is_empty()) | 2462 if (!app_icon.is_empty()) |
| 2463 app->SetString("appIcon", app_icon.spec()); | 2463 app->SetString("appIcon", app_icon.spec()); |
| 2464 GURL doc_icon = FindPreferredIcon(webapp_info->document_icons, | 2464 GURL doc_icon = FindPreferredIcon(app_info->document_icons, |
| 2465 kPreferredIconSize); | 2465 kPreferredIconSize); |
| 2466 if (!doc_icon.is_empty()) | 2466 if (!doc_icon.is_empty()) |
| 2467 app->SetString("docIcon", doc_icon.spec()); | 2467 app->SetString("docIcon", doc_icon.spec()); |
| 2468 app->SetString("objectType", webapp_info->object_type); | 2468 app->SetString("objectType", app_info->object_type); |
| 2469 app->SetBoolean("isPrimary", default_app_id == webapp_info->app_id); | 2469 app->SetBoolean("isPrimary", default_app_id == app_info->app_id); |
| 2470 apps->Append(app); | 2470 apps->Append(app); |
| 2471 } | 2471 } |
| 2472 } | 2472 } |
| 2473 | 2473 |
| 2474 integration_service->file_system()->GetCacheEntryByResourceId( | 2474 integration_service->file_system()->GetCacheEntryByResourceId( |
| 2475 entry->resource_id(), | 2475 entry->resource_id(), |
| 2476 file_specific_info.file_md5(), | 2476 file_specific_info.file_md5(), |
| 2477 base::Bind(&GetDriveEntryPropertiesFunction::CacheStateReceived, this)); | 2477 base::Bind(&GetDriveEntryPropertiesFunction::CacheStateReceived, this)); |
| 2478 } | 2478 } |
| 2479 | 2479 |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3186 OpenNewWindowFunction::OpenNewWindowFunction() {} | 3186 OpenNewWindowFunction::OpenNewWindowFunction() {} |
| 3187 | 3187 |
| 3188 OpenNewWindowFunction::~OpenNewWindowFunction() {} | 3188 OpenNewWindowFunction::~OpenNewWindowFunction() {} |
| 3189 | 3189 |
| 3190 bool OpenNewWindowFunction::RunImpl() { | 3190 bool OpenNewWindowFunction::RunImpl() { |
| 3191 std::string url; | 3191 std::string url; |
| 3192 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 3192 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
| 3193 file_manager_util::OpenNewWindow(profile_, GURL(url)); | 3193 file_manager_util::OpenNewWindow(profile_, GURL(url)); |
| 3194 return true; | 3194 return true; |
| 3195 } | 3195 } |
| OLD | NEW |