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