Index: content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..89913eda244f9c8056c9fedb5cb3e7f00d9c6c40 |
--- /dev/null |
+++ b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java |
@@ -0,0 +1,85 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.content.browser; |
+ |
+import android.app.Activity; |
+import android.content.pm.ActivityInfo; |
+import android.util.Log; |
+ |
+import com.google.common.annotations.VisibleForTesting; |
+ |
+import org.chromium.base.ApplicationStatus; |
+import org.chromium.base.CalledByNative; |
+import org.chromium.base.JNINamespace; |
+import org.chromium.content.common.ScreenOrientationValues; |
+ |
+/** |
+ * This is the implementation of the C++ counterpart ScreenOrientationProvider. |
+ */ |
+@JNINamespace("content") |
+class ScreenOrientationProvider { |
+ private static final String TAG = "ScreenOrientationProvider"; |
+ |
+ private int getOrientationFromWebScreenOrientations(byte orientations) { |
+ switch (orientations) { |
+ case ScreenOrientationValues.PORTRAIT_PRIMARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
+ case ScreenOrientationValues.PORTRAIT_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; |
+ case ScreenOrientationValues.LANDSCAPE_PRIMARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
+ case ScreenOrientationValues.LANDSCAPE_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; |
+ case ScreenOrientationValues.PORTRAIT_PRIMARY | |
+ ScreenOrientationValues.PORTRAIT_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; |
+ case ScreenOrientationValues.LANDSCAPE_PRIMARY | |
+ ScreenOrientationValues.LANDSCAPE_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; |
+ case ScreenOrientationValues.PORTRAIT_PRIMARY | |
+ ScreenOrientationValues.PORTRAIT_SECONDARY | |
+ ScreenOrientationValues.LANDSCAPE_PRIMARY | |
+ ScreenOrientationValues.LANDSCAPE_SECONDARY: |
+ return ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR; |
+ default: |
+ Log.w(TAG, "Trying to lock to unsupported orientation!"); |
+ return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
+ } |
+ } |
+ |
+ @VisibleForTesting |
+ @CalledByNative |
+ static ScreenOrientationProvider create() { |
+ return new ScreenOrientationProvider(); |
+ } |
+ |
+ @CalledByNative |
+ void lockOrientation(byte orientations) { |
+ Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); |
+ if (activity == null) { |
+ return; |
+ } |
+ |
+ int orientation = getOrientationFromWebScreenOrientations(orientations); |
+ if (orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
+ return; |
+ } |
+ |
+ activity.setRequestedOrientation(orientation); |
+ } |
+ |
+ @CalledByNative |
+ void unlockOrientation() { |
+ Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); |
+ if (activity == null) { |
+ return; |
+ } |
+ |
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
+ } |
+ |
+ private ScreenOrientationProvider() { |
+ } |
+} |