| 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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "ppapi/c/dev/ppb_find_dev.h" | 12 #include "ppapi/c/dev/ppb_find_dev.h" |
| 13 #include "ppapi/c/dev/ppb_fullscreen_dev.h" | 13 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
| 14 #include "ppapi/c/dev/ppb_zoom_dev.h" | 14 #include "ppapi/c/dev/ppb_zoom_dev.h" |
| 15 #include "ppapi/c/dev/ppp_find_dev.h" | 15 #include "ppapi/c/dev/ppp_find_dev.h" |
| 16 #include "ppapi/c/dev/ppp_selection_dev.h" | 16 #include "ppapi/c/dev/ppp_selection_dev.h" |
| 17 #include "ppapi/c/dev/ppp_zoom_dev.h" | 17 #include "ppapi/c/dev/ppp_zoom_dev.h" |
| 18 #include "ppapi/c/pp_input_event.h" | 18 #include "ppapi/c/pp_input_event.h" |
| 19 #include "ppapi/c/pp_instance.h" | 19 #include "ppapi/c/pp_instance.h" |
| 20 #include "ppapi/c/pp_rect.h" | 20 #include "ppapi/c/pp_rect.h" |
| 21 #include "ppapi/c/pp_resource.h" | 21 #include "ppapi/c/pp_resource.h" |
| 22 #include "ppapi/c/pp_var.h" | 22 #include "ppapi/c/pp_var.h" |
| 23 #include "ppapi/c/ppb_core.h" | 23 #include "ppapi/c/ppb_core.h" |
| 24 #include "ppapi/c/ppb_instance.h" | 24 #include "ppapi/c/ppb_instance.h" |
| 25 #include "ppapi/c/ppb_messaging.h" | 25 #include "ppapi/c/ppb_messaging.h" |
| 26 #include "ppapi/c/ppp_input_event.h" |
| 26 #include "ppapi/c/ppp_instance.h" | 27 #include "ppapi/c/ppp_instance.h" |
| 27 #include "ppapi/c/ppp_messaging.h" | 28 #include "ppapi/c/ppp_messaging.h" |
| 28 #include "ppapi/c/private/ppb_instance_private.h" | 29 #include "ppapi/c/private/ppb_instance_private.h" |
| 29 #include "ppapi/c/private/ppp_instance_private.h" | 30 #include "ppapi/c/private/ppp_instance_private.h" |
| 30 #include "ppapi/thunk/enter.h" | 31 #include "ppapi/thunk/enter.h" |
| 31 #include "ppapi/thunk/ppb_buffer_api.h" | 32 #include "ppapi/thunk/ppb_buffer_api.h" |
| 32 #include "printing/units.h" | 33 #include "printing/units.h" |
| 33 #include "skia/ext/platform_canvas.h" | 34 #include "skia/ext/platform_canvas.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 48 #include "webkit/plugins/ppapi/common.h" | 49 #include "webkit/plugins/ppapi/common.h" |
| 49 #include "webkit/plugins/ppapi/event_conversion.h" | 50 #include "webkit/plugins/ppapi/event_conversion.h" |
| 50 #include "webkit/plugins/ppapi/fullscreen_container.h" | 51 #include "webkit/plugins/ppapi/fullscreen_container.h" |
| 51 #include "webkit/plugins/ppapi/message_channel.h" | 52 #include "webkit/plugins/ppapi/message_channel.h" |
| 52 #include "webkit/plugins/ppapi/plugin_delegate.h" | 53 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 53 #include "webkit/plugins/ppapi/plugin_module.h" | 54 #include "webkit/plugins/ppapi/plugin_module.h" |
| 54 #include "webkit/plugins/ppapi/plugin_object.h" | 55 #include "webkit/plugins/ppapi/plugin_object.h" |
| 55 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 56 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
| 56 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | 57 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
| 57 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 58 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 59 #include "webkit/plugins/ppapi/ppb_input_event_impl.h" |
| 58 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" | 60 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" |
| 59 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" | 61 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" |
| 60 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" | 62 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" |
| 61 #include "webkit/plugins/ppapi/ppp_pdf.h" | 63 #include "webkit/plugins/ppapi/ppp_pdf.h" |
| 62 #include "webkit/plugins/ppapi/string.h" | 64 #include "webkit/plugins/ppapi/string.h" |
| 63 #include "webkit/plugins/ppapi/var.h" | 65 #include "webkit/plugins/ppapi/var.h" |
| 64 #include "webkit/plugins/sad_plugin.h" | 66 #include "webkit/plugins/sad_plugin.h" |
| 65 | 67 |
| 66 #if defined(OS_MACOSX) | 68 #if defined(OS_MACOSX) |
| 67 #include "base/mac/mac_util.h" | 69 #include "base/mac/mac_util.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 module_(module), | 271 module_(module), |
| 270 instance_interface_(instance_interface), | 272 instance_interface_(instance_interface), |
| 271 pp_instance_(0), | 273 pp_instance_(0), |
| 272 container_(NULL), | 274 container_(NULL), |
| 273 full_frame_(false), | 275 full_frame_(false), |
| 274 has_webkit_focus_(false), | 276 has_webkit_focus_(false), |
| 275 has_content_area_focus_(false), | 277 has_content_area_focus_(false), |
| 276 find_identifier_(-1), | 278 find_identifier_(-1), |
| 277 plugin_find_interface_(NULL), | 279 plugin_find_interface_(NULL), |
| 278 plugin_messaging_interface_(NULL), | 280 plugin_messaging_interface_(NULL), |
| 281 plugin_input_event_interface_(NULL), |
| 282 plugin_private_interface_(NULL), |
| 279 plugin_pdf_interface_(NULL), | 283 plugin_pdf_interface_(NULL), |
| 280 plugin_private_interface_(NULL), | |
| 281 plugin_selection_interface_(NULL), | 284 plugin_selection_interface_(NULL), |
| 282 plugin_zoom_interface_(NULL), | 285 plugin_zoom_interface_(NULL), |
| 286 checked_for_plugin_input_event_interface_(false), |
| 283 checked_for_plugin_messaging_interface_(false), | 287 checked_for_plugin_messaging_interface_(false), |
| 284 plugin_print_interface_(NULL), | 288 plugin_print_interface_(NULL), |
| 285 plugin_graphics_3d_interface_(NULL), | 289 plugin_graphics_3d_interface_(NULL), |
| 286 always_on_top_(false), | 290 always_on_top_(false), |
| 287 fullscreen_container_(NULL), | 291 fullscreen_container_(NULL), |
| 288 fullscreen_(false), | 292 fullscreen_(false), |
| 289 message_channel_(NULL), | 293 message_channel_(NULL), |
| 290 sad_plugin_(NULL) { | 294 sad_plugin_(NULL), |
| 295 input_event_mask_(0), |
| 296 filtered_input_event_mask_(0) { |
| 291 pp_instance_ = ResourceTracker::Get()->AddInstance(this); | 297 pp_instance_ = ResourceTracker::Get()->AddInstance(this); |
| 292 | 298 |
| 293 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 299 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 294 DCHECK(delegate); | 300 DCHECK(delegate); |
| 295 module_->InstanceCreated(this); | 301 module_->InstanceCreated(this); |
| 296 delegate_->InstanceCreated(this); | 302 delegate_->InstanceCreated(this); |
| 297 message_channel_.reset(new MessageChannel(this)); | 303 message_channel_.reset(new MessageChannel(this)); |
| 298 } | 304 } |
| 299 | 305 |
| 300 PluginInstance::~PluginInstance() { | 306 PluginInstance::~PluginInstance() { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { | 503 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { |
| 498 Resource::ScopedResourceId resource(loader); | 504 Resource::ScopedResourceId resource(loader); |
| 499 return PPBoolToBool(instance_interface_->HandleDocumentLoad(pp_instance(), | 505 return PPBoolToBool(instance_interface_->HandleDocumentLoad(pp_instance(), |
| 500 resource.id)); | 506 resource.id)); |
| 501 } | 507 } |
| 502 | 508 |
| 503 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, | 509 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, |
| 504 WebCursorInfo* cursor_info) { | 510 WebCursorInfo* cursor_info) { |
| 505 // Keep a reference on the stack. See NOTE above. | 511 // Keep a reference on the stack. See NOTE above. |
| 506 scoped_refptr<PluginInstance> ref(this); | 512 scoped_refptr<PluginInstance> ref(this); |
| 513 |
| 514 bool rv = false; |
| 515 if (LoadInputEventInterface()) { |
| 516 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); |
| 517 if (!event_class) |
| 518 return false; |
| 519 |
| 520 if ((filtered_input_event_mask_ & event_class) || |
| 521 (input_event_mask_ & event_class)) { |
| 522 // Actually send the event. |
| 523 std::vector< ::ppapi::InputEventData > events; |
| 524 CreateInputEventData(event, &events); |
| 525 |
| 526 // Each input event may generate more than one PP_InputEvent. |
| 527 ResourceTracker* tracker = ResourceTracker::Get(); |
| 528 for (size_t i = 0; i < events.size(); i++) { |
| 529 if (filtered_input_event_mask_ & event_class) |
| 530 events[i].is_filtered = true; |
| 531 scoped_refptr<PPB_InputEvent_Impl> event_resource( |
| 532 new PPB_InputEvent_Impl(this, events[i])); |
| 533 PP_Resource resource = event_resource->GetReference(); |
| 534 |
| 535 rv |= PPBoolToBool(plugin_input_event_interface_->HandleInputEvent( |
| 536 pp_instance(), event_resource->GetReference())); |
| 537 |
| 538 // Release the reference we took above. |
| 539 tracker->UnrefResource(resource); |
| 540 } |
| 541 } |
| 542 } |
| 543 |
| 544 // For compatibility, also send all input events through the old interface. |
| 545 // TODO(brettw) remove this. |
| 507 std::vector<PP_InputEvent> pp_events; | 546 std::vector<PP_InputEvent> pp_events; |
| 508 CreatePPEvent(event, &pp_events); | 547 CreatePPEvent(event, &pp_events); |
| 509 | 548 |
| 510 // Each input event may generate more than one PP_InputEvent. | 549 // Each input event may generate more than one PP_InputEvent. |
| 511 bool rv = false; | |
| 512 for (size_t i = 0; i < pp_events.size(); i++) { | 550 for (size_t i = 0; i < pp_events.size(); i++) { |
| 513 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(), | 551 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(), |
| 514 &pp_events[i])); | 552 &pp_events[i])); |
| 515 } | 553 } |
| 516 | 554 |
| 517 if (cursor_.get()) | 555 if (cursor_.get()) |
| 518 *cursor_info = *cursor_; | 556 *cursor_info = *cursor_; |
| 519 return rv; | 557 return rv; |
| 520 } | 558 } |
| 521 | 559 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 bool PluginInstance::LoadFindInterface() { | 746 bool PluginInstance::LoadFindInterface() { |
| 709 if (!plugin_find_interface_) { | 747 if (!plugin_find_interface_) { |
| 710 plugin_find_interface_ = | 748 plugin_find_interface_ = |
| 711 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( | 749 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( |
| 712 PPP_FIND_DEV_INTERFACE)); | 750 PPP_FIND_DEV_INTERFACE)); |
| 713 } | 751 } |
| 714 | 752 |
| 715 return !!plugin_find_interface_; | 753 return !!plugin_find_interface_; |
| 716 } | 754 } |
| 717 | 755 |
| 756 bool PluginInstance::LoadInputEventInterface() { |
| 757 if (!checked_for_plugin_input_event_interface_) { |
| 758 checked_for_plugin_input_event_interface_ = true; |
| 759 plugin_input_event_interface_ = |
| 760 static_cast<const PPP_InputEvent*>(module_->GetPluginInterface( |
| 761 PPP_INPUT_EVENT_INTERFACE)); |
| 762 } |
| 763 return !!plugin_input_event_interface_; |
| 764 } |
| 765 |
| 718 bool PluginInstance::LoadMessagingInterface() { | 766 bool PluginInstance::LoadMessagingInterface() { |
| 719 if (!checked_for_plugin_messaging_interface_) { | 767 if (!checked_for_plugin_messaging_interface_) { |
| 720 checked_for_plugin_messaging_interface_ = true; | 768 checked_for_plugin_messaging_interface_ = true; |
| 721 plugin_messaging_interface_ = | 769 plugin_messaging_interface_ = |
| 722 static_cast<const PPP_Messaging*>(module_->GetPluginInterface( | 770 static_cast<const PPP_Messaging*>(module_->GetPluginInterface( |
| 723 PPP_MESSAGING_INTERFACE)); | 771 PPP_MESSAGING_INTERFACE)); |
| 724 } | 772 } |
| 725 | 773 |
| 726 return !!plugin_messaging_interface_; | 774 return !!plugin_messaging_interface_; |
| 727 } | 775 } |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 return PP_FALSE; | 1549 return PP_FALSE; |
| 1502 #endif | 1550 #endif |
| 1503 } | 1551 } |
| 1504 | 1552 |
| 1505 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { | 1553 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { |
| 1506 gfx::Size screen_size = delegate()->GetScreenSize(); | 1554 gfx::Size screen_size = delegate()->GetScreenSize(); |
| 1507 *size = PP_MakeSize(screen_size.width(), screen_size.height()); | 1555 *size = PP_MakeSize(screen_size.width(), screen_size.height()); |
| 1508 return PP_TRUE; | 1556 return PP_TRUE; |
| 1509 } | 1557 } |
| 1510 | 1558 |
| 1559 int32_t PluginInstance::RequestInputEvents(PP_Instance instance, |
| 1560 uint32_t event_classes) { |
| 1561 // Don't allow unfiltered keyboard access. The error return value will be |
| 1562 // generated by ValidateRequestInputEvents. |
| 1563 uint32_t fixed_classes = |
| 1564 event_classes & ~uint32_t(PP_INPUTEVENT_CLASS_KEYBOARD); |
| 1565 |
| 1566 input_event_mask_ |= fixed_classes; |
| 1567 filtered_input_event_mask_ &= ~(fixed_classes); |
| 1568 |
| 1569 // Validate based on the original input to catch errors. |
| 1570 return ValidateRequestInputEvents(false, event_classes); |
| 1571 } |
| 1572 |
| 1573 int32_t PluginInstance::RequestFilteringInputEvents(PP_Instance instance, |
| 1574 uint32_t event_classes) { |
| 1575 filtered_input_event_mask_ |= event_classes; |
| 1576 input_event_mask_ &= ~(event_classes); |
| 1577 return ValidateRequestInputEvents(true, event_classes); |
| 1578 } |
| 1579 |
| 1580 void PluginInstance::ClearInputEventRequest(PP_Instance instance, |
| 1581 uint32_t event_classes) { |
| 1582 input_event_mask_ &= ~(event_classes); |
| 1583 filtered_input_event_mask_ &= ~(event_classes); |
| 1584 } |
| 1585 |
| 1511 } // namespace ppapi | 1586 } // namespace ppapi |
| 1512 } // namespace webkit | 1587 } // namespace webkit |
| OLD | NEW |