Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Unified Diff: content/browser/android/dialog_overlay_operations_impl.cc

Issue 2765443004: AndroidOverlay implementation using Dialog. (Closed)
Patch Set: fixed gn Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
boliu 2017/03/30 22:42:02 DCHECK everything here is on UI thread
liberato (no reviews please) 2017/04/04 17:49:28 Done.
+
+ // 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.
boliu 2017/03/30 22:42:02 what if you use DeleteSoon in UnregisterForTokens
liberato (no reviews please) 2017/04/04 17:49:28 good point. i'll explicitly remove the CVC observ
+}
+
+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) {
boliu 2017/03/30 22:42:02 there's a chromium-dev thread by dcheng that this
liberato (no reviews please) 2017/04/04 17:49:28 DCHECK it is then!
+ 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

Powered by Google App Engine
This is Rietveld 408576698