Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 252663002: Track plugin input event latency (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: move InputEventPriavte interface to terfaces_ppb_private.h Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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),
563 is_tracking_latency_(false),
541 view_change_weak_ptr_factory_(this), 564 view_change_weak_ptr_factory_(this),
542 weak_factory_(this) { 565 weak_factory_(this) {
543 pp_instance_ = HostGlobals::Get()->AddInstance(this); 566 pp_instance_ = HostGlobals::Get()->AddInstance(this);
544 567
545 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 568 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
546 module_->InstanceCreated(this); 569 module_->InstanceCreated(this);
547 570
548 if (render_frame) { // NULL in tests 571 if (render_frame) { // NULL in tests
549 render_frame->render_view()->PepperInstanceCreated(this); 572 render_frame->render_view()->PepperInstanceCreated(this);
550 // Bind a callback now so that we can inform the RenderViewImpl when we are 573 // 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
1087 // event. This allows out-of-process plugins to respond to the user 1110 // event. This allows out-of-process plugins to respond to the user
1088 // gesture after processing has finished here. 1111 // gesture after processing has finished here.
1089 if (WebUserGestureIndicator::isProcessingUserGesture()) { 1112 if (WebUserGestureIndicator::isProcessingUserGesture()) {
1090 pending_user_gesture_ = 1113 pending_user_gesture_ =
1091 ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds); 1114 ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds);
1092 pending_user_gesture_token_ = 1115 pending_user_gesture_token_ =
1093 WebUserGestureIndicator::currentUserGestureToken(); 1116 WebUserGestureIndicator::currentUserGestureToken();
1094 pending_user_gesture_token_.setOutOfProcess(); 1117 pending_user_gesture_token_.setOutOfProcess();
1095 } 1118 }
1096 1119
1120 const ui::LatencyInfo* current_event_latency_info = NULL;
1121 if (render_frame_->GetRenderWidget()) {
1122 current_event_latency_info =
1123 render_frame_->GetRenderWidget()->current_event_latency_info();
1124 }
1125
1097 // Each input event may generate more than one PP_InputEvent. 1126 // Each input event may generate more than one PP_InputEvent.
1098 for (size_t i = 0; i < events.size(); i++) { 1127 for (size_t i = 0; i < events.size(); i++) {
1128 if (is_tracking_latency_) {
1129 InitLatencyInfo(&events[i].latency_info,
1130 current_event_latency_info,
1131 event.type,
1132 last_input_number_++);
1133 }
1099 if (filtered_input_event_mask_ & event_class) 1134 if (filtered_input_event_mask_ & event_class)
1100 events[i].is_filtered = true; 1135 events[i].is_filtered = true;
1101 else 1136 else
1102 rv = true; // Unfiltered events are assumed to be handled. 1137 rv = true; // Unfiltered events are assumed to be handled.
1103 scoped_refptr<PPB_InputEvent_Shared> event_resource( 1138 scoped_refptr<PPB_InputEvent_Shared> event_resource(
1104 new PPB_InputEvent_Shared( 1139 new PPB_InputEvent_Shared(
1105 ppapi::OBJECT_IS_IMPL, pp_instance(), events[i])); 1140 ppapi::OBJECT_IS_IMPL, pp_instance(), events[i]));
1106 1141
1107 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent( 1142 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent(
1108 pp_instance(), event_resource->pp_resource())); 1143 pp_instance(), event_resource->pp_resource()));
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 scoped_ptr<cc::SingleReleaseCallback>* release_callback, 2016 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
1982 bool use_shared_memory) { 2017 bool use_shared_memory) {
1983 if (!bound_graphics_2d_platform_) 2018 if (!bound_graphics_2d_platform_)
1984 return false; 2019 return false;
1985 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, 2020 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox,
1986 release_callback); 2021 release_callback);
1987 } 2022 }
1988 2023
1989 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; } 2024 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; }
1990 2025
2026 void PepperPluginInstanceImpl::AddLatencyInfo(
2027 const std::vector<ui::LatencyInfo>& latency_info) {
2028 if (render_frame_ && render_frame_->GetRenderWidget()) {
2029 RenderWidgetCompositor* compositor =
2030 render_frame_->GetRenderWidget()->compositor();
2031 if (compositor) {
2032 for (size_t i = 0; i < latency_info.size(); i++) {
2033 scoped_ptr<cc::SwapPromise> swap_promise(
2034 new cc::LatencyInfoSwapPromise(latency_info[i]));
2035 compositor->QueueSwapPromise(swap_promise.Pass());
2036 }
2037 }
2038 }
2039 }
2040
1991 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) { 2041 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) {
1992 DCHECK(live_plugin_objects_.find(plugin_object) == 2042 DCHECK(live_plugin_objects_.find(plugin_object) ==
1993 live_plugin_objects_.end()); 2043 live_plugin_objects_.end());
1994 live_plugin_objects_.insert(plugin_object); 2044 live_plugin_objects_.insert(plugin_object);
1995 } 2045 }
1996 2046
1997 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) { 2047 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) {
1998 // Don't actually verify that the object is in the set since during module 2048 // 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. 2049 // deletion we'll be in the process of freeing them.
2000 live_plugin_objects_.erase(plugin_object); 2050 live_plugin_objects_.erase(plugin_object);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 return ValidateRequestInputEvents(true, event_classes); 2540 return ValidateRequestInputEvents(true, event_classes);
2491 } 2541 }
2492 2542
2493 void PepperPluginInstanceImpl::ClearInputEventRequest(PP_Instance instance, 2543 void PepperPluginInstanceImpl::ClearInputEventRequest(PP_Instance instance,
2494 uint32_t event_classes) { 2544 uint32_t event_classes) {
2495 input_event_mask_ &= ~(event_classes); 2545 input_event_mask_ &= ~(event_classes);
2496 filtered_input_event_mask_ &= ~(event_classes); 2546 filtered_input_event_mask_ &= ~(event_classes);
2497 RequestInputEventsHelper(event_classes); 2547 RequestInputEventsHelper(event_classes);
2498 } 2548 }
2499 2549
2550 void PepperPluginInstanceImpl::StartTrackingLatency(PP_Instance instance) {
2551 is_tracking_latency_ = true;
dmichael (off chromium) 2014/05/08 21:47:07 Please add a permissions check for this. It might
Yufeng Shen (Slow to review) 2014/05/08 23:49:40 Done.
2552 }
2553
2500 void PepperPluginInstanceImpl::ZoomChanged(PP_Instance instance, 2554 void PepperPluginInstanceImpl::ZoomChanged(PP_Instance instance,
2501 double factor) { 2555 double factor) {
2502 // We only want to tell the page to change its zoom if the whole page is the 2556 // We only want to tell the page to change its zoom if the whole page is the
2503 // plugin. If we're in an iframe, then don't do anything. 2557 // plugin. If we're in an iframe, then don't do anything.
2504 if (!IsFullPagePlugin()) 2558 if (!IsFullPagePlugin())
2505 return; 2559 return;
2506 container()->zoomLevelChanged(content::ZoomFactorToZoomLevel(factor)); 2560 container()->zoomLevelChanged(content::ZoomFactorToZoomLevel(factor));
2507 } 2561 }
2508 2562
2509 void PepperPluginInstanceImpl::ZoomLimitsChanged(PP_Instance instance, 2563 void PepperPluginInstanceImpl::ZoomLimitsChanged(PP_Instance instance,
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 // Running out-of-process. Initiate an IPC call to notify the plugin 3195 // Running out-of-process. Initiate an IPC call to notify the plugin
3142 // process. 3196 // process.
3143 ppapi::proxy::HostDispatcher* dispatcher = 3197 ppapi::proxy::HostDispatcher* dispatcher =
3144 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 3198 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
3145 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 3199 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
3146 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 3200 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
3147 } 3201 }
3148 } 3202 }
3149 3203
3150 } // namespace content 3204 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698