Chromium Code Reviews| 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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/optional.h" | 8 #include "base/optional.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 | 21 |
| 22 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) | 22 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) |
| 23 : WebContentsObserver(web_contents), lock_applied_(false) {} | 23 : WebContentsObserver(web_contents), lock_applied_(false) {} |
| 24 | 24 |
| 25 ScreenOrientationProvider::~ScreenOrientationProvider() { | 25 ScreenOrientationProvider::~ScreenOrientationProvider() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 void ScreenOrientationProvider::LockOrientation( | 28 void ScreenOrientationProvider::LockOrientation( |
| 29 blink::WebScreenOrientationLockType orientation, | 29 blink::WebScreenOrientationLockType orientation, |
| 30 const LockOrientationCallback& callback) { | 30 const LockOrientationCallback& callback) { |
| 31 // ScreenOrientation should have cancelled all pending request at this point. | 31 // ScreenOrientation should have already cancelled all pending request at this |
| 32 DCHECK(on_result_callback_.is_null()); | 32 // point, so we just clear pending status here without any actual operations. |
|
leonhsl(Using Gerrit)
2017/01/16 11:00:18
Although ScreenOrientation have cancelled the pend
| |
| 33 DCHECK(!pending_lock_orientation_.has_value()); | 33 pending_lock_orientation_.reset(); |
| 34 on_result_callback_ = callback; | 34 on_result_callback_ = callback; |
| 35 | 35 |
| 36 if (!delegate_ || !delegate_->ScreenOrientationProviderSupported()) { | 36 if (!delegate_ || !delegate_->ScreenOrientationProviderSupported()) { |
| 37 NotifyLockResult(ScreenOrientationLockResult:: | 37 NotifyLockResult(ScreenOrientationLockResult:: |
| 38 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE); | 38 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE); |
| 39 return; | 39 return; |
| 40 } | 40 } |
| 41 | 41 |
| 42 if (delegate_->FullScreenRequired(web_contents())) { | 42 if (delegate_->FullScreenRequired(web_contents())) { |
| 43 RenderViewHostImpl* rvhi = | 43 RenderViewHostImpl* rvhi = |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 96 |
| 97 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { | 97 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { |
| 98 DCHECK(!on_result_callback_.is_null()); | 98 DCHECK(!on_result_callback_.is_null()); |
| 99 NotifyLockResult( | 99 NotifyLockResult( |
| 100 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); | 100 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 void ScreenOrientationProvider::NotifyLockResult( | 104 void ScreenOrientationProvider::NotifyLockResult( |
| 105 ScreenOrientationLockResult result) { | 105 ScreenOrientationLockResult result) { |
| 106 if (on_result_callback_.is_null()) { | 106 if (!on_result_callback_.is_null()) { |
| 107 pending_lock_orientation_.reset(); | 107 base::ResetAndReturn(&on_result_callback_).Run(result); |
| 108 return; | |
| 109 } | 108 } |
| 110 base::ResetAndReturn(&on_result_callback_).Run(result); | |
| 111 pending_lock_orientation_.reset(); | 109 pending_lock_orientation_.reset(); |
| 112 } | 110 } |
| 113 | 111 |
| 114 void ScreenOrientationProvider::SetDelegate( | 112 void ScreenOrientationProvider::SetDelegate( |
| 115 ScreenOrientationDelegate* delegate) { | 113 ScreenOrientationDelegate* delegate) { |
| 116 delegate_ = delegate; | 114 delegate_ = delegate; |
| 117 } | 115 } |
| 118 | 116 |
| 119 void ScreenOrientationProvider::DidToggleFullscreenModeForTab( | 117 void ScreenOrientationProvider::DidToggleFullscreenModeForTab( |
| 120 bool entered_fullscreen, bool will_cause_resize) { | 118 bool entered_fullscreen, bool will_cause_resize) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 case blink::WebScreenOrientationLockDefault: | 198 case blink::WebScreenOrientationLockDefault: |
| 201 NOTREACHED(); | 199 NOTREACHED(); |
| 202 return false; | 200 return false; |
| 203 } | 201 } |
| 204 | 202 |
| 205 NOTREACHED(); | 203 NOTREACHED(); |
| 206 return false; | 204 return false; |
| 207 } | 205 } |
| 208 | 206 |
| 209 } // namespace content | 207 } // namespace content |
| OLD | NEW |