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 <memory> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/guid.h" | 12 #include "base/guid.h" |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/location.h" | 14 #include "base/location.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
16 #include "base/memory/shared_memory.h" | 17 #include "base/memory/shared_memory.h" |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 | 1148 |
1148 // static | 1149 // static |
1149 void RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting( | 1150 void RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting( |
1150 const blink::WebDeviceOrientationData& data) { | 1151 const blink::WebDeviceOrientationData& data) { |
1151 g_test_device_orientation_data.Get() = data; | 1152 g_test_device_orientation_data.Get() = data; |
1152 } | 1153 } |
1153 | 1154 |
1154 //------------------------------------------------------------------------------ | 1155 //------------------------------------------------------------------------------ |
1155 | 1156 |
1156 // static | 1157 // static |
1157 PlatformEventObserverBase* | 1158 std::unique_ptr<PlatformEventObserverBase> |
1158 RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType( | 1159 RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType( |
1159 blink::WebPlatformEventType type) { | 1160 blink::WebPlatformEventType type) { |
1160 RenderThread* thread = RenderThreadImpl::current(); | 1161 RenderThread* thread = RenderThreadImpl::current(); |
1161 | 1162 |
1162 // When running layout tests, those observers should not listen to the actual | 1163 // When running layout tests, those observers should not listen to the actual |
1163 // hardware changes. In order to make that happen, they will receive a null | 1164 // hardware changes. In order to make that happen, they will receive a null |
1164 // thread. | 1165 // thread. |
1165 if (thread && RenderThreadImpl::current()->layout_test_mode()) | 1166 if (thread && RenderThreadImpl::current()->layout_test_mode()) |
1166 thread = NULL; | 1167 thread = NULL; |
1167 | 1168 |
1168 switch (type) { | 1169 switch (type) { |
1169 case blink::WebPlatformEventTypeDeviceMotion: | 1170 case blink::WebPlatformEventTypeDeviceMotion: |
1170 return new DeviceMotionEventPump(thread); | 1171 return base::MakeUnique<DeviceMotionEventPump>(thread); |
1171 case blink::WebPlatformEventTypeDeviceOrientation: | 1172 case blink::WebPlatformEventTypeDeviceOrientation: |
1172 return new DeviceOrientationEventPump(thread); | 1173 return base::MakeUnique<DeviceOrientationEventPump>(thread); |
1173 case blink::WebPlatformEventTypeDeviceOrientationAbsolute: | 1174 case blink::WebPlatformEventTypeDeviceOrientationAbsolute: |
1174 return new DeviceOrientationAbsoluteEventPump(thread); | 1175 return base::MakeUnique<DeviceOrientationAbsoluteEventPump>(thread); |
1175 case blink::WebPlatformEventTypeDeviceLight: | 1176 case blink::WebPlatformEventTypeDeviceLight: |
1176 return new DeviceLightEventPump(thread); | 1177 return base::MakeUnique<DeviceLightEventPump>(thread); |
1177 case blink::WebPlatformEventTypeGamepad: | 1178 case blink::WebPlatformEventTypeGamepad: |
1178 return new GamepadSharedMemoryReader(thread); | 1179 return base::MakeUnique<GamepadSharedMemoryReader>(thread); |
1179 case blink::WebPlatformEventTypeScreenOrientation: | 1180 case blink::WebPlatformEventTypeScreenOrientation: |
1180 return new ScreenOrientationObserver(); | 1181 return base::MakeUnique<ScreenOrientationObserver>(); |
1181 default: | 1182 default: |
1182 // A default statement is required to prevent compilation errors when | 1183 // A default statement is required to prevent compilation errors when |
1183 // Blink adds a new type. | 1184 // Blink adds a new type. |
1184 DVLOG(1) << "RendererBlinkPlatformImpl::startListening() with " | 1185 DVLOG(1) << "RendererBlinkPlatformImpl::startListening() with " |
1185 "unknown type."; | 1186 "unknown type."; |
1186 } | 1187 } |
1187 | 1188 |
1188 return NULL; | 1189 return NULL; |
1189 } | 1190 } |
1190 | 1191 |
1191 void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting( | 1192 void RendererBlinkPlatformImpl::SetPlatformEventObserverForTesting( |
1192 blink::WebPlatformEventType type, | 1193 blink::WebPlatformEventType type, |
1193 std::unique_ptr<PlatformEventObserverBase> observer) { | 1194 std::unique_ptr<PlatformEventObserverBase> observer) { |
1194 if (platform_event_observers_.Lookup(type)) | 1195 if (platform_event_observers_.Lookup(type)) |
1195 platform_event_observers_.Remove(type); | 1196 platform_event_observers_.Remove(type); |
1196 platform_event_observers_.AddWithID(observer.release(), type); | 1197 platform_event_observers_.AddWithID(std::move(observer), type); |
1197 } | 1198 } |
1198 | 1199 |
1199 blink::InterfaceProvider* RendererBlinkPlatformImpl::interfaceProvider() { | 1200 blink::InterfaceProvider* RendererBlinkPlatformImpl::interfaceProvider() { |
1200 return blink_interface_provider_.get(); | 1201 return blink_interface_provider_.get(); |
1201 } | 1202 } |
1202 | 1203 |
1203 void RendererBlinkPlatformImpl::startListening( | 1204 void RendererBlinkPlatformImpl::startListening( |
1204 blink::WebPlatformEventType type, | 1205 blink::WebPlatformEventType type, |
1205 blink::WebPlatformEventListener* listener) { | 1206 blink::WebPlatformEventListener* listener) { |
1206 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); | 1207 PlatformEventObserverBase* observer = platform_event_observers_.Lookup(type); |
1207 if (!observer) { | 1208 if (!observer) { |
1208 observer = CreatePlatformEventObserverFromType(type); | 1209 std::unique_ptr<PlatformEventObserverBase> new_observer = |
1209 if (!observer) | 1210 CreatePlatformEventObserverFromType(type); |
| 1211 if (!new_observer) |
1210 return; | 1212 return; |
1211 platform_event_observers_.AddWithID(observer, static_cast<int32_t>(type)); | 1213 observer = new_observer.get(); |
| 1214 platform_event_observers_.AddWithID(std::move(new_observer), |
| 1215 static_cast<int32_t>(type)); |
1212 } | 1216 } |
1213 observer->Start(listener); | 1217 observer->Start(listener); |
1214 | 1218 |
1215 // Device events (motion, orientation and light) expect to get an event fired | 1219 // Device events (motion, orientation and light) expect to get an event fired |
1216 // as soon as a listener is registered if a fake data was passed before. | 1220 // as soon as a listener is registered if a fake data was passed before. |
1217 // TODO(mlamouri,timvolodine): make those send mock values directly instead of | 1221 // TODO(mlamouri,timvolodine): make those send mock values directly instead of |
1218 // using this broken pattern. | 1222 // using this broken pattern. |
1219 if (RenderThreadImpl::current() && | 1223 if (RenderThreadImpl::current() && |
1220 RenderThreadImpl::current()->layout_test_mode() && | 1224 RenderThreadImpl::current()->layout_test_mode() && |
1221 (type == blink::WebPlatformEventTypeDeviceMotion || | 1225 (type == blink::WebPlatformEventTypeDeviceMotion || |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 return &trial_token_validator_; | 1295 return &trial_token_validator_; |
1292 } | 1296 } |
1293 | 1297 |
1294 void RendererBlinkPlatformImpl::workerContextCreated( | 1298 void RendererBlinkPlatformImpl::workerContextCreated( |
1295 const v8::Local<v8::Context>& worker) { | 1299 const v8::Local<v8::Context>& worker) { |
1296 GetContentClient()->renderer()->DidInitializeWorkerContextOnWorkerThread( | 1300 GetContentClient()->renderer()->DidInitializeWorkerContextOnWorkerThread( |
1297 worker); | 1301 worker); |
1298 } | 1302 } |
1299 | 1303 |
1300 } // namespace content | 1304 } // namespace content |
OLD | NEW |