| Index: content/browser/android/dialog_overlay_operations_impl.cc
|
| diff --git a/content/browser/android/dialog_overlay_operations_impl.cc b/content/browser/android/dialog_overlay_operations_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7ddcc09a7e347cd02a1ba796988a761b8ae73dd6
|
| --- /dev/null
|
| +++ b/content/browser/android/dialog_overlay_operations_impl.cc
|
| @@ -0,0 +1,134 @@
|
| +// Copyright 2017 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.
|
| +
|
| +#include "content/browser/android/dialog_overlay_operations_impl.h"
|
| +
|
| +#include "content/public/browser/render_frame_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "gpu/ipc/common/gpu_surface_tracker.h"
|
| +#include "jni/DialogOverlayOperationsImpl_jni.h"
|
| +#include "ui/android/window_android.h"
|
| +
|
| +using base::android::AttachCurrentThread;
|
| +using base::android::JavaParamRef;
|
| +using base::android::ScopedJavaLocalRef;
|
| +
|
| +namespace content {
|
| +
|
| +// static
|
| +bool DialogOverlayOperationsImpl::RegisterDialogOverlayOperationsImpl(
|
| + JNIEnv* env) {
|
| + return RegisterNativesImpl(env);
|
| +}
|
| +
|
| +static jlong RegisterForTokens(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj,
|
| + jlong high,
|
| + jlong low) {
|
| + return reinterpret_cast<jlong>(new DialogOverlayOperationsImpl(
|
| + obj, base::UnguessableToken::Deserialize(high, low)));
|
| +}
|
| +
|
| +static void UnregisterForTokens(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj,
|
| + jlong handle) {
|
| + delete reinterpret_cast<DialogOverlayOperationsImpl*>(handle);
|
| +}
|
| +
|
| +DialogOverlayOperationsImpl::DialogOverlayOperationsImpl(
|
| + const JavaParamRef<jobject>& receiver,
|
| + const base::UnguessableToken& token)
|
| + : receiver_(receiver), token_(token), cvc_(nullptr) {
|
| + cvc_ = GetContentViewCore();
|
| +
|
| + // If there's no CVC, then just post a null token immediately.
|
| + if (!cvc_) {
|
| + JNIEnv* env = AttachCurrentThread();
|
| + Java_DialogOverlayOperationsImpl_onDismissed(env, receiver_.obj());
|
| + // |this| might be destroyed.
|
| + return;
|
| + }
|
| +
|
| + cvc_->AddObserver(this);
|
| +
|
| + // Also send the initial token, since we'll only get changes.
|
| + if (ui::WindowAndroid* window = cvc_->GetWindowAndroid()) {
|
| + ScopedJavaLocalRef<jobject> token = window->GetWindowToken();
|
| + if (!token.is_null()) {
|
| + JNIEnv* env = AttachCurrentThread();
|
| + Java_DialogOverlayOperationsImpl_onWindowToken(env, receiver_.obj(),
|
| + token);
|
| + }
|
| + }
|
| +}
|
| +
|
| +DialogOverlayOperationsImpl::~DialogOverlayOperationsImpl() {
|
| + if (cvc_)
|
| + cvc_->RemoveObserver(this);
|
| +}
|
| +
|
| +void DialogOverlayOperationsImpl::OnContentViewCoreDestroyed() {
|
| + cvc_ = nullptr;
|
| +
|
| + JNIEnv* env = AttachCurrentThread();
|
| + Java_DialogOverlayOperationsImpl_onDismissed(env, receiver_.obj());
|
| + // |this| might be destroyed.
|
| +}
|
| +
|
| +void DialogOverlayOperationsImpl::OnAttachedToWindow() {
|
| + JNIEnv* env = AttachCurrentThread();
|
| +
|
| + ScopedJavaLocalRef<jobject> token;
|
| +
|
| + if (ui::WindowAndroid* window = cvc_->GetWindowAndroid())
|
| + token = window->GetWindowToken();
|
| +
|
| + Java_DialogOverlayOperationsImpl_onWindowToken(env, receiver_.obj(), token);
|
| +}
|
| +
|
| +void DialogOverlayOperationsImpl::OnDetachedFromWindow() {
|
| + JNIEnv* env = AttachCurrentThread();
|
| + Java_DialogOverlayOperationsImpl_onWindowToken(env, receiver_.obj(), nullptr);
|
| +}
|
| +
|
| +ContentViewCoreImpl* DialogOverlayOperationsImpl::GetContentViewCore() {
|
| + // Get the frame from the token.
|
| + content::RenderFrameHost* frame =
|
| + content::RenderFrameHost::FromOverlayRoutingToken(token_);
|
| + if (!frame) {
|
| + DVLOG(1) << "Cannot find frame host for token " << token_;
|
| + return nullptr;
|
| + }
|
| +
|
| + content::WebContents* web_contents =
|
| + content::WebContents::FromRenderFrameHost(frame);
|
| + if (!web_contents) {
|
| + DVLOG(1) << "Cannot find web_contents for token " << token_;
|
| + return nullptr;
|
| + }
|
| +
|
| + content::ContentViewCoreImpl* cvc =
|
| + content::ContentViewCoreImpl::FromWebContents(web_contents);
|
| + if (!cvc) {
|
| + DVLOG(1) << "Cannot find cvc for token " << token_;
|
| + return nullptr;
|
| + }
|
| +
|
| + return cvc;
|
| +}
|
| +
|
| +static jint RegisterSurface(JNIEnv* env,
|
| + const base::android::JavaParamRef<jobject>& jcaller,
|
| + const JavaParamRef<jobject>& surface) {
|
| + return gpu::GpuSurfaceTracker::Get()->RegisterViewSurface(surface.obj());
|
| +}
|
| +
|
| +static void UnregisterSurface(
|
| + JNIEnv* env,
|
| + const base::android::JavaParamRef<jobject>& jcaller,
|
| + jint surface_id) {
|
| + gpu::GpuSurfaceTracker::Get()->UnregisterViewSurface(surface_id);
|
| +}
|
| +
|
| +} // namespace content
|
|
|