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