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" | |
| 10 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" | 10 #include "base/logging.h" |
| 12 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | |
| 15 #include "base/metrics/sparse_histogram.h" | |
| 16 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 17 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_offset_string_conversions.h" | 15 #include "base/strings/utf_offset_string_conversions.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 21 #include "cc/base/latency_info_swap_promise.h" | 18 #include "cc/base/latency_info_swap_promise.h" |
| 22 #include "cc/blink/web_layer_impl.h" | 19 #include "cc/blink/web_layer_impl.h" |
| 23 #include "cc/layers/texture_layer.h" | 20 #include "cc/layers/texture_layer.h" |
| 24 #include "cc/trees/layer_tree_host.h" | 21 #include "cc/trees/layer_tree_host.h" |
| 25 #include "content/common/content_constants_internal.h" | 22 #include "content/common/content_constants_internal.h" |
| 26 #include "content/common/frame_messages.h" | 23 #include "content/common/frame_messages.h" |
| 27 #include "content/common/input/web_input_event_traits.h" | 24 #include "content/common/input/web_input_event_traits.h" |
| 28 #include "content/public/common/content_constants.h" | 25 #include "content/public/common/content_constants.h" |
| 29 #include "content/public/common/content_switches.h" | |
| 30 #include "content/public/common/page_zoom.h" | 26 #include "content/public/common/page_zoom.h" |
| 31 #include "content/public/renderer/content_renderer_client.h" | 27 #include "content/public/renderer/content_renderer_client.h" |
| 32 #include "content/renderer/gpu/render_widget_compositor.h" | 28 #include "content/renderer/gpu/render_widget_compositor.h" |
| 33 #include "content/renderer/pepper/content_decryptor_delegate.h" | 29 #include "content/renderer/pepper/content_decryptor_delegate.h" |
| 34 #include "content/renderer/pepper/event_conversion.h" | 30 #include "content/renderer/pepper/event_conversion.h" |
| 35 #include "content/renderer/pepper/fullscreen_container.h" | 31 #include "content/renderer/pepper/fullscreen_container.h" |
| 36 #include "content/renderer/pepper/gfx_conversion.h" | 32 #include "content/renderer/pepper/gfx_conversion.h" |
| 37 #include "content/renderer/pepper/host_dispatcher_wrapper.h" | 33 #include "content/renderer/pepper/host_dispatcher_wrapper.h" |
| 38 #include "content/renderer/pepper/host_globals.h" | 34 #include "content/renderer/pepper/host_globals.h" |
| 39 #include "content/renderer/pepper/message_channel.h" | 35 #include "content/renderer/pepper/message_channel.h" |
| 40 #include "content/renderer/pepper/pepper_browser_connection.h" | 36 #include "content/renderer/pepper/pepper_browser_connection.h" |
| 41 #include "content/renderer/pepper/pepper_compositor_host.h" | 37 #include "content/renderer/pepper/pepper_compositor_host.h" |
| 42 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" | 38 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" |
| 43 #include "content/renderer/pepper/pepper_graphics_2d_host.h" | 39 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
| 44 #include "content/renderer/pepper/pepper_in_process_router.h" | 40 #include "content/renderer/pepper/pepper_in_process_router.h" |
| 45 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 41 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 46 #include "content/renderer/pepper/pepper_plugin_instance_throttler.h" | 42 #include "content/renderer/pepper/pepper_plugin_instance_throttler.h" |
| 47 #include "content/renderer/pepper/pepper_try_catch.h" | 43 #include "content/renderer/pepper/pepper_try_catch.h" |
| 48 #include "content/renderer/pepper/pepper_url_loader_host.h" | 44 #include "content/renderer/pepper/pepper_url_loader_host.h" |
| 49 #include "content/renderer/pepper/plugin_module.h" | 45 #include "content/renderer/pepper/plugin_module.h" |
| 50 #include "content/renderer/pepper/plugin_object.h" | 46 #include "content/renderer/pepper/plugin_object.h" |
| 51 #include "content/renderer/pepper/plugin_power_saver_helper.h" | |
| 52 #include "content/renderer/pepper/ppapi_preferences_builder.h" | 47 #include "content/renderer/pepper/ppapi_preferences_builder.h" |
| 53 #include "content/renderer/pepper/ppb_buffer_impl.h" | 48 #include "content/renderer/pepper/ppb_buffer_impl.h" |
| 54 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" | 49 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
| 55 #include "content/renderer/pepper/ppb_image_data_impl.h" | 50 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| 56 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 51 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
| 57 #include "content/renderer/pepper/url_request_info_util.h" | 52 #include "content/renderer/pepper/url_request_info_util.h" |
| 58 #include "content/renderer/pepper/url_response_info_util.h" | 53 #include "content/renderer/pepper/url_response_info_util.h" |
| 59 #include "content/renderer/render_frame_impl.h" | 54 #include "content/renderer/render_frame_impl.h" |
| 60 #include "content/renderer/render_thread_impl.h" | 55 #include "content/renderer/render_thread_impl.h" |
| 61 #include "content/renderer/render_view_impl.h" | 56 #include "content/renderer/render_view_impl.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 #include "third_party/WebKit/public/platform/WebGamepads.h" | 101 #include "third_party/WebKit/public/platform/WebGamepads.h" |
| 107 #include "third_party/WebKit/public/platform/WebRect.h" | 102 #include "third_party/WebKit/public/platform/WebRect.h" |
| 108 #include "third_party/WebKit/public/platform/WebString.h" | 103 #include "third_party/WebKit/public/platform/WebString.h" |
| 109 #include "third_party/WebKit/public/platform/WebURL.h" | 104 #include "third_party/WebKit/public/platform/WebURL.h" |
| 110 #include "third_party/WebKit/public/platform/WebURLError.h" | 105 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 111 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 106 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 112 #include "third_party/WebKit/public/web/WebBindings.h" | 107 #include "third_party/WebKit/public/web/WebBindings.h" |
| 113 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 108 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
| 114 #include "third_party/WebKit/public/web/WebDataSource.h" | 109 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 115 #include "third_party/WebKit/public/web/WebDocument.h" | 110 #include "third_party/WebKit/public/web/WebDocument.h" |
| 116 #include "third_party/WebKit/public/web/WebElement.h" | |
| 117 #include "third_party/WebKit/public/web/WebInputEvent.h" | 111 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 118 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 112 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 119 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 113 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 120 #include "third_party/WebKit/public/web/WebPrintParams.h" | 114 #include "third_party/WebKit/public/web/WebPrintParams.h" |
| 121 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" | 115 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" |
| 122 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 116 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
| 123 #include "third_party/WebKit/public/web/WebScriptSource.h" | 117 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 124 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 118 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 125 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 119 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 126 #include "third_party/WebKit/public/web/WebView.h" | 120 #include "third_party/WebKit/public/web/WebView.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 using blink::WebURLRequest; | 174 using blink::WebURLRequest; |
| 181 using blink::WebURLResponse; | 175 using blink::WebURLResponse; |
| 182 using blink::WebUserGestureIndicator; | 176 using blink::WebUserGestureIndicator; |
| 183 using blink::WebUserGestureToken; | 177 using blink::WebUserGestureToken; |
| 184 using blink::WebView; | 178 using blink::WebView; |
| 185 | 179 |
| 186 namespace content { | 180 namespace content { |
| 187 | 181 |
| 188 namespace { | 182 namespace { |
| 189 | 183 |
| 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 | |
| 197 // Check PP_TextInput_Type and ui::TextInputType are kept in sync. | 184 // Check PP_TextInput_Type and ui::TextInputType are kept in sync. |
| 198 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NONE) == int(PP_TEXTINPUT_TYPE_NONE), | 185 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NONE) == int(PP_TEXTINPUT_TYPE_NONE), |
| 199 mismatching_enums); | 186 mismatching_enums); |
| 200 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TEXT) == int(PP_TEXTINPUT_TYPE_TEXT), | 187 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TEXT) == int(PP_TEXTINPUT_TYPE_TEXT), |
| 201 mismatching_enums); | 188 mismatching_enums); |
| 202 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_PASSWORD) == | 189 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_PASSWORD) == |
| 203 int(PP_TEXTINPUT_TYPE_PASSWORD), | 190 int(PP_TEXTINPUT_TYPE_PASSWORD), |
| 204 mismatching_enums); | 191 mismatching_enums); |
| 205 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_SEARCH) == int(PP_TEXTINPUT_TYPE_SEARCH), | 192 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_SEARCH) == int(PP_TEXTINPUT_TYPE_SEARCH), |
| 206 mismatching_enums); | 193 mismatching_enums); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 input_sequence); | 379 input_sequence); |
| 393 new_latency->TraceEventType(WebInputEventTraits::GetName(type)); | 380 new_latency->TraceEventType(WebInputEventTraits::GetName(type)); |
| 394 if (old_latency) { | 381 if (old_latency) { |
| 395 new_latency->CopyLatencyFrom(*old_latency, | 382 new_latency->CopyLatencyFrom(*old_latency, |
| 396 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); | 383 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); |
| 397 new_latency->CopyLatencyFrom(*old_latency, | 384 new_latency->CopyLatencyFrom(*old_latency, |
| 398 ui::INPUT_EVENT_LATENCY_UI_COMPONENT); | 385 ui::INPUT_EVENT_LATENCY_UI_COMPONENT); |
| 399 } | 386 } |
| 400 } | 387 } |
| 401 | 388 |
| 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 | |
| 411 // How the throttled power saver is unthrottled, if ever. | |
| 412 // These numeric values are used in UMA logs; do not change them. | |
| 413 enum PowerSaverUnthrottleMethod { | |
| 414 UNTHROTTLE_METHOD_NEVER = 0, | |
| 415 UNTHROTTLE_METHOD_BY_CLICK = 1, | |
| 416 UNTHROTTLE_METHOD_BY_WHITELIST = 2, | |
| 417 UNTHROTTLE_METHOD_NUM_ITEMS | |
| 418 }; | |
| 419 | |
| 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 } | |
| 463 | |
| 464 void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method) { | |
| 465 UMA_HISTOGRAM_ENUMERATION(kPowerSaverUnthrottleHistogram, method, | |
| 466 UNTHROTTLE_METHOD_NUM_ITEMS); | |
| 467 } | |
| 468 | |
| 469 bool IsFlashPlugin(PluginModule* module) { | |
| 470 return module->name() == kFlashPluginName; | |
| 471 } | |
| 472 | |
| 473 } // namespace | 389 } // namespace |
| 474 | 390 |
| 475 // static | 391 // static |
| 476 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( | 392 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( |
| 477 RenderFrameImpl* render_frame, | 393 RenderFrameImpl* render_frame, |
| 478 PluginModule* module, | 394 PluginModule* module, |
| 479 WebPluginContainer* container, | 395 WebPluginContainer* container, |
| 480 const GURL& plugin_url) { | 396 const GURL& plugin_url) { |
| 481 base::Callback<const void*(const char*)> get_plugin_interface_func = | 397 base::Callback<const void*(const char*)> get_plugin_interface_func = |
| 482 base::Bind(&PluginModule::GetPluginInterface, module); | 398 base::Bind(&PluginModule::GetPluginInterface, module); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 const GURL& plugin_url) | 479 const GURL& plugin_url) |
| 564 : RenderFrameObserver(render_frame), | 480 : RenderFrameObserver(render_frame), |
| 565 render_frame_(render_frame), | 481 render_frame_(render_frame), |
| 566 module_(module), | 482 module_(module), |
| 567 instance_interface_(instance_interface), | 483 instance_interface_(instance_interface), |
| 568 pp_instance_(0), | 484 pp_instance_(0), |
| 569 container_(container), | 485 container_(container), |
| 570 layer_bound_to_fullscreen_(false), | 486 layer_bound_to_fullscreen_(false), |
| 571 layer_is_hardware_(false), | 487 layer_is_hardware_(false), |
| 572 plugin_url_(plugin_url), | 488 plugin_url_(plugin_url), |
| 573 has_been_clicked_(false), | |
| 574 power_saver_enabled_(false), | |
| 575 is_peripheral_content_(false), | |
| 576 plugin_throttled_(false), | |
| 577 full_frame_(false), | 489 full_frame_(false), |
| 578 sent_initial_did_change_view_(false), | 490 sent_initial_did_change_view_(false), |
| 579 bound_graphics_2d_platform_(NULL), | 491 bound_graphics_2d_platform_(NULL), |
| 580 bound_compositor_(NULL), | 492 bound_compositor_(NULL), |
| 581 has_webkit_focus_(false), | 493 has_webkit_focus_(false), |
| 582 has_content_area_focus_(false), | 494 has_content_area_focus_(false), |
| 583 find_identifier_(-1), | 495 find_identifier_(-1), |
| 584 plugin_find_interface_(NULL), | 496 plugin_find_interface_(NULL), |
| 585 plugin_input_event_interface_(NULL), | 497 plugin_input_event_interface_(NULL), |
| 586 plugin_mouse_lock_interface_(NULL), | 498 plugin_mouse_lock_interface_(NULL), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 576 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
| 665 | 577 |
| 666 if (GetContentClient()->renderer() && // NULL in unit tests. | 578 if (GetContentClient()->renderer() && // NULL in unit tests. |
| 667 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 579 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
| 668 external_document_load_ = true; | 580 external_document_load_ = true; |
| 669 } | 581 } |
| 670 | 582 |
| 671 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 583 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
| 672 DCHECK(!fullscreen_container_); | 584 DCHECK(!fullscreen_container_); |
| 673 | 585 |
| 674 if (plugin_throttled_) | |
| 675 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); | |
| 676 | |
| 677 // Notify all the plugin objects of deletion. This will prevent blink from | 586 // Notify all the plugin objects of deletion. This will prevent blink from |
| 678 // calling into the plugin any more. | 587 // calling into the plugin any more. |
| 679 // | 588 // |
| 680 // Swap out the set so we can delete from it (the objects will try to | 589 // Swap out the set so we can delete from it (the objects will try to |
| 681 // unregister themselves inside the delete call). | 590 // unregister themselves inside the delete call). |
| 682 PluginObjectSet plugin_object_copy; | 591 PluginObjectSet plugin_object_copy; |
| 683 live_plugin_objects_.swap(plugin_object_copy); | 592 live_plugin_objects_.swap(plugin_object_copy); |
| 684 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | 593 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); |
| 685 i != plugin_object_copy.end(); | 594 i != plugin_object_copy.end(); |
| 686 ++i) { | 595 ++i) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 919 #endif | 828 #endif |
| 920 } | 829 } |
| 921 | 830 |
| 922 bool PepperPluginInstanceImpl::Initialize( | 831 bool PepperPluginInstanceImpl::Initialize( |
| 923 const std::vector<std::string>& arg_names, | 832 const std::vector<std::string>& arg_names, |
| 924 const std::vector<std::string>& arg_values, | 833 const std::vector<std::string>& arg_values, |
| 925 bool full_frame) { | 834 bool full_frame) { |
| 926 if (!render_frame_) | 835 if (!render_frame_) |
| 927 return false; | 836 return false; |
| 928 | 837 |
| 929 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | 838 throttler_.reset(new PepperPluginInstanceThrottler( |
| 930 if (IsFlashPlugin(module_.get())) { | 839 this, base::Bind(&PepperPluginInstanceImpl::SendDidChangeView, |
| 931 RenderThread::Get()->RecordAction( | 840 weak_factory_.GetWeakPtr()))); |
| 932 base::UserMetricsAction("Flash.PluginInstanceCreated")); | |
| 933 RecordFlashSizeMetric(bounds.width, bounds.height); | |
| 934 } | |
| 935 | |
| 936 PluginPowerSaverHelper* power_saver_helper = | |
| 937 render_frame_->plugin_power_saver_helper(); | |
| 938 GURL content_origin = plugin_url_.GetOrigin(); | |
| 939 | |
| 940 bool cross_origin = false; | |
| 941 is_peripheral_content_ = | |
| 942 IsFlashPlugin(module_.get()) && | |
| 943 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, | |
| 944 bounds.height, &cross_origin); | |
| 945 | |
| 946 power_saver_enabled_ = is_peripheral_content_ && | |
| 947 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 948 switches::kEnablePluginPowerSaver); | |
| 949 | |
| 950 if (is_peripheral_content_) { | |
| 951 // To collect UMAs, register peripheral content even if we don't throttle. | |
| 952 power_saver_helper->RegisterPeripheralPlugin( | |
| 953 content_origin, | |
| 954 base::Bind( | |
| 955 &PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist, | |
| 956 weak_factory_.GetWeakPtr())); | |
| 957 | |
| 958 if (power_saver_enabled_) { | |
| 959 throttler_.reset(new PepperPluginInstanceThrottler( | |
| 960 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, | |
| 961 weak_factory_.GetWeakPtr(), true /* throttled */))); | |
| 962 } | |
| 963 } else if (cross_origin) { | |
| 964 power_saver_helper->WhitelistContentOrigin(content_origin); | |
| 965 } | |
| 966 | 841 |
| 967 message_channel_ = MessageChannel::Create(this, &message_channel_object_); | 842 message_channel_ = MessageChannel::Create(this, &message_channel_object_); |
| 968 | 843 |
| 969 full_frame_ = full_frame; | 844 full_frame_ = full_frame; |
| 970 | 845 |
| 971 UpdateTouchEventRequest(); | 846 UpdateTouchEventRequest(); |
| 972 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); | 847 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); |
| 973 | 848 |
| 974 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( | 849 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( |
| 975 render_frame_->render_view()->webkit_preferences())), | 850 render_frame_->render_view()->webkit_preferences())), |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1212 gfx::Rect caret(text_input_caret_); | 1087 gfx::Rect caret(text_input_caret_); |
| 1213 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | 1088 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); |
| 1214 return caret; | 1089 return caret; |
| 1215 } | 1090 } |
| 1216 | 1091 |
| 1217 bool PepperPluginInstanceImpl::HandleInputEvent( | 1092 bool PepperPluginInstanceImpl::HandleInputEvent( |
| 1218 const blink::WebInputEvent& event, | 1093 const blink::WebInputEvent& event, |
| 1219 WebCursorInfo* cursor_info) { | 1094 WebCursorInfo* cursor_info) { |
| 1220 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); | 1095 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
| 1221 | 1096 |
| 1222 if (event.type == blink::WebInputEvent::MouseDown && !has_been_clicked_ && | 1097 if (throttler_->ConsumeInputEvent(event)) |
| 1223 IsFlashPlugin(module_.get())) { | 1098 return true; |
| 1224 has_been_clicked_ = true; | |
| 1225 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | |
| 1226 RecordFlashClickSizeMetric(bounds.width, bounds.height); | |
| 1227 } | |
| 1228 | |
| 1229 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { | |
| 1230 is_peripheral_content_ = false; | |
| 1231 power_saver_enabled_ = false; | |
| 1232 | |
| 1233 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK); | |
| 1234 | |
| 1235 if (plugin_throttled_) { | |
| 1236 SetPluginThrottled(false /* throttled */); | |
| 1237 return true; | |
| 1238 } | |
| 1239 } | |
| 1240 | 1099 |
| 1241 if (!render_frame_) | 1100 if (!render_frame_) |
| 1242 return false; | 1101 return false; |
| 1243 if (WebInputEvent::isMouseEventType(event.type)) { | 1102 if (WebInputEvent::isMouseEventType(event.type)) { |
| 1244 render_frame_->PepperDidReceiveMouseEvent(this); | 1103 render_frame_->PepperDidReceiveMouseEvent(this); |
| 1245 } | 1104 } |
| 1246 | 1105 |
| 1247 // Don't dispatch input events to crashed plugins. | 1106 // Don't dispatch input events to crashed plugins. |
| 1248 if (module()->is_crashed()) | 1107 if (module()->is_crashed()) |
| 1249 return false; | 1108 return false; |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1782 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); | 1641 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 1783 SendDidChangeView(); | 1642 SendDidChangeView(); |
| 1784 } | 1643 } |
| 1785 | 1644 |
| 1786 void PepperPluginInstanceImpl::SendDidChangeView() { | 1645 void PepperPluginInstanceImpl::SendDidChangeView() { |
| 1787 // Don't send DidChangeView to crashed plugins. | 1646 // Don't send DidChangeView to crashed plugins. |
| 1788 if (module()->is_crashed()) | 1647 if (module()->is_crashed()) |
| 1789 return; | 1648 return; |
| 1790 | 1649 |
| 1791 // When plugin is throttled, send ViewData indicating it's in the background. | 1650 // When plugin is throttled, send ViewData indicating it's in the background. |
| 1792 const ppapi::ViewData& view_data = | 1651 const ppapi::ViewData& view_data = throttler_->is_throttled() |
| 1793 plugin_throttled_ ? empty_view_data_ : view_data_; | 1652 ? throttler_->throttled_view_data() |
| 1653 : view_data_; | |
|
raymes
2014/11/12 06:38:20
nit: indentation looks odd. 4 spaces from the marg
tommycli
2014/11/12 21:18:14
I'm just running git cl format on everything.
| |
| 1794 | 1654 |
| 1795 if (view_change_weak_ptr_factory_.HasWeakPtrs() || | 1655 if (view_change_weak_ptr_factory_.HasWeakPtrs() || |
| 1796 (sent_initial_did_change_view_ && | 1656 (sent_initial_did_change_view_ && |
| 1797 last_sent_view_data_.Equals(view_data))) | 1657 last_sent_view_data_.Equals(view_data))) |
| 1798 return; // Nothing to update. | 1658 return; // Nothing to update. |
| 1799 | 1659 |
| 1800 sent_initial_did_change_view_ = true; | 1660 sent_initial_did_change_view_ = true; |
| 1801 last_sent_view_data_ = view_data; | 1661 last_sent_view_data_ = view_data; |
| 1802 ScopedPPResource resource( | 1662 ScopedPPResource resource( |
| 1803 ScopedPPResource::PassRef(), | 1663 ScopedPPResource::PassRef(), |
| (...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3413 } else { | 3273 } else { |
| 3414 // Running out-of-process. Initiate an IPC call to notify the plugin | 3274 // Running out-of-process. Initiate an IPC call to notify the plugin |
| 3415 // process. | 3275 // process. |
| 3416 ppapi::proxy::HostDispatcher* dispatcher = | 3276 ppapi::proxy::HostDispatcher* dispatcher = |
| 3417 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 3277 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
| 3418 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 3278 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
| 3419 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); | 3279 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); |
| 3420 } | 3280 } |
| 3421 } | 3281 } |
| 3422 | 3282 |
| 3423 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { | |
| 3424 // Do not throttle if we've already disabled power saver. | |
| 3425 if (!power_saver_enabled_ && throttled) | |
| 3426 return; | |
| 3427 | |
| 3428 plugin_throttled_ = throttled; | |
| 3429 SendDidChangeView(); | |
| 3430 } | |
| 3431 | |
| 3432 void PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist() { | |
| 3433 if (!is_peripheral_content_) | |
| 3434 return; | |
| 3435 | |
| 3436 is_peripheral_content_ = false; | |
| 3437 power_saver_enabled_ = false; | |
| 3438 SetPluginThrottled(false); | |
| 3439 | |
| 3440 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_WHITELIST); | |
| 3441 } | |
| 3442 | |
| 3443 } // namespace content | 3283 } // namespace content |
| OLD | NEW |