| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/public/browser/screen_orientation_provider.h" | 5 #include "content/public/browser/screen_orientation_provider.h" |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/render_view_host_delegate.h" | 7 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 8 #include "content/public/browser/render_view_host.h" | 8 #include "content/public/browser/render_view_host.h" |
| 9 #include "content/public/browser/screen_orientation_delegate.h" | 9 #include "content/public/browser/screen_orientation_delegate.h" |
| 10 #include "content/public/browser/screen_orientation_dispatcher_host.h" | 10 #include "content/public/browser/screen_orientation_dispatcher_host.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 if (lock_orientation == blink::WebScreenOrientationLockNatural) { | 65 if (lock_orientation == blink::WebScreenOrientationLockNatural) { |
| 66 lock_orientation = GetNaturalLockType(); | 66 lock_orientation = GetNaturalLockType(); |
| 67 if (lock_orientation == blink::WebScreenOrientationLockDefault) { | 67 if (lock_orientation == blink::WebScreenOrientationLockDefault) { |
| 68 // We are in a broken state, let's pretend we got canceled. | 68 // We are in a broken state, let's pretend we got canceled. |
| 69 dispatcher_->NotifyLockError(request_id, | 69 dispatcher_->NotifyLockError(request_id, |
| 70 blink::WebLockOrientationErrorCanceled); | 70 blink::WebLockOrientationErrorCanceled); |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 lock_applied_ = true; | 75 lock_applied_ = delegate_->Lock(web_contents(), lock_orientation); |
| 76 delegate_->Lock(lock_orientation); | 76 if (!lock_applied_) { |
| 77 // The delegate was unable to lock, cancel. |
| 78 dispatcher_->NotifyLockError(request_id, |
| 79 blink::WebLockOrientationErrorCanceled); |
| 80 return; |
| 81 } |
| 77 | 82 |
| 78 // If two calls happen close to each other some platforms will ignore the | 83 // If two calls happen close to each other some platforms will ignore the |
| 79 // first. A successful lock will be once orientation matches the latest | 84 // first. A successful lock will be once orientation matches the latest |
| 80 // request. | 85 // request. |
| 81 pending_lock_.reset(); | 86 pending_lock_.reset(); |
| 82 | 87 |
| 83 // If the orientation we are locking to matches the current orientation, we | 88 // If the orientation we are locking to matches the current orientation, we |
| 84 // should succeed immediately. | 89 // should succeed immediately. |
| 85 if (LockMatchesCurrentOrientation(lock_orientation)) { | 90 if (LockMatchesCurrentOrientation(lock_orientation)) { |
| 86 dispatcher_->NotifyLockSuccess(request_id); | 91 dispatcher_->NotifyLockSuccess(request_id); |
| 87 return; | 92 return; |
| 88 } | 93 } |
| 89 | 94 |
| 90 pending_lock_.reset(new LockInformation(request_id, lock_orientation)); | 95 pending_lock_.reset(new LockInformation(request_id, lock_orientation)); |
| 91 } | 96 } |
| 92 | 97 |
| 93 void ScreenOrientationProvider::UnlockOrientation() { | 98 void ScreenOrientationProvider::UnlockOrientation() { |
| 94 if (!lock_applied_ || !delegate_) | 99 if (!lock_applied_ || !delegate_) |
| 95 return; | 100 return; |
| 96 | 101 |
| 97 delegate_->Unlock(); | 102 delegate_->Unlock(web_contents()); |
| 98 | 103 |
| 99 lock_applied_ = false; | 104 lock_applied_ = false; |
| 100 pending_lock_.reset(); | 105 pending_lock_.reset(); |
| 101 } | 106 } |
| 102 | 107 |
| 103 void ScreenOrientationProvider::OnOrientationChange() { | 108 void ScreenOrientationProvider::OnOrientationChange() { |
| 104 if (!pending_lock_.get()) | 109 if (!pending_lock_.get()) |
| 105 return; | 110 return; |
| 106 | 111 |
| 107 if (LockMatchesCurrentOrientation(pending_lock_->lock)) { | 112 if (LockMatchesCurrentOrientation(pending_lock_->lock)) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 case blink::WebScreenOrientationLockDefault: | 205 case blink::WebScreenOrientationLockDefault: |
| 201 NOTREACHED(); | 206 NOTREACHED(); |
| 202 return false; | 207 return false; |
| 203 } | 208 } |
| 204 | 209 |
| 205 NOTREACHED(); | 210 NOTREACHED(); |
| 206 return false; | 211 return false; |
| 207 } | 212 } |
| 208 | 213 |
| 209 } // namespace content | 214 } // namespace content |
| OLD | NEW |