 Chromium Code Reviews
 Chromium Code Reviews Issue 549603003:
  Create Mojo service for locking/unlocking screen orientation.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 549603003:
  Create Mojo service for locking/unlocking screen orientation.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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..9a26c535a14846743c733eceac685b5440deec61 100644 | 
| --- a/content/browser/screen_orientation/screen_orientation_provider_android.cc | 
| +++ b/content/browser/screen_orientation/screen_orientation_provider_android.cc | 
| @@ -6,32 +6,26 @@ | 
| #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, | 
| + const ScreenOrientationLockCallback& on_result_callback, | 
| WebContents* web_contents) | 
| : ScreenOrientationProvider(), | 
| WebContentsObserver(web_contents), | 
| - dispatcher_(dispatcher), | 
| + on_result_callback_(on_result_callback), | 
| lock_applied_(false), | 
| - pending_lock_(NULL) { | 
| + pending_lock_orientation_(blink::WebScreenOrientationLockDefault) { | 
| } | 
| ScreenOrientationProviderAndroid::~ScreenOrientationProviderAndroid() { | 
| - if (pending_lock_) | 
| - delete pending_lock_; | 
| } | 
| WebContentsImpl* ScreenOrientationProviderAndroid::web_contents_impl() { | 
| @@ -44,8 +38,9 @@ bool ScreenOrientationProviderAndroid::Register(JNIEnv* env) { | 
| } | 
| void ScreenOrientationProviderAndroid::LockOrientation( | 
| - int request_id, | 
| - blink::WebScreenOrientationLockType lock_orientation) { | 
| + ScreenOrientationLockType lock_type) { | 
| + blink::WebScreenOrientationLockType lock_orientation = | 
| + ScreenOrientationLockTypeToWebScreenOrientationLockType(lock_type); | 
| 
blundell
2014/09/18 09:52:46
I didn't bother changing this file to talk in the
 | 
| ContentViewCoreImpl* cvc = | 
| ContentViewCoreImpl::FromWebContents(web_contents()); | 
| bool fullscreen_required = cvc ? cvc->IsFullscreenRequiredForOrientationLock() | 
| @@ -53,9 +48,8 @@ void ScreenOrientationProviderAndroid::LockOrientation( | 
| if (fullscreen_required && | 
| !web_contents_impl()->IsFullscreenForCurrentTab()) { | 
| - dispatcher_->NotifyLockError( | 
| - request_id, | 
| - blink::WebLockOrientationErrorFullScreenRequired); | 
| + on_result_callback_.Run( | 
| + SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED); | 
| return; | 
| } | 
| @@ -63,8 +57,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); | 
| + on_result_callback_.Run(SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | 
| return; | 
| } | 
| } | 
| @@ -73,20 +66,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); | 
| + on_result_callback_.Run(SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); | 
| return; | 
| } | 
| - pending_lock_ = new LockInformation(request_id, lock_orientation); | 
| + pending_lock_orientation_ = lock_orientation; | 
| } | 
| void ScreenOrientationProviderAndroid::UnlockOrientation() { | 
| @@ -99,13 +86,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_)) { | 
| + on_result_callback_.Run(SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); | 
| + pending_lock_orientation_ = blink::WebScreenOrientationLockDefault; | 
| } | 
| } | 
| @@ -216,9 +202,9 @@ void ScreenOrientationProviderAndroid::StopAccurateListening() { | 
| // static | 
| ScreenOrientationProvider* ScreenOrientationProvider::Create( | 
| - ScreenOrientationDispatcherHost* dispatcher, | 
| + const ScreenOrientationLockCallback& on_result_callback, | 
| WebContents* web_contents) { | 
| - return new ScreenOrientationProviderAndroid(dispatcher, web_contents); | 
| + return new ScreenOrientationProviderAndroid(on_result_callback, web_contents); | 
| } | 
| } // namespace content |