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); |
| 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 // Histogram tracking prevalence of tiny Flash instances. Units in pixels. |
| 403 enum PluginFlashTinyContentSize { |
| 404 TINY_CONTENT_SIZE_1_1 = 0, |
| 405 TINY_CONTENT_SIZE_5_5 = 1, |
| 406 TINY_CONTENT_SIZE_10_10 = 2, |
| 407 TINY_CONTENT_SIZE_LARGE = 3, |
| 408 TINY_CONTENT_SIZE_NUM_ITEMS |
| 409 }; |
| 410 |
394 // How the throttled power saver is unthrottled, if ever. | 411 // How the throttled power saver is unthrottled, if ever. |
395 // These numeric values are used in UMA logs; do not change them. | 412 // These numeric values are used in UMA logs; do not change them. |
396 enum PowerSaverUnthrottleMethod { | 413 enum PowerSaverUnthrottleMethod { |
397 UNTHROTTLE_METHOD_NEVER = 0, | 414 UNTHROTTLE_METHOD_NEVER = 0, |
398 UNTHROTTLE_METHOD_BY_CLICK = 1, | 415 UNTHROTTLE_METHOD_BY_CLICK = 1, |
399 UNTHROTTLE_METHOD_BY_WHITELIST = 2, | 416 UNTHROTTLE_METHOD_BY_WHITELIST = 2, |
400 UNTHROTTLE_METHOD_NUM_ITEMS | 417 UNTHROTTLE_METHOD_NUM_ITEMS |
401 }; | 418 }; |
402 | 419 |
403 const char kPowerSaverUnthrottleHistogram[] = "Plugin.PowerSaverUnthrottle"; | 420 const char kFlashClickSizeAspectRatioHistogram[] = |
| 421 "Plugin.Flash.ClickSize.AspectRatio"; |
| 422 const char kFlashClickSizeHeightHistogram[] = "Plugin.Flash.ClickSize.Height"; |
| 423 const char kFlashClickSizeWidthHistogram[] = "Plugin.Flash.ClickSize.Width"; |
| 424 const char kFlashTinyContentSizeHistogram[] = "Plugin.Flash.TinyContentSize"; |
| 425 const char kPowerSaverUnthrottleHistogram[] = "Plugin.PowerSaver.Unthrottle"; |
| 426 |
| 427 // Record size metrics for all Flash instances. |
| 428 void RecordFlashSizeMetric(int width, int height) { |
| 429 PluginFlashTinyContentSize size = TINY_CONTENT_SIZE_LARGE; |
| 430 |
| 431 if (width <= 1 && height <= 1) |
| 432 size = TINY_CONTENT_SIZE_1_1; |
| 433 else if (width <= 5 && height <= 5) |
| 434 size = TINY_CONTENT_SIZE_5_5; |
| 435 else if (width <= 10 && height <= 10) |
| 436 size = TINY_CONTENT_SIZE_10_10; |
| 437 |
| 438 UMA_HISTOGRAM_ENUMERATION(kFlashTinyContentSizeHistogram, size, |
| 439 TINY_CONTENT_SIZE_NUM_ITEMS); |
| 440 } |
| 441 |
| 442 // Records size metrics for Flash instances that are clicked. |
| 443 void RecordFlashClickSizeMetric(int width, int height) { |
| 444 base::HistogramBase* width_histogram = base::LinearHistogram::FactoryGet( |
| 445 kFlashClickSizeWidthHistogram, |
| 446 0, // minimum width |
| 447 500, // maximum width |
| 448 100, // number of buckets. |
| 449 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 450 width_histogram->Add(width); |
| 451 |
| 452 base::HistogramBase* height_histogram = base::LinearHistogram::FactoryGet( |
| 453 kFlashClickSizeHeightHistogram, |
| 454 0, // minimum height |
| 455 400, // maximum height |
| 456 100, // number of buckets. |
| 457 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 458 height_histogram->Add(height); |
| 459 |
| 460 UMA_HISTOGRAM_ASPECT_RATIO(kFlashClickSizeAspectRatioHistogram, width, |
| 461 height); |
| 462 } |
404 | 463 |
405 void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method) { | 464 void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method) { |
406 UMA_HISTOGRAM_ENUMERATION(kPowerSaverUnthrottleHistogram, method, | 465 UMA_HISTOGRAM_ENUMERATION(kPowerSaverUnthrottleHistogram, method, |
407 UNTHROTTLE_METHOD_NUM_ITEMS); | 466 UNTHROTTLE_METHOD_NUM_ITEMS); |
408 } | 467 } |
409 | 468 |
410 bool IsFlashPlugin(PluginModule* module) { | 469 bool IsFlashPlugin(PluginModule* module) { |
411 return module->name() == kFlashPluginName; | 470 return module->name() == kFlashPluginName; |
412 } | 471 } |
413 | 472 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 const GURL& plugin_url) | 563 const GURL& plugin_url) |
505 : RenderFrameObserver(render_frame), | 564 : RenderFrameObserver(render_frame), |
506 render_frame_(render_frame), | 565 render_frame_(render_frame), |
507 module_(module), | 566 module_(module), |
508 instance_interface_(instance_interface), | 567 instance_interface_(instance_interface), |
509 pp_instance_(0), | 568 pp_instance_(0), |
510 container_(container), | 569 container_(container), |
511 layer_bound_to_fullscreen_(false), | 570 layer_bound_to_fullscreen_(false), |
512 layer_is_hardware_(false), | 571 layer_is_hardware_(false), |
513 plugin_url_(plugin_url), | 572 plugin_url_(plugin_url), |
| 573 has_been_clicked_(false), |
514 power_saver_enabled_(false), | 574 power_saver_enabled_(false), |
515 is_peripheral_content_(false), | 575 is_peripheral_content_(false), |
516 plugin_throttled_(false), | 576 plugin_throttled_(false), |
517 full_frame_(false), | 577 full_frame_(false), |
518 sent_initial_did_change_view_(false), | 578 sent_initial_did_change_view_(false), |
519 bound_graphics_2d_platform_(NULL), | 579 bound_graphics_2d_platform_(NULL), |
520 bound_compositor_(NULL), | 580 bound_compositor_(NULL), |
521 has_webkit_focus_(false), | 581 has_webkit_focus_(false), |
522 has_content_area_focus_(false), | 582 has_content_area_focus_(false), |
523 find_identifier_(-1), | 583 find_identifier_(-1), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 GetPluginURL()); | 659 GetPluginURL()); |
600 } | 660 } |
601 } | 661 } |
602 | 662 |
603 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 663 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
604 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 664 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
605 | 665 |
606 if (GetContentClient()->renderer() && // NULL in unit tests. | 666 if (GetContentClient()->renderer() && // NULL in unit tests. |
607 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 667 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
608 external_document_load_ = true; | 668 external_document_load_ = true; |
609 | |
610 if (IsFlashPlugin(module_.get())) { | |
611 RenderThread::Get()->RecordAction( | |
612 base::UserMetricsAction("Flash.PluginInstanceCreated")); | |
613 } | |
614 } | 669 } |
615 | 670 |
616 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 671 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
617 DCHECK(!fullscreen_container_); | 672 DCHECK(!fullscreen_container_); |
618 | 673 |
619 if (plugin_throttled_) | 674 if (plugin_throttled_) |
620 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); | 675 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); |
621 | 676 |
622 // Notify all the plugin objects of deletion. This will prevent blink from | 677 // Notify all the plugin objects of deletion. This will prevent blink from |
623 // calling into the plugin any more. | 678 // calling into the plugin any more. |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 #endif | 919 #endif |
865 } | 920 } |
866 | 921 |
867 bool PepperPluginInstanceImpl::Initialize( | 922 bool PepperPluginInstanceImpl::Initialize( |
868 const std::vector<std::string>& arg_names, | 923 const std::vector<std::string>& arg_names, |
869 const std::vector<std::string>& arg_values, | 924 const std::vector<std::string>& arg_values, |
870 bool full_frame) { | 925 bool full_frame) { |
871 if (!render_frame_) | 926 if (!render_frame_) |
872 return false; | 927 return false; |
873 | 928 |
| 929 blink::WebRect bounds = container_->element().boundsInViewportSpace(); |
| 930 if (IsFlashPlugin(module_.get())) { |
| 931 RenderThread::Get()->RecordAction( |
| 932 base::UserMetricsAction("Flash.PluginInstanceCreated")); |
| 933 RecordFlashSizeMetric(bounds.width, bounds.height); |
| 934 } |
| 935 |
874 PluginPowerSaverHelper* power_saver_helper = | 936 PluginPowerSaverHelper* power_saver_helper = |
875 render_frame_->plugin_power_saver_helper(); | 937 render_frame_->plugin_power_saver_helper(); |
876 GURL content_origin = plugin_url_.GetOrigin(); | 938 GURL content_origin = plugin_url_.GetOrigin(); |
877 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | |
878 | 939 |
879 bool cross_origin = false; | 940 bool cross_origin = false; |
880 is_peripheral_content_ = | 941 is_peripheral_content_ = |
881 IsFlashPlugin(module_.get()) && | 942 IsFlashPlugin(module_.get()) && |
882 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, | 943 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, |
883 bounds.height, &cross_origin); | 944 bounds.height, &cross_origin); |
884 | 945 |
885 power_saver_enabled_ = is_peripheral_content_ && | 946 power_saver_enabled_ = is_peripheral_content_ && |
886 base::CommandLine::ForCurrentProcess()->HasSwitch( | 947 base::CommandLine::ForCurrentProcess()->HasSwitch( |
887 switches::kEnablePluginPowerSaver); | 948 switches::kEnablePluginPowerSaver); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 gfx::Rect caret(text_input_caret_); | 1212 gfx::Rect caret(text_input_caret_); |
1152 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | 1213 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); |
1153 return caret; | 1214 return caret; |
1154 } | 1215 } |
1155 | 1216 |
1156 bool PepperPluginInstanceImpl::HandleInputEvent( | 1217 bool PepperPluginInstanceImpl::HandleInputEvent( |
1157 const blink::WebInputEvent& event, | 1218 const blink::WebInputEvent& event, |
1158 WebCursorInfo* cursor_info) { | 1219 WebCursorInfo* cursor_info) { |
1159 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); | 1220 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
1160 | 1221 |
| 1222 if (event.type == blink::WebInputEvent::MouseDown && !has_been_clicked_ && |
| 1223 IsFlashPlugin(module_.get())) { |
| 1224 has_been_clicked_ = true; |
| 1225 blink::WebRect bounds = container_->element().boundsInViewportSpace(); |
| 1226 RecordFlashClickSizeMetric(bounds.width, bounds.height); |
| 1227 } |
| 1228 |
1161 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { | 1229 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { |
1162 is_peripheral_content_ = false; | 1230 is_peripheral_content_ = false; |
1163 power_saver_enabled_ = false; | 1231 power_saver_enabled_ = false; |
1164 | 1232 |
1165 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK); | 1233 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK); |
1166 | 1234 |
1167 if (plugin_throttled_) { | 1235 if (plugin_throttled_) { |
1168 SetPluginThrottled(false /* throttled */); | 1236 SetPluginThrottled(false /* throttled */); |
1169 return true; | 1237 return true; |
1170 } | 1238 } |
(...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3366 return; | 3434 return; |
3367 | 3435 |
3368 is_peripheral_content_ = false; | 3436 is_peripheral_content_ = false; |
3369 power_saver_enabled_ = false; | 3437 power_saver_enabled_ = false; |
3370 SetPluginThrottled(false); | 3438 SetPluginThrottled(false); |
3371 | 3439 |
3372 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_WHITELIST); | 3440 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_WHITELIST); |
3373 } | 3441 } |
3374 | 3442 |
3375 } // namespace content | 3443 } // namespace content |
OLD | NEW |