| Index: content/public/browser/screen_orientation_provider.cc
|
| diff --git a/content/public/browser/screen_orientation_provider.cc b/content/public/browser/screen_orientation_provider.cc
|
| index 6c120fc7d892f67eb6004aeac8b89d7d57f3f76f..f02bf60e02efb5b3a62b1a80b53e9b6d40c31e01 100644
|
| --- a/content/public/browser/screen_orientation_provider.cc
|
| +++ b/content/public/browser/screen_orientation_provider.cc
|
| @@ -14,31 +14,29 @@
|
|
|
| namespace content {
|
|
|
| -ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr;
|
| +using ::blink::mojom::ScreenOrientationLockResult;
|
|
|
| -ScreenOrientationProvider::LockInformation::LockInformation(int request_id,
|
| - blink::WebScreenOrientationLockType lock)
|
| - : request_id(request_id),
|
| - lock(lock) {
|
| -}
|
| +ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr;
|
|
|
| -ScreenOrientationProvider::ScreenOrientationProvider(
|
| - ScreenOrientationDispatcherHost* dispatcher_host,
|
| - WebContents* web_contents)
|
| +ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents)
|
| : WebContentsObserver(web_contents),
|
| - dispatcher_(dispatcher_host),
|
| - lock_applied_(false) {
|
| -}
|
| + lock_applied_(false),
|
| + pending_lock_orientation_(blink::WebScreenOrientationLockDefault) {}
|
|
|
| ScreenOrientationProvider::~ScreenOrientationProvider() {
|
| }
|
|
|
| -void ScreenOrientationProvider::LockOrientation(int request_id,
|
| - blink::WebScreenOrientationLockType lock_orientation) {
|
| +void ScreenOrientationProvider::LockOrientation(
|
| + blink::WebScreenOrientationLockType orientation,
|
| + const LockOrientationCallback& callback) {
|
| + // Cancel any pending requests.
|
| + NotifyLockResult(ScreenOrientationLockResult::
|
| + SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
|
| + on_result_callback_ = callback;
|
|
|
| if (!delegate_ || !delegate_->ScreenOrientationProviderSupported()) {
|
| - dispatcher_->NotifyLockError(request_id,
|
| - blink::WebLockOrientationErrorNotAvailable);
|
| + NotifyLockResult(ScreenOrientationLockResult::
|
| + SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE);
|
| return;
|
| }
|
|
|
| @@ -46,44 +44,41 @@ void ScreenOrientationProvider::LockOrientation(int request_id,
|
| RenderViewHostImpl* rvhi =
|
| static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost());
|
| if (!rvhi) {
|
| - dispatcher_->NotifyLockError(request_id,
|
| - blink::WebLockOrientationErrorCanceled);
|
| + NotifyLockResult(ScreenOrientationLockResult::
|
| + SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
|
| return;
|
| }
|
| if (!static_cast<WebContentsImpl*>(web_contents())
|
| ->IsFullscreenForCurrentTab()) {
|
| - dispatcher_->NotifyLockError(request_id,
|
| - blink::WebLockOrientationErrorFullscreenRequired);
|
| + NotifyLockResult(
|
| + ScreenOrientationLockResult::
|
| + SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED);
|
| return;
|
| }
|
| }
|
|
|
| - if (lock_orientation == blink::WebScreenOrientationLockNatural) {
|
| - lock_orientation = GetNaturalLockType();
|
| - if (lock_orientation == blink::WebScreenOrientationLockDefault) {
|
| + if (orientation == blink::WebScreenOrientationLockNatural) {
|
| + orientation = GetNaturalLockType();
|
| + if (orientation == blink::WebScreenOrientationLockDefault) {
|
| // We are in a broken state, let's pretend we got canceled.
|
| - dispatcher_->NotifyLockError(request_id,
|
| - blink::WebLockOrientationErrorCanceled);
|
| + NotifyLockResult(ScreenOrientationLockResult::
|
| + SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
|
| return;
|
| }
|
| }
|
|
|
| lock_applied_ = true;
|
| - delegate_->Lock(web_contents(), lock_orientation);
|
| -
|
| - // If two calls happen close to each other some platforms will ignore the
|
| - // first. A successful lock will be once orientation matches the latest
|
| - // request.
|
| - pending_lock_.reset();
|
| + delegate_->Lock(web_contents(), orientation);
|
|
|
| // If the orientation we are locking to matches the current orientation, we
|
| // should succeed immediately.
|
| - if (LockMatchesCurrentOrientation(lock_orientation)) {
|
| - dispatcher_->NotifyLockSuccess(request_id);
|
| + if (LockMatchesCurrentOrientation(orientation)) {
|
| + NotifyLockResult(
|
| + ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS);
|
| return;
|
| }
|
|
|
| - pending_lock_.reset(new LockInformation(request_id, lock_orientation));
|
| + pending_lock_orientation_ = orientation;
|
| }
|
|
|
| void ScreenOrientationProvider::UnlockOrientation() {
|
| @@ -93,19 +88,28 @@ void ScreenOrientationProvider::UnlockOrientation() {
|
| delegate_->Unlock(web_contents());
|
|
|
| lock_applied_ = false;
|
| - pending_lock_.reset();
|
| }
|
|
|
| void ScreenOrientationProvider::OnOrientationChange() {
|
| - if (!pending_lock_.get())
|
| + if (pending_lock_orientation_ == blink::WebScreenOrientationLockDefault)
|
| return;
|
|
|
| - if (LockMatchesCurrentOrientation(pending_lock_->lock)) {
|
| - dispatcher_->NotifyLockSuccess(pending_lock_->request_id);
|
| - pending_lock_.reset();
|
| + if (LockMatchesCurrentOrientation(pending_lock_orientation_)) {
|
| + DCHECK(!on_result_callback_.is_null());
|
| + NotifyLockResult(
|
| + ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS);
|
| }
|
| }
|
|
|
| +void ScreenOrientationProvider::NotifyLockResult(
|
| + ScreenOrientationLockResult result) {
|
| + if (on_result_callback_.is_null())
|
| + return;
|
| + on_result_callback_.Run(result);
|
| + pending_lock_orientation_ = blink::WebScreenOrientationLockDefault;
|
| + on_result_callback_ = LockOrientationCallback();
|
| +}
|
| +
|
| void ScreenOrientationProvider::SetDelegate(
|
| ScreenOrientationDelegate* delegate) {
|
| delegate_ = delegate;
|
|
|