| 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/renderer_webkitplatformsupport_impl.h" | 5 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "content/child/web_database_observer_impl.h" | 26 #include "content/child/web_database_observer_impl.h" |
| 27 #include "content/child/webblobregistry_impl.h" | 27 #include "content/child/webblobregistry_impl.h" |
| 28 #include "content/child/webfileutilities_impl.h" | 28 #include "content/child/webfileutilities_impl.h" |
| 29 #include "content/child/webmessageportchannel_impl.h" | 29 #include "content/child/webmessageportchannel_impl.h" |
| 30 #include "content/common/file_utilities_messages.h" | 30 #include "content/common/file_utilities_messages.h" |
| 31 #include "content/common/gpu/client/context_provider_command_buffer.h" | 31 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 32 #include "content/common/gpu/client/gpu_channel_host.h" | 32 #include "content/common/gpu/client/gpu_channel_host.h" |
| 33 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 33 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 34 #include "content/common/gpu/gpu_process_launch_causes.h" | 34 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 35 #include "content/common/mime_registry_messages.h" | 35 #include "content/common/mime_registry_messages.h" |
| 36 #include "content/common/screen_orientation_messages.h" |
| 36 #include "content/common/view_messages.h" | 37 #include "content/common/view_messages.h" |
| 37 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
| 38 #include "content/public/common/webplugininfo.h" | 39 #include "content/public/common/webplugininfo.h" |
| 39 #include "content/public/renderer/content_renderer_client.h" | 40 #include "content/public/renderer/content_renderer_client.h" |
| 40 #include "content/renderer/battery_status/battery_status_dispatcher.h" | 41 #include "content/renderer/battery_status/battery_status_dispatcher.h" |
| 42 #include "content/renderer/battery_status/fake_battery_status_dispatcher.h" |
| 41 #include "content/renderer/device_sensors/device_light_event_pump.h" | 43 #include "content/renderer/device_sensors/device_light_event_pump.h" |
| 42 #include "content/renderer/device_sensors/device_motion_event_pump.h" | 44 #include "content/renderer/device_sensors/device_motion_event_pump.h" |
| 43 #include "content/renderer/device_sensors/device_orientation_event_pump.h" | 45 #include "content/renderer/device_sensors/device_orientation_event_pump.h" |
| 44 #include "content/renderer/dom_storage/webstoragenamespace_impl.h" | 46 #include "content/renderer/dom_storage/webstoragenamespace_impl.h" |
| 45 #include "content/renderer/gamepad_shared_memory_reader.h" | 47 #include "content/renderer/gamepad_shared_memory_reader.h" |
| 46 #include "content/renderer/media/audio_decoder.h" | 48 #include "content/renderer/media/audio_decoder.h" |
| 47 #include "content/renderer/media/crypto/key_systems.h" | 49 #include "content/renderer/media/crypto/key_systems.h" |
| 48 #include "content/renderer/media/renderer_webaudiodevice_impl.h" | 50 #include "content/renderer/media/renderer_webaudiodevice_impl.h" |
| 49 #include "content/renderer/media/renderer_webmidiaccessor_impl.h" | 51 #include "content/renderer/media/renderer_webmidiaccessor_impl.h" |
| 50 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" | 52 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" |
| 51 #include "content/renderer/render_thread_impl.h" | 53 #include "content/renderer/render_thread_impl.h" |
| 52 #include "content/renderer/renderer_clipboard_client.h" | 54 #include "content/renderer/renderer_clipboard_client.h" |
| 53 #include "content/renderer/screen_orientation/screen_orientation_observer.h" | |
| 54 #include "content/renderer/webclipboard_impl.h" | 55 #include "content/renderer/webclipboard_impl.h" |
| 55 #include "content/renderer/webgraphicscontext3d_provider_impl.h" | 56 #include "content/renderer/webgraphicscontext3d_provider_impl.h" |
| 56 #include "content/renderer/webpublicsuffixlist_impl.h" | 57 #include "content/renderer/webpublicsuffixlist_impl.h" |
| 57 #include "gpu/config/gpu_info.h" | 58 #include "gpu/config/gpu_info.h" |
| 58 #include "ipc/ipc_sync_message_filter.h" | 59 #include "ipc/ipc_sync_message_filter.h" |
| 59 #include "media/audio/audio_output_device.h" | 60 #include "media/audio/audio_output_device.h" |
| 60 #include "media/base/audio_hardware_config.h" | 61 #include "media/base/audio_hardware_config.h" |
| 61 #include "media/filters/stream_parser_factory.h" | 62 #include "media/filters/stream_parser_factory.h" |
| 62 #include "net/base/mime_util.h" | 63 #include "net/base/mime_util.h" |
| 63 #include "net/base/net_util.h" | 64 #include "net/base/net_util.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 namespace content { | 144 namespace content { |
| 144 | 145 |
| 145 namespace { | 146 namespace { |
| 146 | 147 |
| 147 bool g_sandbox_enabled = true; | 148 bool g_sandbox_enabled = true; |
| 148 double g_test_device_light_data = -1; | 149 double g_test_device_light_data = -1; |
| 149 base::LazyInstance<blink::WebDeviceMotionData>::Leaky | 150 base::LazyInstance<blink::WebDeviceMotionData>::Leaky |
| 150 g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER; | 151 g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER; |
| 151 base::LazyInstance<blink::WebDeviceOrientationData>::Leaky | 152 base::LazyInstance<blink::WebDeviceOrientationData>::Leaky |
| 152 g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER; | 153 g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER; |
| 154 base::LazyInstance<FakeBatteryStatusDispatcher>::Leaky |
| 155 g_test_battery_status_dispatcher = LAZY_INSTANCE_INITIALIZER; |
| 153 | 156 |
| 154 } // namespace | 157 } // namespace |
| 155 | 158 |
| 156 //------------------------------------------------------------------------------ | 159 //------------------------------------------------------------------------------ |
| 157 | 160 |
| 158 class RendererWebKitPlatformSupportImpl::MimeRegistry | 161 class RendererWebKitPlatformSupportImpl::MimeRegistry |
| 159 : public SimpleWebMimeRegistryImpl { | 162 : public SimpleWebMimeRegistryImpl { |
| 160 public: | 163 public: |
| 161 virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType( | 164 virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType( |
| 162 const blink::WebString& mime_type, | 165 const blink::WebString& mime_type, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 225 |
| 223 //------------------------------------------------------------------------------ | 226 //------------------------------------------------------------------------------ |
| 224 | 227 |
| 225 RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() | 228 RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() |
| 226 : clipboard_client_(new RendererClipboardClient), | 229 : clipboard_client_(new RendererClipboardClient), |
| 227 clipboard_(new WebClipboardImpl(clipboard_client_.get())), | 230 clipboard_(new WebClipboardImpl(clipboard_client_.get())), |
| 228 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry), | 231 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry), |
| 229 sudden_termination_disables_(0), | 232 sudden_termination_disables_(0), |
| 230 plugin_refresh_allowed_(true), | 233 plugin_refresh_allowed_(true), |
| 231 child_thread_loop_(base::MessageLoopProxy::current()), | 234 child_thread_loop_(base::MessageLoopProxy::current()), |
| 232 web_scrollbar_behavior_(new WebScrollbarBehaviorImpl) { | 235 web_scrollbar_behavior_(new WebScrollbarBehaviorImpl), |
| 236 gamepad_provider_(NULL) { |
| 233 if (g_sandbox_enabled && sandboxEnabled()) { | 237 if (g_sandbox_enabled && sandboxEnabled()) { |
| 234 sandbox_support_.reset( | 238 sandbox_support_.reset( |
| 235 new RendererWebKitPlatformSupportImpl::SandboxSupport); | 239 new RendererWebKitPlatformSupportImpl::SandboxSupport); |
| 236 } else { | 240 } else { |
| 237 DVLOG(1) << "Disabling sandbox support for testing."; | 241 DVLOG(1) << "Disabling sandbox support for testing."; |
| 238 } | 242 } |
| 239 | 243 |
| 240 // ChildThread may not exist in some tests. | 244 // ChildThread may not exist in some tests. |
| 241 if (ChildThread::current()) { | 245 if (ChildThread::current()) { |
| 242 sync_message_filter_ = ChildThread::current()->sync_message_filter(); | 246 sync_message_filter_ = ChildThread::current()->sync_message_filter(); |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 //------------------------------------------------------------------------------ | 866 //------------------------------------------------------------------------------ |
| 863 | 867 |
| 864 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { | 868 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { |
| 865 // blob_registry_ can be NULL when running some tests. | 869 // blob_registry_ can be NULL when running some tests. |
| 866 return blob_registry_.get(); | 870 return blob_registry_.get(); |
| 867 } | 871 } |
| 868 | 872 |
| 869 //------------------------------------------------------------------------------ | 873 //------------------------------------------------------------------------------ |
| 870 | 874 |
| 871 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { | 875 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { |
| 872 PlatformEventObserverBase* observer = | 876 DCHECK(gamepad_provider_); |
| 873 platform_event_observers_.Lookup(blink::WebPlatformEventGamepad); | 877 gamepad_provider_->SampleGamepads(gamepads); |
| 874 if (!observer) | |
| 875 return; | |
| 876 static_cast<RendererGamepadProvider*>(observer)->SampleGamepads(gamepads); | |
| 877 } | 878 } |
| 878 | 879 |
| 879 //------------------------------------------------------------------------------ | 880 //------------------------------------------------------------------------------ |
| 880 | 881 |
| 881 WebRTCPeerConnectionHandler* | 882 WebRTCPeerConnectionHandler* |
| 882 RendererWebKitPlatformSupportImpl::createRTCPeerConnectionHandler( | 883 RendererWebKitPlatformSupportImpl::createRTCPeerConnectionHandler( |
| 883 WebRTCPeerConnectionHandlerClient* client) { | 884 WebRTCPeerConnectionHandlerClient* client) { |
| 884 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 885 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 885 DCHECK(render_thread); | 886 DCHECK(render_thread); |
| 886 if (!render_thread) | 887 if (!render_thread) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 RenderThread::Get()->Send( | 1032 RenderThread::Get()->Send( |
| 1032 new ViewHostMsg_Vibrate(base::checked_cast<int64>(milliseconds))); | 1033 new ViewHostMsg_Vibrate(base::checked_cast<int64>(milliseconds))); |
| 1033 } | 1034 } |
| 1034 | 1035 |
| 1035 void RendererWebKitPlatformSupportImpl::cancelVibration() { | 1036 void RendererWebKitPlatformSupportImpl::cancelVibration() { |
| 1036 RenderThread::Get()->Send(new ViewHostMsg_CancelVibration()); | 1037 RenderThread::Get()->Send(new ViewHostMsg_CancelVibration()); |
| 1037 } | 1038 } |
| 1038 | 1039 |
| 1039 //------------------------------------------------------------------------------ | 1040 //------------------------------------------------------------------------------ |
| 1040 | 1041 |
| 1041 // static | 1042 void RendererWebKitPlatformSupportImpl::startListening( |
| 1042 PlatformEventObserverBase* | 1043 blink::WebPlatformEventType type, |
| 1043 RendererWebKitPlatformSupportImpl::CreatePlatformEventObserverFromType( | 1044 blink::WebPlatformEventListener* listener) { |
| 1044 blink::WebPlatformEventType type) { | |
| 1045 RenderThread* thread = RenderThreadImpl::current(); | |
| 1046 | |
| 1047 // When running layout tests, those observers should not listen to the actual | |
| 1048 // hardware changes. In order to make that happen, they will receive a null | |
| 1049 // thread. | |
| 1050 if (thread && RenderThreadImpl::current()->layout_test_mode()) | |
| 1051 thread = 0; | |
| 1052 | |
| 1053 switch (type) { | 1045 switch (type) { |
| 1054 case blink::WebPlatformEventDeviceMotion: { | 1046 case blink::WebPlatformEventDeviceMotion: |
| 1055 return new DeviceMotionEventPump(thread); | 1047 SetDeviceMotionListener( |
| 1056 } | 1048 static_cast<blink::WebDeviceMotionListener*>(listener)); |
| 1057 case blink::WebPlatformEventDeviceOrientation: { | 1049 break; |
| 1058 return new DeviceOrientationEventPump(thread); | 1050 case blink::WebPlatformEventDeviceOrientation: |
| 1059 } | 1051 SetDeviceOrientationListener( |
| 1060 case blink::WebPlatformEventDeviceLight: { | 1052 static_cast<blink::WebDeviceOrientationListener*>(listener)); |
| 1061 return new DeviceLightEventPump(thread); | 1053 break; |
| 1062 } | 1054 case blink::WebPlatformEventDeviceLight: |
| 1063 case blink::WebPlatformEventBattery: { | 1055 SetDeviceLightListener( |
| 1064 return new BatteryStatusDispatcher(thread); | 1056 static_cast<blink::WebDeviceLightListener*>(listener)); |
| 1065 } | 1057 break; |
| 1058 case blink::WebPlatformEventBattery: |
| 1059 SetBatteryStatusListener( |
| 1060 static_cast<blink::WebBatteryStatusListener*>(listener)); |
| 1061 break; |
| 1066 case blink::WebPlatformEventGamepad: | 1062 case blink::WebPlatformEventGamepad: |
| 1067 return new GamepadSharedMemoryReader(thread); | 1063 SetGamepadListener( |
| 1064 static_cast<blink::WebGamepadListener*>(listener)); |
| 1068 break; | 1065 break; |
| 1069 case blink::WebPlatformEventScreenOrientation: | 1066 case blink::WebPlatformEventScreenOrientation: |
| 1070 return new ScreenOrientationObserver(); | 1067 RenderThread::Get()->Send(new ScreenOrientationHostMsg_StartListening()); |
| 1068 break; |
| 1071 default: | 1069 default: |
| 1072 // A default statement is required to prevent compilation errors when Blink | 1070 // A default statement is required to prevent compilation errors when Blink |
| 1073 // adds a new type. | 1071 // adds a new type. |
| 1074 VLOG(1) << "RendererWebKitPlatformSupportImpl::startListening() with " | 1072 VLOG(1) << "RendererWebKitPlatformSupportImpl::startListening() with " |
| 1075 "unknown type."; | 1073 "unknown type."; |
| 1076 } | 1074 } |
| 1077 | |
| 1078 return 0; | |
| 1079 } | |
| 1080 | |
| 1081 void RendererWebKitPlatformSupportImpl::SetPlatformEventObserverForTesting( | |
| 1082 blink::WebPlatformEventType type, | |
| 1083 scoped_ptr<PlatformEventObserverBase> observer) { | |
| 1084 if (platform_event_observers_.Lookup(type)) | |
| 1085 platform_event_observers_.Remove(type); | |
| 1086 platform_event_observers_.AddWithID(observer.release(), type); | |
| 1087 } | |
| 1088 | |
| 1089 | |
| 1090 void RendererWebKitPlatformSupportImpl::startListening( | |
| 1091 blink::WebPlatformEventType type, | |
| 1092 blink::WebPlatformEventListener* listener) { | |
| 1093 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); | |
| 1094 if (!observer) { | |
| 1095 observer = CreatePlatformEventObserverFromType(type); | |
| 1096 if (!observer) | |
| 1097 return; | |
| 1098 platform_event_observers_.AddWithID(observer, static_cast<int32>(type)); | |
| 1099 } | |
| 1100 observer->Start(listener); | |
| 1101 | |
| 1102 // Device events (motion, orientation and light) expect to get an event fired | |
| 1103 // as soon as a listener is registered if a fake data was passed before. | |
| 1104 // TODO(mlamouri,timvolodine): make those send mock values directly instead of | |
| 1105 // using this broken pattern. | |
| 1106 if (RenderThreadImpl::current() && | |
| 1107 RenderThreadImpl::current()->layout_test_mode() && | |
| 1108 (type == blink::WebPlatformEventDeviceMotion || | |
| 1109 type == blink::WebPlatformEventDeviceOrientation || | |
| 1110 type == blink::WebPlatformEventDeviceLight)) { | |
| 1111 SendFakeDeviceEventDataForTesting(type); | |
| 1112 } | |
| 1113 } | |
| 1114 | |
| 1115 void RendererWebKitPlatformSupportImpl::SendFakeDeviceEventDataForTesting( | |
| 1116 blink::WebPlatformEventType type) { | |
| 1117 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); | |
| 1118 CHECK(observer); | |
| 1119 | |
| 1120 void* data = 0; | |
| 1121 | |
| 1122 switch (type) { | |
| 1123 case blink::WebPlatformEventDeviceMotion: | |
| 1124 if (!(g_test_device_motion_data == 0)) | |
| 1125 data = &g_test_device_motion_data.Get(); | |
| 1126 break; | |
| 1127 case blink::WebPlatformEventDeviceOrientation: | |
| 1128 if (!(g_test_device_orientation_data == 0)) | |
| 1129 data = &g_test_device_orientation_data.Get(); | |
| 1130 break; | |
| 1131 case blink::WebPlatformEventDeviceLight: | |
| 1132 if (g_test_device_light_data >= 0) | |
| 1133 data = &g_test_device_light_data; | |
| 1134 break; | |
| 1135 default: | |
| 1136 NOTREACHED(); | |
| 1137 break; | |
| 1138 } | |
| 1139 | |
| 1140 if (!data) | |
| 1141 return; | |
| 1142 | |
| 1143 base::MessageLoopProxy::current()->PostTask( | |
| 1144 FROM_HERE, | |
| 1145 base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting, | |
| 1146 base::Unretained(observer), data)); | |
| 1147 } | 1075 } |
| 1148 | 1076 |
| 1149 void RendererWebKitPlatformSupportImpl::stopListening( | 1077 void RendererWebKitPlatformSupportImpl::stopListening( |
| 1150 blink::WebPlatformEventType type) { | 1078 blink::WebPlatformEventType type) { |
| 1151 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); | 1079 switch (type) { |
| 1152 if (!observer) | 1080 case blink::WebPlatformEventDeviceMotion: |
| 1081 SetDeviceMotionListener(0); |
| 1082 break; |
| 1083 case blink::WebPlatformEventDeviceOrientation: |
| 1084 SetDeviceOrientationListener(0); |
| 1085 break; |
| 1086 case blink::WebPlatformEventDeviceLight: |
| 1087 SetDeviceLightListener(0); |
| 1088 break; |
| 1089 case blink::WebPlatformEventBattery: |
| 1090 SetBatteryStatusListener(0); |
| 1091 break; |
| 1092 case blink::WebPlatformEventGamepad: |
| 1093 SetGamepadListener(0); |
| 1094 break; |
| 1095 case blink::WebPlatformEventScreenOrientation: |
| 1096 RenderThread::Get()->Send(new ScreenOrientationHostMsg_StopListening()); |
| 1097 break; |
| 1098 default: |
| 1099 // A default statement is required to prevent compilation errors when Blink |
| 1100 // adds a new type. |
| 1101 VLOG(1) << "RendererWebKitPlatformSupportImpl::stopListening() with " |
| 1102 "unknown type."; |
| 1103 } |
| 1104 } |
| 1105 |
| 1106 void RendererWebKitPlatformSupportImpl::SetDeviceMotionListener( |
| 1107 blink::WebDeviceMotionListener* listener) { |
| 1108 if (g_test_device_motion_data == 0) { |
| 1109 if (!device_motion_event_pump_) { |
| 1110 device_motion_event_pump_.reset(new DeviceMotionEventPump); |
| 1111 device_motion_event_pump_->Attach(RenderThreadImpl::current()); |
| 1112 } |
| 1113 device_motion_event_pump_->SetListener(listener); |
| 1114 } else if (listener) { |
| 1115 // Testing mode: just echo the test data to the listener. |
| 1116 base::MessageLoopProxy::current()->PostTask( |
| 1117 FROM_HERE, |
| 1118 base::Bind(&blink::WebDeviceMotionListener::didChangeDeviceMotion, |
| 1119 base::Unretained(listener), |
| 1120 g_test_device_motion_data.Get())); |
| 1121 } |
| 1122 } |
| 1123 |
| 1124 void RendererWebKitPlatformSupportImpl::SetDeviceOrientationListener( |
| 1125 blink::WebDeviceOrientationListener* listener) { |
| 1126 if (g_test_device_orientation_data == 0) { |
| 1127 if (!device_orientation_event_pump_) { |
| 1128 device_orientation_event_pump_.reset(new DeviceOrientationEventPump); |
| 1129 device_orientation_event_pump_->Attach(RenderThreadImpl::current()); |
| 1130 } |
| 1131 device_orientation_event_pump_->SetListener(listener); |
| 1132 } else if (listener) { |
| 1133 // Testing mode: just echo the test data to the listener. |
| 1134 base::MessageLoopProxy::current()->PostTask( |
| 1135 FROM_HERE, |
| 1136 base::Bind( |
| 1137 &blink::WebDeviceOrientationListener::didChangeDeviceOrientation, |
| 1138 base::Unretained(listener), |
| 1139 g_test_device_orientation_data.Get())); |
| 1140 } |
| 1141 } |
| 1142 |
| 1143 void RendererWebKitPlatformSupportImpl::SetDeviceLightListener( |
| 1144 blink::WebDeviceLightListener* listener) { |
| 1145 if (g_test_device_light_data < 0) { |
| 1146 if (!device_light_event_pump_) { |
| 1147 device_light_event_pump_.reset(new DeviceLightEventPump); |
| 1148 device_light_event_pump_->Attach(RenderThreadImpl::current()); |
| 1149 } |
| 1150 device_light_event_pump_->SetListener(listener); |
| 1151 } else if (listener) { |
| 1152 // Testing mode: just echo the test data to the listener. |
| 1153 base::MessageLoopProxy::current()->PostTask( |
| 1154 FROM_HERE, |
| 1155 base::Bind(&blink::WebDeviceLightListener::didChangeDeviceLight, |
| 1156 base::Unretained(listener), |
| 1157 g_test_device_light_data)); |
| 1158 } |
| 1159 } |
| 1160 |
| 1161 void RendererWebKitPlatformSupportImpl::SetGamepadListener( |
| 1162 blink::WebGamepadListener* listener) { |
| 1163 DCHECK(gamepad_provider_); |
| 1164 gamepad_provider_->SetGamepadListener(listener); |
| 1165 } |
| 1166 |
| 1167 void RendererWebKitPlatformSupportImpl::SetBatteryStatusListener( |
| 1168 blink::WebBatteryStatusListener* listener) { |
| 1169 if (RenderThreadImpl::current() && |
| 1170 RenderThreadImpl::current()->layout_test_mode()) { |
| 1171 // If we are in test mode, we want to use a fake battery status dispatcher, |
| 1172 // which does not communicate with the browser process. Battery status |
| 1173 // changes are signalled by invoking MockBatteryStatusChangedForTesting(). |
| 1174 g_test_battery_status_dispatcher.Get().SetListener(listener); |
| 1153 return; | 1175 return; |
| 1154 observer->Stop(); | 1176 } |
| 1177 |
| 1178 if (!battery_status_dispatcher_) { |
| 1179 battery_status_dispatcher_.reset( |
| 1180 new BatteryStatusDispatcher(RenderThreadImpl::current())); |
| 1181 } |
| 1182 battery_status_dispatcher_->SetListener(listener); |
| 1155 } | 1183 } |
| 1156 | 1184 |
| 1157 //------------------------------------------------------------------------------ | 1185 //------------------------------------------------------------------------------ |
| 1158 | 1186 |
| 1159 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( | 1187 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( |
| 1160 const blink::WebURL& storage_partition, | 1188 const blink::WebURL& storage_partition, |
| 1161 blink::WebStorageQuotaType type, | 1189 blink::WebStorageQuotaType type, |
| 1162 blink::WebStorageQuotaCallbacks callbacks) { | 1190 blink::WebStorageQuotaCallbacks callbacks) { |
| 1163 if (!thread_safe_sender_.get() || !quota_message_filter_.get()) | 1191 if (!thread_safe_sender_.get() || !quota_message_filter_.get()) |
| 1164 return; | 1192 return; |
| 1165 QuotaDispatcher::ThreadSpecificInstance( | 1193 QuotaDispatcher::ThreadSpecificInstance( |
| 1166 thread_safe_sender_.get(), | 1194 thread_safe_sender_.get(), |
| 1167 quota_message_filter_.get())->QueryStorageUsageAndQuota( | 1195 quota_message_filter_.get())->QueryStorageUsageAndQuota( |
| 1168 storage_partition, | 1196 storage_partition, |
| 1169 static_cast<quota::StorageType>(type), | 1197 static_cast<quota::StorageType>(type), |
| 1170 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); | 1198 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
| 1171 } | 1199 } |
| 1172 | 1200 |
| 1173 //------------------------------------------------------------------------------ | 1201 //------------------------------------------------------------------------------ |
| 1174 | 1202 |
| 1203 // static |
| 1175 void RendererWebKitPlatformSupportImpl::MockBatteryStatusChangedForTesting( | 1204 void RendererWebKitPlatformSupportImpl::MockBatteryStatusChangedForTesting( |
| 1176 const blink::WebBatteryStatus& status) { | 1205 const blink::WebBatteryStatus& status) { |
| 1177 PlatformEventObserverBase* observer = | 1206 g_test_battery_status_dispatcher.Get().PostBatteryStatusChange(status); |
| 1178 platform_event_observers_.Lookup(blink::WebPlatformEventBattery); | |
| 1179 if (!observer) | |
| 1180 return; | |
| 1181 observer->SendFakeDataForTesting((void*)&status); | |
| 1182 } | 1207 } |
| 1183 | 1208 |
| 1184 } // namespace content | 1209 } // namespace content |
| OLD | NEW |