| 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 "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/render_widget_host.h" | 11 #include "content/public/browser/render_widget_host.h" |
| 11 #include "content/public/browser/screen_orientation_delegate.h" | 12 #include "content/public/browser/screen_orientation_delegate.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 13 #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" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 using device::mojom::ScreenOrientationLockResult; | 18 using device::mojom::ScreenOrientationLockResult; |
| 18 | 19 |
| 19 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr; | 20 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr; |
| 20 | 21 |
| 21 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) | 22 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) |
| 22 : WebContentsObserver(web_contents), lock_applied_(false) {} | 23 : WebContentsObserver(web_contents), |
| 24 lock_applied_(false), |
| 25 bindings_(web_contents, this) {} |
| 23 | 26 |
| 24 ScreenOrientationProvider::~ScreenOrientationProvider() { | 27 ScreenOrientationProvider::~ScreenOrientationProvider() { |
| 25 } | 28 } |
| 26 | 29 |
| 27 void ScreenOrientationProvider::LockOrientation( | 30 void ScreenOrientationProvider::LockOrientation( |
| 28 blink::WebScreenOrientationLockType orientation, | 31 blink::WebScreenOrientationLockType orientation, |
| 29 const LockOrientationCallback& callback) { | 32 const LockOrientationCallback& callback) { |
| 30 // Cancel any pending lock request. | 33 // Cancel any pending lock request. |
| 31 NotifyLockResult(ScreenOrientationLockResult:: | 34 NotifyLockResult(ScreenOrientationLockResult:: |
| 32 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | 35 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 102 |
| 100 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { | 103 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { |
| 101 DCHECK(!pending_callback_.is_null()); | 104 DCHECK(!pending_callback_.is_null()); |
| 102 NotifyLockResult( | 105 NotifyLockResult( |
| 103 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); | 106 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); |
| 104 } | 107 } |
| 105 } | 108 } |
| 106 | 109 |
| 107 void ScreenOrientationProvider::NotifyLockResult( | 110 void ScreenOrientationProvider::NotifyLockResult( |
| 108 ScreenOrientationLockResult result) { | 111 ScreenOrientationLockResult result) { |
| 109 if (!pending_callback_.is_null()) { | 112 if (!pending_callback_.is_null()) |
| 110 base::ResetAndReturn(&pending_callback_).Run(result); | 113 base::ResetAndReturn(&pending_callback_).Run(result); |
| 111 } | 114 |
| 112 pending_lock_orientation_.reset(); | 115 pending_lock_orientation_.reset(); |
| 113 } | 116 } |
| 114 | 117 |
| 115 void ScreenOrientationProvider::SetDelegate( | 118 void ScreenOrientationProvider::SetDelegate( |
| 116 ScreenOrientationDelegate* delegate) { | 119 ScreenOrientationDelegate* delegate) { |
| 117 delegate_ = delegate; | 120 delegate_ = delegate; |
| 118 } | 121 } |
| 119 | 122 |
| 120 void ScreenOrientationProvider::DidToggleFullscreenModeForTab( | 123 void ScreenOrientationProvider::DidToggleFullscreenModeForTab( |
| 121 bool entered_fullscreen, bool will_cause_resize) { | 124 bool entered_fullscreen, bool will_cause_resize) { |
| 122 if (!lock_applied_ || !delegate_) | 125 if (!lock_applied_ || !delegate_) |
| 123 return; | 126 return; |
| 124 | 127 |
| 125 // If fullscreen is not required in order to lock orientation, don't unlock | 128 // If fullscreen is not required in order to lock orientation, don't unlock |
| 126 // when fullscreen state changes. | 129 // when fullscreen state changes. |
| 127 if (!delegate_->FullScreenRequired(web_contents())) | 130 if (!delegate_->FullScreenRequired(web_contents())) |
| 128 return; | 131 return; |
| 129 | 132 |
| 130 DCHECK(!entered_fullscreen); | 133 DCHECK(!entered_fullscreen); |
| 131 UnlockOrientation(); | 134 UnlockOrientation(); |
| 132 } | 135 } |
| 133 | 136 |
| 137 void ScreenOrientationProvider::DidFinishNavigation( |
| 138 NavigationHandle* navigation_handle) { |
| 139 if (!navigation_handle->IsInMainFrame() || |
| 140 !navigation_handle->HasCommitted() || navigation_handle->IsSamePage()) { |
| 141 return; |
| 142 } |
| 143 UnlockOrientation(); |
| 144 } |
| 145 |
| 134 blink::WebScreenOrientationLockType | 146 blink::WebScreenOrientationLockType |
| 135 ScreenOrientationProvider::GetNaturalLockType() const { | 147 ScreenOrientationProvider::GetNaturalLockType() const { |
| 136 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget(); | 148 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget(); |
| 137 if (!rwh) | 149 if (!rwh) |
| 138 return blink::WebScreenOrientationLockDefault; | 150 return blink::WebScreenOrientationLockDefault; |
| 139 | 151 |
| 140 ScreenInfo screen_info; | 152 ScreenInfo screen_info; |
| 141 rwh->GetScreenInfo(&screen_info); | 153 rwh->GetScreenInfo(&screen_info); |
| 142 | 154 |
| 143 switch (screen_info.orientation_type) { | 155 switch (screen_info.orientation_type) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 case blink::WebScreenOrientationLockDefault: | 213 case blink::WebScreenOrientationLockDefault: |
| 202 NOTREACHED(); | 214 NOTREACHED(); |
| 203 return false; | 215 return false; |
| 204 } | 216 } |
| 205 | 217 |
| 206 NOTREACHED(); | 218 NOTREACHED(); |
| 207 return false; | 219 return false; |
| 208 } | 220 } |
| 209 | 221 |
| 210 } // namespace content | 222 } // namespace content |
| OLD | NEW |