Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: content/renderer/renderer_webkitplatformsupport_impl.cc

Issue 268673015: Support screen.lockOrientation() / screen.unlockOrientation() when running layout tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix coding style Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 namespace content { 138 namespace content {
139 139
140 static bool g_sandbox_enabled = true; 140 static bool g_sandbox_enabled = true;
141 static blink::WebGamepadListener* web_gamepad_listener = NULL; 141 static blink::WebGamepadListener* web_gamepad_listener = NULL;
142 base::LazyInstance<WebGamepads>::Leaky g_test_gamepads = 142 base::LazyInstance<WebGamepads>::Leaky g_test_gamepads =
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::WebScreenOrientationLockType g_test_current_screen_lock =
jochen (gone - plz use gerrit) 2014/05/07 06:48:41 i'd rather not have so many variables here. Is it
149 blink::WebScreenOrientationLockDefault;
150 static blink::WebScreenOrientationType g_test_device_screen_orientation =
151 blink::WebScreenOrientationPortraitPrimary;
152 static blink::WebScreenOrientationType g_test_current_screen_orientation =
153 blink::WebScreenOrientationPortraitPrimary;
148 static blink::WebScreenOrientationListener* 154 static blink::WebScreenOrientationListener*
149 g_test_screen_orientation_listener = NULL; 155 g_test_screen_orientation_listener = NULL;
150 156
151 //------------------------------------------------------------------------------ 157 //------------------------------------------------------------------------------
152 158
153 class RendererWebKitPlatformSupportImpl::MimeRegistry 159 class RendererWebKitPlatformSupportImpl::MimeRegistry
154 : public SimpleWebMimeRegistryImpl { 160 : public SimpleWebMimeRegistryImpl {
155 public: 161 public:
156 virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType( 162 virtual blink::WebMimeRegistry::SupportsType supportsMediaMIMEType(
157 const blink::WebString& mime_type, 163 const blink::WebString& mime_type,
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 } 1137 }
1132 1138
1133 if (!screen_orientation_dispatcher_) { 1139 if (!screen_orientation_dispatcher_) {
1134 screen_orientation_dispatcher_.reset( 1140 screen_orientation_dispatcher_.reset(
1135 new ScreenOrientationDispatcher(RenderThread::Get())); 1141 new ScreenOrientationDispatcher(RenderThread::Get()));
1136 } 1142 }
1137 1143
1138 screen_orientation_dispatcher_->setListener(listener); 1144 screen_orientation_dispatcher_->setListener(listener);
1139 } 1145 }
1140 1146
1147 namespace {
1148
1149 bool isScreenOrientationAllowedByTestingLock(
jochen (gone - plz use gerrit) 2014/05/07 06:48:41 methods should start with capital letters
Inactive 2014/05/07 18:41:05 Done.
1150 blink::WebScreenOrientationType orientation) {
1151 if (g_test_current_screen_lock == blink::WebScreenOrientationLockDefault ||
1152 g_test_current_screen_lock == blink::WebScreenOrientationLockAny)
1153 return true;
jochen (gone - plz use gerrit) 2014/05/07 06:48:41 nit { } since the if part is multiline
Inactive 2014/05/07 18:41:05 Done.
1154
1155 switch (orientation) {
1156 case blink::WebScreenOrientationPortraitPrimary:
1157 return g_test_current_screen_lock ==
1158 blink::WebScreenOrientationLockPortraitPrimary ||
1159 g_test_current_screen_lock ==
1160 blink::WebScreenOrientationLockPortrait;
1161 case blink::WebScreenOrientationPortraitSecondary:
1162 return g_test_current_screen_lock ==
1163 blink::WebScreenOrientationLockPortraitSecondary ||
1164 g_test_current_screen_lock ==
1165 blink::WebScreenOrientationLockPortrait;
1166 case blink::WebScreenOrientationLandscapePrimary:
1167 return g_test_current_screen_lock ==
1168 blink::WebScreenOrientationLockLandscapePrimary ||
1169 g_test_current_screen_lock ==
1170 blink::WebScreenOrientationLockLandscape;
1171 case blink::WebScreenOrientationLandscapeSecondary:
1172 return g_test_current_screen_lock ==
1173 blink::WebScreenOrientationLockLandscapeSecondary ||
1174 g_test_current_screen_lock ==
1175 blink::WebScreenOrientationLockLandscape;
1176 default:
1177 return false;
1178 }
1179 }
1180
1181 blink::WebScreenOrientationType suitableScreenOrientationForTestingLock() {
1182 switch (g_test_current_screen_lock) {
1183 case blink::WebScreenOrientationLockPortraitSecondary:
1184 return blink::WebScreenOrientationPortraitSecondary;
1185 case blink::WebScreenOrientationLockLandscapePrimary:
1186 case blink::WebScreenOrientationLockLandscape:
1187 return blink::WebScreenOrientationLandscapePrimary;
1188 case blink::WebScreenOrientationLockLandscapeSecondary:
1189 return blink::WebScreenOrientationLandscapePrimary;
1190 default:
1191 return blink::WebScreenOrientationPortraitPrimary;
1192 }
1193 }
1194
1195 void updateScreenOrientationForTesting(
1196 blink::WebScreenOrientationType orientation) {
1197 if (orientation == g_test_current_screen_orientation)
1198 return;
1199 g_test_current_screen_orientation = orientation;
1200 if (g_test_screen_orientation_listener)
1201 g_test_screen_orientation_listener->didChangeScreenOrientation(orientation);
1202 }
1203
1204 } // namespace
1205
1141 void RendererWebKitPlatformSupportImpl::lockOrientation( 1206 void RendererWebKitPlatformSupportImpl::lockOrientation(
1142 blink::WebScreenOrientationLockType orientation) { 1207 blink::WebScreenOrientationLockType orientation) {
1143 if (RenderThreadImpl::current() && 1208 if (RenderThreadImpl::current() &&
1144 RenderThreadImpl::current()->layout_test_mode()) { 1209 RenderThreadImpl::current()->layout_test_mode()) {
1210 g_test_current_screen_lock = orientation;
1211 if (!isScreenOrientationAllowedByTestingLock(
1212 g_test_current_screen_orientation)) {
1213 g_test_current_screen_orientation =
1214 suitableScreenOrientationForTestingLock();
1215 if (g_test_screen_orientation_listener) {
1216 g_test_screen_orientation_listener->didChangeScreenOrientation(
1217 g_test_current_screen_orientation);
1218 }
1219 }
1145 return; 1220 return;
1146 } 1221 }
1147 RenderThread::Get()->Send(new ScreenOrientationHostMsg_Lock(orientation)); 1222 RenderThread::Get()->Send(new ScreenOrientationHostMsg_Lock(orientation));
1148 } 1223 }
1149 1224
1150 void RendererWebKitPlatformSupportImpl::unlockOrientation() { 1225 void RendererWebKitPlatformSupportImpl::unlockOrientation() {
1151 if (RenderThreadImpl::current() && 1226 if (RenderThreadImpl::current() &&
1152 RenderThreadImpl::current()->layout_test_mode()) { 1227 RenderThreadImpl::current()->layout_test_mode()) {
1228 bool should_update_current_screen_orientation =
1229 !isScreenOrientationAllowedByTestingLock(
1230 g_test_device_screen_orientation);
1231 g_test_current_screen_lock = blink::WebScreenOrientationLockDefault;
1232 if (should_update_current_screen_orientation)
1233 updateScreenOrientationForTesting(g_test_device_screen_orientation);
1153 return; 1234 return;
1154 } 1235 }
1155 RenderThread::Get()->Send(new ScreenOrientationHostMsg_Unlock); 1236 RenderThread::Get()->Send(new ScreenOrientationHostMsg_Unlock);
1156 } 1237 }
1157 1238
1158 // static 1239 // static
1159 void RendererWebKitPlatformSupportImpl::SetMockScreenOrientationForTesting( 1240 void RendererWebKitPlatformSupportImpl::SetMockScreenOrientationForTesting(
1160 blink::WebScreenOrientationType orientation) { 1241 blink::WebScreenOrientationType orientation) {
1161 if (!g_test_screen_orientation_listener) 1242 g_test_device_screen_orientation = orientation;
1243 if (!isScreenOrientationAllowedByTestingLock(orientation))
jochen (gone - plz use gerrit) 2014/05/07 06:48:41 what happens if a test fails before it unlocks?
Inactive 2014/05/07 18:41:05 Flakes :) I added a ResetMockScreenOrientationForT
1162 return; 1244 return;
1163 g_test_screen_orientation_listener->didChangeScreenOrientation(orientation); 1245 updateScreenOrientationForTesting(g_test_device_screen_orientation);
1164 } 1246 }
1165 1247
1166 //------------------------------------------------------------------------------ 1248 //------------------------------------------------------------------------------
1167 1249
1168 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota( 1250 void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota(
1169 const blink::WebURL& storage_partition, 1251 const blink::WebURL& storage_partition,
1170 blink::WebStorageQuotaType type, 1252 blink::WebStorageQuotaType type,
1171 blink::WebStorageQuotaCallbacks callbacks) { 1253 blink::WebStorageQuotaCallbacks callbacks) {
1172 if (!thread_safe_sender_.get() || !quota_message_filter_.get()) 1254 if (!thread_safe_sender_.get() || !quota_message_filter_.get())
1173 return; 1255 return;
1174 QuotaDispatcher::ThreadSpecificInstance( 1256 QuotaDispatcher::ThreadSpecificInstance(
1175 thread_safe_sender_.get(), 1257 thread_safe_sender_.get(),
1176 quota_message_filter_.get())->QueryStorageUsageAndQuota( 1258 quota_message_filter_.get())->QueryStorageUsageAndQuota(
1177 storage_partition, 1259 storage_partition,
1178 static_cast<quota::StorageType>(type), 1260 static_cast<quota::StorageType>(type),
1179 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks)); 1261 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
1180 } 1262 }
1181 1263
1182 } // namespace content 1264 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698