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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 module_(module), | 247 module_(module), |
246 instance_interface_(instance_interface), | 248 instance_interface_(instance_interface), |
247 pp_instance_(0), | 249 pp_instance_(0), |
248 container_(NULL), | 250 container_(NULL), |
249 full_frame_(false), | 251 full_frame_(false), |
250 has_webkit_focus_(false), | 252 has_webkit_focus_(false), |
251 has_content_area_focus_(false), | 253 has_content_area_focus_(false), |
252 find_identifier_(-1), | 254 find_identifier_(-1), |
253 plugin_find_interface_(NULL), | 255 plugin_find_interface_(NULL), |
254 plugin_messaging_interface_(NULL), | 256 plugin_messaging_interface_(NULL), |
257 plugin_input_event_interface_(NULL), | |
258 plugin_private_interface_(NULL), | |
255 plugin_pdf_interface_(NULL), | 259 plugin_pdf_interface_(NULL), |
256 plugin_private_interface_(NULL), | |
257 plugin_selection_interface_(NULL), | 260 plugin_selection_interface_(NULL), |
258 plugin_zoom_interface_(NULL), | 261 plugin_zoom_interface_(NULL), |
262 checked_for_plugin_input_event_interface_(false), | |
259 checked_for_plugin_messaging_interface_(false), | 263 checked_for_plugin_messaging_interface_(false), |
260 plugin_print_interface_(NULL), | 264 plugin_print_interface_(NULL), |
261 plugin_graphics_3d_interface_(NULL), | 265 plugin_graphics_3d_interface_(NULL), |
262 always_on_top_(false), | 266 always_on_top_(false), |
263 fullscreen_container_(NULL), | 267 fullscreen_container_(NULL), |
264 fullscreen_(false), | 268 fullscreen_(false), |
265 message_channel_(NULL), | 269 message_channel_(NULL), |
266 sad_plugin_(NULL) { | 270 sad_plugin_(NULL), |
271 input_event_mask_(0), | |
272 filtered_input_event_mask_(0) { | |
267 pp_instance_ = ResourceTracker::Get()->AddInstance(this); | 273 pp_instance_ = ResourceTracker::Get()->AddInstance(this); |
268 | 274 |
269 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 275 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
270 DCHECK(delegate); | 276 DCHECK(delegate); |
271 module_->InstanceCreated(this); | 277 module_->InstanceCreated(this); |
272 delegate_->InstanceCreated(this); | 278 delegate_->InstanceCreated(this); |
273 message_channel_.reset(new MessageChannel(this)); | 279 message_channel_.reset(new MessageChannel(this)); |
274 } | 280 } |
275 | 281 |
276 PluginInstance::~PluginInstance() { | 282 PluginInstance::~PluginInstance() { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { | 479 bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { |
474 Resource::ScopedResourceId resource(loader); | 480 Resource::ScopedResourceId resource(loader); |
475 return PPBoolToBool(instance_interface_->HandleDocumentLoad(pp_instance(), | 481 return PPBoolToBool(instance_interface_->HandleDocumentLoad(pp_instance(), |
476 resource.id)); | 482 resource.id)); |
477 } | 483 } |
478 | 484 |
479 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, | 485 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, |
480 WebCursorInfo* cursor_info) { | 486 WebCursorInfo* cursor_info) { |
481 // Keep a reference on the stack. See NOTE above. | 487 // Keep a reference on the stack. See NOTE above. |
482 scoped_refptr<PluginInstance> ref(this); | 488 scoped_refptr<PluginInstance> ref(this); |
489 | |
490 bool rv = false; | |
491 if (LoadInputEventInterface()) { | |
492 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); | |
493 if (!event_class) | |
494 return false; | |
495 | |
496 if ((filtered_input_event_mask_ & event_class) || | |
497 (input_event_mask_ & event_class)) { | |
498 // Actually send the event. | |
499 std::vector< ::ppapi::InputEventData > events; | |
500 CreateInputEventData(event, &events); | |
501 | |
502 // Each input event may generate more than one PP_InputEvent. | |
503 ResourceTracker* tracker = ResourceTracker::Get(); | |
504 for (size_t i = 0; i < events.size(); i++) { | |
505 if (filtered_input_event_mask_ & event_class) | |
506 events[i].is_filtered = true; | |
507 scoped_refptr<PPB_InputEvent_Impl> event_resource( | |
508 new PPB_InputEvent_Impl(this, events[i])); | |
509 PP_Resource resource = event_resource->GetReference(); | |
510 | |
511 rv |= PPBoolToBool(plugin_input_event_interface_->HandleInputEvent( | |
512 pp_instance(), event_resource->GetReference())); | |
513 | |
514 // Release the reference we took above. | |
515 tracker->UnrefResource(resource); | |
516 } | |
517 } | |
518 } | |
519 | |
520 // For compatibility, also send all input events through the old interface. | |
521 // TODO(brettw) remove this. | |
483 std::vector<PP_InputEvent> pp_events; | 522 std::vector<PP_InputEvent> pp_events; |
484 CreatePPEvent(event, &pp_events); | 523 CreatePPEvent(event, &pp_events); |
485 | 524 |
486 // Each input event may generate more than one PP_InputEvent. | 525 // Each input event may generate more than one PP_InputEvent. |
487 bool rv = false; | |
488 for (size_t i = 0; i < pp_events.size(); i++) { | 526 for (size_t i = 0; i < pp_events.size(); i++) { |
489 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(), | 527 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(), |
490 &pp_events[i])); | 528 &pp_events[i])); |
491 } | 529 } |
492 | 530 |
493 if (cursor_.get()) | 531 if (cursor_.get()) |
494 *cursor_info = *cursor_; | 532 *cursor_info = *cursor_; |
495 return rv; | 533 return rv; |
496 } | 534 } |
497 | 535 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 bool PluginInstance::LoadFindInterface() { | 722 bool PluginInstance::LoadFindInterface() { |
685 if (!plugin_find_interface_) { | 723 if (!plugin_find_interface_) { |
686 plugin_find_interface_ = | 724 plugin_find_interface_ = |
687 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( | 725 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( |
688 PPP_FIND_DEV_INTERFACE)); | 726 PPP_FIND_DEV_INTERFACE)); |
689 } | 727 } |
690 | 728 |
691 return !!plugin_find_interface_; | 729 return !!plugin_find_interface_; |
692 } | 730 } |
693 | 731 |
732 bool PluginInstance::LoadInputEventInterface() { | |
733 if (!checked_for_plugin_input_event_interface_) { | |
734 checked_for_plugin_input_event_interface_ = true; | |
735 plugin_input_event_interface_ = | |
736 static_cast<const PPP_InputEvent*>(module_->GetPluginInterface( | |
737 PPP_INPUT_EVENT_INTERFACE)); | |
738 } | |
739 return !!plugin_input_event_interface_; | |
740 } | |
741 | |
694 PluginInstance::PPP_Instance_Combined::PPP_Instance_Combined( | 742 PluginInstance::PPP_Instance_Combined::PPP_Instance_Combined( |
695 const PPP_Instance_0_5& instance_if) | 743 const PPP_Instance_0_5& instance_if) |
696 : PPP_Instance_0_5(instance_if), | 744 : PPP_Instance_0_5(instance_if), |
697 GetInstanceObject_0_4(NULL) {} | 745 GetInstanceObject_0_4(NULL) {} |
698 | 746 |
699 PluginInstance::PPP_Instance_Combined::PPP_Instance_Combined( | 747 PluginInstance::PPP_Instance_Combined::PPP_Instance_Combined( |
700 const PPP_Instance_0_4& instance_if) | 748 const PPP_Instance_0_4& instance_if) |
701 : PPP_Instance_0_5(), // Zero-initialize. | 749 : PPP_Instance_0_5(), // Zero-initialize. |
702 GetInstanceObject_0_4(instance_if.GetInstanceObject) { | 750 GetInstanceObject_0_4(instance_if.GetInstanceObject) { |
703 DidCreate = instance_if.DidCreate; | 751 DidCreate = instance_if.DidCreate; |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1499 return PP_FALSE; | 1547 return PP_FALSE; |
1500 #endif | 1548 #endif |
1501 } | 1549 } |
1502 | 1550 |
1503 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { | 1551 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { |
1504 gfx::Size screen_size = delegate()->GetScreenSize(); | 1552 gfx::Size screen_size = delegate()->GetScreenSize(); |
1505 *size = PP_MakeSize(screen_size.width(), screen_size.height()); | 1553 *size = PP_MakeSize(screen_size.width(), screen_size.height()); |
1506 return PP_TRUE; | 1554 return PP_TRUE; |
1507 } | 1555 } |
1508 | 1556 |
1557 int32_t PluginInstance::RequestInputEvents(PP_Instance instance, | |
1558 uint32_t event_classes) { | |
1559 // Don't allow unfiltered keyboard access. The error return value will be | |
1560 // generated by ValidateRequestInputEvents. | |
1561 uint32_t fixed_classes = | |
1562 event_classes & ~uint32_t(PP_INPUTEVENT_CLASS_KEYBOARD); | |
dmichael (off chromium)
2011/07/01 20:04:19
static_cast
| |
1563 | |
1564 input_event_mask_ |= fixed_classes; | |
1565 filtered_input_event_mask_ &= ~(fixed_classes); | |
1566 | |
1567 // Validate based on the original input to catch errors. | |
1568 return ValidateRequestInputEvents(false, event_classes); | |
1569 } | |
1570 | |
1571 int32_t PluginInstance::RequestFilteringInputEvents(PP_Instance instance, | |
1572 uint32_t event_classes) { | |
1573 filtered_input_event_mask_ &= event_classes; | |
dmichael (off chromium)
2011/07/01 20:04:19
Shouldn't that be |=?
| |
1574 input_event_mask_ &= ~(event_classes); | |
1575 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
| |
1576 } | |
1577 | |
1578 void PluginInstance::ClearInputEventRequest(PP_Instance instance, | |
1579 uint32_t event_classes) { | |
1580 input_event_mask_ &= ~(event_classes); | |
1581 filtered_input_event_mask_ &= ~(event_classes); | |
1582 } | |
1583 | |
1509 } // namespace ppapi | 1584 } // namespace ppapi |
1510 } // namespace webkit | 1585 } // namespace webkit |
OLD | NEW |