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/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 LAZY_INSTANCE_INITIALIZER; | 143 LAZY_INSTANCE_INITIALIZER; |
144 base::LazyInstance<blink::WebDeviceMotionData>::Leaky | 144 base::LazyInstance<blink::WebDeviceMotionData>::Leaky |
145 g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER; | 145 g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER; |
146 base::LazyInstance<blink::WebDeviceOrientationData>::Leaky | 146 base::LazyInstance<blink::WebDeviceOrientationData>::Leaky |
147 g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER; | 147 g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER; |
148 static blink::WebScreenOrientationListener* | 148 static blink::WebScreenOrientationListener* |
149 g_test_screen_orientation_listener = NULL; | 149 g_test_screen_orientation_listener = NULL; |
150 | 150 |
151 //------------------------------------------------------------------------------ | 151 //------------------------------------------------------------------------------ |
152 | 152 |
153 class ScreenOrientationDataForTesting { | |
jochen (gone - plz use gerrit)
2014/05/08 07:12:49
can you move this class and the lazy instance abov
Inactive
2014/05/08 20:07:47
Done.
| |
154 public: | |
155 ScreenOrientationDataForTesting() | |
156 : current_lock(blink::WebScreenOrientationLockDefault), | |
157 device_orientation(blink::WebScreenOrientationPortraitPrimary), | |
158 current_orientation(blink::WebScreenOrientationPortraitPrimary) {} | |
159 | |
160 blink::WebScreenOrientationLockType current_lock; | |
161 blink::WebScreenOrientationType device_orientation; | |
162 blink::WebScreenOrientationType current_orientation; | |
163 }; | |
164 base::LazyInstance<ScreenOrientationDataForTesting>::Leaky | |
165 g_test_screen_orientation_data = LAZY_INSTANCE_INITIALIZER; | |
166 | |
153 class RendererWebKitPlatformSupportImpl::MimeRegistry | 167 class RendererWebKitPlatformSupportImpl::MimeRegistry |
154 : public SimpleWebMimeRegistryImpl { | 168 : public SimpleWebMimeRegistryImpl { |
155 public: | 169 public: |
156 virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType( | 170 virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType( |
157 const blink::WebString& mime_type, | 171 const blink::WebString& mime_type, |
158 const blink::WebString& codecs, | 172 const blink::WebString& codecs, |
159 const blink::WebString& key_system); | 173 const blink::WebString& key_system); |
160 virtual bool supportsMediaSourceMIMEType(const blink::WebString& mime_type, | 174 virtual bool supportsMediaSourceMIMEType(const blink::WebString& mime_type, |
161 const blink::WebString& codecs); | 175 const blink::WebString& codecs); |
162 virtual bool supportsEncryptedMediaMIMEType(const WebString& key_system, | 176 virtual bool supportsEncryptedMediaMIMEType(const WebString& key_system, |
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1071 g_test_device_motion_data.Get())); | 1085 g_test_device_motion_data.Get())); |
1072 } | 1086 } |
1073 } | 1087 } |
1074 | 1088 |
1075 // static | 1089 // static |
1076 void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting( | 1090 void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting( |
1077 const blink::WebDeviceMotionData& data) { | 1091 const blink::WebDeviceMotionData& data) { |
1078 g_test_device_motion_data.Get() = data; | 1092 g_test_device_motion_data.Get() = data; |
1079 } | 1093 } |
1080 | 1094 |
1095 // static | |
1096 void RendererWebKitPlatformSupportImpl::ResetMockScreenOrientationForTesting() | |
1097 { | |
1098 g_test_screen_orientation_data.Get() = ScreenOrientationDataForTesting(); | |
1099 } | |
1100 | |
1081 //------------------------------------------------------------------------------ | 1101 //------------------------------------------------------------------------------ |
1082 | 1102 |
1083 void RendererWebKitPlatformSupportImpl::setDeviceOrientationListener( | 1103 void RendererWebKitPlatformSupportImpl::setDeviceOrientationListener( |
1084 blink::WebDeviceOrientationListener* listener) { | 1104 blink::WebDeviceOrientationListener* listener) { |
1085 if (g_test_device_orientation_data == 0) { | 1105 if (g_test_device_orientation_data == 0) { |
1086 if (!device_orientation_event_pump_) { | 1106 if (!device_orientation_event_pump_) { |
1087 device_orientation_event_pump_.reset(new DeviceOrientationEventPump); | 1107 device_orientation_event_pump_.reset(new DeviceOrientationEventPump); |
1088 device_orientation_event_pump_->Attach(RenderThreadImpl::current()); | 1108 device_orientation_event_pump_->Attach(RenderThreadImpl::current()); |
1089 } | 1109 } |
1090 device_orientation_event_pump_->SetListener(listener); | 1110 device_orientation_event_pump_->SetListener(listener); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1131 } | 1151 } |
1132 | 1152 |
1133 if (!screen_orientation_dispatcher_) { | 1153 if (!screen_orientation_dispatcher_) { |
1134 screen_orientation_dispatcher_.reset( | 1154 screen_orientation_dispatcher_.reset( |
1135 new ScreenOrientationDispatcher(RenderThread::Get())); | 1155 new ScreenOrientationDispatcher(RenderThread::Get())); |
1136 } | 1156 } |
1137 | 1157 |
1138 screen_orientation_dispatcher_->setListener(listener); | 1158 screen_orientation_dispatcher_->setListener(listener); |
1139 } | 1159 } |
1140 | 1160 |
1161 namespace { | |
1162 | |
1163 bool IsScreenOrientationAllowedByTestingLock( | |
jochen (gone - plz use gerrit)
2014/05/08 07:12:49
can these now be members on the ScreenOrientatinoD
Inactive
2014/05/08 20:07:47
Done.
| |
1164 blink::WebScreenOrientationType orientation) { | |
1165 if (g_test_screen_orientation_data.Get().current_lock == | |
1166 blink::WebScreenOrientationLockDefault || | |
1167 g_test_screen_orientation_data.Get().current_lock == | |
1168 blink::WebScreenOrientationLockAny) { | |
1169 return true; | |
1170 } | |
1171 | |
1172 switch (orientation) { | |
1173 case blink::WebScreenOrientationPortraitPrimary: | |
1174 return g_test_screen_orientation_data.Get().current_lock == | |
1175 blink::WebScreenOrientationLockPortraitPrimary || | |
1176 g_test_screen_orientation_data.Get().current_lock == | |
1177 blink::WebScreenOrientationLockPortrait; | |
1178 case blink::WebScreenOrientationPortraitSecondary: | |
1179 return g_test_screen_orientation_data.Get().current_lock == | |
1180 blink::WebScreenOrientationLockPortraitSecondary || | |
1181 g_test_screen_orientation_data.Get().current_lock == | |
1182 blink::WebScreenOrientationLockPortrait; | |
1183 case blink::WebScreenOrientationLandscapePrimary: | |
1184 return g_test_screen_orientation_data.Get().current_lock == | |
1185 blink::WebScreenOrientationLockLandscapePrimary || | |
1186 g_test_screen_orientation_data.Get().current_lock == | |
1187 blink::WebScreenOrientationLockLandscape; | |
1188 case blink::WebScreenOrientationLandscapeSecondary: | |
1189 return g_test_screen_orientation_data.Get().current_lock == | |
1190 blink::WebScreenOrientationLockLandscapeSecondary || | |
1191 g_test_screen_orientation_data.Get().current_lock == | |
1192 blink::WebScreenOrientationLockLandscape; | |
1193 default: | |
1194 return false; | |
1195 } | |
1196 } | |
1197 | |
1198 blink::WebScreenOrientationType SuitableScreenOrientationForTestingLock() { | |
1199 switch (g_test_screen_orientation_data.Get().current_lock) { | |
1200 case blink::WebScreenOrientationLockPortraitSecondary: | |
1201 return blink::WebScreenOrientationPortraitSecondary; | |
1202 case blink::WebScreenOrientationLockLandscapePrimary: | |
1203 case blink::WebScreenOrientationLockLandscape: | |
1204 return blink::WebScreenOrientationLandscapePrimary; | |
1205 case blink::WebScreenOrientationLockLandscapeSecondary: | |
1206 return blink::WebScreenOrientationLandscapePrimary; | |
1207 default: | |
1208 return blink::WebScreenOrientationPortraitPrimary; | |
1209 } | |
1210 } | |
1211 | |
1212 void UpdateScreenOrientationForTesting( | |
1213 blink::WebScreenOrientationType orientation) { | |
1214 if (orientation == g_test_screen_orientation_data.Get().current_orientation) | |
1215 return; | |
1216 g_test_screen_orientation_data.Get().current_orientation = orientation; | |
1217 if (g_test_screen_orientation_listener) { | |
1218 g_test_screen_orientation_listener->didChangeScreenOrientation( | |
1219 orientation); | |
1220 } | |
1221 } | |
1222 | |
1223 } // namespace | |
1224 | |
1141 void RendererWebKitPlatformSupportImpl::lockOrientation( | 1225 void RendererWebKitPlatformSupportImpl::lockOrientation( |
1142 blink::WebScreenOrientationLockType orientation) { | 1226 blink::WebScreenOrientationLockType orientation) { |
1143 if (RenderThreadImpl::current() && | 1227 if (RenderThreadImpl::current() && |
1144 RenderThreadImpl::current()->layout_test_mode()) { | 1228 RenderThreadImpl::current()->layout_test_mode()) { |
1229 g_test_screen_orientation_data.Get().current_lock = orientation; | |
1230 if (!IsScreenOrientationAllowedByTestingLock( | |
1231 g_test_screen_orientation_data.Get().current_orientation)) { | |
1232 g_test_screen_orientation_data.Get().current_orientation = | |
1233 SuitableScreenOrientationForTestingLock(); | |
1234 if (g_test_screen_orientation_listener) { | |
1235 g_test_screen_orientation_listener->didChangeScreenOrientation( | |
1236 g_test_screen_orientation_data.Get().current_orientation); | |
1237 } | |
1238 } | |
1145 return; | 1239 return; |
1146 } | 1240 } |
1147 RenderThread::Get()->Send(new ScreenOrientationHostMsg_Lock(orientation)); | 1241 RenderThread::Get()->Send(new ScreenOrientationHostMsg_Lock(orientation)); |
1148 } | 1242 } |
1149 | 1243 |
1150 void RendererWebKitPlatformSupportImpl::unlockOrientation() { | 1244 void RendererWebKitPlatformSupportImpl::unlockOrientation() { |
1151 if (RenderThreadImpl::current() && | 1245 if (RenderThreadImpl::current() && |
1152 RenderThreadImpl::current()->layout_test_mode()) { | 1246 RenderThreadImpl::current()->layout_test_mode()) { |
1247 bool should_update_current_screen_orientation = | |
1248 !IsScreenOrientationAllowedByTestingLock( | |
1249 g_test_screen_orientation_data.Get().device_orientation); | |
1250 g_test_screen_orientation_data.Get().current_lock = | |
1251 blink::WebScreenOrientationLockDefault; | |
1252 if (should_update_current_screen_orientation) { | |
1253 UpdateScreenOrientationForTesting( | |
1254 g_test_screen_orientation_data.Get().device_orientation); | |
1255 } | |
1153 return; | 1256 return; |
1154 } | 1257 } |
1155 RenderThread::Get()->Send(new ScreenOrientationHostMsg_Unlock); | 1258 RenderThread::Get()->Send(new ScreenOrientationHostMsg_Unlock); |
1156 } | 1259 } |
1157 | 1260 |
1158 // static | 1261 // static |
1159 void RendererWebKitPlatformSupportImpl::SetMockScreenOrientationForTesting( | 1262 void RendererWebKitPlatformSupportImpl::SetMockScreenOrientationForTesting( |
1160 blink::WebScreenOrientationType orientation) { | 1263 blink::WebScreenOrientationType orientation) { |
1161 if (!g_test_screen_orientation_listener) | 1264 g_test_screen_orientation_data.Get().device_orientation = orientation; |
1265 if (!IsScreenOrientationAllowedByTestingLock(orientation)) | |
1162 return; | 1266 return; |
1163 g_test_screen_orientation_listener->didChangeScreenOrientation(orientation); | 1267 UpdateScreenOrientationForTesting( |
1268 g_test_screen_orientation_data.Get().device_orientation); | |
1164 } | 1269 } |
1165 | 1270 |
1166 //------------------------------------------------------------------------------ | 1271 //------------------------------------------------------------------------------ |
1167 | 1272 |
1168 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( | 1273 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( |
1169 const blink::WebURL& storage_partition, | 1274 const blink::WebURL& storage_partition, |
1170 blink::WebStorageQuotaType type, | 1275 blink::WebStorageQuotaType type, |
1171 blink::WebStorageQuotaCallbacks callbacks) { | 1276 blink::WebStorageQuotaCallbacks callbacks) { |
1172 if (!thread_safe_sender_.get() || !quota_message_filter_.get()) | 1277 if (!thread_safe_sender_.get() || !quota_message_filter_.get()) |
1173 return; | 1278 return; |
1174 QuotaDispatcher::ThreadSpecificInstance( | 1279 QuotaDispatcher::ThreadSpecificInstance( |
1175 thread_safe_sender_.get(), | 1280 thread_safe_sender_.get(), |
1176 quota_message_filter_.get())->QueryStorageUsageAndQuota( | 1281 quota_message_filter_.get())->QueryStorageUsageAndQuota( |
1177 storage_partition, | 1282 storage_partition, |
1178 static_cast<quota::StorageType>(type), | 1283 static_cast<quota::StorageType>(type), |
1179 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); | 1284 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); |
1180 } | 1285 } |
1181 | 1286 |
1182 } // namespace content | 1287 } // namespace content |
OLD | NEW |