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 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 // static | 1049 // static |
1050 PlatformEventObserverBase* | 1050 PlatformEventObserverBase* |
1051 RendererWebKitPlatformSupportImpl::CreatePlatformEventObserverFromType( | 1051 RendererWebKitPlatformSupportImpl::CreatePlatformEventObserverFromType( |
1052 blink::WebPlatformEventType type) { | 1052 blink::WebPlatformEventType type) { |
1053 RenderThread* thread = RenderThreadImpl::current(); | 1053 RenderThread* thread = RenderThreadImpl::current(); |
1054 | 1054 |
1055 // When running layout tests, those observers should not listen to the actual | 1055 // When running layout tests, those observers should not listen to the actual |
1056 // hardware changes. In order to make that happen, they will receive a null | 1056 // hardware changes. In order to make that happen, they will receive a null |
1057 // thread. | 1057 // thread. |
1058 if (thread && RenderThreadImpl::current()->layout_test_mode()) | 1058 if (thread && RenderThreadImpl::current()->layout_test_mode()) |
1059 thread = 0; | 1059 thread = NULL; |
1060 | 1060 |
1061 switch (type) { | 1061 switch (type) { |
1062 case blink::WebPlatformEventDeviceMotion: { | 1062 case blink::WebPlatformEventDeviceMotion: |
1063 return new DeviceMotionEventPump(thread); | 1063 return new DeviceMotionEventPump(thread); |
1064 } | 1064 case blink::WebPlatformEventDeviceOrientation: |
1065 case blink::WebPlatformEventDeviceOrientation: { | 1065 return new DeviceOrientationEventPump(thread); |
1066 return new DeviceOrientationEventPump(thread); | 1066 case blink::WebPlatformEventDeviceLight: |
1067 } | 1067 return new DeviceLightEventPump(thread); |
1068 case blink::WebPlatformEventDeviceLight: { | 1068 case blink::WebPlatformEventGamepad: |
1069 return new DeviceLightEventPump(thread); | 1069 return new GamepadSharedMemoryReader(thread); |
1070 } | 1070 case blink::WebPlatformEventScreenOrientation: |
1071 case blink::WebPlatformEventBattery: { | 1071 return new ScreenOrientationObserver(); |
1072 return new BatteryStatusDispatcher(thread); | 1072 default: |
1073 } | 1073 // A default statement is required to prevent compilation errors when |
1074 case blink::WebPlatformEventGamepad: | 1074 // Blink adds a new type. |
1075 return new GamepadSharedMemoryReader(thread); | 1075 VLOG(1) << "RendererWebKitPlatformSupportImpl::startListening() with " |
1076 break; | 1076 "unknown type."; |
1077 case blink::WebPlatformEventScreenOrientation: | |
1078 return new ScreenOrientationObserver(); | |
1079 default: | |
1080 // A default statement is required to prevent compilation errors when Blink | |
1081 // adds a new type. | |
1082 VLOG(1) << "RendererWebKitPlatformSupportImpl::startListening() with " | |
1083 "unknown type."; | |
1084 } | 1077 } |
1085 | 1078 |
1086 return 0; | 1079 return NULL; |
1087 } | 1080 } |
1088 | 1081 |
1089 void RendererWebKitPlatformSupportImpl::SetPlatformEventObserverForTesting( | 1082 void RendererWebKitPlatformSupportImpl::SetPlatformEventObserverForTesting( |
1090 blink::WebPlatformEventType type, | 1083 blink::WebPlatformEventType type, |
1091 scoped_ptr<PlatformEventObserverBase> observer) { | 1084 scoped_ptr<PlatformEventObserverBase> observer) { |
| 1085 DCHECK(type != blink::WebPlatformEventBattery); |
| 1086 |
1092 if (platform_event_observers_.Lookup(type)) | 1087 if (platform_event_observers_.Lookup(type)) |
1093 platform_event_observers_.Remove(type); | 1088 platform_event_observers_.Remove(type); |
1094 platform_event_observers_.AddWithID(observer.release(), type); | 1089 platform_event_observers_.AddWithID(observer.release(), type); |
1095 } | 1090 } |
1096 | 1091 |
1097 void RendererWebKitPlatformSupportImpl::startListening( | 1092 void RendererWebKitPlatformSupportImpl::startListening( |
1098 blink::WebPlatformEventType type, | 1093 blink::WebPlatformEventType type, |
1099 blink::WebPlatformEventListener* listener) { | 1094 blink::WebPlatformEventListener* listener) { |
| 1095 if (type == blink::WebPlatformEventBattery) { |
| 1096 battery_status_dispatcher_.reset(new BatteryStatusDispatcher( |
| 1097 static_cast<blink::WebBatteryStatusListener*>(listener))); |
| 1098 return; |
| 1099 } |
| 1100 |
1100 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); | 1101 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); |
1101 if (!observer) { | 1102 if (!observer) { |
1102 observer = CreatePlatformEventObserverFromType(type); | 1103 observer = CreatePlatformEventObserverFromType(type); |
1103 if (!observer) | 1104 if (!observer) |
1104 return; | 1105 return; |
1105 platform_event_observers_.AddWithID(observer, static_cast<int32>(type)); | 1106 platform_event_observers_.AddWithID(observer, static_cast<int32>(type)); |
1106 } | 1107 } |
1107 observer->Start(listener); | 1108 observer->Start(listener); |
1108 | 1109 |
1109 // Device events (motion, orientation and light) expect to get an event fired | 1110 // Device events (motion, orientation and light) expect to get an event fired |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 return; | 1149 return; |
1149 | 1150 |
1150 base::MessageLoopProxy::current()->PostTask( | 1151 base::MessageLoopProxy::current()->PostTask( |
1151 FROM_HERE, | 1152 FROM_HERE, |
1152 base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting, | 1153 base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting, |
1153 base::Unretained(observer), data)); | 1154 base::Unretained(observer), data)); |
1154 } | 1155 } |
1155 | 1156 |
1156 void RendererWebKitPlatformSupportImpl::stopListening( | 1157 void RendererWebKitPlatformSupportImpl::stopListening( |
1157 blink::WebPlatformEventType type) { | 1158 blink::WebPlatformEventType type) { |
| 1159 if (type == blink::WebPlatformEventBattery) { |
| 1160 battery_status_dispatcher_.reset(); |
| 1161 return; |
| 1162 } |
| 1163 |
1158 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); | 1164 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); |
1159 if (!observer) | 1165 if (!observer) |
1160 return; | 1166 return; |
1161 observer->Stop(); | 1167 observer->Stop(); |
1162 } | 1168 } |
1163 | 1169 |
1164 //------------------------------------------------------------------------------ | 1170 //------------------------------------------------------------------------------ |
1165 | 1171 |
1166 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( | 1172 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( |
1167 const blink::WebURL& storage_partition, | 1173 const blink::WebURL& storage_partition, |
(...skipping 14 matching lines...) Expand all Loading... |
1182 void RendererWebKitPlatformSupportImpl::MockBatteryStatusChangedForTesting( | 1188 void RendererWebKitPlatformSupportImpl::MockBatteryStatusChangedForTesting( |
1183 const blink::WebBatteryStatus& status) { | 1189 const blink::WebBatteryStatus& status) { |
1184 PlatformEventObserverBase* observer = | 1190 PlatformEventObserverBase* observer = |
1185 platform_event_observers_.Lookup(blink::WebPlatformEventBattery); | 1191 platform_event_observers_.Lookup(blink::WebPlatformEventBattery); |
1186 if (!observer) | 1192 if (!observer) |
1187 return; | 1193 return; |
1188 observer->SendFakeDataForTesting((void*)&status); | 1194 observer->SendFakeDataForTesting((void*)&status); |
1189 } | 1195 } |
1190 | 1196 |
1191 } // namespace content | 1197 } // namespace content |
OLD | NEW |