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 "webkit/plugins/ppapi/ppb_flash_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_flash_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
| 10 #include "base/time.h" |
| 11 #include "base/utf_string_conversions.h" |
10 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
11 #include "ppapi/c/dev/ppb_font_dev.h" | 13 #include "ppapi/c/dev/ppb_font_dev.h" |
12 #include "ppapi/c/private/ppb_flash.h" | 14 #include "ppapi/c/private/ppb_flash.h" |
| 15 #include "ppapi/shared_impl/file_path.h" |
| 16 #include "ppapi/shared_impl/file_type_conversion.h" |
13 #include "ppapi/shared_impl/time_conversion.h" | 17 #include "ppapi/shared_impl/time_conversion.h" |
14 #include "ppapi/shared_impl/var.h" | 18 #include "ppapi/shared_impl/var.h" |
15 #include "ppapi/thunk/enter.h" | 19 #include "ppapi/thunk/enter.h" |
| 20 #include "ppapi/thunk/ppb_file_ref_api.h" |
16 #include "ppapi/thunk/ppb_image_data_api.h" | 21 #include "ppapi/thunk/ppb_image_data_api.h" |
17 #include "ppapi/thunk/ppb_url_request_info_api.h" | 22 #include "ppapi/thunk/ppb_url_request_info_api.h" |
18 #include "skia/ext/platform_canvas.h" | 23 #include "skia/ext/platform_canvas.h" |
19 #include "third_party/skia/include/core/SkCanvas.h" | 24 #include "third_party/skia/include/core/SkCanvas.h" |
20 #include "third_party/skia/include/core/SkMatrix.h" | 25 #include "third_party/skia/include/core/SkMatrix.h" |
21 #include "third_party/skia/include/core/SkPaint.h" | 26 #include "third_party/skia/include/core/SkPaint.h" |
22 #include "third_party/skia/include/core/SkPoint.h" | 27 #include "third_party/skia/include/core/SkPoint.h" |
23 #include "third_party/skia/include/core/SkTemplates.h" | 28 #include "third_party/skia/include/core/SkTemplates.h" |
24 #include "third_party/skia/include/core/SkTypeface.h" | 29 #include "third_party/skia/include/core/SkTypeface.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
28 #include "ui/gfx/rect.h" | 33 #include "ui/gfx/rect.h" |
29 #include "webkit/plugins/ppapi/common.h" | 34 #include "webkit/plugins/ppapi/common.h" |
30 #include "webkit/plugins/ppapi/host_globals.h" | 35 #include "webkit/plugins/ppapi/host_globals.h" |
31 #include "webkit/plugins/ppapi/plugin_delegate.h" | 36 #include "webkit/plugins/ppapi/plugin_delegate.h" |
32 #include "webkit/plugins/ppapi/plugin_module.h" | 37 #include "webkit/plugins/ppapi/plugin_module.h" |
33 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 38 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 39 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
34 #include "webkit/plugins/ppapi/resource_helper.h" | 40 #include "webkit/plugins/ppapi/resource_helper.h" |
35 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 41 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
36 | 42 |
37 using ppapi::PPTimeToTime; | 43 using ppapi::PPTimeToTime; |
38 using ppapi::StringVar; | 44 using ppapi::StringVar; |
| 45 using ppapi::TimeToPPTime; |
| 46 using ppapi::thunk::EnterResource; |
39 using ppapi::thunk::EnterResourceNoLock; | 47 using ppapi::thunk::EnterResourceNoLock; |
| 48 using ppapi::thunk::PPB_FileRef_API; |
40 using ppapi::thunk::PPB_ImageData_API; | 49 using ppapi::thunk::PPB_ImageData_API; |
41 using ppapi::thunk::PPB_URLRequestInfo_API; | 50 using ppapi::thunk::PPB_URLRequestInfo_API; |
42 | 51 |
43 namespace webkit { | 52 namespace webkit { |
44 namespace ppapi { | 53 namespace ppapi { |
45 | 54 |
46 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) | 55 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) |
47 : instance_(instance) { | 56 : instance_(instance) { |
48 } | 57 } |
49 | 58 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 instance_->delegate()->GetLocalDataRestrictions( | 206 instance_->delegate()->GetLocalDataRestrictions( |
198 instance_->container()->element().document().url(), | 207 instance_->container()->element().document().url(), |
199 instance_->plugin_url())); | 208 instance_->plugin_url())); |
200 } | 209 } |
201 default: | 210 default: |
202 // No other settings are supported in-process. | 211 // No other settings are supported in-process. |
203 return PP_MakeUndefined(); | 212 return PP_MakeUndefined(); |
204 } | 213 } |
205 } | 214 } |
206 | 215 |
| 216 bool PPB_Flash_Impl::CreateThreadAdapterForInstance(PP_Instance instance) { |
| 217 return false; // No multithreaded access allowed. |
| 218 } |
| 219 |
| 220 void PPB_Flash_Impl::ClearThreadAdapterForInstance(PP_Instance instance) { |
| 221 } |
| 222 |
| 223 int32_t PPB_Flash_Impl::OpenFile(PP_Instance pp_instance, |
| 224 const char* path, |
| 225 int32_t mode, |
| 226 PP_FileHandle* file) { |
| 227 int flags = 0; |
| 228 if (!path || |
| 229 !::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || |
| 230 !file) |
| 231 return PP_ERROR_BADARGUMENT; |
| 232 |
| 233 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 234 if (!instance) |
| 235 return PP_ERROR_FAILED; |
| 236 |
| 237 base::PlatformFile base_file; |
| 238 base::PlatformFileError result = instance->delegate()->OpenFile( |
| 239 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 240 instance->module()->name(), path), |
| 241 flags, |
| 242 &base_file); |
| 243 *file = base_file; |
| 244 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 245 } |
| 246 |
| 247 int32_t PPB_Flash_Impl::RenameFile(PP_Instance pp_instance, |
| 248 const char* path_from, |
| 249 const char* path_to) { |
| 250 if (!path_from || !path_to) |
| 251 return PP_ERROR_BADARGUMENT; |
| 252 |
| 253 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 254 if (!instance) |
| 255 return PP_ERROR_FAILED; |
| 256 |
| 257 base::PlatformFileError result = instance->delegate()->RenameFile( |
| 258 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 259 instance->module()->name(), path_from), |
| 260 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 261 instance->module()->name(), path_to)); |
| 262 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 263 } |
| 264 |
| 265 int32_t PPB_Flash_Impl::DeleteFileOrDir(PP_Instance pp_instance, |
| 266 const char* path, |
| 267 PP_Bool recursive) { |
| 268 if (!path) |
| 269 return PP_ERROR_BADARGUMENT; |
| 270 |
| 271 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 272 if (!instance) |
| 273 return PP_ERROR_FAILED; |
| 274 |
| 275 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( |
| 276 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 277 instance->module()->name(), path), |
| 278 PPBoolToBool(recursive)); |
| 279 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 280 } |
| 281 |
| 282 int32_t PPB_Flash_Impl::CreateDir(PP_Instance pp_instance, const char* path) { |
| 283 if (!path) |
| 284 return PP_ERROR_BADARGUMENT; |
| 285 |
| 286 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 287 if (!instance) |
| 288 return PP_ERROR_FAILED; |
| 289 |
| 290 base::PlatformFileError result = instance->delegate()->CreateDir( |
| 291 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 292 instance->module()->name(), path)); |
| 293 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 294 } |
| 295 |
| 296 int32_t PPB_Flash_Impl::QueryFile(PP_Instance pp_instance, |
| 297 const char* path, |
| 298 PP_FileInfo* info) { |
| 299 if (!path || !info) |
| 300 return PP_ERROR_BADARGUMENT; |
| 301 |
| 302 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 303 if (!instance) |
| 304 return PP_ERROR_FAILED; |
| 305 |
| 306 base::PlatformFileInfo file_info; |
| 307 base::PlatformFileError result = instance->delegate()->QueryFile( |
| 308 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 309 instance->module()->name(), path), |
| 310 &file_info); |
| 311 if (result == base::PLATFORM_FILE_OK) { |
| 312 info->size = file_info.size; |
| 313 info->creation_time = TimeToPPTime(file_info.creation_time); |
| 314 info->last_access_time = TimeToPPTime(file_info.last_accessed); |
| 315 info->last_modified_time = TimeToPPTime(file_info.last_modified); |
| 316 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; |
| 317 if (file_info.is_directory) |
| 318 info->type = PP_FILETYPE_DIRECTORY; |
| 319 else |
| 320 info->type = PP_FILETYPE_REGULAR; |
| 321 } |
| 322 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 323 } |
| 324 |
| 325 int32_t PPB_Flash_Impl::GetDirContents(PP_Instance pp_instance, |
| 326 const char* path, |
| 327 PP_DirContents_Dev** contents) { |
| 328 if (!path || !contents) |
| 329 return PP_ERROR_BADARGUMENT; |
| 330 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 331 if (!instance) |
| 332 return PP_ERROR_FAILED; |
| 333 |
| 334 *contents = NULL; |
| 335 ::ppapi::DirContents pepper_contents; |
| 336 base::PlatformFileError result = instance->delegate()->GetDirContents( |
| 337 ::ppapi::PepperFilePath::MakeModuleLocal( |
| 338 instance->module()->name(), path), |
| 339 &pepper_contents); |
| 340 |
| 341 if (result != base::PLATFORM_FILE_OK) |
| 342 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 343 |
| 344 *contents = new PP_DirContents_Dev; |
| 345 size_t count = pepper_contents.size(); |
| 346 (*contents)->count = count; |
| 347 (*contents)->entries = new PP_DirEntry_Dev[count]; |
| 348 for (size_t i = 0; i < count; ++i) { |
| 349 PP_DirEntry_Dev& entry = (*contents)->entries[i]; |
| 350 #if defined(OS_WIN) |
| 351 const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value()); |
| 352 #else |
| 353 const std::string& name = pepper_contents[i].name.value(); |
| 354 #endif |
| 355 size_t size = name.size() + 1; |
| 356 char* name_copy = new char[size]; |
| 357 memcpy(name_copy, name.c_str(), size); |
| 358 entry.name = name_copy; |
| 359 entry.is_dir = BoolToPPBool(pepper_contents[i].is_dir); |
| 360 } |
| 361 return PP_OK; |
| 362 } |
| 363 |
| 364 int32_t PPB_Flash_Impl::CreateTemporaryFile(PP_Instance instance, |
| 365 PP_FileHandle* file) { |
| 366 if (!file) |
| 367 return PP_ERROR_BADARGUMENT; |
| 368 |
| 369 PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance); |
| 370 if (!plugin_instance) { |
| 371 *file = PP_kInvalidFileHandle; |
| 372 return PP_ERROR_FAILED; |
| 373 } |
| 374 |
| 375 base::PlatformFileError result = |
| 376 plugin_instance->delegate()->CreateTemporaryFile(file); |
| 377 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 378 } |
| 379 |
| 380 int32_t PPB_Flash_Impl::OpenFileRef(PP_Instance pp_instance, |
| 381 PP_Resource file_ref_id, |
| 382 int32_t mode, |
| 383 PP_FileHandle* file) { |
| 384 int flags = 0; |
| 385 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file) |
| 386 return PP_ERROR_BADARGUMENT; |
| 387 |
| 388 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_id, true); |
| 389 if (enter.failed()) |
| 390 return PP_ERROR_BADRESOURCE; |
| 391 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); |
| 392 |
| 393 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 394 if (!instance) |
| 395 return PP_ERROR_FAILED; |
| 396 |
| 397 base::PlatformFile base_file; |
| 398 base::PlatformFileError result = instance->delegate()->OpenFile( |
| 399 ::ppapi::PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| 400 flags, |
| 401 &base_file); |
| 402 *file = base_file; |
| 403 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 404 } |
| 405 |
| 406 int32_t PPB_Flash_Impl::QueryFileRef(PP_Instance pp_instance, |
| 407 PP_Resource file_ref_id, |
| 408 PP_FileInfo* info) { |
| 409 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); |
| 410 if (enter.failed()) |
| 411 return PP_ERROR_BADRESOURCE; |
| 412 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); |
| 413 |
| 414 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 415 if (!instance) |
| 416 return PP_ERROR_FAILED; |
| 417 |
| 418 base::PlatformFileInfo file_info; |
| 419 base::PlatformFileError result = instance->delegate()->QueryFile( |
| 420 ::ppapi::PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), |
| 421 &file_info); |
| 422 if (result == base::PLATFORM_FILE_OK) { |
| 423 info->size = file_info.size; |
| 424 info->creation_time = TimeToPPTime(file_info.creation_time); |
| 425 info->last_access_time = TimeToPPTime(file_info.last_accessed); |
| 426 info->last_modified_time = TimeToPPTime(file_info.last_modified); |
| 427 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; |
| 428 if (file_info.is_directory) |
| 429 info->type = PP_FILETYPE_DIRECTORY; |
| 430 else |
| 431 info->type = PP_FILETYPE_REGULAR; |
| 432 } |
| 433 return ::ppapi::PlatformFileErrorToPepperError(result); |
| 434 } |
| 435 |
207 } // namespace ppapi | 436 } // namespace ppapi |
208 } // namespace webkit | 437 } // namespace webkit |
OLD | NEW |