Home | History | Annotate | Download | only in screen_orientation
      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
      3 // found in the LICENSE file.
      4 
      5 #include "content/browser/screen_orientation/screen_orientation_provider_android.h"
      6 
      7 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
      8 #include "jni/ScreenOrientationProvider_jni.h"
      9 
     10 namespace content {
     11 
     12 ScreenOrientationProviderAndroid::ScreenOrientationProviderAndroid() {
     13 }
     14 
     15 ScreenOrientationProviderAndroid::~ScreenOrientationProviderAndroid() {
     16 }
     17 
     18 // static
     19 bool ScreenOrientationProviderAndroid::Register(JNIEnv* env) {
     20   return RegisterNativesImpl(env);
     21 }
     22 
     23 void ScreenOrientationProviderAndroid::LockOrientation(
     24     blink::WebScreenOrientationLockType orientation) {
     25   if (j_screen_orientation_provider_.is_null()) {
     26     j_screen_orientation_provider_.Reset(Java_ScreenOrientationProvider_create(
     27         base::android::AttachCurrentThread()));
     28   }
     29 
     30   Java_ScreenOrientationProvider_lockOrientation(
     31       base::android::AttachCurrentThread(),
     32       j_screen_orientation_provider_.obj(), orientation);
     33 }
     34 
     35 void ScreenOrientationProviderAndroid::UnlockOrientation() {
     36   // j_screen_orientation_provider_ is set when locking. If the screen
     37   // orientation was not locked, unlocking should be a no-op.
     38   if (j_screen_orientation_provider_.is_null())
     39     return;
     40 
     41   Java_ScreenOrientationProvider_unlockOrientation(
     42       base::android::AttachCurrentThread(),
     43       j_screen_orientation_provider_.obj());
     44 }
     45 
     46 // static
     47 ScreenOrientationProvider* ScreenOrientationDispatcherHost::CreateProvider() {
     48   return new ScreenOrientationProviderAndroid();
     49 }
     50 
     51 } // namespace content
     52