Chromium Code Reviews| 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 enum PluginFlashTinyContentSize { | |
|
raymes
2014/11/10 02:54:30
You may want to make a comment about what this is
tommycli
2014/11/10 15:40:30
Done.
| |
| 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) { | |
|
raymes
2014/11/10 02:54:30
nit: Comments for these helper functions would be
tommycli
2014/11/10 15:40:30
Done.
| |
| 427 PluginFlashTinyContentSize size = TINY_CONTENT_SIZE_LARGE; | |
| 428 | |
| 429 if (width <= 1 && height <= 1) | |
| 430 size = TINY_CONTENT_SIZE_1_1; | |
| 431 else if (width <= 5 && height <= 5) | |
| 432 size = TINY_CONTENT_SIZE_5_5; | |
| 433 else if (width <= 10 && height <= 10) | |
| 434 size = TINY_CONTENT_SIZE_10_10; | |
| 435 | |
| 436 UMA_HISTOGRAM_ENUMERATION(kFlashTinyContentSizeHistogram, size, | |
| 437 TINY_CONTENT_SIZE_NUM_ITEMS); | |
| 438 } | |
| 439 | |
| 440 void RecordFlashClickSizeMetric(int width, int height) { | |
| 441 base::HistogramBase* width_histogram = base::LinearHistogram::FactoryGet( | |
| 442 kFlashClickSizeWidthHistogram, | |
| 443 0, // minimum width | |
| 444 500, // maximum width | |
| 445 100, // number of buckets. | |
| 446 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 447 width_histogram->Add(width); | |
| 448 | |
| 449 base::HistogramBase* height_histogram = base::LinearHistogram::FactoryGet( | |
| 450 kFlashClickSizeHeightHistogram, | |
| 451 0, // minimum height | |
| 452 400, // maximum height | |
| 453 100, // number of buckets. | |
| 454 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 455 height_histogram->Add(height); | |
| 456 | |
| 457 UMA_HISTOGRAM_ASPECT_RATIO(kFlashClickSizeAspectRatioHistogram, width, | |
| 458 height); | |
| 459 } | |
| 404 | 460 |
| 405 void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method) { | 461 void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method) { |
| 406 UMA_HISTOGRAM_ENUMERATION(kPowerSaverUnthrottleHistogram, method, | 462 UMA_HISTOGRAM_ENUMERATION(kPowerSaverUnthrottleHistogram, method, |
| 407 UNTHROTTLE_METHOD_NUM_ITEMS); | 463 UNTHROTTLE_METHOD_NUM_ITEMS); |
| 408 } | 464 } |
| 409 | 465 |
| 410 bool IsFlashPlugin(PluginModule* module) { | 466 bool IsFlashPlugin(PluginModule* module) { |
| 411 return module->name() == kFlashPluginName; | 467 return module->name() == kFlashPluginName; |
| 412 } | 468 } |
| 413 | 469 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 const GURL& plugin_url) | 560 const GURL& plugin_url) |
| 505 : RenderFrameObserver(render_frame), | 561 : RenderFrameObserver(render_frame), |
| 506 render_frame_(render_frame), | 562 render_frame_(render_frame), |
| 507 module_(module), | 563 module_(module), |
| 508 instance_interface_(instance_interface), | 564 instance_interface_(instance_interface), |
| 509 pp_instance_(0), | 565 pp_instance_(0), |
| 510 container_(container), | 566 container_(container), |
| 511 layer_bound_to_fullscreen_(false), | 567 layer_bound_to_fullscreen_(false), |
| 512 layer_is_hardware_(false), | 568 layer_is_hardware_(false), |
| 513 plugin_url_(plugin_url), | 569 plugin_url_(plugin_url), |
| 570 has_been_clicked_(false), | |
| 514 power_saver_enabled_(false), | 571 power_saver_enabled_(false), |
| 515 is_peripheral_content_(false), | 572 is_peripheral_content_(false), |
| 516 plugin_throttled_(false), | 573 plugin_throttled_(false), |
| 517 full_frame_(false), | 574 full_frame_(false), |
| 518 sent_initial_did_change_view_(false), | 575 sent_initial_did_change_view_(false), |
| 519 bound_graphics_2d_platform_(NULL), | 576 bound_graphics_2d_platform_(NULL), |
| 520 bound_compositor_(NULL), | 577 bound_compositor_(NULL), |
| 521 has_webkit_focus_(false), | 578 has_webkit_focus_(false), |
| 522 has_content_area_focus_(false), | 579 has_content_area_focus_(false), |
| 523 find_identifier_(-1), | 580 find_identifier_(-1), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 GetPluginURL()); | 656 GetPluginURL()); |
| 600 } | 657 } |
| 601 } | 658 } |
| 602 | 659 |
| 603 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 660 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
| 604 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 661 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
| 605 | 662 |
| 606 if (GetContentClient()->renderer() && // NULL in unit tests. | 663 if (GetContentClient()->renderer() && // NULL in unit tests. |
| 607 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 664 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
| 608 external_document_load_ = true; | 665 external_document_load_ = true; |
| 609 | |
| 610 if (IsFlashPlugin(module_.get())) { | |
| 611 RenderThread::Get()->RecordAction( | |
| 612 base::UserMetricsAction("Flash.PluginInstanceCreated")); | |
| 613 } | |
| 614 } | 666 } |
| 615 | 667 |
| 616 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 668 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
| 617 DCHECK(!fullscreen_container_); | 669 DCHECK(!fullscreen_container_); |
| 618 | 670 |
| 619 if (plugin_throttled_) | 671 if (plugin_throttled_) |
| 620 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); | 672 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); |
| 621 | 673 |
| 622 // Notify all the plugin objects of deletion. This will prevent blink from | 674 // Notify all the plugin objects of deletion. This will prevent blink from |
| 623 // calling into the plugin any more. | 675 // calling into the plugin any more. |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 #endif | 916 #endif |
| 865 } | 917 } |
| 866 | 918 |
| 867 bool PepperPluginInstanceImpl::Initialize( | 919 bool PepperPluginInstanceImpl::Initialize( |
| 868 const std::vector<std::string>& arg_names, | 920 const std::vector<std::string>& arg_names, |
| 869 const std::vector<std::string>& arg_values, | 921 const std::vector<std::string>& arg_values, |
| 870 bool full_frame) { | 922 bool full_frame) { |
| 871 if (!render_frame_) | 923 if (!render_frame_) |
| 872 return false; | 924 return false; |
| 873 | 925 |
| 926 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | |
| 927 if (IsFlashPlugin(module_.get())) { | |
| 928 RenderThread::Get()->RecordAction( | |
| 929 base::UserMetricsAction("Flash.PluginInstanceCreated")); | |
| 930 RecordFlashSizeMetric(bounds.width, bounds.height); | |
| 931 } | |
| 932 | |
| 874 PluginPowerSaverHelper* power_saver_helper = | 933 PluginPowerSaverHelper* power_saver_helper = |
| 875 render_frame_->plugin_power_saver_helper(); | 934 render_frame_->plugin_power_saver_helper(); |
| 876 GURL content_origin = plugin_url_.GetOrigin(); | 935 GURL content_origin = plugin_url_.GetOrigin(); |
| 877 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | |
| 878 | 936 |
| 879 bool cross_origin = false; | 937 bool cross_origin = false; |
| 880 is_peripheral_content_ = | 938 is_peripheral_content_ = |
| 881 IsFlashPlugin(module_.get()) && | 939 IsFlashPlugin(module_.get()) && |
| 882 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, | 940 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, |
| 883 bounds.height, &cross_origin); | 941 bounds.height, &cross_origin); |
| 884 | 942 |
| 885 power_saver_enabled_ = is_peripheral_content_ && | 943 power_saver_enabled_ = is_peripheral_content_ && |
| 886 base::CommandLine::ForCurrentProcess()->HasSwitch( | 944 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 887 switches::kEnablePluginPowerSaver); | 945 switches::kEnablePluginPowerSaver); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 gfx::Rect caret(text_input_caret_); | 1209 gfx::Rect caret(text_input_caret_); |
| 1152 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | 1210 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); |
| 1153 return caret; | 1211 return caret; |
| 1154 } | 1212 } |
| 1155 | 1213 |
| 1156 bool PepperPluginInstanceImpl::HandleInputEvent( | 1214 bool PepperPluginInstanceImpl::HandleInputEvent( |
| 1157 const blink::WebInputEvent& event, | 1215 const blink::WebInputEvent& event, |
| 1158 WebCursorInfo* cursor_info) { | 1216 WebCursorInfo* cursor_info) { |
| 1159 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); | 1217 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
| 1160 | 1218 |
| 1219 if (event.type == blink::WebInputEvent::MouseDown && !has_been_clicked_ && | |
| 1220 IsFlashPlugin(module_.get())) { | |
| 1221 has_been_clicked_ = true; | |
| 1222 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | |
| 1223 RecordFlashClickSizeMetric(bounds.width, bounds.height); | |
| 1224 } | |
| 1225 | |
| 1161 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { | 1226 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { |
| 1162 is_peripheral_content_ = false; | 1227 is_peripheral_content_ = false; |
| 1163 power_saver_enabled_ = false; | 1228 power_saver_enabled_ = false; |
| 1164 | 1229 |
| 1165 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK); | 1230 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK); |
| 1166 | 1231 |
| 1167 if (plugin_throttled_) { | 1232 if (plugin_throttled_) { |
| 1168 SetPluginThrottled(false /* throttled */); | 1233 SetPluginThrottled(false /* throttled */); |
| 1169 return true; | 1234 return true; |
| 1170 } | 1235 } |
| (...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3366 return; | 3431 return; |
| 3367 | 3432 |
| 3368 is_peripheral_content_ = false; | 3433 is_peripheral_content_ = false; |
| 3369 power_saver_enabled_ = false; | 3434 power_saver_enabled_ = false; |
| 3370 SetPluginThrottled(false); | 3435 SetPluginThrottled(false); |
| 3371 | 3436 |
| 3372 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_WHITELIST); | 3437 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_WHITELIST); |
| 3373 } | 3438 } |
| 3374 | 3439 |
| 3375 } // namespace content | 3440 } // namespace content |
| OLD | NEW |