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 4fa0cfa110a3e8501353867fabfa2e662ba8fdc7..b7e48413705f3c52d0e99f98be70dbbb4ac297b8 100644 |
--- a/content/browser/screen_orientation/screen_orientation_provider.cc |
+++ b/content/browser/screen_orientation/screen_orientation_provider.cc |
@@ -24,9 +24,7 @@ using device::mojom::ScreenOrientationLockResult; |
ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr; |
ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) |
- : WebContentsObserver(web_contents), |
- lock_applied_(false), |
- bindings_(web_contents, this) {} |
+ : WebContentsObserver(web_contents), lock_applied_(false) {} |
ScreenOrientationProvider::~ScreenOrientationProvider() { |
#if defined(OS_ANDROID) |
@@ -35,6 +33,30 @@ ScreenOrientationProvider::~ScreenOrientationProvider() { |
#endif |
} |
+// static |
+void ScreenOrientationProvider::SetDelegate( |
+ ScreenOrientationDelegate* delegate) { |
+ delegate_ = delegate; |
+} |
+ |
+// static |
+void ScreenOrientationProvider::BindRequest( |
+ RenderFrameHost* render_frame_host, |
+ device::mojom::ScreenOrientationRequest request) { |
+ WebContents* web_contents = |
+ WebContents::FromRenderFrameHost(render_frame_host); |
+ DCHECK(web_contents); |
+ |
+ static_cast<WebContentsImpl*>(web_contents) |
+ ->GetScreenOrientationProvider() |
+ ->AddBinding(std::move(request)); |
+} |
+ |
+void ScreenOrientationProvider::AddBinding( |
+ device::mojom::ScreenOrientationRequest request) { |
+ bindings_.AddBinding(this, std::move(request)); |
+} |
+ |
void ScreenOrientationProvider::LockOrientation( |
blink::WebScreenOrientationLockType orientation, |
const LockOrientationCallback& callback) { |
@@ -43,6 +65,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:: |
@@ -69,6 +92,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:: |
@@ -87,8 +111,6 @@ void ScreenOrientationProvider::LockOrientation( |
ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); |
return; |
} |
- |
- pending_lock_orientation_ = orientation; |
} |
void ScreenOrientationProvider::UnlockOrientation() { |
@@ -134,15 +156,14 @@ void ScreenOrientationProvider::OnOrientationChange() { |
void ScreenOrientationProvider::NotifyLockResult( |
ScreenOrientationLockResult result) { |
- if (!pending_callback_.is_null()) |
- base::ResetAndReturn(&pending_callback_).Run(result); |
- |
- pending_lock_orientation_.reset(); |
-} |
- |
-void ScreenOrientationProvider::SetDelegate( |
- ScreenOrientationDelegate* delegate) { |
- delegate_ = delegate; |
+ if (!pending_callback_.is_null()) { |
+ DCHECK(pending_lock_orientation_.has_value()); |
+ base::ResetAndReturn(&pending_callback_) |
+ .Run(result, pending_lock_orientation_.value()); |
+ pending_lock_orientation_.reset(); |
+ } else { |
+ DCHECK(!pending_lock_orientation_.has_value()); |
+ } |
} |
void ScreenOrientationProvider::DidToggleFullscreenModeForTab( |