1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/screen_orientation/screen_orientation_delegate_android.h"
#include "base/android/scoped_java_ref.h"
#include "content/browser/screen_orientation/screen_orientation_provider.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "ui/base/device_form_factor.h"
// Must come after all headers that specialize FromJniType() / ToJniType().
#include "content/public/android/content_jni_headers/ScreenOrientationProviderImpl_jni.h"
namespace content {
ScreenOrientationDelegateAndroid::ScreenOrientationDelegateAndroid() {
ScreenOrientationProvider::SetDelegate(this);
}
ScreenOrientationDelegateAndroid::~ScreenOrientationDelegateAndroid() {
ScreenOrientationProvider::SetDelegate(nullptr);
}
bool ScreenOrientationDelegateAndroid::FullScreenRequired(
WebContents* web_contents) {
return true;
}
void ScreenOrientationDelegateAndroid::Lock(
WebContents* web_contents,
device::mojom::ScreenOrientationLockType lock_orientation) {
base::android::ScopedJavaLocalRef<jobject> java_instance =
Java_ScreenOrientationProviderImpl_getInstance(
base::android::AttachCurrentThread());
Java_ScreenOrientationProviderImpl_lockOrientationForWebContents(
base::android::AttachCurrentThread(), java_instance,
static_cast<WebContentsImpl*>(web_contents)->GetJavaWebContents(),
static_cast<jbyte>(lock_orientation));
}
bool ScreenOrientationDelegateAndroid::IsPhone() const {
return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_PHONE;
}
bool ScreenOrientationDelegateAndroid::ScreenOrientationProviderSupported(
WebContents* web_contentss) {
// Since orientation lock behavior is unpredictable on non-phone form factors,
// don't claim to support it.
if (base::FeatureList::IsEnabled(
features::kRestrictOrientationLockToPhones) &&
!IsPhone()) {
return false;
}
// TODO(MLamouri): Consider moving isOrientationLockEnabled to a separate
// function, so reported error messages can differentiate between the device
// never supporting orientation or currently not support orientation.
base::android::ScopedJavaLocalRef<jobject> java_instance =
Java_ScreenOrientationProviderImpl_getInstance(
base::android::AttachCurrentThread());
return Java_ScreenOrientationProviderImpl_isOrientationLockEnabled(
base::android::AttachCurrentThread(), java_instance);
}
void ScreenOrientationDelegateAndroid::Unlock(WebContents* web_contents) {
base::android::ScopedJavaLocalRef<jobject> java_instance =
Java_ScreenOrientationProviderImpl_getInstance(
base::android::AttachCurrentThread());
Java_ScreenOrientationProviderImpl_unlockOrientationForWebContents(
base::android::AttachCurrentThread(), java_instance,
static_cast<WebContentsImpl*>(web_contents)->GetJavaWebContents());
}
} // namespace content
|