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 "content/ppapi_plugin/ppapi_thread.h" | 5 #include "content/ppapi_plugin/ppapi_thread.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "content/common/child_process.h" | 14 #include "content/common/child_process.h" |
| 15 #include "content/common/child_process_messages.h" | 15 #include "content/common/child_process_messages.h" |
| 16 #include "content/common/pepper_file_messages.h" | |
| 16 #include "content/ppapi_plugin/broker_process_dispatcher.h" | 17 #include "content/ppapi_plugin/broker_process_dispatcher.h" |
| 17 #include "content/ppapi_plugin/plugin_process_dispatcher.h" | 18 #include "content/ppapi_plugin/plugin_process_dispatcher.h" |
| 18 #include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" | 19 #include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" |
| 19 #include "content/public/common/sandbox_init.h" | 20 #include "content/public/common/sandbox_init.h" |
| 20 #include "ipc/ipc_channel_handle.h" | 21 #include "ipc/ipc_channel_handle.h" |
| 21 #include "ipc/ipc_platform_file.h" | 22 #include "ipc/ipc_platform_file.h" |
| 22 #include "ipc/ipc_sync_channel.h" | 23 #include "ipc/ipc_sync_channel.h" |
| 23 #include "ppapi/c/dev/ppp_network_state_dev.h" | 24 #include "ppapi/c/dev/ppp_network_state_dev.h" |
| 24 #include "ppapi/c/pp_errors.h" | 25 #include "ppapi/c/pp_errors.h" |
| 25 #include "ppapi/c/ppp.h" | 26 #include "ppapi/c/ppp.h" |
| 26 #include "ppapi/proxy/plugin_globals.h" | 27 #include "ppapi/proxy/plugin_globals.h" |
| 27 #include "ppapi/proxy/ppapi_messages.h" | 28 #include "ppapi/proxy/ppapi_messages.h" |
| 28 #include "ppapi/proxy/interface_list.h" | 29 #include "ppapi/proxy/interface_list.h" |
| 30 #include "ppapi/shared_impl/file_type_conversion.h" | |
| 31 #include "ppapi/shared_impl/time_conversion.h" | |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 30 #include "webkit/plugins/plugin_switches.h" | 33 #include "webkit/plugins/plugin_switches.h" |
| 31 | 34 |
| 32 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 33 #include "sandbox/src/sandbox.h" | 36 #include "sandbox/src/sandbox.h" |
| 34 #elif defined(OS_MACOSX) | 37 #elif defined(OS_MACOSX) |
| 35 #include "content/common/sandbox_init_mac.h" | 38 #include "content/common/sandbox_init_mac.h" |
| 36 #endif | 39 #endif |
| 37 | 40 |
| 38 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 return Send(msg); | 160 return Send(msg); |
| 158 } | 161 } |
| 159 | 162 |
| 160 void PpapiThread::PreCacheFont(const void* logfontw) { | 163 void PpapiThread::PreCacheFont(const void* logfontw) { |
| 161 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
| 162 Send(new ChildProcessHostMsg_PreCacheFont( | 165 Send(new ChildProcessHostMsg_PreCacheFont( |
| 163 *static_cast<const LOGFONTW*>(logfontw))); | 166 *static_cast<const LOGFONTW*>(logfontw))); |
| 164 #endif | 167 #endif |
| 165 } | 168 } |
| 166 | 169 |
| 170 int32_t PpapiThread::SendOpenFileRequestToBrowser(const char* path, | |
| 171 int32_t mode, | |
| 172 PP_FileHandle* file) { | |
| 173 int flags = 0; | |
| 174 if (!path || | |
| 175 !ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || | |
| 176 !file) | |
| 177 return PP_ERROR_BADARGUMENT; | |
| 178 | |
| 179 base::PlatformFileError error; | |
| 180 IPC::PlatformFileForTransit transit_file; | |
| 181 webkit::ppapi::PepperFilePath pepper_path( | |
| 182 webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 183 FilePath::FromUTF8Unsafe(path)); | |
| 184 | |
| 185 if (Send(new PepperFileMsg_OpenFile(pepper_path, flags, | |
| 186 &error, &transit_file))) { | |
| 187 *file = IPC::PlatformFileForTransitToPlatformFile(transit_file); | |
| 188 } else { | |
| 189 *file = base::kInvalidPlatformFileValue; | |
| 190 error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 191 } | |
| 192 | |
| 193 return ppapi::PlatformFileErrorToPepperError(error); | |
| 194 } | |
| 195 | |
| 196 int32_t PpapiThread::SendRenameFileRequestToBrowser(const char* from_path, | |
| 197 const char* to_path) { | |
| 198 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 199 webkit::ppapi::PepperFilePath pepper_from( | |
| 200 webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 201 FilePath::FromUTF8Unsafe(from_path)); | |
| 202 webkit::ppapi::PepperFilePath pepper_to( | |
| 203 webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 204 FilePath::FromUTF8Unsafe(to_path)); | |
| 205 | |
| 206 Send(new PepperFileMsg_RenameFile(pepper_from, pepper_to, &error)); | |
| 207 return ppapi::PlatformFileErrorToPepperError(error); | |
| 208 } | |
| 209 | |
| 210 int32_t PpapiThread::SendDeleteFileOrDirRequestToBrowser(const char* path, | |
| 211 PP_Bool recursive) { | |
| 212 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
|
brettw
2012/05/29 18:14:15
Is it possible to put all of this message construc
| |
| 213 webkit::ppapi::PepperFilePath pepper_path( | |
| 214 webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 215 FilePath::FromUTF8Unsafe(path)); | |
| 216 | |
| 217 Send(new PepperFileMsg_DeleteFileOrDir( | |
| 218 pepper_path, PP_ToBool(recursive), &error)); | |
| 219 | |
| 220 return ppapi::PlatformFileErrorToPepperError(error); | |
| 221 } | |
| 222 | |
| 223 int32_t PpapiThread::SendCreateDirRequestToBrowser(const char* path) { | |
| 224 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 225 webkit::ppapi::PepperFilePath pepper_path( | |
| 226 webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 227 FilePath::FromUTF8Unsafe(path)); | |
| 228 | |
| 229 Send(new PepperFileMsg_CreateDir(pepper_path, &error)); | |
| 230 return ppapi::PlatformFileErrorToPepperError(error); | |
| 231 } | |
| 232 | |
| 233 int32_t PpapiThread::SendQueryFileRequestToBrowser(const char* path, | |
| 234 PP_FileInfo* info) { | |
| 235 base::PlatformFileInfo file_info; | |
| 236 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 237 webkit::ppapi::PepperFilePath pepper_path( | |
| 238 webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 239 FilePath::FromUTF8Unsafe(path)); | |
| 240 | |
| 241 Send(new PepperFileMsg_QueryFile(pepper_path, &file_info, &error)); | |
| 242 | |
| 243 if (error == base::PLATFORM_FILE_OK) { | |
| 244 info->size = file_info.size; | |
| 245 info->creation_time = ppapi::TimeToPPTime(file_info.creation_time); | |
| 246 info->last_access_time = ppapi::TimeToPPTime(file_info.last_accessed); | |
| 247 info->last_modified_time = ppapi::TimeToPPTime(file_info.last_modified); | |
| 248 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
| 249 if (file_info.is_directory) | |
| 250 info->type = PP_FILETYPE_DIRECTORY; | |
| 251 else | |
| 252 info->type = PP_FILETYPE_REGULAR; | |
| 253 } | |
| 254 | |
| 255 return ppapi::PlatformFileErrorToPepperError(error); | |
| 256 } | |
| 257 | |
| 258 int32_t PpapiThread::SendGetDirContentsRequestToBrowser( | |
| 259 const char* path, | |
| 260 PP_DirContents_Dev** contents) { | |
| 261 webkit::ppapi::DirContents entries; | |
| 262 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | |
| 263 webkit::ppapi::PepperFilePath pepper_path( | |
| 264 webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL, | |
| 265 FilePath::FromUTF8Unsafe(path)); | |
| 266 | |
| 267 Send(new PepperFileMsg_GetDirContents(pepper_path, &entries, &error)); | |
| 268 | |
| 269 if (error == base::PLATFORM_FILE_OK) { | |
| 270 // Copy the serialized dir entries to the output struct. | |
| 271 *contents = new PP_DirContents_Dev; | |
| 272 (*contents)->count = static_cast<int32_t>(entries.size()); | |
| 273 (*contents)->entries = new PP_DirEntry_Dev[entries.size()]; | |
| 274 for (size_t i = 0; i < entries.size(); i++) { | |
| 275 const webkit::ppapi::DirEntry& source = entries[i]; | |
| 276 PP_DirEntry_Dev* dest = &(*contents)->entries[i]; | |
| 277 std::string name = source.name.AsUTF8Unsafe(); | |
| 278 char* name_copy = new char[name.size() + 1]; | |
| 279 memcpy(name_copy, name.c_str(), name.size() + 1); | |
| 280 dest->name = name_copy; | |
| 281 dest->is_dir = PP_FromBool(source.is_dir); | |
| 282 } | |
| 283 } | |
| 284 | |
| 285 return ppapi::PlatformFileErrorToPepperError(error); | |
| 286 } | |
| 287 | |
| 167 uint32 PpapiThread::Register(ppapi::proxy::PluginDispatcher* plugin_dispatcher) { | 288 uint32 PpapiThread::Register(ppapi::proxy::PluginDispatcher* plugin_dispatcher) { |
| 168 if (!plugin_dispatcher || | 289 if (!plugin_dispatcher || |
| 169 plugin_dispatchers_.size() >= std::numeric_limits<uint32>::max()) { | 290 plugin_dispatchers_.size() >= std::numeric_limits<uint32>::max()) { |
| 170 return 0; | 291 return 0; |
| 171 } | 292 } |
| 172 | 293 |
| 173 uint32 id = 0; | 294 uint32 id = 0; |
| 174 do { | 295 do { |
| 175 // Although it is unlikely, make sure that we won't cause any trouble when | 296 // Although it is unlikely, make sure that we won't cause any trouble when |
| 176 // the counter overflows. | 297 // the counter overflows. |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 | 470 |
| 350 // From here, the dispatcher will manage its own lifetime according to the | 471 // From here, the dispatcher will manage its own lifetime according to the |
| 351 // lifetime of the attached channel. | 472 // lifetime of the attached channel. |
| 352 return true; | 473 return true; |
| 353 } | 474 } |
| 354 | 475 |
| 355 void PpapiThread::SavePluginName(const FilePath& path) { | 476 void PpapiThread::SavePluginName(const FilePath& path) { |
| 356 ppapi::proxy::PluginGlobals::Get()->set_plugin_name( | 477 ppapi::proxy::PluginGlobals::Get()->set_plugin_name( |
| 357 path.BaseName().AsUTF8Unsafe()); | 478 path.BaseName().AsUTF8Unsafe()); |
| 358 } | 479 } |
| OLD | NEW |