File: exclusive_access_manager_android.cc

package info (click to toggle)
chromium 143.0.7499.109-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,786,824 kB
  • sloc: cpp: 35,783,839; ansic: 7,477,365; javascript: 3,962,116; python: 1,480,521; xml: 764,832; asm: 710,816; pascal: 188,028; sh: 88,717; perl: 88,692; objc: 79,984; sql: 57,625; cs: 42,265; fortran: 24,101; makefile: 22,509; tcl: 15,277; php: 14,018; yacc: 9,043; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (153 lines) | stat: -rw-r--r-- 5,541 bytes parent folder | download | duplicates (5)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// 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_activity,
    const jni_zero::JavaRef<jobject>& j_fullscreen_manager,
    const jni_zero::JavaRef<jobject>& j_activity_tab_provider)
    : eac_(std::make_unique<ExclusiveAccessContextAndroid>(
          env,
          j_activity,
          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,
    jlong displayId) {
  FullscreenTabParams fullscreen_tab_params{displayId, prefersNavigationBar,
                                            prefersStatusBar};
  eam_.fullscreen_controller()->EnterFullscreenModeForTab(
      reinterpret_cast<content::RenderFrameHost*>(requesting_frame),
      fullscreen_tab_params);
}

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::HasExclusiveAccess(JNIEnv* env) {
  return eam_.fullscreen_controller()->IsTabFullscreen() ||
         eam_.pointer_lock_controller()->IsPointerLocked() ||
         eam_.keyboard_lock_controller()->IsKeyboardLockActive();
}

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::RequestPointerLock(
    JNIEnv* env,
    const jni_zero::JavaRef<jobject>& jweb_contents,
    bool user_gesture,
    bool last_unlocked_by_target) {
  content::WebContents* wc =
      content::WebContents::FromJavaWebContents(jweb_contents);
  DCHECK(wc != nullptr);
  eam_.pointer_lock_controller()->RequestToLockPointer(wc, user_gesture,
                                                       last_unlocked_by_target);
}

void ExclusiveAccessManagerAndroid::LostPointerLock(JNIEnv* env) {
  eam_.pointer_lock_controller()->ExitExclusiveAccessToPreviousState();
}

void ExclusiveAccessManagerAndroid::ExitExclusiveAccess(JNIEnv* env) {
  eam_.ExitExclusiveAccess();
}

void ExclusiveAccessManagerAndroid::OnTabDeactivated(
    JNIEnv* env,
    const jni_zero::JavaRef<jobject>& jweb_contents) {
  eam_.OnTabDeactivated(
      content::WebContents::FromJavaWebContents(jweb_contents));
}

void ExclusiveAccessManagerAndroid::OnTabDetachedFromView(
    JNIEnv* env,
    const jni_zero::JavaRef<jobject>& jweb_contents) {
  eam_.OnTabDetachedFromView(
      content::WebContents::FromJavaWebContents(jweb_contents));
}

void ExclusiveAccessManagerAndroid::OnTabClosing(
    JNIEnv* env,
    const jni_zero::JavaRef<jobject>& jweb_contents) {
  eam_.OnTabClosing(content::WebContents::FromJavaWebContents(jweb_contents));
}

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_activity,
    const jni_zero::JavaParamRef<jobject>& j_fullscreen_manager,
    const jni_zero::JavaParamRef<jobject>& j_activity_tab_provider) {
  ExclusiveAccessManagerAndroid* content = new ExclusiveAccessManagerAndroid(
      env, jeam, j_activity, j_fullscreen_manager, j_activity_tab_provider);
  return reinterpret_cast<intptr_t>(content);
}