OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/pepper_plugin_instance_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_offset_string_conversions.h" | 16 #include "base/strings/utf_offset_string_conversions.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "cc/base/latency_info_swap_promise.h" | |
19 #include "cc/layers/texture_layer.h" | 20 #include "cc/layers/texture_layer.h" |
21 #include "cc/trees/layer_tree_host.h" | |
20 #include "content/common/content_constants_internal.h" | 22 #include "content/common/content_constants_internal.h" |
23 #include "content/common/input/web_input_event_traits.h" | |
21 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
22 #include "content/public/common/page_zoom.h" | 25 #include "content/public/common/page_zoom.h" |
23 #include "content/public/renderer/content_renderer_client.h" | 26 #include "content/public/renderer/content_renderer_client.h" |
27 #include "content/renderer/gpu/render_widget_compositor.h" | |
24 #include "content/renderer/pepper/common.h" | 28 #include "content/renderer/pepper/common.h" |
25 #include "content/renderer/pepper/content_decryptor_delegate.h" | 29 #include "content/renderer/pepper/content_decryptor_delegate.h" |
26 #include "content/renderer/pepper/event_conversion.h" | 30 #include "content/renderer/pepper/event_conversion.h" |
27 #include "content/renderer/pepper/fullscreen_container.h" | 31 #include "content/renderer/pepper/fullscreen_container.h" |
28 #include "content/renderer/pepper/gfx_conversion.h" | 32 #include "content/renderer/pepper/gfx_conversion.h" |
29 #include "content/renderer/pepper/host_dispatcher_wrapper.h" | 33 #include "content/renderer/pepper/host_dispatcher_wrapper.h" |
30 #include "content/renderer/pepper/host_globals.h" | 34 #include "content/renderer/pepper/host_globals.h" |
31 #include "content/renderer/pepper/message_channel.h" | 35 #include "content/renderer/pepper/message_channel.h" |
32 #include "content/renderer/pepper/npapi_glue.h" | 36 #include "content/renderer/pepper/npapi_glue.h" |
33 #include "content/renderer/pepper/pepper_browser_connection.h" | 37 #include "content/renderer/pepper/pepper_browser_connection.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 virtual bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) | 399 virtual bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) |
396 OVERRIDE { | 400 OVERRIDE { |
397 plugin_->HandleMouseLockedInputEvent(event); | 401 plugin_->HandleMouseLockedInputEvent(event); |
398 return true; | 402 return true; |
399 } | 403 } |
400 | 404 |
401 private: | 405 private: |
402 PepperPluginInstanceImpl* plugin_; | 406 PepperPluginInstanceImpl* plugin_; |
403 }; | 407 }; |
404 | 408 |
409 void InitLatencyInfo(ui::LatencyInfo* new_latency, | |
410 const ui::LatencyInfo* old_latency, | |
411 blink::WebInputEvent::Type type, | |
412 int64 input_sequence) { | |
413 new_latency->AddLatencyNumber( | |
414 ui::INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT, | |
415 0, | |
416 input_sequence); | |
417 new_latency->TraceEventType(WebInputEventTraits::GetName(type)); | |
418 if (old_latency) { | |
419 new_latency->CopyLatencyFrom(*old_latency, | |
420 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); | |
421 new_latency->CopyLatencyFrom(*old_latency, | |
422 ui::INPUT_EVENT_LATENCY_UI_COMPONENT); | |
423 } | |
424 } | |
425 | |
405 } // namespace | 426 } // namespace |
406 | 427 |
407 // static | 428 // static |
408 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( | 429 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( |
409 RenderFrameImpl* render_frame, | 430 RenderFrameImpl* render_frame, |
410 PluginModule* module, | 431 PluginModule* module, |
411 WebPluginContainer* container, | 432 WebPluginContainer* container, |
412 const GURL& plugin_url) { | 433 const GURL& plugin_url) { |
413 base::Callback<const void*(const char*)> get_plugin_interface_func = | 434 base::Callback<const void*(const char*)> get_plugin_interface_func = |
414 base::Bind(&PluginModule::GetPluginInterface, module); | 435 base::Bind(&PluginModule::GetPluginInterface, module); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 text_input_caret_bounds_(0, 0, 0, 0), | 552 text_input_caret_bounds_(0, 0, 0, 0), |
532 text_input_caret_set_(false), | 553 text_input_caret_set_(false), |
533 selection_caret_(0), | 554 selection_caret_(0), |
534 selection_anchor_(0), | 555 selection_anchor_(0), |
535 pending_user_gesture_(0.0), | 556 pending_user_gesture_(0.0), |
536 document_loader_(NULL), | 557 document_loader_(NULL), |
537 external_document_load_(false), | 558 external_document_load_(false), |
538 npp_(new NPP_t), | 559 npp_(new NPP_t), |
539 isolate_(v8::Isolate::GetCurrent()), | 560 isolate_(v8::Isolate::GetCurrent()), |
540 is_deleted_(false), | 561 is_deleted_(false), |
562 last_input_number_(0), | |
541 view_change_weak_ptr_factory_(this), | 563 view_change_weak_ptr_factory_(this), |
542 weak_factory_(this) { | 564 weak_factory_(this) { |
543 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 565 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
544 | 566 |
545 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 567 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
546 module_->InstanceCreated(this); | 568 module_->InstanceCreated(this); |
547 | 569 |
548 if (render_frame) { // NULL in tests | 570 if (render_frame) { // NULL in tests |
549 render_frame->render_view()->PepperInstanceCreated(this); | 571 render_frame->render_view()->PepperInstanceCreated(this); |
550 // Bind a callback now so that we can inform the RenderViewImpl when we are | 572 // Bind a callback now so that we can inform the RenderViewImpl when we are |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 // event. This allows out-of-process plugins to respond to the user | 1109 // event. This allows out-of-process plugins to respond to the user |
1088 // gesture after processing has finished here. | 1110 // gesture after processing has finished here. |
1089 if (WebUserGestureIndicator::isProcessingUserGesture()) { | 1111 if (WebUserGestureIndicator::isProcessingUserGesture()) { |
1090 pending_user_gesture_ = | 1112 pending_user_gesture_ = |
1091 ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds); | 1113 ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds); |
1092 pending_user_gesture_token_ = | 1114 pending_user_gesture_token_ = |
1093 WebUserGestureIndicator::currentUserGestureToken(); | 1115 WebUserGestureIndicator::currentUserGestureToken(); |
1094 pending_user_gesture_token_.setOutOfProcess(); | 1116 pending_user_gesture_token_.setOutOfProcess(); |
1095 } | 1117 } |
1096 | 1118 |
1119 const ui::LatencyInfo* current_event_latency_info = NULL; | |
1120 if (render_frame_->GetRenderWidget()) { | |
1121 current_event_latency_info = | |
1122 render_frame_->GetRenderWidget()->current_event_latency_info(); | |
1123 } | |
1124 | |
1097 // Each input event may generate more than one PP_InputEvent. | 1125 // Each input event may generate more than one PP_InputEvent. |
1098 for (size_t i = 0; i < events.size(); i++) { | 1126 for (size_t i = 0; i < events.size(); i++) { |
1127 InitLatencyInfo(&events[i].latency_info, | |
dmichael (off chromium)
2014/05/05 22:20:32
You're doing some work here even if the plugin isn
Yufeng Shen (Slow to review)
2014/05/07 17:12:14
done.
| |
1128 current_event_latency_info, | |
1129 event.type, | |
1130 last_input_number_++); | |
1099 if (filtered_input_event_mask_ & event_class) | 1131 if (filtered_input_event_mask_ & event_class) |
1100 events[i].is_filtered = true; | 1132 events[i].is_filtered = true; |
1101 else | 1133 else |
1102 rv = true; // Unfiltered events are assumed to be handled. | 1134 rv = true; // Unfiltered events are assumed to be handled. |
1103 scoped_refptr<PPB_InputEvent_Shared> event_resource( | 1135 scoped_refptr<PPB_InputEvent_Shared> event_resource( |
1104 new PPB_InputEvent_Shared( | 1136 new PPB_InputEvent_Shared( |
1105 ppapi::OBJECT_IS_IMPL, pp_instance(), events[i])); | 1137 ppapi::OBJECT_IS_IMPL, pp_instance(), events[i])); |
1106 | 1138 |
1107 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent( | 1139 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent( |
1108 pp_instance(), event_resource->pp_resource())); | 1140 pp_instance(), event_resource->pp_resource())); |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1981 scoped_ptr<cc::SingleReleaseCallback>* release_callback, | 2013 scoped_ptr<cc::SingleReleaseCallback>* release_callback, |
1982 bool use_shared_memory) { | 2014 bool use_shared_memory) { |
1983 if (!bound_graphics_2d_platform_) | 2015 if (!bound_graphics_2d_platform_) |
1984 return false; | 2016 return false; |
1985 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, | 2017 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, |
1986 release_callback); | 2018 release_callback); |
1987 } | 2019 } |
1988 | 2020 |
1989 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; } | 2021 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; } |
1990 | 2022 |
2023 void PepperPluginInstanceImpl::AddLatencyInfo( | |
2024 const std::vector<ui::LatencyInfo>& latency_info) { | |
2025 if (render_frame_ && render_frame_->GetRenderWidget()) { | |
2026 RenderWidgetCompositor* compositor = | |
2027 render_frame_->GetRenderWidget()->compositor(); | |
2028 if (compositor) { | |
2029 for (size_t i = 0; i < latency_info.size(); i++) { | |
2030 scoped_ptr<cc::SwapPromise> swap_promise( | |
2031 new cc::LatencyInfoSwapPromise(latency_info[i])); | |
2032 compositor->QueueSwapPromise(swap_promise.Pass()); | |
2033 } | |
2034 } | |
2035 } | |
2036 } | |
2037 | |
1991 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) { | 2038 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) { |
1992 DCHECK(live_plugin_objects_.find(plugin_object) == | 2039 DCHECK(live_plugin_objects_.find(plugin_object) == |
1993 live_plugin_objects_.end()); | 2040 live_plugin_objects_.end()); |
1994 live_plugin_objects_.insert(plugin_object); | 2041 live_plugin_objects_.insert(plugin_object); |
1995 } | 2042 } |
1996 | 2043 |
1997 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) { | 2044 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) { |
1998 // Don't actually verify that the object is in the set since during module | 2045 // Don't actually verify that the object is in the set since during module |
1999 // deletion we'll be in the process of freeing them. | 2046 // deletion we'll be in the process of freeing them. |
2000 live_plugin_objects_.erase(plugin_object); | 2047 live_plugin_objects_.erase(plugin_object); |
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3141 // Running out-of-process. Initiate an IPC call to notify the plugin | 3188 // Running out-of-process. Initiate an IPC call to notify the plugin |
3142 // process. | 3189 // process. |
3143 ppapi::proxy::HostDispatcher* dispatcher = | 3190 ppapi::proxy::HostDispatcher* dispatcher = |
3144 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 3191 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
3145 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 3192 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
3146 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); | 3193 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); |
3147 } | 3194 } |
3148 } | 3195 } |
3149 | 3196 |
3150 } // namespace content | 3197 } // namespace content |
OLD | NEW |