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_manager/file_handler_util.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/file_handler_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 const char kTaskDrive[] = "drive"; | 55 const char kTaskDrive[] = "drive"; |
| 56 const char kTaskApp[] = "app"; | 56 const char kTaskApp[] = "app"; |
| 57 | 57 |
| 58 namespace { | 58 namespace { |
| 59 | 59 |
| 60 // Legacy Drive task extension prefix, used by CrackTaskID. | 60 // Legacy Drive task extension prefix, used by CrackTaskID. |
| 61 const char kDriveTaskExtensionPrefix[] = "drive-app:"; | 61 const char kDriveTaskExtensionPrefix[] = "drive-app:"; |
| 62 const size_t kDriveTaskExtensionPrefixLength = | 62 const size_t kDriveTaskExtensionPrefixLength = |
| 63 arraysize(kDriveTaskExtensionPrefix) - 1; | 63 arraysize(kDriveTaskExtensionPrefix) - 1; |
| 64 | 64 |
| 65 const int kReadWriteFilePermissions = base::PLATFORM_FILE_OPEN | | |
| 66 base::PLATFORM_FILE_CREATE | | |
| 67 base::PLATFORM_FILE_OPEN_ALWAYS | | |
| 68 base::PLATFORM_FILE_CREATE_ALWAYS | | |
| 69 base::PLATFORM_FILE_OPEN_TRUNCATED | | |
| 70 base::PLATFORM_FILE_READ | | |
| 71 base::PLATFORM_FILE_WRITE | | |
| 72 base::PLATFORM_FILE_EXCLUSIVE_READ | | |
| 73 base::PLATFORM_FILE_EXCLUSIVE_WRITE | | |
| 74 base::PLATFORM_FILE_ASYNC | | |
| 75 base::PLATFORM_FILE_WRITE_ATTRIBUTES; | |
| 76 | |
| 77 const int kReadOnlyFilePermissions = base::PLATFORM_FILE_OPEN | | |
| 78 base::PLATFORM_FILE_READ | | |
| 79 base::PLATFORM_FILE_EXCLUSIVE_READ | | |
| 80 base::PLATFORM_FILE_ASYNC; | |
| 81 | |
| 82 // Returns process id of the process the extension is running in. | 65 // Returns process id of the process the extension is running in. |
| 83 int ExtractProcessFromExtensionId(Profile* profile, | 66 int ExtractProcessFromExtensionId(Profile* profile, |
| 84 const std::string& extension_id) { | 67 const std::string& extension_id) { |
| 85 GURL extension_url = | 68 GURL extension_url = |
| 86 Extension::GetBaseURLFromExtensionId(extension_id); | 69 Extension::GetBaseURLFromExtensionId(extension_id); |
| 87 ExtensionProcessManager* manager = | 70 ExtensionProcessManager* manager = |
| 88 extensions::ExtensionSystem::Get(profile)->process_manager(); | 71 extensions::ExtensionSystem::Get(profile)->process_manager(); |
| 89 | 72 |
| 90 SiteInstance* site_instance = manager->GetSiteInstanceForURL(extension_url); | 73 SiteInstance* site_instance = manager->GetSiteInstanceForURL(extension_url); |
| 91 if (!site_instance || !site_instance->HasProcess()) | 74 if (!site_instance || !site_instance->HasProcess()) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 102 for (FileBrowserHandler::List::const_iterator action_iter = | 85 for (FileBrowserHandler::List::const_iterator action_iter = |
| 103 handler_list->begin(); | 86 handler_list->begin(); |
| 104 action_iter != handler_list->end(); | 87 action_iter != handler_list->end(); |
| 105 ++action_iter) { | 88 ++action_iter) { |
| 106 if (action_iter->get()->id() == action_id) | 89 if (action_iter->get()->id() == action_id) |
| 107 return action_iter->get(); | 90 return action_iter->get(); |
| 108 } | 91 } |
| 109 return NULL; | 92 return NULL; |
| 110 } | 93 } |
| 111 | 94 |
| 112 unsigned int GetAccessPermissionsForFileBrowserHandler( | |
| 113 const Extension* extension, | |
| 114 const std::string& action_id) { | |
| 115 const FileBrowserHandler* action = | |
| 116 FindFileBrowserHandler(extension, action_id); | |
| 117 if (!action) | |
| 118 return 0; | |
| 119 unsigned int result = 0; | |
| 120 if (action->CanRead()) | |
| 121 result |= kReadOnlyFilePermissions; | |
| 122 if (action->CanWrite()) | |
| 123 result |= kReadWriteFilePermissions; | |
| 124 // TODO(tbarzic): We don't handle Create yet. | |
| 125 return result; | |
| 126 } | |
| 127 | |
| 128 std::string EscapedUtf8ToLower(const std::string& str) { | 95 std::string EscapedUtf8ToLower(const std::string& str) { |
| 129 string16 utf16 = UTF8ToUTF16( | 96 string16 utf16 = UTF8ToUTF16( |
| 130 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL)); | 97 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL)); |
| 131 return net::EscapeUrlEncodedData( | 98 return net::EscapeUrlEncodedData( |
| 132 UTF16ToUTF8(base::i18n::ToLower(utf16)), | 99 UTF16ToUTF8(base::i18n::ToLower(utf16)), |
| 133 false /* do not replace space with plus */); | 100 false /* do not replace space with plus */); |
| 134 } | 101 } |
| 135 | 102 |
| 136 bool GetFileBrowserHandlers(Profile* profile, | 103 bool GetFileBrowserHandlers(Profile* profile, |
| 137 const GURL& selected_file_url, | 104 const GURL& selected_file_url, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 profile->GetPrefs()->GetDictionary(prefs::kDefaultTasksBySuffix); | 230 profile->GetPrefs()->GetDictionary(prefs::kDefaultTasksBySuffix); |
| 264 DCHECK(suffix_task_prefs); | 231 DCHECK(suffix_task_prefs); |
| 265 LOG_IF(ERROR, !suffix_task_prefs) << "Unable to open suffix prefs"; | 232 LOG_IF(ERROR, !suffix_task_prefs) << "Unable to open suffix prefs"; |
| 266 std::string lower_suffix = StringToLowerASCII(suffix); | 233 std::string lower_suffix = StringToLowerASCII(suffix); |
| 267 if (suffix_task_prefs) | 234 if (suffix_task_prefs) |
| 268 suffix_task_prefs->GetStringWithoutPathExpansion(lower_suffix, &task_id); | 235 suffix_task_prefs->GetStringWithoutPathExpansion(lower_suffix, &task_id); |
| 269 VLOG_IF(1, !task_id.empty()) << "Found suffix default handler: " << task_id; | 236 VLOG_IF(1, !task_id.empty()) << "Found suffix default handler: " << task_id; |
| 270 return task_id; | 237 return task_id; |
| 271 } | 238 } |
| 272 | 239 |
| 273 int GetReadWritePermissions() { | |
| 274 return kReadWriteFilePermissions; | |
| 275 } | |
| 276 | |
| 277 int GetReadOnlyPermissions() { | |
| 278 return kReadOnlyFilePermissions; | |
| 279 } | |
| 280 | |
| 281 std::string MakeTaskID(const std::string& extension_id, | 240 std::string MakeTaskID(const std::string& extension_id, |
| 282 const std::string& task_type, | 241 const std::string& task_type, |
| 283 const std::string& action_id) { | 242 const std::string& action_id) { |
| 284 DCHECK(task_type == kTaskFile || | 243 DCHECK(task_type == kTaskFile || |
| 285 task_type == kTaskDrive || | 244 task_type == kTaskDrive || |
| 286 task_type == kTaskApp); | 245 task_type == kTaskApp); |
| 287 return base::StringPrintf("%s|%s|%s", | 246 return base::StringPrintf("%s|%s|%s", |
| 288 extension_id.c_str(), | 247 extension_id.c_str(), |
| 289 task_type.c_str(), | 248 task_type.c_str(), |
| 290 action_id.c_str()); | 249 action_id.c_str()); |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 event->restrict_to_profile = profile_; | 833 event->restrict_to_profile = profile_; |
| 875 event_router->DispatchEventToExtension(extension_->id(), event.Pass()); | 834 event_router->DispatchEventToExtension(extension_->id(), event.Pass()); |
| 876 | 835 |
| 877 ExecuteDoneOnUIThread(true); | 836 ExecuteDoneOnUIThread(true); |
| 878 } | 837 } |
| 879 | 838 |
| 880 void ExtensionTaskExecutor::SetupHandlerHostFileAccessPermissions( | 839 void ExtensionTaskExecutor::SetupHandlerHostFileAccessPermissions( |
| 881 const FileDefinitionList& file_list, | 840 const FileDefinitionList& file_list, |
| 882 const Extension* extension, | 841 const Extension* extension, |
| 883 int handler_pid) { | 842 int handler_pid) { |
| 843 const FileBrowserHandler* action = FindFileBrowserHandler(extension_, | |
| 844 action_id_); | |
| 884 for (FileDefinitionList::const_iterator iter = file_list.begin(); | 845 for (FileDefinitionList::const_iterator iter = file_list.begin(); |
| 885 iter != file_list.end(); | 846 iter != file_list.end(); |
| 886 ++iter) { | 847 ++iter) { |
| 887 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( | 848 if (!action) |
| 888 handler_pid, | 849 continue; |
| 889 iter->absolute_path, | 850 if (action->CanRead()) { |
| 890 GetAccessPermissionsForFileBrowserHandler(extension_, action_id_)); | 851 content::ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( |
|
vandebo (ex-Chrome)
2013/06/27 22:35:17
read is a subset of readwrite, so we really only n
Greg Billock
2013/06/28 18:40:33
I saw this, but decided to preserve the calls sinc
| |
| 852 handler_pid, iter->absolute_path); | |
| 853 } | |
| 854 if (action->CanWrite()) { | |
| 855 content::ChildProcessSecurityPolicy::GetInstance()->GrantReadWriteFile( | |
| 856 handler_pid, iter->absolute_path); | |
| 857 } | |
| 891 } | 858 } |
| 892 } | 859 } |
| 893 | 860 |
| 894 } // namespace file_handler_util | 861 } // namespace file_handler_util |
| OLD | NEW |