OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 PluginModule* module, | 193 PluginModule* module, |
194 const void* ppp_instance_if_0_5) { | 194 const void* ppp_instance_if_0_5) { |
195 const PPP_Instance_0_5* interface = | 195 const PPP_Instance_0_5* interface = |
196 static_cast<const PPP_Instance_0_5*>(ppp_instance_if_0_5); | 196 static_cast<const PPP_Instance_0_5*>(ppp_instance_if_0_5); |
197 return new PluginInstance( | 197 return new PluginInstance( |
198 delegate, | 198 delegate, |
199 module, | 199 module, |
200 new ::ppapi::PPP_Instance_Combined(*interface)); | 200 new ::ppapi::PPP_Instance_Combined(*interface)); |
201 } | 201 } |
202 | 202 |
| 203 // static |
| 204 PluginInstance* PluginInstance::Create1_0(PluginDelegate* delegate, |
| 205 PluginModule* module, |
| 206 const void* ppp_instance_if_1_0) { |
| 207 const PPP_Instance_1_0* interface = |
| 208 static_cast<const PPP_Instance_1_0*>(ppp_instance_if_1_0); |
| 209 return new PluginInstance( |
| 210 delegate, |
| 211 module, |
| 212 new ::ppapi::PPP_Instance_Combined(*interface)); |
| 213 } |
| 214 |
203 PluginInstance::PluginInstance( | 215 PluginInstance::PluginInstance( |
204 PluginDelegate* delegate, | 216 PluginDelegate* delegate, |
205 PluginModule* module, | 217 PluginModule* module, |
206 ::ppapi::PPP_Instance_Combined* instance_interface) | 218 ::ppapi::PPP_Instance_Combined* instance_interface) |
207 : delegate_(delegate), | 219 : delegate_(delegate), |
208 module_(module), | 220 module_(module), |
209 instance_interface_(instance_interface), | 221 instance_interface_(instance_interface), |
210 pp_instance_(0), | 222 pp_instance_(0), |
211 container_(NULL), | 223 container_(NULL), |
212 full_frame_(false), | 224 full_frame_(false), |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 424 |
413 size_t argc = 0; | 425 size_t argc = 0; |
414 scoped_array<const char*> argn(new const char*[arg_names.size()]); | 426 scoped_array<const char*> argn(new const char*[arg_names.size()]); |
415 scoped_array<const char*> argv(new const char*[arg_names.size()]); | 427 scoped_array<const char*> argv(new const char*[arg_names.size()]); |
416 for (size_t i = 0; i < arg_names.size(); ++i) { | 428 for (size_t i = 0; i < arg_names.size(); ++i) { |
417 argn[argc] = arg_names[i].c_str(); | 429 argn[argc] = arg_names[i].c_str(); |
418 argv[argc] = arg_values[i].c_str(); | 430 argv[argc] = arg_values[i].c_str(); |
419 argc++; | 431 argc++; |
420 } | 432 } |
421 | 433 |
422 return PPBoolToBool(instance_interface_->DidCreate(pp_instance(), | 434 return PP_ToBool(instance_interface_->DidCreate(pp_instance(), |
423 argc, | 435 argc, |
424 argn.get(), | 436 argn.get(), |
425 argv.get())); | 437 argv.get())); |
426 } | 438 } |
427 | 439 |
428 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { | 440 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { |
429 Resource::ScopedResourceId resource(loader); | 441 Resource::ScopedResourceId resource(loader); |
430 return PPBoolToBool(instance_interface_->HandleDocumentLoad(pp_instance(), | 442 return PP_ToBool(instance_interface_->HandleDocumentLoad(pp_instance(), |
431 resource.id)); | 443 resource.id)); |
432 } | 444 } |
433 | 445 |
434 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, | 446 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, |
435 WebCursorInfo* cursor_info) { | 447 WebCursorInfo* cursor_info) { |
436 // Keep a reference on the stack. See NOTE above. | 448 // Keep a reference on the stack. See NOTE above. |
437 scoped_refptr<PluginInstance> ref(this); | 449 scoped_refptr<PluginInstance> ref(this); |
438 | 450 |
439 bool rv = false; | 451 bool rv = false; |
440 if (LoadInputEventInterface()) { | 452 if (LoadInputEventInterface()) { |
441 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); | 453 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); |
(...skipping 10 matching lines...) Expand all Loading... |
452 ResourceTracker* tracker = ResourceTracker::Get(); | 464 ResourceTracker* tracker = ResourceTracker::Get(); |
453 for (size_t i = 0; i < events.size(); i++) { | 465 for (size_t i = 0; i < events.size(); i++) { |
454 if (filtered_input_event_mask_ & event_class) | 466 if (filtered_input_event_mask_ & event_class) |
455 events[i].is_filtered = true; | 467 events[i].is_filtered = true; |
456 else | 468 else |
457 rv = true; // Unfiltered events are assumed to be handled. | 469 rv = true; // Unfiltered events are assumed to be handled. |
458 scoped_refptr<PPB_InputEvent_Impl> event_resource( | 470 scoped_refptr<PPB_InputEvent_Impl> event_resource( |
459 new PPB_InputEvent_Impl(this, events[i])); | 471 new PPB_InputEvent_Impl(this, events[i])); |
460 PP_Resource resource = event_resource->GetReference(); | 472 PP_Resource resource = event_resource->GetReference(); |
461 | 473 |
462 rv |= PPBoolToBool(plugin_input_event_interface_->HandleInputEvent( | 474 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent( |
463 pp_instance(), event_resource->GetReference())); | 475 pp_instance(), event_resource->GetReference())); |
464 | 476 |
465 // Release the reference we took above. | 477 // Release the reference we took above. |
466 tracker->UnrefResource(resource); | 478 tracker->UnrefResource(resource); |
467 } | 479 } |
468 } | 480 } |
469 } | 481 } |
470 | 482 |
471 // For compatibility, also send all input events through the old interface. | 483 // For compatibility, also send all input events through the old interface, |
| 484 // if it exists. |
472 // TODO(brettw) remove this. | 485 // TODO(brettw) remove this. |
473 std::vector<PP_InputEvent> pp_events; | 486 if (instance_interface_->HandleInputEvent_0_5) { |
474 CreatePPEvent(event, &pp_events); | 487 std::vector<PP_InputEvent> pp_events; |
| 488 CreatePPEvent(event, &pp_events); |
475 | 489 |
476 // Each input event may generate more than one PP_InputEvent. | 490 // Each input event may generate more than one PP_InputEvent. |
477 for (size_t i = 0; i < pp_events.size(); i++) { | 491 for (size_t i = 0; i < pp_events.size(); i++) { |
478 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(), | 492 rv |= PP_ToBool( |
479 &pp_events[i])); | 493 instance_interface_->HandleInputEvent_0_5(pp_instance(), |
| 494 &pp_events[i])); |
| 495 } |
480 } | 496 } |
481 | 497 |
482 if (cursor_.get()) | 498 if (cursor_.get()) |
483 *cursor_info = *cursor_; | 499 *cursor_info = *cursor_; |
484 return rv; | 500 return rv; |
485 } | 501 } |
486 | 502 |
487 void PluginInstance::HandleMessage(PP_Var message) { | 503 void PluginInstance::HandleMessage(PP_Var message) { |
488 // Keep a reference on the stack. See NOTE above. | 504 // Keep a reference on the stack. See NOTE above. |
489 scoped_refptr<PluginInstance> ref(this); | 505 scoped_refptr<PluginInstance> ref(this); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 | 542 |
527 void PluginInstance::SetWebKitFocus(bool has_focus) { | 543 void PluginInstance::SetWebKitFocus(bool has_focus) { |
528 if (has_webkit_focus_ == has_focus) | 544 if (has_webkit_focus_ == has_focus) |
529 return; | 545 return; |
530 | 546 |
531 bool old_plugin_focus = PluginHasFocus(); | 547 bool old_plugin_focus = PluginHasFocus(); |
532 has_webkit_focus_ = has_focus; | 548 has_webkit_focus_ = has_focus; |
533 if (PluginHasFocus() != old_plugin_focus) { | 549 if (PluginHasFocus() != old_plugin_focus) { |
534 delegate()->PluginFocusChanged(PluginHasFocus()); | 550 delegate()->PluginFocusChanged(PluginHasFocus()); |
535 instance_interface_->DidChangeFocus(pp_instance(), | 551 instance_interface_->DidChangeFocus(pp_instance(), |
536 BoolToPPBool(PluginHasFocus())); | 552 PP_FromBool(PluginHasFocus())); |
537 } | 553 } |
538 } | 554 } |
539 | 555 |
540 void PluginInstance::SetContentAreaFocus(bool has_focus) { | 556 void PluginInstance::SetContentAreaFocus(bool has_focus) { |
541 if (has_content_area_focus_ == has_focus) | 557 if (has_content_area_focus_ == has_focus) |
542 return; | 558 return; |
543 | 559 |
544 bool old_plugin_focus = PluginHasFocus(); | 560 bool old_plugin_focus = PluginHasFocus(); |
545 has_content_area_focus_ = has_focus; | 561 has_content_area_focus_ = has_focus; |
546 if (PluginHasFocus() != old_plugin_focus) { | 562 if (PluginHasFocus() != old_plugin_focus) { |
547 instance_interface_->DidChangeFocus(pp_instance(), | 563 instance_interface_->DidChangeFocus(pp_instance(), |
548 BoolToPPBool(PluginHasFocus())); | 564 PP_FromBool(PluginHasFocus())); |
549 } | 565 } |
550 } | 566 } |
551 | 567 |
552 void PluginInstance::ViewInitiatedPaint() { | 568 void PluginInstance::ViewInitiatedPaint() { |
553 if (GetBoundGraphics2D()) | 569 if (GetBoundGraphics2D()) |
554 GetBoundGraphics2D()->ViewInitiatedPaint(); | 570 GetBoundGraphics2D()->ViewInitiatedPaint(); |
555 else if (GetBoundGraphics3D()) | 571 else if (GetBoundGraphics3D()) |
556 GetBoundGraphics3D()->ViewInitiatedPaint(); | 572 GetBoundGraphics3D()->ViewInitiatedPaint(); |
557 else if (GetBoundSurface3D()) | 573 else if (GetBoundSurface3D()) |
558 GetBoundSurface3D()->ViewInitiatedPaint(); | 574 GetBoundSurface3D()->ViewInitiatedPaint(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 return true; | 614 return true; |
599 } | 615 } |
600 | 616 |
601 string16 PluginInstance::GetSelectedText(bool html) { | 617 string16 PluginInstance::GetSelectedText(bool html) { |
602 // Keep a reference on the stack. See NOTE above. | 618 // Keep a reference on the stack. See NOTE above. |
603 scoped_refptr<PluginInstance> ref(this); | 619 scoped_refptr<PluginInstance> ref(this); |
604 if (!LoadSelectionInterface()) | 620 if (!LoadSelectionInterface()) |
605 return string16(); | 621 return string16(); |
606 | 622 |
607 PP_Var rv = plugin_selection_interface_->GetSelectedText(pp_instance(), | 623 PP_Var rv = plugin_selection_interface_->GetSelectedText(pp_instance(), |
608 BoolToPPBool(html)); | 624 PP_FromBool(html)); |
609 scoped_refptr<StringVar> string(StringVar::FromPPVar(rv)); | 625 scoped_refptr<StringVar> string(StringVar::FromPPVar(rv)); |
610 Var::PluginReleasePPVar(rv); // Release the ref the plugin transfered to us. | 626 Var::PluginReleasePPVar(rv); // Release the ref the plugin transfered to us. |
611 if (!string) | 627 if (!string) |
612 return string16(); | 628 return string16(); |
613 return UTF8ToUTF16(string->value()); | 629 return UTF8ToUTF16(string->value()); |
614 } | 630 } |
615 | 631 |
616 string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) { | 632 string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) { |
617 // Keep a reference on the stack. See NOTE above. | 633 // Keep a reference on the stack. See NOTE above. |
618 scoped_refptr<PluginInstance> ref(this); | 634 scoped_refptr<PluginInstance> ref(this); |
619 if (!LoadPdfInterface()) | 635 if (!LoadPdfInterface()) |
620 return string16(); | 636 return string16(); |
621 | 637 |
622 PP_Point p; | 638 PP_Point p; |
623 p.x = point.x(); | 639 p.x = point.x(); |
624 p.y = point.y(); | 640 p.y = point.y(); |
625 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); | 641 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); |
626 scoped_refptr<StringVar> string(StringVar::FromPPVar(rv)); | 642 scoped_refptr<StringVar> string(StringVar::FromPPVar(rv)); |
627 Var::PluginReleasePPVar(rv); // Release the ref the plugin transfered to us. | 643 Var::PluginReleasePPVar(rv); // Release the ref the plugin transfered to us. |
628 if (!string) | 644 if (!string) |
629 return string16(); | 645 return string16(); |
630 return UTF8ToUTF16(string->value()); | 646 return UTF8ToUTF16(string->value()); |
631 } | 647 } |
632 | 648 |
633 void PluginInstance::Zoom(double factor, bool text_only) { | 649 void PluginInstance::Zoom(double factor, bool text_only) { |
634 // Keep a reference on the stack. See NOTE above. | 650 // Keep a reference on the stack. See NOTE above. |
635 scoped_refptr<PluginInstance> ref(this); | 651 scoped_refptr<PluginInstance> ref(this); |
636 if (!LoadZoomInterface()) | 652 if (!LoadZoomInterface()) |
637 return; | 653 return; |
638 plugin_zoom_interface_->Zoom(pp_instance(), factor, BoolToPPBool(text_only)); | 654 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); |
639 } | 655 } |
640 | 656 |
641 bool PluginInstance::StartFind(const string16& search_text, | 657 bool PluginInstance::StartFind(const string16& search_text, |
642 bool case_sensitive, | 658 bool case_sensitive, |
643 int identifier) { | 659 int identifier) { |
644 // Keep a reference on the stack. See NOTE above. | 660 // Keep a reference on the stack. See NOTE above. |
645 scoped_refptr<PluginInstance> ref(this); | 661 scoped_refptr<PluginInstance> ref(this); |
646 if (!LoadFindInterface()) | 662 if (!LoadFindInterface()) |
647 return false; | 663 return false; |
648 find_identifier_ = identifier; | 664 find_identifier_ = identifier; |
649 return PPBoolToBool( | 665 return PP_ToBool( |
650 plugin_find_interface_->StartFind( | 666 plugin_find_interface_->StartFind( |
651 pp_instance(), | 667 pp_instance(), |
652 UTF16ToUTF8(search_text.c_str()).c_str(), | 668 UTF16ToUTF8(search_text.c_str()).c_str(), |
653 BoolToPPBool(case_sensitive))); | 669 PP_FromBool(case_sensitive))); |
654 } | 670 } |
655 | 671 |
656 void PluginInstance::SelectFindResult(bool forward) { | 672 void PluginInstance::SelectFindResult(bool forward) { |
657 // Keep a reference on the stack. See NOTE above. | 673 // Keep a reference on the stack. See NOTE above. |
658 scoped_refptr<PluginInstance> ref(this); | 674 scoped_refptr<PluginInstance> ref(this); |
659 if (LoadFindInterface()) | 675 if (LoadFindInterface()) |
660 plugin_find_interface_->SelectFindResult(pp_instance(), | 676 plugin_find_interface_->SelectFindResult(pp_instance(), |
661 BoolToPPBool(forward)); | 677 PP_FromBool(forward)); |
662 } | 678 } |
663 | 679 |
664 void PluginInstance::StopFind() { | 680 void PluginInstance::StopFind() { |
665 // Keep a reference on the stack. See NOTE above. | 681 // Keep a reference on the stack. See NOTE above. |
666 scoped_refptr<PluginInstance> ref(this); | 682 scoped_refptr<PluginInstance> ref(this); |
667 if (!LoadFindInterface()) | 683 if (!LoadFindInterface()) |
668 return; | 684 return; |
669 find_identifier_ = -1; | 685 find_identifier_ = -1; |
670 plugin_find_interface_->StopFind(pp_instance()); | 686 plugin_find_interface_->StopFind(pp_instance()); |
671 } | 687 } |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 } | 1511 } |
1496 | 1512 |
1497 PP_Bool PluginInstance::IsFullscreen(PP_Instance instance) { | 1513 PP_Bool PluginInstance::IsFullscreen(PP_Instance instance) { |
1498 return PP_FromBool(fullscreen_); | 1514 return PP_FromBool(fullscreen_); |
1499 } | 1515 } |
1500 | 1516 |
1501 PP_Bool PluginInstance::SetFullscreen(PP_Instance instance, | 1517 PP_Bool PluginInstance::SetFullscreen(PP_Instance instance, |
1502 PP_Bool fullscreen) { | 1518 PP_Bool fullscreen) { |
1503 // TODO(yzshen): Re-enable it once fullscreen mode is supported on Windows. | 1519 // TODO(yzshen): Re-enable it once fullscreen mode is supported on Windows. |
1504 #if !defined(OS_WIN) | 1520 #if !defined(OS_WIN) |
1505 SetFullscreen(PPBoolToBool(fullscreen), true); | 1521 SetFullscreen(PP_ToBool(fullscreen), true); |
1506 return PP_TRUE; | 1522 return PP_TRUE; |
1507 #else | 1523 #else |
1508 return PP_FALSE; | 1524 return PP_FALSE; |
1509 #endif | 1525 #endif |
1510 } | 1526 } |
1511 | 1527 |
1512 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { | 1528 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { |
1513 gfx::Size screen_size = delegate()->GetScreenSize(); | 1529 gfx::Size screen_size = delegate()->GetScreenSize(); |
1514 *size = PP_MakeSize(screen_size.width(), screen_size.height()); | 1530 *size = PP_MakeSize(screen_size.width(), screen_size.height()); |
1515 return PP_TRUE; | 1531 return PP_TRUE; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 } | 1586 } |
1571 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); | 1587 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); |
1572 } | 1588 } |
1573 | 1589 |
1574 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) { | 1590 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) { |
1575 message_channel_->PostMessageToJavaScript(message); | 1591 message_channel_->PostMessageToJavaScript(message); |
1576 } | 1592 } |
1577 | 1593 |
1578 } // namespace ppapi | 1594 } // namespace ppapi |
1579 } // namespace webkit | 1595 } // namespace webkit |
OLD | NEW |