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

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

Issue 2792063003: Factor out RenderWidgetHostConnector (Closed)
Patch Set: format Created 3 years, 8 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/selection_popup_controller.cc
diff --git a/content/browser/android/selection_popup_controller.cc b/content/browser/android/selection_popup_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..52a912155b985fa273e4350d55f72f307e8ea507
--- /dev/null
+++ b/content/browser/android/selection_popup_controller.cc
@@ -0,0 +1,80 @@
+// 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/selection_popup_controller.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/android/scoped_java_ref.h"
+#include "content/browser/renderer_host/render_widget_host_view_android.h"
+#include "content/public/browser/web_contents.h"
+#include "jni/SelectionPopupController_jni.h"
+
+using base::android::AttachCurrentThread;
+using base::android::ConvertUTF8ToJavaString;
+using base::android::JavaParamRef;
+using base::android::ScopedJavaLocalRef;
+
+namespace content {
+
+void Init(JNIEnv* env,
+ const JavaParamRef<jobject>& obj,
+ const JavaParamRef<jobject>& jweb_contents) {
+ WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents);
+ DCHECK(web_contents);
+
+ // Left unowned but will be destroyed when |WebContentsDestroyed| is called.
+ new SelectionPopupController(env, obj, web_contents);
+}
+
+bool RegisterSelectionPopupController(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+SelectionPopupController::SelectionPopupController(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& obj,
+ WebContents* web_contents)
+ : RenderProcessConnector(web_contents) {
+ java_obj_ = JavaObjectWeakGlobalRef(env, obj);
+}
+
+SelectionPopupController::~SelectionPopupController() {
+ UpdateRenderProcessConnection(rwhva(), nullptr);
+}
+
+void SelectionPopupController::UpdateRenderProcessConnection(
+ RenderWidgetHostViewAndroid* old_rwhva,
+ RenderWidgetHostViewAndroid* new_rwhva) {
+ if (old_rwhva)
+ old_rwhva->set_selection_popup_controller(nullptr);
+ if (new_rwhva)
+ new_rwhva->set_selection_popup_controller(this);
+}
+
+void SelectionPopupController::OnSelectionEvent(
+ ui::SelectionEventType event,
+ const gfx::PointF& selection_anchor,
+ const gfx::RectF& selection_rect) {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj = java_obj_.get(env);
+ if (obj.is_null())
+ return;
+
+ Java_SelectionPopupController_onSelectionEvent(
+ env, obj, event, selection_anchor.x(), selection_anchor.y(),
+ selection_rect.x(), selection_rect.y(), selection_rect.right(),
+ selection_rect.bottom());
+}
+
+void SelectionPopupController::OnSelectionChanged(const std::string& text) {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj = java_obj_.get(env);
+ if (obj.is_null())
+ return;
+ ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text);
+ Java_SelectionPopupController_onSelectionChanged(env, obj, jtext);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698