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/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/metrics/sparse_histogram.h" | |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_offset_string_conversions.h" | 18 #include "base/strings/utf_offset_string_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
20 #include "cc/base/latency_info_swap_promise.h" | 21 #include "cc/base/latency_info_swap_promise.h" |
21 #include "cc/blink/web_layer_impl.h" | 22 #include "cc/blink/web_layer_impl.h" |
22 #include "cc/layers/texture_layer.h" | 23 #include "cc/layers/texture_layer.h" |
23 #include "cc/trees/layer_tree_host.h" | 24 #include "cc/trees/layer_tree_host.h" |
24 #include "content/common/content_constants_internal.h" | 25 #include "content/common/content_constants_internal.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 using blink::WebURLRequest; | 180 using blink::WebURLRequest; |
180 using blink::WebURLResponse; | 181 using blink::WebURLResponse; |
181 using blink::WebUserGestureIndicator; | 182 using blink::WebUserGestureIndicator; |
182 using blink::WebUserGestureToken; | 183 using blink::WebUserGestureToken; |
183 using blink::WebView; | 184 using blink::WebView; |
184 | 185 |
185 namespace content { | 186 namespace content { |
186 | 187 |
187 namespace { | 188 namespace { |
188 | 189 |
190 static const int kInfiniteRatio = 99999; | |
191 | |
192 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ | |
193 UMA_HISTOGRAM_SPARSE_SLOWLY( \ | |
194 name, \ | |
195 (height) ? ((width) * 100) / (height) : kInfiniteRatio); | |
Ilya Sherman
2014/11/07 23:20:08
nit: Why define this as a macro rather than as a f
tommycli
2014/11/08 00:02:25
It's from https://code.google.com/p/chromium/codes
| |
196 | |
189 // Check PP_TextInput_Type and ui::TextInputType are kept in sync. | 197 // Check PP_TextInput_Type and ui::TextInputType are kept in sync. |
190 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NONE) == int(PP_TEXTINPUT_TYPE_NONE), | 198 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NONE) == int(PP_TEXTINPUT_TYPE_NONE), |
191 mismatching_enums); | 199 mismatching_enums); |
192 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TEXT) == int(PP_TEXTINPUT_TYPE_TEXT), | 200 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TEXT) == int(PP_TEXTINPUT_TYPE_TEXT), |
193 mismatching_enums); | 201 mismatching_enums); |
194 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_PASSWORD) == | 202 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_PASSWORD) == |
195 int(PP_TEXTINPUT_TYPE_PASSWORD), | 203 int(PP_TEXTINPUT_TYPE_PASSWORD), |
196 mismatching_enums); | 204 mismatching_enums); |
197 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_SEARCH) == int(PP_TEXTINPUT_TYPE_SEARCH), | 205 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_SEARCH) == int(PP_TEXTINPUT_TYPE_SEARCH), |
198 mismatching_enums); | 206 mismatching_enums); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 input_sequence); | 392 input_sequence); |
385 new_latency->TraceEventType(WebInputEventTraits::GetName(type)); | 393 new_latency->TraceEventType(WebInputEventTraits::GetName(type)); |
386 if (old_latency) { | 394 if (old_latency) { |
387 new_latency->CopyLatencyFrom(*old_latency, | 395 new_latency->CopyLatencyFrom(*old_latency, |
388 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); | 396 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); |
389 new_latency->CopyLatencyFrom(*old_latency, | 397 new_latency->CopyLatencyFrom(*old_latency, |
390 ui::INPUT_EVENT_LATENCY_UI_COMPONENT); | 398 ui::INPUT_EVENT_LATENCY_UI_COMPONENT); |
391 } | 399 } |
392 } | 400 } |
393 | 401 |
402 enum PluginFlashTinyContentSize { | |
403 TINY_CONTENT_SIZE_1_1 = 0, | |
404 TINY_CONTENT_SIZE_5_5 = 1, | |
405 TINY_CONTENT_SIZE_10_10 = 2, | |
406 TINY_CONTENT_SIZE_LARGE = 3, | |
407 TINY_CONTENT_SIZE_NUM_ITEMS | |
408 }; | |
409 | |
394 // How the throttled power saver is unthrottled, if ever. | 410 // How the throttled power saver is unthrottled, if ever. |
395 // These numeric values are used in UMA logs; do not change them. | 411 // These numeric values are used in UMA logs; do not change them. |
396 enum PowerSaverUnthrottleMethod { | 412 enum PowerSaverUnthrottleMethod { |
397 UNTHROTTLE_METHOD_NEVER = 0, | 413 UNTHROTTLE_METHOD_NEVER = 0, |
398 UNTHROTTLE_METHOD_BY_CLICK = 1, | 414 UNTHROTTLE_METHOD_BY_CLICK = 1, |
399 UNTHROTTLE_METHOD_BY_WHITELIST = 2, | 415 UNTHROTTLE_METHOD_BY_WHITELIST = 2, |
400 UNTHROTTLE_METHOD_NUM_ITEMS | 416 UNTHROTTLE_METHOD_NUM_ITEMS |
401 }; | 417 }; |
402 | 418 |
403 const char kPowerSaverUnthrottleHistogram[] = "Plugin.PowerSaverUnthrottle"; | 419 const char kFlashClickSizeAspectRatioHistogram[] = |
420 "Plugin.Flash.ClickSize.AspectRatio"; | |
421 const char kFlashClickSizeHeightHistogram[] = "Plugin.Flash.ClickSize.Height"; | |
422 const char kFlashClickSizeWidthHistogram[] = "Plugin.Flash.ClickSize.Width"; | |
423 const char kFlashTinyContentSizeHistogram[] = "Plugin.Flash.TinyContentSize"; | |
424 const char kPowerSaverUnthrottleHistogram[] = "Plugin.PowerSaver.Unthrottle"; | |
425 | |
426 void RecordFlashSizeMetric(int width, int height) { | |
427 if (width <= 1 && height <= 1) { | |
428 UMA_HISTOGRAM_ENUMERATION(kFlashTinyContentSizeHistogram, | |
429 TINY_CONTENT_SIZE_1_1, | |
430 TINY_CONTENT_SIZE_NUM_ITEMS); | |
431 } else if (width <= 5 && height <= 5) { | |
432 UMA_HISTOGRAM_ENUMERATION(kFlashTinyContentSizeHistogram, | |
433 TINY_CONTENT_SIZE_5_5, | |
434 TINY_CONTENT_SIZE_NUM_ITEMS); | |
435 } else if (width <= 10 && height <= 10) { | |
436 UMA_HISTOGRAM_ENUMERATION(kFlashTinyContentSizeHistogram, | |
437 TINY_CONTENT_SIZE_10_10, | |
438 TINY_CONTENT_SIZE_NUM_ITEMS); | |
439 } else { | |
440 UMA_HISTOGRAM_ENUMERATION(kFlashTinyContentSizeHistogram, | |
441 TINY_CONTENT_SIZE_LARGE, | |
442 TINY_CONTENT_SIZE_NUM_ITEMS); | |
443 } | |
Ilya Sherman
2014/11/07 23:20:08
Rather than repeating the UMA_HISTOGRAM_ENUMERATIO
tommycli
2014/11/08 00:02:25
Done.
| |
444 } | |
445 | |
446 void RecordFlashClickSizeMetric(int width, int height) { | |
447 base::HistogramBase* width_histogram = base::LinearHistogram::FactoryGet( | |
448 kFlashClickSizeWidthHistogram, | |
449 0, // minimum width | |
groby-ooo-7-16
2014/11/07 23:02:20
Min/max width should be ~ 300-500. I don't believe
tommycli
2014/11/07 23:14:10
I feel that if we're going to collect the histogra
groby-ooo-7-16
2014/11/08 00:21:36
I'm happy to trade resolution for range *iff* ther
tommycli
2014/11/08 02:01:20
Well alright I changed it since it's not that big
| |
450 1000, // maximum width | |
451 100, // number of buckets. | |
452 base::HistogramBase::kUmaTargetedHistogramFlag); | |
453 width_histogram->Add(width); | |
454 | |
455 base::HistogramBase* height_histogram = base::LinearHistogram::FactoryGet( | |
456 kFlashClickSizeHeightHistogram, | |
457 0, // minimum height | |
groby-ooo-7-16
2014/11/07 23:02:20
min/max height should probably be 200-400
tommycli
2014/11/07 23:14:10
See above. It's not a huge deal, but it seems nice
| |
458 1000, // maximum height | |
459 100, // number of buckets. | |
460 base::HistogramBase::kUmaTargetedHistogramFlag); | |
461 height_histogram->Add(height); | |
462 | |
463 UMA_HISTOGRAM_ASPECT_RATIO(kFlashClickSizeAspectRatioHistogram, width, | |
464 height); | |
465 } | |
404 | 466 |
405 void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method) { | 467 void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method) { |
406 UMA_HISTOGRAM_ENUMERATION(kPowerSaverUnthrottleHistogram, method, | 468 UMA_HISTOGRAM_ENUMERATION(kPowerSaverUnthrottleHistogram, method, |
407 UNTHROTTLE_METHOD_NUM_ITEMS); | 469 UNTHROTTLE_METHOD_NUM_ITEMS); |
408 } | 470 } |
409 | 471 |
410 bool IsFlashPlugin(PluginModule* module) { | 472 bool IsFlashPlugin(PluginModule* module) { |
411 return module->name() == kFlashPluginName; | 473 return module->name() == kFlashPluginName; |
412 } | 474 } |
413 | 475 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 const GURL& plugin_url) | 566 const GURL& plugin_url) |
505 : RenderFrameObserver(render_frame), | 567 : RenderFrameObserver(render_frame), |
506 render_frame_(render_frame), | 568 render_frame_(render_frame), |
507 module_(module), | 569 module_(module), |
508 instance_interface_(instance_interface), | 570 instance_interface_(instance_interface), |
509 pp_instance_(0), | 571 pp_instance_(0), |
510 container_(container), | 572 container_(container), |
511 layer_bound_to_fullscreen_(false), | 573 layer_bound_to_fullscreen_(false), |
512 layer_is_hardware_(false), | 574 layer_is_hardware_(false), |
513 plugin_url_(plugin_url), | 575 plugin_url_(plugin_url), |
576 has_been_clicked_(false), | |
514 power_saver_enabled_(false), | 577 power_saver_enabled_(false), |
515 is_peripheral_content_(false), | 578 is_peripheral_content_(false), |
516 plugin_throttled_(false), | 579 plugin_throttled_(false), |
517 full_frame_(false), | 580 full_frame_(false), |
518 sent_initial_did_change_view_(false), | 581 sent_initial_did_change_view_(false), |
519 bound_graphics_2d_platform_(NULL), | 582 bound_graphics_2d_platform_(NULL), |
520 bound_compositor_(NULL), | 583 bound_compositor_(NULL), |
521 has_webkit_focus_(false), | 584 has_webkit_focus_(false), |
522 has_content_area_focus_(false), | 585 has_content_area_focus_(false), |
523 find_identifier_(-1), | 586 find_identifier_(-1), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 GetPluginURL()); | 662 GetPluginURL()); |
600 } | 663 } |
601 } | 664 } |
602 | 665 |
603 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 666 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
604 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 667 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
605 | 668 |
606 if (GetContentClient()->renderer() && // NULL in unit tests. | 669 if (GetContentClient()->renderer() && // NULL in unit tests. |
607 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 670 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
608 external_document_load_ = true; | 671 external_document_load_ = true; |
609 | |
610 if (IsFlashPlugin(module_.get())) { | |
611 RenderThread::Get()->RecordAction( | |
612 base::UserMetricsAction("Flash.PluginInstanceCreated")); | |
613 } | |
614 } | 672 } |
615 | 673 |
616 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 674 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
617 DCHECK(!fullscreen_container_); | 675 DCHECK(!fullscreen_container_); |
618 | 676 |
619 if (plugin_throttled_) | 677 if (plugin_throttled_) |
620 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); | 678 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); |
621 | 679 |
622 // Notify all the plugin objects of deletion. This will prevent blink from | 680 // Notify all the plugin objects of deletion. This will prevent blink from |
623 // calling into the plugin any more. | 681 // calling into the plugin any more. |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 #endif | 922 #endif |
865 } | 923 } |
866 | 924 |
867 bool PepperPluginInstanceImpl::Initialize( | 925 bool PepperPluginInstanceImpl::Initialize( |
868 const std::vector<std::string>& arg_names, | 926 const std::vector<std::string>& arg_names, |
869 const std::vector<std::string>& arg_values, | 927 const std::vector<std::string>& arg_values, |
870 bool full_frame) { | 928 bool full_frame) { |
871 if (!render_frame_) | 929 if (!render_frame_) |
872 return false; | 930 return false; |
873 | 931 |
932 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | |
933 if (IsFlashPlugin(module_.get())) { | |
934 RenderThread::Get()->RecordAction( | |
935 base::UserMetricsAction("Flash.PluginInstanceCreated")); | |
936 RecordFlashSizeMetric(bounds.width, bounds.height); | |
937 } | |
938 | |
874 PluginPowerSaverHelper* power_saver_helper = | 939 PluginPowerSaverHelper* power_saver_helper = |
875 render_frame_->plugin_power_saver_helper(); | 940 render_frame_->plugin_power_saver_helper(); |
876 GURL content_origin = plugin_url_.GetOrigin(); | 941 GURL content_origin = plugin_url_.GetOrigin(); |
877 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | |
878 | 942 |
879 bool cross_origin = false; | 943 bool cross_origin = false; |
880 is_peripheral_content_ = | 944 is_peripheral_content_ = |
881 IsFlashPlugin(module_.get()) && | 945 IsFlashPlugin(module_.get()) && |
882 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, | 946 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, |
883 bounds.height, &cross_origin); | 947 bounds.height, &cross_origin); |
884 | 948 |
885 power_saver_enabled_ = is_peripheral_content_ && | 949 power_saver_enabled_ = is_peripheral_content_ && |
886 base::CommandLine::ForCurrentProcess()->HasSwitch( | 950 base::CommandLine::ForCurrentProcess()->HasSwitch( |
887 switches::kEnablePluginPowerSaver); | 951 switches::kEnablePluginPowerSaver); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1151 gfx::Rect caret(text_input_caret_); | 1215 gfx::Rect caret(text_input_caret_); |
1152 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | 1216 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); |
1153 return caret; | 1217 return caret; |
1154 } | 1218 } |
1155 | 1219 |
1156 bool PepperPluginInstanceImpl::HandleInputEvent( | 1220 bool PepperPluginInstanceImpl::HandleInputEvent( |
1157 const blink::WebInputEvent& event, | 1221 const blink::WebInputEvent& event, |
1158 WebCursorInfo* cursor_info) { | 1222 WebCursorInfo* cursor_info) { |
1159 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); | 1223 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
1160 | 1224 |
1225 if (event.type == blink::WebInputEvent::MouseDown && !has_been_clicked_ && | |
1226 IsFlashPlugin(module_.get())) { | |
1227 has_been_clicked_ = true; | |
1228 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | |
1229 RecordFlashClickSizeMetric(bounds.width, bounds.height); | |
1230 } | |
1231 | |
1161 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { | 1232 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { |
1162 is_peripheral_content_ = false; | 1233 is_peripheral_content_ = false; |
1163 power_saver_enabled_ = false; | 1234 power_saver_enabled_ = false; |
1164 | 1235 |
1165 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK); | 1236 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK); |
1166 | 1237 |
1167 if (plugin_throttled_) { | 1238 if (plugin_throttled_) { |
1168 SetPluginThrottled(false /* throttled */); | 1239 SetPluginThrottled(false /* throttled */); |
1169 return true; | 1240 return true; |
1170 } | 1241 } |
(...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3366 return; | 3437 return; |
3367 | 3438 |
3368 is_peripheral_content_ = false; | 3439 is_peripheral_content_ = false; |
3369 power_saver_enabled_ = false; | 3440 power_saver_enabled_ = false; |
3370 SetPluginThrottled(false); | 3441 SetPluginThrottled(false); |
3371 | 3442 |
3372 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_WHITELIST); | 3443 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_WHITELIST); |
3373 } | 3444 } |
3374 | 3445 |
3375 } // namespace content | 3446 } // namespace content |
OLD | NEW |