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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "content/renderer/pepper/fullscreen_container.h" | 31 #include "content/renderer/pepper/fullscreen_container.h" |
32 #include "content/renderer/pepper/gfx_conversion.h" | 32 #include "content/renderer/pepper/gfx_conversion.h" |
33 #include "content/renderer/pepper/host_dispatcher_wrapper.h" | 33 #include "content/renderer/pepper/host_dispatcher_wrapper.h" |
34 #include "content/renderer/pepper/host_globals.h" | 34 #include "content/renderer/pepper/host_globals.h" |
35 #include "content/renderer/pepper/message_channel.h" | 35 #include "content/renderer/pepper/message_channel.h" |
36 #include "content/renderer/pepper/pepper_browser_connection.h" | 36 #include "content/renderer/pepper/pepper_browser_connection.h" |
37 #include "content/renderer/pepper/pepper_compositor_host.h" | 37 #include "content/renderer/pepper/pepper_compositor_host.h" |
38 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" | 38 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" |
39 #include "content/renderer/pepper/pepper_graphics_2d_host.h" | 39 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
40 #include "content/renderer/pepper/pepper_in_process_router.h" | 40 #include "content/renderer/pepper/pepper_in_process_router.h" |
41 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 41 #include "content/renderer/pepper/pepper_plugin_instance_metrics.h" |
42 #include "content/renderer/pepper/pepper_plugin_instance_throttler.h" | |
43 #include "content/renderer/pepper/pepper_try_catch.h" | 42 #include "content/renderer/pepper/pepper_try_catch.h" |
44 #include "content/renderer/pepper/pepper_url_loader_host.h" | 43 #include "content/renderer/pepper/pepper_url_loader_host.h" |
45 #include "content/renderer/pepper/plugin_module.h" | 44 #include "content/renderer/pepper/plugin_module.h" |
46 #include "content/renderer/pepper/plugin_object.h" | 45 #include "content/renderer/pepper/plugin_object.h" |
47 #include "content/renderer/pepper/ppapi_preferences_builder.h" | 46 #include "content/renderer/pepper/ppapi_preferences_builder.h" |
48 #include "content/renderer/pepper/ppb_buffer_impl.h" | 47 #include "content/renderer/pepper/ppb_buffer_impl.h" |
49 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" | 48 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
50 #include "content/renderer/pepper/ppb_image_data_impl.h" | 49 #include "content/renderer/pepper/ppb_image_data_impl.h" |
51 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 50 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
52 #include "content/renderer/pepper/url_request_info_util.h" | 51 #include "content/renderer/pepper/url_request_info_util.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
73 #include "ppapi/c/private/ppb_find_private.h" | 72 #include "ppapi/c/private/ppb_find_private.h" |
74 #include "ppapi/c/private/ppp_find_private.h" | 73 #include "ppapi/c/private/ppp_find_private.h" |
75 #include "ppapi/c/private/ppp_instance_private.h" | 74 #include "ppapi/c/private/ppp_instance_private.h" |
76 #include "ppapi/c/private/ppp_pdf.h" | 75 #include "ppapi/c/private/ppp_pdf.h" |
77 #include "ppapi/host/ppapi_host.h" | 76 #include "ppapi/host/ppapi_host.h" |
78 #include "ppapi/proxy/ppapi_messages.h" | 77 #include "ppapi/proxy/ppapi_messages.h" |
79 #include "ppapi/proxy/serialized_var.h" | 78 #include "ppapi/proxy/serialized_var.h" |
80 #include "ppapi/proxy/uma_private_resource.h" | 79 #include "ppapi/proxy/uma_private_resource.h" |
81 #include "ppapi/proxy/url_loader_resource.h" | 80 #include "ppapi/proxy/url_loader_resource.h" |
82 #include "ppapi/shared_impl/ppapi_permissions.h" | 81 #include "ppapi/shared_impl/ppapi_permissions.h" |
83 #include "ppapi/shared_impl/ppapi_preferences.h" | |
84 #include "ppapi/shared_impl/ppb_gamepad_shared.h" | 82 #include "ppapi/shared_impl/ppb_gamepad_shared.h" |
85 #include "ppapi/shared_impl/ppb_input_event_shared.h" | 83 #include "ppapi/shared_impl/ppb_input_event_shared.h" |
86 #include "ppapi/shared_impl/ppb_url_util_shared.h" | 84 #include "ppapi/shared_impl/ppb_url_util_shared.h" |
87 #include "ppapi/shared_impl/ppb_view_shared.h" | 85 #include "ppapi/shared_impl/ppb_view_shared.h" |
88 #include "ppapi/shared_impl/ppp_instance_combined.h" | 86 #include "ppapi/shared_impl/ppp_instance_combined.h" |
89 #include "ppapi/shared_impl/resource.h" | 87 #include "ppapi/shared_impl/resource.h" |
90 #include "ppapi/shared_impl/scoped_pp_resource.h" | 88 #include "ppapi/shared_impl/scoped_pp_resource.h" |
91 #include "ppapi/shared_impl/scoped_pp_var.h" | 89 #include "ppapi/shared_impl/scoped_pp_var.h" |
92 #include "ppapi/shared_impl/time_conversion.h" | 90 #include "ppapi/shared_impl/time_conversion.h" |
93 #include "ppapi/shared_impl/url_request_info_data.h" | 91 #include "ppapi/shared_impl/url_request_info_data.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
122 #include "third_party/khronos/GLES2/gl2.h" | 120 #include "third_party/khronos/GLES2/gl2.h" |
123 #include "ui/gfx/image/image_skia.h" | 121 #include "ui/gfx/image/image_skia.h" |
124 #include "ui/gfx/image/image_skia_rep.h" | 122 #include "ui/gfx/image/image_skia_rep.h" |
125 #include "ui/gfx/range/range.h" | 123 #include "ui/gfx/range/range.h" |
126 #include "v8/include/v8.h" | 124 #include "v8/include/v8.h" |
127 | 125 |
128 #if defined(OS_CHROMEOS) | 126 #if defined(OS_CHROMEOS) |
129 #include "ui/events/keycodes/keyboard_codes_posix.h" | 127 #include "ui/events/keycodes/keyboard_codes_posix.h" |
130 #endif | 128 #endif |
131 | 129 |
132 #if defined(OS_WIN) | |
133 #include "base/metrics/histogram.h" | |
134 #include "base/win/windows_version.h" | |
135 #include "skia/ext/platform_canvas.h" | |
136 #endif | |
137 | |
138 using base::StringPrintf; | 130 using base::StringPrintf; |
139 using ppapi::InputEventData; | 131 using ppapi::InputEventData; |
140 using ppapi::PpapiGlobals; | 132 using ppapi::PpapiGlobals; |
141 using ppapi::PPB_InputEvent_Shared; | 133 using ppapi::PPB_InputEvent_Shared; |
142 using ppapi::PPB_View_Shared; | 134 using ppapi::PPB_View_Shared; |
143 using ppapi::PPP_Instance_Combined; | 135 using ppapi::PPP_Instance_Combined; |
144 using ppapi::Resource; | 136 using ppapi::Resource; |
145 using ppapi::ScopedPPResource; | 137 using ppapi::ScopedPPResource; |
146 using ppapi::ScopedPPVar; | 138 using ppapi::ScopedPPVar; |
147 using ppapi::StringVar; | 139 using ppapi::StringVar; |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 : RenderFrameObserver(render_frame), | 471 : RenderFrameObserver(render_frame), |
480 render_frame_(render_frame), | 472 render_frame_(render_frame), |
481 module_(module), | 473 module_(module), |
482 instance_interface_(instance_interface), | 474 instance_interface_(instance_interface), |
483 pp_instance_(0), | 475 pp_instance_(0), |
484 container_(container), | 476 container_(container), |
485 layer_bound_to_fullscreen_(false), | 477 layer_bound_to_fullscreen_(false), |
486 layer_is_hardware_(false), | 478 layer_is_hardware_(false), |
487 plugin_url_(plugin_url), | 479 plugin_url_(plugin_url), |
488 is_flash_plugin_(module->name() == kFlashPluginName), | 480 is_flash_plugin_(module->name() == kFlashPluginName), |
481 has_been_clicked_(false), | |
489 javascript_used_(false), | 482 javascript_used_(false), |
490 full_frame_(false), | 483 full_frame_(false), |
491 sent_initial_did_change_view_(false), | 484 sent_initial_did_change_view_(false), |
492 bound_graphics_2d_platform_(NULL), | 485 bound_graphics_2d_platform_(NULL), |
493 bound_compositor_(NULL), | 486 bound_compositor_(NULL), |
494 has_webkit_focus_(false), | 487 has_webkit_focus_(false), |
495 has_content_area_focus_(false), | 488 has_content_area_focus_(false), |
496 find_identifier_(-1), | 489 find_identifier_(-1), |
497 plugin_find_interface_(NULL), | 490 plugin_find_interface_(NULL), |
498 plugin_input_event_interface_(NULL), | 491 plugin_input_event_interface_(NULL), |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
615 | 608 |
616 UnSetAndDeleteLockTargetAdapter(); | 609 UnSetAndDeleteLockTargetAdapter(); |
617 module_->InstanceDeleted(this); | 610 module_->InstanceDeleted(this); |
618 // If we switched from the NaCl plugin module, notify it too. | 611 // If we switched from the NaCl plugin module, notify it too. |
619 if (original_module_.get()) | 612 if (original_module_.get()) |
620 original_module_->InstanceDeleted(this); | 613 original_module_->InstanceDeleted(this); |
621 | 614 |
622 // This should be last since some of the above "instance deleted" calls will | 615 // This should be last since some of the above "instance deleted" calls will |
623 // want to look up in the global map to get info off of our object. | 616 // want to look up in the global map to get info off of our object. |
624 HostGlobals::Get()->InstanceDeleted(pp_instance_); | 617 HostGlobals::Get()->InstanceDeleted(pp_instance_); |
618 | |
619 if (throttler_) | |
620 throttler_->RemoveObserver(this); | |
625 } | 621 } |
626 | 622 |
627 // NOTE: Any of these methods that calls into the plugin needs to take into | 623 // NOTE: Any of these methods that calls into the plugin needs to take into |
628 // account that the plugin may use Var to remove the <embed> from the DOM, which | 624 // account that the plugin may use Var to remove the <embed> from the DOM, which |
629 // will make the PepperWebPluginImpl drop its reference, usually the last one. | 625 // will make the PepperWebPluginImpl drop its reference, usually the last one. |
630 // If a method needs to access a member of the instance after the call has | 626 // If a method needs to access a member of the instance after the call has |
631 // returned, then it needs to keep its own reference on the stack. | 627 // returned, then it needs to keep its own reference on the stack. |
632 | 628 |
633 v8::Local<v8::Object> PepperPluginInstanceImpl::GetMessageChannelObject() { | 629 v8::Local<v8::Object> PepperPluginInstanceImpl::GetMessageChannelObject() { |
634 return v8::Local<v8::Object>::New(isolate_, message_channel_object_); | 630 return v8::Local<v8::Object>::New(isolate_, message_channel_object_); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
791 if (content_decryptor_delegate_) { | 787 if (content_decryptor_delegate_) { |
792 content_decryptor_delegate_->InstanceCrashed(); | 788 content_decryptor_delegate_->InstanceCrashed(); |
793 content_decryptor_delegate_.reset(); | 789 content_decryptor_delegate_.reset(); |
794 } | 790 } |
795 | 791 |
796 if (render_frame_) | 792 if (render_frame_) |
797 render_frame_->PluginCrashed(module_->path(), module_->GetPeerProcessId()); | 793 render_frame_->PluginCrashed(module_->path(), module_->GetPeerProcessId()); |
798 UnSetAndDeleteLockTargetAdapter(); | 794 UnSetAndDeleteLockTargetAdapter(); |
799 } | 795 } |
800 | 796 |
801 static void SetGPUHistogram(const ppapi::Preferences& prefs, | |
802 const std::vector<std::string>& arg_names, | |
803 const std::vector<std::string>& arg_values) { | |
804 // Calculate a histogram to let us determine how likely people are to try to | |
805 // run Stage3D content on machines that have it blacklisted. | |
806 #if defined(OS_WIN) | |
807 bool needs_gpu = false; | |
808 bool is_xp = base::win::GetVersion() <= base::win::VERSION_XP; | |
809 | |
810 for (size_t i = 0; i < arg_names.size(); i++) { | |
811 if (arg_names[i] == "wmode") { | |
812 // In theory content other than Flash could have a "wmode" argument, | |
813 // but that's pretty unlikely. | |
814 if (arg_values[i] == "direct" || arg_values[i] == "gpu") | |
815 needs_gpu = true; | |
816 break; | |
817 } | |
818 } | |
819 // 0 : No 3D content and GPU is blacklisted | |
820 // 1 : No 3D content and GPU is not blacklisted | |
821 // 2 : 3D content but GPU is blacklisted | |
822 // 3 : 3D content and GPU is not blacklisted | |
823 // 4 : No 3D content and GPU is blacklisted on XP | |
824 // 5 : No 3D content and GPU is not blacklisted on XP | |
825 // 6 : 3D content but GPU is blacklisted on XP | |
826 // 7 : 3D content and GPU is not blacklisted on XP | |
827 UMA_HISTOGRAM_ENUMERATION( | |
828 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); | |
829 #endif | |
830 } | |
831 | |
832 bool PepperPluginInstanceImpl::Initialize( | 797 bool PepperPluginInstanceImpl::Initialize( |
833 const std::vector<std::string>& arg_names, | 798 const std::vector<std::string>& arg_names, |
834 const std::vector<std::string>& arg_values, | 799 const std::vector<std::string>& arg_values, |
835 bool full_frame, | 800 bool full_frame, |
836 RenderFrame::PluginPowerSaverMode power_saver_mode) { | 801 PluginInstanceThrottler* throttler) { |
837 if (!render_frame_) | 802 if (!render_frame_) |
838 return false; | 803 return false; |
839 | 804 |
840 blink::WebRect bounds = container()->element().boundsInViewportSpace(); | 805 if (is_flash_plugin_ && RenderThread::Get()) { |
806 RenderThread::Get()->RecordAction( | |
807 base::UserMetricsAction("Flash.PluginInstanceCreated")); | |
808 blink::WebRect bounds = container()->element().boundsInViewportSpace(); | |
809 RecordFlashSizeMetric(bounds.width, bounds.height); | |
810 } | |
841 | 811 |
842 throttler_.reset(new PepperPluginInstanceThrottler( | 812 if (throttler) { |
Bernhard Bauer
2015/01/13 23:29:36
If this is called with a nullptr and |throttler_|
tommycli
2015/01/14 01:45:00
Done.
| |
843 render_frame(), bounds, is_flash_plugin_, plugin_url_, power_saver_mode, | 813 throttler_.reset(throttler); |
844 base::Bind(&PepperPluginInstanceImpl::SendDidChangeView, | 814 throttler_->AddObserver(this); |
845 weak_factory_.GetWeakPtr()))); | 815 } |
846 | 816 |
847 message_channel_ = MessageChannel::Create(this, &message_channel_object_); | 817 message_channel_ = MessageChannel::Create(this, &message_channel_object_); |
848 | 818 |
849 full_frame_ = full_frame; | 819 full_frame_ = full_frame; |
850 | 820 |
851 UpdateTouchEventRequest(); | 821 UpdateTouchEventRequest(); |
852 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); | 822 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); |
853 | 823 |
854 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( | 824 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( |
855 render_frame_->render_view()->webkit_preferences())), | 825 render_frame_->render_view()->webkit_preferences())), |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1092 gfx::Rect caret(text_input_caret_); | 1062 gfx::Rect caret(text_input_caret_); |
1093 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | 1063 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); |
1094 return caret; | 1064 return caret; |
1095 } | 1065 } |
1096 | 1066 |
1097 bool PepperPluginInstanceImpl::HandleInputEvent( | 1067 bool PepperPluginInstanceImpl::HandleInputEvent( |
1098 const blink::WebInputEvent& event, | 1068 const blink::WebInputEvent& event, |
1099 WebCursorInfo* cursor_info) { | 1069 WebCursorInfo* cursor_info) { |
1100 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); | 1070 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
1101 | 1071 |
1102 if (throttler_->ConsumeInputEvent(event)) | 1072 if (!has_been_clicked_ && is_flash_plugin_ && |
1073 event.type == blink::WebInputEvent::MouseDown && | |
1074 (event.modifiers & blink::WebInputEvent::LeftButtonDown)) { | |
1075 has_been_clicked_ = true; | |
1076 blink::WebRect bounds = container()->element().boundsInViewportSpace(); | |
1077 RecordFlashClickSizeMetric(bounds.width, bounds.height); | |
1078 } | |
1079 | |
1080 if (throttler_ && throttler_->ConsumeInputEvent(event)) | |
1103 return true; | 1081 return true; |
1104 | 1082 |
1105 if (!render_frame_) | 1083 if (!render_frame_) |
1106 return false; | 1084 return false; |
1107 if (WebInputEvent::isMouseEventType(event.type)) { | 1085 if (WebInputEvent::isMouseEventType(event.type)) { |
1108 render_frame_->PepperDidReceiveMouseEvent(this); | 1086 render_frame_->PepperDidReceiveMouseEvent(this); |
1109 } | 1087 } |
1110 | 1088 |
1111 // Don't dispatch input events to crashed plugins. | 1089 // Don't dispatch input events to crashed plugins. |
1112 if (module()->is_crashed()) | 1090 if (module()->is_crashed()) |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2051 scoped_ptr<cc::SingleReleaseCallback>* release_callback, | 2029 scoped_ptr<cc::SingleReleaseCallback>* release_callback, |
2052 bool use_shared_memory) { | 2030 bool use_shared_memory) { |
2053 if (!bound_graphics_2d_platform_) | 2031 if (!bound_graphics_2d_platform_) |
2054 return false; | 2032 return false; |
2055 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, | 2033 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, |
2056 release_callback); | 2034 release_callback); |
2057 } | 2035 } |
2058 | 2036 |
2059 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; } | 2037 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; } |
2060 | 2038 |
2039 void PepperPluginInstanceImpl::OnThrottleStateChange() { | |
2040 SendDidChangeView(); | |
2041 } | |
2042 | |
2061 void PepperPluginInstanceImpl::AddLatencyInfo( | 2043 void PepperPluginInstanceImpl::AddLatencyInfo( |
2062 const std::vector<ui::LatencyInfo>& latency_info) { | 2044 const std::vector<ui::LatencyInfo>& latency_info) { |
2063 if (render_frame_ && render_frame_->GetRenderWidget()) { | 2045 if (render_frame_ && render_frame_->GetRenderWidget()) { |
2064 RenderWidgetCompositor* compositor = | 2046 RenderWidgetCompositor* compositor = |
2065 render_frame_->GetRenderWidget()->compositor(); | 2047 render_frame_->GetRenderWidget()->compositor(); |
2066 if (compositor) { | 2048 if (compositor) { |
2067 for (size_t i = 0; i < latency_info.size(); i++) { | 2049 for (size_t i = 0; i < latency_info.size(); i++) { |
2068 scoped_ptr<cc::SwapPromise> swap_promise( | 2050 scoped_ptr<cc::SwapPromise> swap_promise( |
2069 new cc::LatencyInfoSwapPromise(latency_info[i])); | 2051 new cc::LatencyInfoSwapPromise(latency_info[i])); |
2070 compositor->QueueSwapPromise(swap_promise.Pass()); | 2052 compositor->QueueSwapPromise(swap_promise.Pass()); |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3292 | 3274 |
3293 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() { | 3275 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() { |
3294 if (!javascript_used_ && is_flash_plugin_) { | 3276 if (!javascript_used_ && is_flash_plugin_) { |
3295 javascript_used_ = true; | 3277 javascript_used_ = true; |
3296 RenderThread::Get()->RecordAction( | 3278 RenderThread::Get()->RecordAction( |
3297 base::UserMetricsAction("Flash.JavaScriptUsed")); | 3279 base::UserMetricsAction("Flash.JavaScriptUsed")); |
3298 } | 3280 } |
3299 } | 3281 } |
3300 | 3282 |
3301 } // namespace content | 3283 } // namespace content |
OLD | NEW |