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