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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 1030533002: Add a whitelist for chrome.fileSystem.requestFileSystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed ids. Created 5 years, 9 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/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "apps/saved_files_service.h" 9 #include "apps/saved_files_service.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "ui/shell_dialogs/selected_file_info.h" 53 #include "ui/shell_dialogs/selected_file_info.h"
54 54
55 #if defined(OS_MACOSX) 55 #if defined(OS_MACOSX)
56 #include <CoreFoundation/CoreFoundation.h> 56 #include <CoreFoundation/CoreFoundation.h>
57 #include "base/mac/foundation_util.h" 57 #include "base/mac/foundation_util.h"
58 #endif 58 #endif
59 59
60 #if defined(OS_CHROMEOS) 60 #if defined(OS_CHROMEOS)
61 #include "base/thread_task_runner_handle.h" 61 #include "base/thread_task_runner_handle.h"
62 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 62 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
63 #include "chrome/browser/chromeos/file_manager/app_id.h"
63 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" 64 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
64 #include "chrome/browser/chromeos/file_manager/volume_manager.h" 65 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
65 #include "components/user_manager/user_manager.h" 66 #include "components/user_manager/user_manager.h"
66 #include "extensions/common/constants.h" 67 #include "extensions/common/constants.h"
67 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" 68 #include "extensions/common/manifest_handlers/kiosk_mode_info.h"
68 #include "url/url_constants.h" 69 #include "url/url_constants.h"
69 #endif 70 #endif
70 71
71 using apps::SavedFileEntry; 72 using apps::SavedFileEntry;
72 using apps::SavedFilesService; 73 using apps::SavedFilesService;
(...skipping 12 matching lines...) Expand all
85 const char kUnknownIdError[] = "Unknown id"; 86 const char kUnknownIdError[] = "Unknown id";
86 87
87 #if !defined(OS_CHROMEOS) 88 #if !defined(OS_CHROMEOS)
88 const char kNotSupportedOnCurrentPlatformError[] = 89 const char kNotSupportedOnCurrentPlatformError[] =
89 "Operation not supported on the current platform."; 90 "Operation not supported on the current platform.";
90 #else 91 #else
91 const char kNotSupportedOnNonKioskSessionError[] = 92 const char kNotSupportedOnNonKioskSessionError[] =
92 "Operation only supported for kiosk apps running in a kiosk session."; 93 "Operation only supported for kiosk apps running in a kiosk session.";
93 const char kVolumeNotFoundError[] = "Volume not found."; 94 const char kVolumeNotFoundError[] = "Volume not found.";
94 const char kSecurityError[] = "Security error."; 95 const char kSecurityError[] = "Security error.";
96
97 // List of whitelisted component apps and extensions by their ids for
98 // chrome.fileSystem.requestFileSystem.
99 const char* const kRequestFileSystemComponentWhitelist[] = {
100 file_manager::kFileManagerAppId,
101 file_manager::kVideoPlayerAppId,
102 file_manager::kGalleryAppId,
103 file_manager::kAudioPlayerAppId,
104 file_manager::kImageLoaderExtensionId,
105 "pkplfbidichfdicaijlchgnapepdginl" // Testing extensions.
106 };
95 #endif 107 #endif
96 108
97 namespace file_system = extensions::api::file_system; 109 namespace file_system = extensions::api::file_system;
98 namespace ChooseEntry = file_system::ChooseEntry; 110 namespace ChooseEntry = file_system::ChooseEntry;
99 111
100 namespace { 112 namespace {
101 113
102 bool g_skip_picker_for_test = false; 114 bool g_skip_picker_for_test = false;
103 bool g_use_suggested_path_for_test = false; 115 bool g_use_suggested_path_for_test = false;
104 base::FilePath* g_path_to_be_picked_for_test; 116 base::FilePath* g_path_to_be_picked_for_test;
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() { 1029 ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() {
1018 using extensions::api::file_system::RequestFileSystem::Params; 1030 using extensions::api::file_system::RequestFileSystem::Params;
1019 const scoped_ptr<Params> params(Params::Create(*args_)); 1031 const scoped_ptr<Params> params(Params::Create(*args_));
1020 EXTENSION_FUNCTION_VALIDATE(params); 1032 EXTENSION_FUNCTION_VALIDATE(params);
1021 1033
1022 #if !defined(OS_CHROMEOS) 1034 #if !defined(OS_CHROMEOS)
1023 NOTIMPLEMENTED(); 1035 NOTIMPLEMENTED();
1024 return RespondNow(Error(kNotSupportedOnCurrentPlatformError)); 1036 return RespondNow(Error(kNotSupportedOnCurrentPlatformError));
1025 1037
1026 #else 1038 #else
1027 // Only kiosk apps in kiosk sessions can use this API. Additionally component 1039 // Only kiosk apps in kiosk sessions can use this API.
1028 // extensions and apps, which is not documented though. 1040 // Additionally whitelisted component extensions and apps.
1041 bool is_whitelisted_component = false;
1042 if (extension()->location() == Manifest::COMPONENT) {
1043 for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist) {
1044 if (extension_id().compare(whitelisted_id) == 0) {
1045 is_whitelisted_component = true;
1046 break;
1047 }
1048 }
1049 }
1029 if ((!user_manager::UserManager::Get()->IsLoggedInAsKioskApp() || 1050 if ((!user_manager::UserManager::Get()->IsLoggedInAsKioskApp() ||
1030 !KioskModeInfo::IsKioskEnabled(extension())) && 1051 !KioskModeInfo::IsKioskEnabled(extension())) &&
1031 extension()->location() != Manifest::COMPONENT) { 1052 !is_whitelisted_component) {
1032 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); 1053 return RespondNow(Error(kNotSupportedOnNonKioskSessionError));
1033 } 1054 }
1034 1055
1035 using file_manager::VolumeManager; 1056 using file_manager::VolumeManager;
1036 using file_manager::VolumeInfo; 1057 using file_manager::VolumeInfo;
1037 VolumeManager* const volume_manager = 1058 VolumeManager* const volume_manager =
1038 VolumeManager::Get(chrome_details_.GetProfile()); 1059 VolumeManager::Get(chrome_details_.GetProfile());
1039 DCHECK(volume_manager); 1060 DCHECK(volume_manager);
1040 1061
1041 const bool writable = 1062 const bool writable =
(...skipping 22 matching lines...) Expand all
1064 if (!backend->GetVirtualPath(volume_info.mount_path, &virtual_path)) 1085 if (!backend->GetVirtualPath(volume_info.mount_path, &virtual_path))
1065 return RespondNow(Error(kSecurityError)); 1086 return RespondNow(Error(kSecurityError));
1066 1087
1067 if (writable && (volume_info.is_read_only)) 1088 if (writable && (volume_info.is_read_only))
1068 return RespondNow(Error(kSecurityError)); 1089 return RespondNow(Error(kSecurityError));
1069 1090
1070 chromeos::KioskAppManager::App app_info; 1091 chromeos::KioskAppManager::App app_info;
1071 const bool is_auto_launched = 1092 const bool is_auto_launched =
1072 chromeos::KioskAppManager::Get()->GetApp(extension_id(), &app_info) && 1093 chromeos::KioskAppManager::Get()->GetApp(extension_id(), &app_info) &&
1073 app_info.was_auto_launched_with_zero_delay; 1094 app_info.was_auto_launched_with_zero_delay;
1074 const bool requires_consent = 1095 const bool requires_consent = !is_auto_launched && !is_whitelisted_component;
1075 !is_auto_launched && extension()->location() != Manifest::COMPONENT;
1076 1096
1077 if (!requires_consent) { 1097 if (!requires_consent) {
1078 // Grant the permission without showing the dialog. 1098 // Grant the permission without showing the dialog.
1079 base::ThreadTaskRunnerHandle::Get()->PostTask( 1099 base::ThreadTaskRunnerHandle::Get()->PostTask(
1080 FROM_HERE, 1100 FROM_HERE,
1081 base::Bind(&FileSystemRequestFileSystemFunction::OnConsentReceived, 1101 base::Bind(&FileSystemRequestFileSystemFunction::OnConsentReceived,
1082 this, volume_info.volume_id, writable, true /* granted */)); 1102 this, volume_info.volume_id, writable, true /* granted */));
1083 } else { 1103 } else {
1084 // TODO(mtomasz): Create a better display name, which is the most meaningful 1104 // TODO(mtomasz): Create a better display name, which is the most meaningful
1085 // to the user. 1105 // to the user.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 base::DictionaryValue* const dict = new base::DictionaryValue(); 1226 base::DictionaryValue* const dict = new base::DictionaryValue();
1207 dict->SetString("file_system_id", file_system_id); 1227 dict->SetString("file_system_id", file_system_id);
1208 dict->SetString("file_system_path", register_name); 1228 dict->SetString("file_system_path", register_name);
1209 1229
1210 SetResult(dict); 1230 SetResult(dict);
1211 SendResponse(true); 1231 SendResponse(true);
1212 } 1232 }
1213 #endif 1233 #endif
1214 1234
1215 } // namespace extensions 1235 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/app_id.h ('k') | chrome/common/extensions/api/_permission_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698