Chromium Code Reviews| 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 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 return blob_registry_.get(); | 881 return blob_registry_.get(); |
| 882 } | 882 } |
| 883 | 883 |
| 884 //------------------------------------------------------------------------------ | 884 //------------------------------------------------------------------------------ |
| 885 | 885 |
| 886 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { | 886 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { |
| 887 DCHECK(gamepad_provider_); | 887 DCHECK(gamepad_provider_); |
| 888 gamepad_provider_->SampleGamepads(gamepads); | 888 gamepad_provider_->SampleGamepads(gamepads); |
| 889 } | 889 } |
| 890 | 890 |
| 891 void RendererWebKitPlatformSupportImpl::setGamepadListener( | |
| 892 blink::WebGamepadListener* listener) { | |
| 893 DCHECK(gamepad_provider_); | |
| 894 gamepad_provider_->SetGamepadListener(listener); | |
| 895 } | |
| 896 | |
| 897 //------------------------------------------------------------------------------ | 891 //------------------------------------------------------------------------------ |
| 898 | 892 |
| 899 WebRTCPeerConnectionHandler* | 893 WebRTCPeerConnectionHandler* |
| 900 RendererWebKitPlatformSupportImpl::createRTCPeerConnectionHandler( | 894 RendererWebKitPlatformSupportImpl::createRTCPeerConnectionHandler( |
| 901 WebRTCPeerConnectionHandlerClient* client) { | 895 WebRTCPeerConnectionHandlerClient* client) { |
| 902 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 896 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 903 DCHECK(render_thread); | 897 DCHECK(render_thread); |
| 904 if (!render_thread) | 898 if (!render_thread) |
| 905 return NULL; | 899 return NULL; |
| 906 | 900 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1014 //------------------------------------------------------------------------------ | 1008 //------------------------------------------------------------------------------ |
| 1015 | 1009 |
| 1016 blink::WebString RendererWebKitPlatformSupportImpl::convertIDNToUnicode( | 1010 blink::WebString RendererWebKitPlatformSupportImpl::convertIDNToUnicode( |
| 1017 const blink::WebString& host, | 1011 const blink::WebString& host, |
| 1018 const blink::WebString& languages) { | 1012 const blink::WebString& languages) { |
| 1019 return net::IDNToUnicode(host.utf8(), languages.utf8()); | 1013 return net::IDNToUnicode(host.utf8(), languages.utf8()); |
| 1020 } | 1014 } |
| 1021 | 1015 |
| 1022 //------------------------------------------------------------------------------ | 1016 //------------------------------------------------------------------------------ |
| 1023 | 1017 |
| 1024 void RendererWebKitPlatformSupportImpl::setDeviceLightListener( | |
| 1025 blink::WebDeviceLightListener* listener) { | |
| 1026 if (g_test_device_light_data < 0) { | |
| 1027 if (!device_light_event_pump_) { | |
| 1028 device_light_event_pump_.reset(new DeviceLightEventPump); | |
| 1029 device_light_event_pump_->Attach(RenderThreadImpl::current()); | |
| 1030 } | |
| 1031 device_light_event_pump_->SetListener(listener); | |
| 1032 } else if (listener) { | |
| 1033 // Testing mode: just echo the test data to the listener. | |
| 1034 base::MessageLoopProxy::current()->PostTask( | |
| 1035 FROM_HERE, | |
| 1036 base::Bind(&blink::WebDeviceLightListener::didChangeDeviceLight, | |
| 1037 base::Unretained(listener), | |
| 1038 g_test_device_light_data)); | |
| 1039 } | |
| 1040 } | |
| 1041 | |
| 1042 // static | 1018 // static |
| 1043 void RendererWebKitPlatformSupportImpl::SetMockDeviceLightDataForTesting( | 1019 void RendererWebKitPlatformSupportImpl::SetMockDeviceLightDataForTesting( |
| 1044 double data) { | 1020 double data) { |
| 1045 g_test_device_light_data = data; | 1021 g_test_device_light_data = data; |
| 1046 } | 1022 } |
| 1047 | 1023 |
| 1048 //------------------------------------------------------------------------------ | 1024 //------------------------------------------------------------------------------ |
| 1049 | 1025 |
| 1050 void RendererWebKitPlatformSupportImpl::setDeviceMotionListener( | 1026 // static |
| 1027 void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting( | |
| 1028 const blink::WebDeviceMotionData& data) { | |
| 1029 g_test_device_motion_data.Get() = data; | |
| 1030 } | |
| 1031 | |
| 1032 //------------------------------------------------------------------------------ | |
| 1033 | |
| 1034 // static | |
| 1035 void RendererWebKitPlatformSupportImpl::SetMockDeviceOrientationDataForTesting( | |
| 1036 const blink::WebDeviceOrientationData& data) { | |
| 1037 g_test_device_orientation_data.Get() = data; | |
| 1038 } | |
| 1039 | |
| 1040 //------------------------------------------------------------------------------ | |
| 1041 | |
| 1042 void RendererWebKitPlatformSupportImpl::vibrate(unsigned int milliseconds) { | |
| 1043 RenderThread::Get()->Send( | |
| 1044 new ViewHostMsg_Vibrate(base::checked_cast<int64>(milliseconds))); | |
| 1045 } | |
| 1046 | |
| 1047 void RendererWebKitPlatformSupportImpl::cancelVibration() { | |
| 1048 RenderThread::Get()->Send(new ViewHostMsg_CancelVibration()); | |
| 1049 } | |
| 1050 | |
| 1051 //------------------------------------------------------------------------------ | |
| 1052 | |
| 1053 void RendererWebKitPlatformSupportImpl::startListening( | |
| 1054 blink::WebPlatformEventType type, | |
| 1055 blink::WebPlatformEventListener* listener) { | |
| 1056 switch (type) { | |
| 1057 case blink::WebPlatformEventDeviceMotion: | |
| 1058 SetDeviceMotionListener( | |
| 1059 static_cast<blink::WebDeviceMotionListener*>(listener)); | |
| 1060 break; | |
| 1061 case blink::WebPlatformEventDeviceOrientation: | |
| 1062 SetDeviceOrientationListener( | |
| 1063 static_cast<blink::WebDeviceOrientationListener*>(listener)); | |
| 1064 break; | |
| 1065 case blink::WebPlatformEventDeviceLight: | |
| 1066 SetDeviceLightListener( | |
| 1067 static_cast<blink::WebDeviceLightListener*>(listener)); | |
| 1068 break; | |
| 1069 case blink::WebPlatformEventBattery: | |
| 1070 SetBatteryStatusListener( | |
| 1071 static_cast<blink::WebBatteryStatusListener*>(listener)); | |
| 1072 break; | |
| 1073 case blink::WebPlatformEventGamepad: | |
| 1074 SetGamepadListener( | |
| 1075 static_cast<blink::WebGamepadListener*>(listener)); | |
| 1076 break; | |
| 1077 default: | |
| 1078 // A default statement is required to prevent compilation errors when Blink | |
| 1079 // adds a new type. | |
| 1080 LOG(ERROR) << "RendererWebKitPlatformSupportImpl::startListening() with " | |
| 1081 "unknown type."; | |
| 1082 } | |
| 1083 } | |
| 1084 | |
| 1085 void RendererWebKitPlatformSupportImpl::stopListening( | |
| 1086 blink::WebPlatformEventType type) { | |
| 1087 switch (type) { | |
| 1088 case blink::WebPlatformEventDeviceMotion: | |
| 1089 SetDeviceMotionListener(0); | |
| 1090 break; | |
| 1091 case blink::WebPlatformEventDeviceOrientation: | |
| 1092 SetDeviceOrientationListener(0); | |
| 1093 break; | |
| 1094 case blink::WebPlatformEventDeviceLight: | |
| 1095 SetDeviceLightListener(0); | |
| 1096 break; | |
| 1097 case blink::WebPlatformEventBattery: | |
| 1098 SetBatteryStatusListener(0); | |
| 1099 break; | |
| 1100 case blink::WebPlatformEventGamepad: | |
| 1101 SetGamepadListener(0); | |
| 1102 break; | |
| 1103 default: | |
| 1104 // A default statement is required to prevent compilation errors when Blink | |
| 1105 // adds a new type. | |
| 1106 LOG(ERROR) << "RendererWebKitPlatformSupportImpl::stopListening() with " | |
|
jochen (gone - plz use gerrit)
2014/08/04 12:44:20
VLOG(1) ?
mlamouri (slow - plz ping)
2014/08/04 14:28:44
Done. For startListening() too.
| |
| 1107 "unknown type."; | |
| 1108 } | |
| 1109 } | |
| 1110 | |
| 1111 void RendererWebKitPlatformSupportImpl::SetDeviceMotionListener( | |
| 1051 blink::WebDeviceMotionListener* listener) { | 1112 blink::WebDeviceMotionListener* listener) { |
| 1052 if (g_test_device_motion_data == 0) { | 1113 if (g_test_device_motion_data == 0) { |
| 1053 if (!device_motion_event_pump_) { | 1114 if (!device_motion_event_pump_) { |
| 1054 device_motion_event_pump_.reset(new DeviceMotionEventPump); | 1115 device_motion_event_pump_.reset(new DeviceMotionEventPump); |
| 1055 device_motion_event_pump_->Attach(RenderThreadImpl::current()); | 1116 device_motion_event_pump_->Attach(RenderThreadImpl::current()); |
| 1056 } | 1117 } |
| 1057 device_motion_event_pump_->SetListener(listener); | 1118 device_motion_event_pump_->SetListener(listener); |
| 1058 } else if (listener) { | 1119 } else if (listener) { |
| 1059 // Testing mode: just echo the test data to the listener. | 1120 // Testing mode: just echo the test data to the listener. |
| 1060 base::MessageLoopProxy::current()->PostTask( | 1121 base::MessageLoopProxy::current()->PostTask( |
| 1061 FROM_HERE, | 1122 FROM_HERE, |
| 1062 base::Bind(&blink::WebDeviceMotionListener::didChangeDeviceMotion, | 1123 base::Bind(&blink::WebDeviceMotionListener::didChangeDeviceMotion, |
| 1063 base::Unretained(listener), | 1124 base::Unretained(listener), |
| 1064 g_test_device_motion_data.Get())); | 1125 g_test_device_motion_data.Get())); |
| 1065 } | 1126 } |
| 1066 } | 1127 } |
| 1067 | 1128 |
| 1068 // static | 1129 void RendererWebKitPlatformSupportImpl::SetDeviceOrientationListener( |
| 1069 void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting( | |
| 1070 const blink::WebDeviceMotionData& data) { | |
| 1071 g_test_device_motion_data.Get() = data; | |
| 1072 } | |
| 1073 | |
| 1074 //------------------------------------------------------------------------------ | |
| 1075 | |
| 1076 void RendererWebKitPlatformSupportImpl::setDeviceOrientationListener( | |
| 1077 blink::WebDeviceOrientationListener* listener) { | 1130 blink::WebDeviceOrientationListener* listener) { |
| 1078 if (g_test_device_orientation_data == 0) { | 1131 if (g_test_device_orientation_data == 0) { |
| 1079 if (!device_orientation_event_pump_) { | 1132 if (!device_orientation_event_pump_) { |
| 1080 device_orientation_event_pump_.reset(new DeviceOrientationEventPump); | 1133 device_orientation_event_pump_.reset(new DeviceOrientationEventPump); |
| 1081 device_orientation_event_pump_->Attach(RenderThreadImpl::current()); | 1134 device_orientation_event_pump_->Attach(RenderThreadImpl::current()); |
| 1082 } | 1135 } |
| 1083 device_orientation_event_pump_->SetListener(listener); | 1136 device_orientation_event_pump_->SetListener(listener); |
| 1084 } else if (listener) { | 1137 } else if (listener) { |
| 1085 // Testing mode: just echo the test data to the listener. | 1138 // Testing mode: just echo the test data to the listener. |
| 1086 base::MessageLoopProxy::current()->PostTask( | 1139 base::MessageLoopProxy::current()->PostTask( |
| 1087 FROM_HERE, | 1140 FROM_HERE, |
| 1088 base::Bind( | 1141 base::Bind( |
| 1089 &blink::WebDeviceOrientationListener::didChangeDeviceOrientation, | 1142 &blink::WebDeviceOrientationListener::didChangeDeviceOrientation, |
| 1090 base::Unretained(listener), | 1143 base::Unretained(listener), |
| 1091 g_test_device_orientation_data.Get())); | 1144 g_test_device_orientation_data.Get())); |
| 1092 } | 1145 } |
| 1093 } | 1146 } |
| 1094 | 1147 |
| 1095 // static | 1148 void RendererWebKitPlatformSupportImpl::SetDeviceLightListener( |
| 1096 void RendererWebKitPlatformSupportImpl::SetMockDeviceOrientationDataForTesting( | 1149 blink::WebDeviceLightListener* listener) { |
| 1097 const blink::WebDeviceOrientationData& data) { | 1150 if (g_test_device_light_data < 0) { |
| 1098 g_test_device_orientation_data.Get() = data; | 1151 if (!device_light_event_pump_) { |
| 1152 device_light_event_pump_.reset(new DeviceLightEventPump); | |
| 1153 device_light_event_pump_->Attach(RenderThreadImpl::current()); | |
| 1154 } | |
| 1155 device_light_event_pump_->SetListener(listener); | |
| 1156 } else if (listener) { | |
| 1157 // Testing mode: just echo the test data to the listener. | |
| 1158 base::MessageLoopProxy::current()->PostTask( | |
| 1159 FROM_HERE, | |
| 1160 base::Bind(&blink::WebDeviceLightListener::didChangeDeviceLight, | |
| 1161 base::Unretained(listener), | |
| 1162 g_test_device_light_data)); | |
| 1163 } | |
| 1164 } | |
| 1165 | |
| 1166 void RendererWebKitPlatformSupportImpl::SetGamepadListener( | |
| 1167 blink::WebGamepadListener* listener) { | |
| 1168 DCHECK(gamepad_provider_); | |
| 1169 gamepad_provider_->SetGamepadListener(listener); | |
| 1170 } | |
| 1171 | |
| 1172 void RendererWebKitPlatformSupportImpl::SetBatteryStatusListener( | |
| 1173 blink::WebBatteryStatusListener* listener) { | |
| 1174 if (RenderThreadImpl::current() && | |
| 1175 RenderThreadImpl::current()->layout_test_mode()) { | |
| 1176 // If we are in test mode, we want to use a fake battery status dispatcher, | |
| 1177 // which does not communicate with the browser process. Battery status | |
| 1178 // changes are signalled by invoking MockBatteryStatusChangedForTesting(). | |
| 1179 g_test_battery_status_dispatcher.Get().SetListener(listener); | |
| 1180 return; | |
| 1181 } | |
| 1182 | |
| 1183 if (!battery_status_dispatcher_) { | |
| 1184 battery_status_dispatcher_.reset( | |
| 1185 new BatteryStatusDispatcher(RenderThreadImpl::current())); | |
| 1186 } | |
| 1187 battery_status_dispatcher_->SetListener(listener); | |
| 1099 } | 1188 } |
| 1100 | 1189 |
| 1101 //------------------------------------------------------------------------------ | 1190 //------------------------------------------------------------------------------ |
| 1102 | |
| 1103 void RendererWebKitPlatformSupportImpl::vibrate(unsigned int milliseconds) { | |
| 1104 RenderThread::Get()->Send( | |
| 1105 new ViewHostMsg_Vibrate(base::checked_cast<int64>(milliseconds))); | |
| 1106 } | |
| 1107 | |
| 1108 void RendererWebKitPlatformSupportImpl::cancelVibration() { | |
| 1109 RenderThread::Get()->Send(new ViewHostMsg_CancelVibration()); | |
| 1110 } | |
| 1111 | |
| 1112 //------------------------------------------------------------------------------ | |
| 1113 | 1191 |
| 1114 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( | 1192 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( |
| 1115 const blink::WebURL& storage_partition, | 1193 const blink::WebURL& storage_partition, |
| 1116 blink::WebStorageQuotaType type, | 1194 blink::WebStorageQuotaType type, |
| 1117 blink::WebStorageQuotaCallbacks callbacks) { | 1195 blink::WebStorageQuotaCallbacks callbacks) { |
| 1118 if (!thread_safe_sender_.get() || !quota_message_filter_.get()) | 1196 if (!thread_safe_sender_.get() || !quota_message_filter_.get()) |
| 1119 return; | 1197 return; |
| 1120 QuotaDispatcher::ThreadSpecificInstance( | 1198 QuotaDispatcher::ThreadSpecificInstance( |
| 1121 thread_safe_sender_.get(), | 1199 thread_safe_sender_.get(), |
| 1122 quota_message_filter_.get())->QueryStorageUsageAndQuota( | 1200 quota_message_filter_.get())->QueryStorageUsageAndQuota( |
| 1123 storage_partition, | 1201 storage_partition, |
| 1124 static_cast<quota::StorageType>(type), | 1202 static_cast<quota::StorageType>(type), |
| 1125 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); | 1203 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
| 1126 } | 1204 } |
| 1127 | 1205 |
| 1128 //------------------------------------------------------------------------------ | 1206 //------------------------------------------------------------------------------ |
| 1129 | 1207 |
| 1130 void RendererWebKitPlatformSupportImpl::setBatteryStatusListener( | |
| 1131 blink::WebBatteryStatusListener* listener) { | |
| 1132 if (RenderThreadImpl::current() && | |
| 1133 RenderThreadImpl::current()->layout_test_mode()) { | |
| 1134 // If we are in test mode, we want to use a fake battery status dispatcher, | |
| 1135 // which does not communicate with the browser process. Battery status | |
| 1136 // changes are signalled by invoking MockBatteryStatusChangedForTesting(). | |
| 1137 g_test_battery_status_dispatcher.Get().SetListener(listener); | |
| 1138 return; | |
| 1139 } | |
| 1140 | |
| 1141 if (!battery_status_dispatcher_) { | |
| 1142 battery_status_dispatcher_.reset( | |
| 1143 new BatteryStatusDispatcher(RenderThreadImpl::current())); | |
| 1144 } | |
| 1145 battery_status_dispatcher_->SetListener(listener); | |
| 1146 } | |
| 1147 | |
| 1148 // static | 1208 // static |
| 1149 void RendererWebKitPlatformSupportImpl::MockBatteryStatusChangedForTesting( | 1209 void RendererWebKitPlatformSupportImpl::MockBatteryStatusChangedForTesting( |
| 1150 const blink::WebBatteryStatus& status) { | 1210 const blink::WebBatteryStatus& status) { |
| 1151 g_test_battery_status_dispatcher.Get().PostBatteryStatusChange(status); | 1211 g_test_battery_status_dispatcher.Get().PostBatteryStatusChange(status); |
| 1152 } | 1212 } |
| 1153 | 1213 |
| 1154 } // namespace content | 1214 } // namespace content |
| OLD | NEW |