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/browser/screen_orientation/screen_orientation_provider.h" | 5 #include "content/browser/screen_orientation/screen_orientation_provider.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/public/browser/navigation_handle.h" | 10 #include "content/public/browser/navigation_handle.h" |
11 #include "content/public/browser/render_widget_host.h" | 11 #include "content/public/browser/render_widget_host.h" |
12 #include "content/public/browser/screen_orientation_delegate.h" | 12 #include "content/public/browser/screen_orientation_delegate.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO
rientationError.h" | 14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO
rientationError.h" |
15 | 15 |
| 16 #if defined(OS_ANDROID) |
| 17 #include "content/browser/screen_orientation/screen_orientation_delegate_android
.h" |
| 18 #endif |
| 19 |
16 namespace content { | 20 namespace content { |
17 | 21 |
18 using device::mojom::ScreenOrientationLockResult; | 22 using device::mojom::ScreenOrientationLockResult; |
19 | 23 |
20 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr; | 24 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr; |
21 | 25 |
22 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) | 26 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) |
23 : WebContentsObserver(web_contents), | 27 : WebContentsObserver(web_contents), |
24 lock_applied_(false), | 28 lock_applied_(false), |
25 bindings_(web_contents, this) {} | 29 bindings_(web_contents, this) {} |
26 | 30 |
27 ScreenOrientationProvider::~ScreenOrientationProvider() = default; | 31 ScreenOrientationProvider::~ScreenOrientationProvider() { |
| 32 #if defined(OS_ANDROID) |
| 33 if (accurate_listener_count_ > 0) |
| 34 ScreenOrientationDelegateAndroid::StopAccurateListening(); |
| 35 #endif |
| 36 } |
28 | 37 |
29 void ScreenOrientationProvider::LockOrientation( | 38 void ScreenOrientationProvider::LockOrientation( |
30 blink::WebScreenOrientationLockType orientation, | 39 blink::WebScreenOrientationLockType orientation, |
31 const LockOrientationCallback& callback) { | 40 const LockOrientationCallback& callback) { |
32 // Cancel any pending lock request. | 41 // Cancel any pending lock request. |
33 NotifyLockResult(ScreenOrientationLockResult:: | 42 NotifyLockResult(ScreenOrientationLockResult:: |
34 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | 43 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
35 // Record new pending lock request. | 44 // Record new pending lock request. |
36 pending_callback_ = callback; | 45 pending_callback_ = callback; |
37 | 46 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | 97 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
89 | 98 |
90 if (!lock_applied_ || !delegate_) | 99 if (!lock_applied_ || !delegate_) |
91 return; | 100 return; |
92 | 101 |
93 delegate_->Unlock(web_contents()); | 102 delegate_->Unlock(web_contents()); |
94 | 103 |
95 lock_applied_ = false; | 104 lock_applied_ = false; |
96 } | 105 } |
97 | 106 |
| 107 void ScreenOrientationProvider::StartAccurateListen() { |
| 108 #if defined(OS_ANDROID) |
| 109 ++accurate_listener_count_; |
| 110 if (accurate_listener_count_ == 1) |
| 111 ScreenOrientationDelegateAndroid::StartAccurateListening(); |
| 112 #endif |
| 113 } |
| 114 |
| 115 void ScreenOrientationProvider::StopAccurateListen() { |
| 116 #if defined(OS_ANDROID) |
| 117 DCHECK(accurate_listener_count_ > 0); |
| 118 --accurate_listener_count_; |
| 119 if (accurate_listener_count_ == 0) |
| 120 ScreenOrientationDelegateAndroid::StopAccurateListening(); |
| 121 #endif |
| 122 } |
| 123 |
98 void ScreenOrientationProvider::OnOrientationChange() { | 124 void ScreenOrientationProvider::OnOrientationChange() { |
99 if (!pending_lock_orientation_.has_value()) | 125 if (!pending_lock_orientation_.has_value()) |
100 return; | 126 return; |
101 | 127 |
102 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { | 128 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { |
103 DCHECK(!pending_callback_.is_null()); | 129 DCHECK(!pending_callback_.is_null()); |
104 NotifyLockResult( | 130 NotifyLockResult( |
105 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); | 131 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); |
106 } | 132 } |
107 } | 133 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 case blink::WebScreenOrientationLockDefault: | 239 case blink::WebScreenOrientationLockDefault: |
214 NOTREACHED(); | 240 NOTREACHED(); |
215 return false; | 241 return false; |
216 } | 242 } |
217 | 243 |
218 NOTREACHED(); | 244 NOTREACHED(); |
219 return false; | 245 return false; |
220 } | 246 } |
221 | 247 |
222 } // namespace content | 248 } // namespace content |
OLD | NEW |