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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "exclusive_access_manager_android.h"
#include <cstddef>
#include "chrome/android/chrome_jni_headers/ExclusiveAccessManager_jni.h"
#include "chrome/browser/ui/android/exclusive_access/exclusive_access_context_android.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
#include "components/input/native_web_keyboard_event.h"
#include "content/public/browser/web_contents.h"
#include "third_party/jni_zero/jni_zero.h"
ExclusiveAccessManagerAndroid::ExclusiveAccessManagerAndroid(
JNIEnv* env,
const jni_zero::JavaRef<jobject>& j_eam,
const jni_zero::JavaRef<jobject>& j_fullscreen_manager,
const jni_zero::JavaRef<jobject>& j_activity_tab_provider)
: eac_(std::make_unique<ExclusiveAccessContextAndroid>(
env,
j_fullscreen_manager,
j_activity_tab_provider)),
eam_(eac_.get()) {
j_eam_.Reset(j_eam);
}
ExclusiveAccessManagerAndroid::~ExclusiveAccessManagerAndroid() = default;
void ExclusiveAccessManagerAndroid::EnterFullscreenModeForTab(
JNIEnv* env,
jlong requesting_frame,
bool prefersNavigationBar,
bool prefersStatusBar) {
eam_.fullscreen_controller()->EnterFullscreenModeForTab(
reinterpret_cast<content::RenderFrameHost*>(requesting_frame));
}
void ExclusiveAccessManagerAndroid::ExitFullscreenModeForTab(
JNIEnv* env,
const jni_zero::JavaRef<jobject>& jweb_contents) {
content::WebContents* wc =
content::WebContents::FromJavaWebContents(jweb_contents);
DCHECK(wc != nullptr);
eam_.fullscreen_controller()->ExitFullscreenModeForTab(wc);
}
bool ExclusiveAccessManagerAndroid::IsFullscreenForTabOrPending(
JNIEnv* env,
const jni_zero::JavaRef<jobject>& jweb_contents) {
content::WebContents* wc =
content::WebContents::FromJavaWebContents(jweb_contents);
DCHECK(wc != nullptr);
auto state = eam_.fullscreen_controller()->GetFullscreenState(wc);
return state.target_mode == content::FullscreenMode::kContent ||
state.target_mode == content::FullscreenMode::kPseudoContent;
}
bool ExclusiveAccessManagerAndroid::PreHandleKeyboardEvent(
JNIEnv* env,
jlong nativeKeyEvent) {
return eam_.HandleUserKeyEvent(
*reinterpret_cast<input::NativeWebKeyboardEvent*>(nativeKeyEvent));
}
void ExclusiveAccessManagerAndroid::RequestKeyboardLock(
JNIEnv* env,
const jni_zero::JavaRef<jobject>& jweb_contents,
bool escKeyLocked) {
content::WebContents* wc =
content::WebContents::FromJavaWebContents(jweb_contents);
DCHECK_NE(wc, nullptr);
eam_.keyboard_lock_controller()->RequestKeyboardLock(wc, escKeyLocked);
}
void ExclusiveAccessManagerAndroid::CancelKeyboardLockRequest(
JNIEnv* env,
const jni_zero::JavaRef<jobject>& jweb_contents) {
content::WebContents* wc =
content::WebContents::FromJavaWebContents(jweb_contents);
DCHECK_NE(wc, nullptr);
eam_.keyboard_lock_controller()->CancelKeyboardLockRequest(wc);
}
void ExclusiveAccessManagerAndroid::Destroy(JNIEnv* env) {
delete this;
}
jlong JNI_ExclusiveAccessManager_Init(
JNIEnv* env,
const jni_zero::JavaParamRef<jobject>& jeam,
const jni_zero::JavaParamRef<jobject>& j_fullscreen_manager,
const jni_zero::JavaParamRef<jobject>& j_activity_tab_provider) {
ExclusiveAccessManagerAndroid* content = new ExclusiveAccessManagerAndroid(
env, jeam, j_fullscreen_manager, j_activity_tab_provider);
return reinterpret_cast<intptr_t>(content);
}
|