1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/android/find_in_page/find_in_page_bridge.h"
7 #include "base/android/jni_string.h"
8 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
9 #include "content/public/browser/web_contents.h"
10 #include "jni/FindInPageBridge_jni.h"
12 using base::android::ConvertUTF16ToJavaString
;
14 FindInPageBridge::FindInPageBridge(JNIEnv
* env
,
16 jobject j_web_contents
)
17 : weak_java_ref_(env
, obj
) {
18 web_contents_
= content::WebContents::FromJavaWebContents(j_web_contents
);
21 void FindInPageBridge::Destroy(JNIEnv
*, jobject
) {
25 void FindInPageBridge::StartFinding(JNIEnv
* env
,
27 jstring search_string
,
28 jboolean forward_direction
,
29 jboolean case_sensitive
) {
30 FindTabHelper::FromWebContents(web_contents_
)->
32 base::android::ConvertJavaStringToUTF16(env
, search_string
),
37 void FindInPageBridge::StopFinding(JNIEnv
* env
,
39 jboolean clearSelection
) {
40 FindTabHelper::FromWebContents(web_contents_
)->
41 StopFinding(clearSelection
? FindBarController::kClearSelectionOnPage
42 : FindBarController::kKeepSelectionOnPage
);
45 ScopedJavaLocalRef
<jstring
> FindInPageBridge::GetPreviousFindText(JNIEnv
* env
,
47 return ConvertUTF16ToJavaString(
48 env
, FindTabHelper::FromWebContents(web_contents_
)->previous_find_text());
51 void FindInPageBridge::RequestFindMatchRects(JNIEnv
* env
,
53 jint current_version
) {
54 FindTabHelper::FromWebContents(web_contents_
)->
55 RequestFindMatchRects(current_version
);
58 void FindInPageBridge::ActivateNearestFindResult(JNIEnv
* env
,
62 FindTabHelper::FromWebContents(web_contents_
)->
63 ActivateNearestFindResult(x
, y
);
66 void FindInPageBridge::ActivateFindInPageResultForAccessibility(
67 JNIEnv
* env
, jobject obj
) {
68 FindTabHelper::FromWebContents(web_contents_
)->
69 ActivateFindInPageResultForAccessibility();
73 static jlong
Init(JNIEnv
* env
, jobject obj
, jobject j_web_contents
) {
74 FindInPageBridge
* bridge
= new FindInPageBridge(env
, obj
, j_web_contents
);
75 return reinterpret_cast<intptr_t>(bridge
);
78 bool FindInPageBridge::RegisterFindInPageBridge(JNIEnv
* env
) {
79 return RegisterNativesImpl(env
);