| 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_blink_platform_impl.h" | 5 #include "content/renderer/renderer_blink_platform_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 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 // static | 1038 // static |
| 1039 PlatformEventObserverBase* | 1039 PlatformEventObserverBase* |
| 1040 RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType( | 1040 RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType( |
| 1041 blink::WebPlatformEventType type) { | 1041 blink::WebPlatformEventType type) { |
| 1042 RenderThread* thread = RenderThreadImpl::current(); | 1042 RenderThread* thread = RenderThreadImpl::current(); |
| 1043 | 1043 |
| 1044 // When running layout tests, those observers should not listen to the actual | 1044 // When running layout tests, those observers should not listen to the actual |
| 1045 // hardware changes. In order to make that happen, they will receive a null | 1045 // hardware changes. In order to make that happen, they will receive a null |
| 1046 // thread. | 1046 // thread. |
| 1047 if (thread && RenderThreadImpl::current()->layout_test_mode()) | 1047 if (thread && RenderThreadImpl::current()->layout_test_mode()) |
| 1048 thread = NULL; | 1048 thread = 0; |
| 1049 | 1049 |
| 1050 switch (type) { | 1050 switch (type) { |
| 1051 case blink::WebPlatformEventDeviceMotion: | 1051 case blink::WebPlatformEventDeviceMotion: { |
| 1052 return new DeviceMotionEventPump(thread); | 1052 return new DeviceMotionEventPump(thread); |
| 1053 case blink::WebPlatformEventDeviceOrientation: | 1053 } |
| 1054 return new DeviceOrientationEventPump(thread); | 1054 case blink::WebPlatformEventDeviceOrientation: { |
| 1055 case blink::WebPlatformEventDeviceLight: | 1055 return new DeviceOrientationEventPump(thread); |
| 1056 return new DeviceLightEventPump(thread); | 1056 } |
| 1057 case blink::WebPlatformEventGamepad: | 1057 case blink::WebPlatformEventDeviceLight: { |
| 1058 return new GamepadSharedMemoryReader(thread); | 1058 return new DeviceLightEventPump(thread); |
| 1059 case blink::WebPlatformEventScreenOrientation: | 1059 } |
| 1060 return new ScreenOrientationObserver(); | 1060 case blink::WebPlatformEventBattery: { |
| 1061 default: | 1061 return new BatteryStatusDispatcher(thread); |
| 1062 // A default statement is required to prevent compilation errors when | 1062 } |
| 1063 // Blink adds a new type. | 1063 case blink::WebPlatformEventGamepad: |
| 1064 VLOG(1) << "RendererBlinkPlatformImpl::startListening() with " | 1064 return new GamepadSharedMemoryReader(thread); |
| 1065 "unknown type."; | 1065 break; |
| 1066 case blink::WebPlatformEventScreenOrientation: |
| 1067 return new ScreenOrientationObserver(); |
| 1068 default: |
| 1069 // A default statement is required to prevent compilation errors when Blink |
| 1070 // adds a new type. |
| 1071 VLOG(1) << "RendererBlinkPlatformImpl::startListening() with " |
| 1072 "unknown type."; |
| 1066 } | 1073 } |
| 1067 | 1074 |
| 1068 return NULL; | 1075 return 0; |
| 1069 } | 1076 } |
| 1070 | 1077 |
| 1071 void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting( | 1078 void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting( |
| 1072 blink::WebPlatformEventType type, | 1079 blink::WebPlatformEventType type, |
| 1073 scoped_ptr<PlatformEventObserverBase> observer) { | 1080 scoped_ptr<PlatformEventObserverBase> observer) { |
| 1074 DCHECK(type != blink::WebPlatformEventBattery); | |
| 1075 | |
| 1076 if (platform_event_observers_.Lookup(type)) | 1081 if (platform_event_observers_.Lookup(type)) |
| 1077 platform_event_observers_.Remove(type); | 1082 platform_event_observers_.Remove(type); |
| 1078 platform_event_observers_.AddWithID(observer.release(), type); | 1083 platform_event_observers_.AddWithID(observer.release(), type); |
| 1079 } | 1084 } |
| 1080 | 1085 |
| 1081 void RendererBlinkPlatformImpl::startListening( | 1086 void RendererBlinkPlatformImpl::startListening( |
| 1082 blink::WebPlatformEventType type, | 1087 blink::WebPlatformEventType type, |
| 1083 blink::WebPlatformEventListener* listener) { | 1088 blink::WebPlatformEventListener* listener) { |
| 1084 if (type == blink::WebPlatformEventBattery) { | |
| 1085 battery_status_dispatcher_.reset(new BatteryStatusDispatcher( | |
| 1086 static_cast<blink::WebBatteryStatusListener*>(listener))); | |
| 1087 return; | |
| 1088 } | |
| 1089 | |
| 1090 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); | 1089 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); |
| 1091 if (!observer) { | 1090 if (!observer) { |
| 1092 observer = CreatePlatformEventObserverFromType(type); | 1091 observer = CreatePlatformEventObserverFromType(type); |
| 1093 if (!observer) | 1092 if (!observer) |
| 1094 return; | 1093 return; |
| 1095 platform_event_observers_.AddWithID(observer, static_cast<int32>(type)); | 1094 platform_event_observers_.AddWithID(observer, static_cast<int32>(type)); |
| 1096 } | 1095 } |
| 1097 observer->Start(listener); | 1096 observer->Start(listener); |
| 1098 | 1097 |
| 1099 // Device events (motion, orientation and light) expect to get an event fired | 1098 // 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... |
| 1138 return; | 1137 return; |
| 1139 | 1138 |
| 1140 base::MessageLoopProxy::current()->PostTask( | 1139 base::MessageLoopProxy::current()->PostTask( |
| 1141 FROM_HERE, | 1140 FROM_HERE, |
| 1142 base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting, | 1141 base::Bind(&PlatformEventObserverBase::SendFakeDataForTesting, |
| 1143 base::Unretained(observer), data)); | 1142 base::Unretained(observer), data)); |
| 1144 } | 1143 } |
| 1145 | 1144 |
| 1146 void RendererBlinkPlatformImpl::stopListening( | 1145 void RendererBlinkPlatformImpl::stopListening( |
| 1147 blink::WebPlatformEventType type) { | 1146 blink::WebPlatformEventType type) { |
| 1148 if (type == blink::WebPlatformEventBattery) { | |
| 1149 battery_status_dispatcher_.reset(); | |
| 1150 return; | |
| 1151 } | |
| 1152 | |
| 1153 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); | 1147 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); |
| 1154 if (!observer) | 1148 if (!observer) |
| 1155 return; | 1149 return; |
| 1156 observer->Stop(); | 1150 observer->Stop(); |
| 1157 } | 1151 } |
| 1158 | 1152 |
| 1159 //------------------------------------------------------------------------------ | 1153 //------------------------------------------------------------------------------ |
| 1160 | 1154 |
| 1161 void RendererBlinkPlatformImpl::queryStorageUsageAndQuota( | 1155 void RendererBlinkPlatformImpl::queryStorageUsageAndQuota( |
| 1162 const blink::WebURL& storage_partition, | 1156 const blink::WebURL& storage_partition, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1177 void RendererBlinkPlatformImpl::MockBatteryStatusChangedForTesting( | 1171 void RendererBlinkPlatformImpl::MockBatteryStatusChangedForTesting( |
| 1178 const blink::WebBatteryStatus& status) { | 1172 const blink::WebBatteryStatus& status) { |
| 1179 PlatformEventObserverBase* observer = | 1173 PlatformEventObserverBase* observer = |
| 1180 platform_event_observers_.Lookup(blink::WebPlatformEventBattery); | 1174 platform_event_observers_.Lookup(blink::WebPlatformEventBattery); |
| 1181 if (!observer) | 1175 if (!observer) |
| 1182 return; | 1176 return; |
| 1183 observer->SendFakeDataForTesting((void*)&status); | 1177 observer->SendFakeDataForTesting((void*)&status); |
| 1184 } | 1178 } |
| 1185 | 1179 |
| 1186 } // namespace content | 1180 } // namespace content |
| OLD | NEW |