| 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/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
| 26 #include "third_party/skia/include/core/SkMatrix.h" | 26 #include "third_party/skia/include/core/SkMatrix.h" |
| 27 #include "third_party/skia/include/core/SkPaint.h" | 27 #include "third_party/skia/include/core/SkPaint.h" |
| 28 #include "third_party/skia/include/core/SkPoint.h" | 28 #include "third_party/skia/include/core/SkPoint.h" |
| 29 #include "third_party/skia/include/core/SkTemplates.h" | 29 #include "third_party/skia/include/core/SkTemplates.h" |
| 30 #include "third_party/skia/include/core/SkTypeface.h" | 30 #include "third_party/skia/include/core/SkTypeface.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 34 #include "ui/gfx/rect.h" | 34 #include "ui/gfx/rect.h" |
| 35 #include "webkit/glue/clipboard_client.h" | |
| 36 #include "webkit/glue/scoped_clipboard_writer_glue.h" | |
| 37 #include "webkit/plugins/ppapi/common.h" | 35 #include "webkit/plugins/ppapi/common.h" |
| 38 #include "webkit/plugins/ppapi/host_globals.h" | 36 #include "webkit/plugins/ppapi/host_globals.h" |
| 39 #include "webkit/plugins/ppapi/plugin_delegate.h" | 37 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 40 #include "webkit/plugins/ppapi/plugin_module.h" | 38 #include "webkit/plugins/ppapi/plugin_module.h" |
| 41 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 39 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 42 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 40 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 43 #include "webkit/plugins/ppapi/resource_helper.h" | 41 #include "webkit/plugins/ppapi/resource_helper.h" |
| 44 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 42 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 45 | 43 |
| 46 using ppapi::PPTimeToTime; | 44 using ppapi::PPTimeToTime; |
| 47 using ppapi::StringVar; | 45 using ppapi::StringVar; |
| 48 using ppapi::TimeToPPTime; | 46 using ppapi::TimeToPPTime; |
| 49 using ppapi::thunk::EnterResource; | 47 using ppapi::thunk::EnterResource; |
| 50 using ppapi::thunk::EnterResourceNoLock; | 48 using ppapi::thunk::EnterResourceNoLock; |
| 51 using ppapi::thunk::PPB_FileRef_API; | 49 using ppapi::thunk::PPB_FileRef_API; |
| 52 using ppapi::thunk::PPB_ImageData_API; | 50 using ppapi::thunk::PPB_ImageData_API; |
| 53 using ppapi::thunk::PPB_URLRequestInfo_API; | 51 using ppapi::thunk::PPB_URLRequestInfo_API; |
| 54 | 52 |
| 55 namespace webkit { | 53 namespace webkit { |
| 56 namespace ppapi { | 54 namespace ppapi { |
| 57 | 55 |
| 58 namespace { | |
| 59 | |
| 60 const size_t kMaxClipboardWriteSize = 1000000; | |
| 61 | |
| 62 ui::Clipboard::Buffer ConvertClipboardType( | |
| 63 PP_Flash_Clipboard_Type type) { | |
| 64 switch (type) { | |
| 65 case PP_FLASH_CLIPBOARD_TYPE_STANDARD: | |
| 66 return ui::Clipboard::BUFFER_STANDARD; | |
| 67 case PP_FLASH_CLIPBOARD_TYPE_SELECTION: | |
| 68 return ui::Clipboard::BUFFER_SELECTION; | |
| 69 } | |
| 70 NOTREACHED(); | |
| 71 return ui::Clipboard::BUFFER_STANDARD; | |
| 72 } | |
| 73 | |
| 74 } // namespace | |
| 75 | |
| 76 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) | 56 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) |
| 77 : instance_(instance) { | 57 : instance_(instance) { |
| 78 } | 58 } |
| 79 | 59 |
| 80 PPB_Flash_Impl::~PPB_Flash_Impl() { | 60 PPB_Flash_Impl::~PPB_Flash_Impl() { |
| 81 } | 61 } |
| 82 | 62 |
| 83 void PPB_Flash_Impl::SetInstanceAlwaysOnTop(PP_Instance instance, | 63 void PPB_Flash_Impl::SetInstanceAlwaysOnTop(PP_Instance instance, |
| 84 PP_Bool on_top) { | 64 PP_Bool on_top) { |
| 85 instance_->set_always_on_top(PP_ToBool(on_top)); | 65 instance_->set_always_on_top(PP_ToBool(on_top)); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 251 } |
| 272 } | 252 } |
| 273 | 253 |
| 274 PP_Bool PPB_Flash_Impl::SetCrashData(PP_Instance instance, | 254 PP_Bool PPB_Flash_Impl::SetCrashData(PP_Instance instance, |
| 275 PP_FlashCrashKey key, | 255 PP_FlashCrashKey key, |
| 276 PP_Var value) { | 256 PP_Var value) { |
| 277 // Not implemented in process. | 257 // Not implemented in process. |
| 278 return PP_FALSE; | 258 return PP_FALSE; |
| 279 } | 259 } |
| 280 | 260 |
| 281 | |
| 282 PP_Bool PPB_Flash_Impl::IsClipboardFormatAvailable( | |
| 283 PP_Instance instance, | |
| 284 PP_Flash_Clipboard_Type clipboard_type, | |
| 285 PP_Flash_Clipboard_Format format) { | |
| 286 if (!InitClipboard()) | |
| 287 return PP_FALSE; | |
| 288 | |
| 289 if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { | |
| 290 NOTIMPLEMENTED(); | |
| 291 return PP_FALSE; | |
| 292 } | |
| 293 | |
| 294 ui::Clipboard::Buffer buffer_type = ConvertClipboardType(clipboard_type); | |
| 295 switch (format) { | |
| 296 case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { | |
| 297 bool plain = clipboard_client_->IsFormatAvailable( | |
| 298 ui::Clipboard::GetPlainTextFormatType(), buffer_type); | |
| 299 bool plainw = clipboard_client_->IsFormatAvailable( | |
| 300 ui::Clipboard::GetPlainTextWFormatType(), buffer_type); | |
| 301 return BoolToPPBool(plain || plainw); | |
| 302 } | |
| 303 case PP_FLASH_CLIPBOARD_FORMAT_HTML: | |
| 304 return BoolToPPBool(clipboard_client_->IsFormatAvailable( | |
| 305 ui::Clipboard::GetHtmlFormatType(), buffer_type)); | |
| 306 case PP_FLASH_CLIPBOARD_FORMAT_RTF: | |
| 307 return BoolToPPBool(clipboard_client_->IsFormatAvailable( | |
| 308 ui::Clipboard::GetRtfFormatType(), buffer_type)); | |
| 309 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: | |
| 310 break; | |
| 311 } | |
| 312 | |
| 313 return PP_FALSE; | |
| 314 } | |
| 315 | |
| 316 PP_Var PPB_Flash_Impl::ReadClipboardData( | |
| 317 PP_Instance instance, | |
| 318 PP_Flash_Clipboard_Type clipboard_type, | |
| 319 PP_Flash_Clipboard_Format format) { | |
| 320 if (!InitClipboard()) | |
| 321 return PP_MakeUndefined(); | |
| 322 | |
| 323 if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { | |
| 324 NOTIMPLEMENTED(); | |
| 325 return PP_MakeUndefined(); | |
| 326 } | |
| 327 | |
| 328 if (!IsClipboardFormatAvailable(instance, clipboard_type, format)) | |
| 329 return PP_MakeNull(); | |
| 330 | |
| 331 ui::Clipboard::Buffer buffer_type = ConvertClipboardType(clipboard_type); | |
| 332 | |
| 333 switch (format) { | |
| 334 case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { | |
| 335 if (clipboard_client_->IsFormatAvailable( | |
| 336 ui::Clipboard::GetPlainTextWFormatType(), buffer_type)) { | |
| 337 string16 text; | |
| 338 clipboard_client_->ReadText(buffer_type, &text); | |
| 339 if (!text.empty()) | |
| 340 return StringVar::StringToPPVar(UTF16ToUTF8(text)); | |
| 341 } | |
| 342 | |
| 343 if (clipboard_client_->IsFormatAvailable( | |
| 344 ui::Clipboard::GetPlainTextFormatType(), buffer_type)) { | |
| 345 std::string text; | |
| 346 clipboard_client_->ReadAsciiText(buffer_type, &text); | |
| 347 if (!text.empty()) | |
| 348 return StringVar::StringToPPVar(text); | |
| 349 } | |
| 350 | |
| 351 return PP_MakeNull(); | |
| 352 } | |
| 353 case PP_FLASH_CLIPBOARD_FORMAT_HTML: { | |
| 354 string16 html; | |
| 355 GURL gurl; | |
| 356 uint32 fragment_start; | |
| 357 uint32 fragment_end; | |
| 358 clipboard_client_->ReadHTML(buffer_type, | |
| 359 &html, | |
| 360 &gurl, | |
| 361 &fragment_start, | |
| 362 &fragment_end); | |
| 363 return StringVar::StringToPPVar(UTF16ToUTF8( | |
| 364 html.substr(fragment_start, fragment_end - fragment_start))); | |
| 365 } | |
| 366 case PP_FLASH_CLIPBOARD_FORMAT_RTF: { | |
| 367 std::string result; | |
| 368 clipboard_client_->ReadRTF(buffer_type, &result); | |
| 369 return ::ppapi::PpapiGlobals::Get()->GetVarTracker()-> | |
| 370 MakeArrayBufferPPVar(result.size(), result.data()); | |
| 371 } | |
| 372 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: | |
| 373 break; | |
| 374 } | |
| 375 | |
| 376 return PP_MakeUndefined(); | |
| 377 } | |
| 378 | |
| 379 int32_t PPB_Flash_Impl::WriteClipboardData( | |
| 380 PP_Instance instance, | |
| 381 PP_Flash_Clipboard_Type clipboard_type, | |
| 382 uint32_t data_item_count, | |
| 383 const PP_Flash_Clipboard_Format formats[], | |
| 384 const PP_Var data_items[]) { | |
| 385 if (!InitClipboard()) | |
| 386 return PP_ERROR_FAILED; | |
| 387 | |
| 388 if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { | |
| 389 NOTIMPLEMENTED(); | |
| 390 return PP_ERROR_FAILED; | |
| 391 } | |
| 392 | |
| 393 if (data_item_count == 0) { | |
| 394 clipboard_client_->Clear(ConvertClipboardType(clipboard_type)); | |
| 395 return PP_OK; | |
| 396 } | |
| 397 ScopedClipboardWriterGlue scw(clipboard_client_.get()); | |
| 398 for (uint32_t i = 0; i < data_item_count; ++i) { | |
| 399 int32_t res = WriteClipboardDataItem(formats[i], data_items[i], &scw); | |
| 400 if (res != PP_OK) { | |
| 401 // Need to clear the objects so nothing is written. | |
| 402 scw.Reset(); | |
| 403 return res; | |
| 404 } | |
| 405 } | |
| 406 | |
| 407 return PP_OK; | |
| 408 } | |
| 409 | |
| 410 bool PPB_Flash_Impl::CreateThreadAdapterForInstance(PP_Instance instance) { | 261 bool PPB_Flash_Impl::CreateThreadAdapterForInstance(PP_Instance instance) { |
| 411 return false; // No multithreaded access allowed. | 262 return false; // No multithreaded access allowed. |
| 412 } | 263 } |
| 413 | 264 |
| 414 void PPB_Flash_Impl::ClearThreadAdapterForInstance(PP_Instance instance) { | 265 void PPB_Flash_Impl::ClearThreadAdapterForInstance(PP_Instance instance) { |
| 415 } | 266 } |
| 416 | 267 |
| 417 int32_t PPB_Flash_Impl::OpenFile(PP_Instance pp_instance, | 268 int32_t PPB_Flash_Impl::OpenFile(PP_Instance pp_instance, |
| 418 const char* path, | 269 const char* path, |
| 419 int32_t mode, | 270 int32_t mode, |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 PP_Bool fullscreen) { | 486 PP_Bool fullscreen) { |
| 636 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true); | 487 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true); |
| 637 return PP_TRUE; | 488 return PP_TRUE; |
| 638 } | 489 } |
| 639 | 490 |
| 640 PP_Bool PPB_Flash_Impl::FlashGetScreenSize(PP_Instance instance, | 491 PP_Bool PPB_Flash_Impl::FlashGetScreenSize(PP_Instance instance, |
| 641 PP_Size* size) { | 492 PP_Size* size) { |
| 642 return instance_->GetScreenSize(instance, size); | 493 return instance_->GetScreenSize(instance, size); |
| 643 } | 494 } |
| 644 | 495 |
| 645 bool PPB_Flash_Impl::InitClipboard() { | |
| 646 // Initialize the ClipboardClient for writing to the clipboard. | |
| 647 if (!clipboard_client_.get()) { | |
| 648 if (!instance_) | |
| 649 return false; | |
| 650 PluginDelegate* plugin_delegate = instance_->delegate(); | |
| 651 if (!plugin_delegate) | |
| 652 return false; | |
| 653 clipboard_client_.reset(plugin_delegate->CreateClipboardClient()); | |
| 654 } | |
| 655 return true; | |
| 656 } | |
| 657 | |
| 658 int32_t PPB_Flash_Impl::WriteClipboardDataItem( | |
| 659 const PP_Flash_Clipboard_Format format, | |
| 660 const PP_Var& data, | |
| 661 ScopedClipboardWriterGlue* scw) { | |
| 662 switch (format) { | |
| 663 case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { | |
| 664 StringVar* text_string = StringVar::FromPPVar(data); | |
| 665 if (!text_string) | |
| 666 return PP_ERROR_BADARGUMENT; | |
| 667 | |
| 668 if (text_string->value().length() > kMaxClipboardWriteSize) | |
| 669 return PP_ERROR_NOSPACE; | |
| 670 | |
| 671 scw->WriteText(UTF8ToUTF16(text_string->value())); | |
| 672 return PP_OK; | |
| 673 } | |
| 674 case PP_FLASH_CLIPBOARD_FORMAT_HTML: { | |
| 675 StringVar* text_string = StringVar::FromPPVar(data); | |
| 676 if (!text_string) | |
| 677 return PP_ERROR_BADARGUMENT; | |
| 678 | |
| 679 if (text_string->value().length() > kMaxClipboardWriteSize) | |
| 680 return PP_ERROR_NOSPACE; | |
| 681 | |
| 682 scw->WriteHTML(UTF8ToUTF16(text_string->value()), ""); | |
| 683 return PP_OK; | |
| 684 } | |
| 685 case PP_FLASH_CLIPBOARD_FORMAT_RTF: { | |
| 686 ::ppapi::ArrayBufferVar* rtf_data = | |
| 687 ::ppapi::ArrayBufferVar::FromPPVar(data); | |
| 688 if (!rtf_data) | |
| 689 return PP_ERROR_BADARGUMENT; | |
| 690 | |
| 691 if (rtf_data->ByteLength() > kMaxClipboardWriteSize) | |
| 692 return PP_ERROR_NOSPACE; | |
| 693 | |
| 694 scw->WriteRTF(std::string(static_cast<char*>(rtf_data->Map()), | |
| 695 rtf_data->ByteLength())); | |
| 696 return PP_OK; | |
| 697 } | |
| 698 case PP_FLASH_CLIPBOARD_FORMAT_INVALID: | |
| 699 break; | |
| 700 } | |
| 701 | |
| 702 return PP_ERROR_BADARGUMENT; | |
| 703 } | |
| 704 | |
| 705 } // namespace ppapi | 496 } // namespace ppapi |
| 706 } // namespace webkit | 497 } // namespace webkit |
| OLD | NEW |