Chromium Code Reviews| Index: content/browser/screen_orientation/screen_orientation_provider_android.cc |
| diff --git a/content/browser/screen_orientation/screen_orientation_provider_android.cc b/content/browser/screen_orientation/screen_orientation_provider_android.cc |
| index 1b085cb6730973fc861532674fd23211beaa3bcd..033e815f89600d22b300a47250c5bb77a627ea3b 100644 |
| --- a/content/browser/screen_orientation/screen_orientation_provider_android.cc |
| +++ b/content/browser/screen_orientation/screen_orientation_provider_android.cc |
| @@ -6,32 +6,24 @@ |
| #include "content/browser/android/content_view_core_impl.h" |
| #include "content/browser/web_contents/web_contents_impl.h" |
| +#include "content/common/screen_orientation_utils.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/render_widget_host.h" |
| -#include "content/public/browser/screen_orientation_dispatcher_host.h" |
| #include "jni/ScreenOrientationProvider_jni.h" |
| #include "third_party/WebKit/public/platform/WebLockOrientationError.h" |
| #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| namespace content { |
| -ScreenOrientationProviderAndroid::LockInformation::LockInformation( |
| - int request_id, blink::WebScreenOrientationLockType lock) |
| - : request_id(request_id), lock(lock) {} |
| - |
| ScreenOrientationProviderAndroid::ScreenOrientationProviderAndroid( |
| - ScreenOrientationDispatcherHost* dispatcher, |
| WebContents* web_contents) |
| : ScreenOrientationProvider(), |
| WebContentsObserver(web_contents), |
| - dispatcher_(dispatcher), |
| lock_applied_(false), |
| - pending_lock_(NULL) { |
| + pending_lock_orientation_(blink::WebScreenOrientationLockDefault) { |
| } |
| ScreenOrientationProviderAndroid::~ScreenOrientationProviderAndroid() { |
| - if (pending_lock_) |
| - delete pending_lock_; |
| } |
| WebContentsImpl* ScreenOrientationProviderAndroid::web_contents_impl() { |
| @@ -43,9 +35,24 @@ bool ScreenOrientationProviderAndroid::Register(JNIEnv* env) { |
| return RegisterNativesImpl(env); |
| } |
| +void ScreenOrientationProviderAndroid::NotifyLockResult( |
| + ScreenOrientationLockResult result) { |
| + if (on_result_callback_.is_null()) |
| + return; |
| + on_result_callback_.Run(result); |
| + pending_lock_orientation_ = blink::WebScreenOrientationLockDefault; |
| + on_result_callback_ = ScreenOrientationLockCallback(); |
| +} |
| + |
| void ScreenOrientationProviderAndroid::LockOrientation( |
| - int request_id, |
| - blink::WebScreenOrientationLockType lock_orientation) { |
| + ScreenOrientationLockType lock_type, |
| + const ScreenOrientationLockCallback& callback) { |
| + // Cancel any pending request. |
| + NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
| + on_result_callback_ = callback; |
| + |
| + blink::WebScreenOrientationLockType lock_orientation = |
| + ScreenOrientationLockTypeToWebScreenOrientationLockType(lock_type); |
| ContentViewCoreImpl* cvc = |
| ContentViewCoreImpl::FromWebContents(web_contents()); |
| bool fullscreen_required = cvc ? cvc->IsFullscreenRequiredForOrientationLock() |
| @@ -53,9 +60,7 @@ void ScreenOrientationProviderAndroid::LockOrientation( |
| if (fullscreen_required && |
| !web_contents_impl()->IsFullscreenForCurrentTab()) { |
| - dispatcher_->NotifyLockError( |
| - request_id, |
| - blink::WebLockOrientationErrorFullScreenRequired); |
| + NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED); |
| return; |
| } |
| @@ -63,8 +68,7 @@ void ScreenOrientationProviderAndroid::LockOrientation( |
| lock_orientation = GetNaturalLockType(); |
| if (lock_orientation == blink::WebScreenOrientationLockDefault) { |
| // We are in a broken state, let's pretend we got canceled. |
| - dispatcher_->NotifyLockError(request_id, |
| - blink::WebLockOrientationErrorCanceled); |
| + NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
| return; |
| } |
| } |
| @@ -73,20 +77,14 @@ void ScreenOrientationProviderAndroid::LockOrientation( |
| Java_ScreenOrientationProvider_lockOrientation( |
| base::android::AttachCurrentThread(), lock_orientation); |
| - // If two calls happen close to each other, Android will ignore the first. |
| - if (pending_lock_) { |
| - delete pending_lock_; |
| - pending_lock_ = NULL; |
| - } |
| - |
| // If the orientation we are locking to matches the current orientation, we |
| // should succeed immediately. |
| if (LockMatchesCurrentOrientation(lock_orientation)) { |
| - dispatcher_->NotifyLockSuccess(request_id); |
| + NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); |
| return; |
| } |
| - pending_lock_ = new LockInformation(request_id, lock_orientation); |
| + pending_lock_orientation_ = lock_orientation; |
| } |
| void ScreenOrientationProviderAndroid::UnlockOrientation() { |
| @@ -99,13 +97,12 @@ void ScreenOrientationProviderAndroid::UnlockOrientation() { |
| } |
| void ScreenOrientationProviderAndroid::OnOrientationChange() { |
| - if (!pending_lock_) |
| + if (pending_lock_orientation_ == blink::WebScreenOrientationLockDefault) |
| return; |
| - if (LockMatchesCurrentOrientation(pending_lock_->lock)) { |
| - dispatcher_->NotifyLockSuccess(pending_lock_->request_id); |
| - delete pending_lock_; |
| - pending_lock_ = NULL; |
| + if (LockMatchesCurrentOrientation(pending_lock_orientation_)) { |
|
qsr
2014/09/23 08:22:59
I don't understand exactly why we need this. If we
|
| + DCHECK(!on_result_callback_.is_null()); |
| + NotifyLockResult(SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); |
| } |
| } |
| @@ -216,9 +213,8 @@ void ScreenOrientationProviderAndroid::StopAccurateListening() { |
| // static |
| ScreenOrientationProvider* ScreenOrientationProvider::Create( |
| - ScreenOrientationDispatcherHost* dispatcher, |
| WebContents* web_contents) { |
| - return new ScreenOrientationProviderAndroid(dispatcher, web_contents); |
| + return new ScreenOrientationProviderAndroid(web_contents); |
| } |
| } // namespace content |