Chromium Code Reviews| Index: webkit/plugins/ppapi/ppapi_plugin_instance.cc |
| =================================================================== |
| --- webkit/plugins/ppapi/ppapi_plugin_instance.cc (revision 90976) |
| +++ webkit/plugins/ppapi/ppapi_plugin_instance.cc (working copy) |
| @@ -23,6 +23,7 @@ |
| #include "ppapi/c/ppb_core.h" |
| #include "ppapi/c/ppb_instance.h" |
| #include "ppapi/c/ppb_messaging.h" |
| +#include "ppapi/c/ppp_input_event.h" |
| #include "ppapi/c/ppp_instance.h" |
| #include "ppapi/c/ppp_messaging.h" |
| #include "ppapi/c/private/ppb_instance_private.h" |
| @@ -55,6 +56,7 @@ |
| #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
| #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
| #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| +#include "webkit/plugins/ppapi/ppb_input_event_impl.h" |
| #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" |
| #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" |
| #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" |
| @@ -252,10 +254,12 @@ |
| find_identifier_(-1), |
| plugin_find_interface_(NULL), |
| plugin_messaging_interface_(NULL), |
| + plugin_input_event_interface_(NULL), |
| + plugin_private_interface_(NULL), |
| plugin_pdf_interface_(NULL), |
| - plugin_private_interface_(NULL), |
| plugin_selection_interface_(NULL), |
| plugin_zoom_interface_(NULL), |
| + checked_for_plugin_input_event_interface_(false), |
| checked_for_plugin_messaging_interface_(false), |
| plugin_print_interface_(NULL), |
| plugin_graphics_3d_interface_(NULL), |
| @@ -263,7 +267,9 @@ |
| fullscreen_container_(NULL), |
| fullscreen_(false), |
| message_channel_(NULL), |
| - sad_plugin_(NULL) { |
| + sad_plugin_(NULL), |
| + input_event_mask_(0), |
| + filtered_input_event_mask_(0) { |
| pp_instance_ = ResourceTracker::Get()->AddInstance(this); |
| memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| @@ -480,11 +486,43 @@ |
| WebCursorInfo* cursor_info) { |
| // Keep a reference on the stack. See NOTE above. |
| scoped_refptr<PluginInstance> ref(this); |
| + |
| + bool rv = false; |
| + if (LoadInputEventInterface()) { |
| + PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); |
| + if (!event_class) |
| + return false; |
| + |
| + if ((filtered_input_event_mask_ & event_class) || |
| + (input_event_mask_ & event_class)) { |
| + // Actually send the event. |
| + std::vector< ::ppapi::InputEventData > events; |
| + CreateInputEventData(event, &events); |
| + |
| + // Each input event may generate more than one PP_InputEvent. |
| + ResourceTracker* tracker = ResourceTracker::Get(); |
| + for (size_t i = 0; i < events.size(); i++) { |
| + if (filtered_input_event_mask_ & event_class) |
| + events[i].is_filtered = true; |
| + scoped_refptr<PPB_InputEvent_Impl> event_resource( |
| + new PPB_InputEvent_Impl(this, events[i])); |
| + PP_Resource resource = event_resource->GetReference(); |
| + |
| + rv |= PPBoolToBool(plugin_input_event_interface_->HandleInputEvent( |
| + pp_instance(), event_resource->GetReference())); |
| + |
| + // Release the reference we took above. |
| + tracker->UnrefResource(resource); |
| + } |
| + } |
| + } |
| + |
| + // For compatibility, also send all input events through the old interface. |
| + // TODO(brettw) remove this. |
| std::vector<PP_InputEvent> pp_events; |
| CreatePPEvent(event, &pp_events); |
| // Each input event may generate more than one PP_InputEvent. |
| - bool rv = false; |
| for (size_t i = 0; i < pp_events.size(); i++) { |
| rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(), |
| &pp_events[i])); |
| @@ -691,6 +729,16 @@ |
| return !!plugin_find_interface_; |
| } |
| +bool PluginInstance::LoadInputEventInterface() { |
| + if (!checked_for_plugin_input_event_interface_) { |
| + checked_for_plugin_input_event_interface_ = true; |
| + plugin_input_event_interface_ = |
| + static_cast<const PPP_InputEvent*>(module_->GetPluginInterface( |
| + PPP_INPUT_EVENT_INTERFACE)); |
| + } |
| + return !!plugin_input_event_interface_; |
| +} |
| + |
| PluginInstance::PPP_Instance_Combined::PPP_Instance_Combined( |
| const PPP_Instance_0_5& instance_if) |
| : PPP_Instance_0_5(instance_if), |
| @@ -1506,5 +1554,32 @@ |
| return PP_TRUE; |
| } |
| +int32_t PluginInstance::RequestInputEvents(PP_Instance instance, |
| + uint32_t event_classes) { |
| + // Don't allow unfiltered keyboard access. The error return value will be |
| + // generated by ValidateRequestInputEvents. |
| + uint32_t fixed_classes = |
| + event_classes & ~uint32_t(PP_INPUTEVENT_CLASS_KEYBOARD); |
|
dmichael (off chromium)
2011/07/01 20:04:19
static_cast
|
| + |
| + input_event_mask_ |= fixed_classes; |
| + filtered_input_event_mask_ &= ~(fixed_classes); |
| + |
| + // Validate based on the original input to catch errors. |
| + return ValidateRequestInputEvents(false, event_classes); |
| +} |
| + |
| +int32_t PluginInstance::RequestFilteringInputEvents(PP_Instance instance, |
| + uint32_t event_classes) { |
| + filtered_input_event_mask_ &= event_classes; |
|
dmichael (off chromium)
2011/07/01 20:04:19
Shouldn't that be |=?
|
| + input_event_mask_ &= ~(event_classes); |
| + return ValidateRequestInputEvents(true, event_classes); |
|
dmichael (off chromium)
2011/07/01 20:04:19
Maybe it doesn't matter, but it looks from all of
brettw
2011/07/01 21:14:52
I thought about this but it's kind of a pain to im
|
| +} |
| + |
| +void PluginInstance::ClearInputEventRequest(PP_Instance instance, |
| + uint32_t event_classes) { |
| + input_event_mask_ &= ~(event_classes); |
| + filtered_input_event_mask_ &= ~(event_classes); |
| +} |
| + |
| } // namespace ppapi |
| } // namespace webkit |