File: overlay_panel_content.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (118 lines) | stat: -rw-r--r-- 4,445 bytes parent folder | download | duplicates (6)
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
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/android/bottombar/overlay_panel_content.h"

#include <memory>
#include <set>

#include "base/android/jni_string.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "cc/input/browser_controls_offset_tag_modifications.h"
#include "cc/input/browser_controls_state.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "components/embedder_support/android/delegate/web_contents_delegate_android.h"
#include "components/navigation_interception/intercept_navigation_delegate.h"
#include "components/variations/variations_associated_data.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "ui/android/view_android.h"

// Must come after all headers that specialize FromJniType() / ToJniType().
#include "chrome/android/chrome_jni_headers/OverlayPanelContent_jni.h"

using base::android::JavaParamRef;


// This class manages the native behavior of the panel.
// Instances of this class are owned by the Java OverlayPanelContentl.
OverlayPanelContent::OverlayPanelContent(JNIEnv* env, jobject obj) {
  java_manager_.Reset(env, obj);
}

OverlayPanelContent::~OverlayPanelContent() {
  JNIEnv* env = base::android::AttachCurrentThread();
  Java_OverlayPanelContent_clearNativePanelContentPtr(env, java_manager_);
}

void OverlayPanelContent::Destroy(JNIEnv* env) {
  delete this;
}

void OverlayPanelContent::OnPhysicalBackingSizeChanged(
    JNIEnv* env,
    content::WebContents* web_contents,
    jint width,
    jint height) {
  gfx::Size size(width, height);
  web_contents->GetNativeView()->OnPhysicalBackingSizeChanged(size);
  web_contents->GetNativeView()->OnSizeChanged(width, height);
}

void OverlayPanelContent::SetWebContents(
    JNIEnv* env,
    content::WebContents* web_contents,
    const JavaParamRef<jobject>& jweb_contents_delegate) {
  // NOTE(pedrosimonetti): Takes ownership of the WebContents. This is to make
  // sure that the WebContens and the Compositor are in the same process.
  // TODO(pedrosimonetti): Confirm with dtrainor@ if the comment above
  // is accurate.
  web_contents_.reset(web_contents);
  web_contents_->SetOwnerLocationForDebug(FROM_HERE);

  web_contents_->SetIsOverlayContent(true);
  // TODO(pedrosimonetti): confirm if we need this after promoting it
  // to a real tab.
  TabAndroid::AttachTabHelpers(web_contents_.get());
  web_contents_delegate_ = std::make_unique<
      web_contents_delegate_android::WebContentsDelegateAndroid>(
      env, jweb_contents_delegate);
  web_contents_->SetDelegate(web_contents_delegate_.get());
}

void OverlayPanelContent::DestroyWebContents(JNIEnv* env) {
  DCHECK(web_contents_.get());
  // At the time this is called we may be deeply nested in a callback from
  // WebContents. WebContents does not support being deleted from a callback
  // (crashes). To avoid this problem DeleteSoon() is used. See
  // https://crbug.com/1262098.
  base::SingleThreadTaskRunner::GetCurrentDefault()->DeleteSoon(
      FROM_HERE, web_contents_.release());
  // |web_contents_delegate_| may already be NULL at this point.
  web_contents_delegate_.reset();
}

void OverlayPanelContent::SetInterceptNavigationDelegate(
    JNIEnv* env,
    const JavaParamRef<jobject>& delegate,
    content::WebContents* web_contents) {
  navigation_interception::InterceptNavigationDelegate::Associate(
      web_contents,
      std::make_unique<navigation_interception::InterceptNavigationDelegate>(
          env, delegate));
}

void OverlayPanelContent::UpdateBrowserControlsState(
    JNIEnv* env,
    jboolean are_controls_hidden) {
  if (!web_contents_)
    return;

  cc::BrowserControlsState state = cc::BrowserControlsState::kShown;
  if (are_controls_hidden)
    state = cc::BrowserControlsState::kHidden;

  web_contents_->UpdateBrowserControlsState(
      state, cc::BrowserControlsState::kBoth, false, std::nullopt);
}

jlong JNI_OverlayPanelContent_Init(JNIEnv* env,
                                   const JavaParamRef<jobject>& obj) {
  OverlayPanelContent* content = new OverlayPanelContent(env, obj);
  return reinterpret_cast<intptr_t>(content);
}