Index: content/browser/screen_orientation/screen_orientation_provider.cc |
diff --git a/content/browser/screen_orientation/screen_orientation_provider.cc b/content/browser/screen_orientation/screen_orientation_provider.cc |
index 1ab00dfa12866d15c41d0cb815ce0091f08d72af..c676a3b2c772f683934e61c413149b64b323a9d1 100644 |
--- a/content/browser/screen_orientation/screen_orientation_provider.cc |
+++ b/content/browser/screen_orientation/screen_orientation_provider.cc |
@@ -34,6 +34,7 @@ void ScreenOrientationProvider::LockOrientation( |
SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
// Record new pending lock request. |
pending_callback_ = callback; |
+ pending_lock_orientation_ = orientation; |
if (!delegate_ || !delegate_->ScreenOrientationProviderSupported()) { |
NotifyLockResult(ScreenOrientationLockResult:: |
@@ -60,6 +61,7 @@ void ScreenOrientationProvider::LockOrientation( |
if (orientation == blink::WebScreenOrientationLockNatural) { |
orientation = GetNaturalLockType(); |
+ pending_lock_orientation_ = orientation; |
if (orientation == blink::WebScreenOrientationLockDefault) { |
// We are in a broken state, let's pretend we got canceled. |
NotifyLockResult(ScreenOrientationLockResult:: |
@@ -78,8 +80,18 @@ void ScreenOrientationProvider::LockOrientation( |
ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); |
return; |
} |
- |
- pending_lock_orientation_ = orientation; |
+// After delegate_ calls Lock() above, on Android we expect the actual |
+// orientation value be returned asynchronous from OnOrientationChange() being |
+// called later, but on other platforms we do expect current orientation has |
+// changed to the value we wanted to lock to, otherwise let's pretend the lock |
+// got cancelled to resolve the promise in blink side. |
+#if !defined(OS_ANDROID) |
+ else { |
+ NotifyLockResult(ScreenOrientationLockResult:: |
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
+ return; |
+ } |
+#endif |
} |
void ScreenOrientationProvider::UnlockOrientation() { |
@@ -95,16 +107,24 @@ void ScreenOrientationProvider::UnlockOrientation() { |
lock_applied_ = false; |
} |
+#if defined(OS_ANDROID) |
void ScreenOrientationProvider::OnOrientationChange() { |
if (!pending_lock_orientation_.has_value()) |
return; |
+ DCHECK(!pending_callback_.is_null()); |
if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { |
- DCHECK(!pending_callback_.is_null()); |
NotifyLockResult( |
ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); |
+ } else { |
+ // Screen orientation changed to a value not matching with current pending |
+ // lock request, let's pretend it's cancelled to resolve the promise in |
+ // blink side. |
+ NotifyLockResult(ScreenOrientationLockResult:: |
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
} |
} |
+#endif |
void ScreenOrientationProvider::NotifyLockResult( |
ScreenOrientationLockResult result) { |