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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/findinpage/FindInPageBridge.java

Issue 633743002: Add FindInPageBridge (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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: chrome/android/java/src/org/chromium/chrome/browser/findinpage/FindInPageBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/findinpage/FindInPageBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/findinpage/FindInPageBridge.java
new file mode 100644
index 0000000000000000000000000000000000000000..b9e626596df58b6fe54814a57e12aec75890ab25
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/findinpage/FindInPageBridge.java
@@ -0,0 +1,89 @@
+// Copyright 2014 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.
+
+package org.chromium.chrome.browser.findinpage;
+
+import org.chromium.content_public.browser.WebContents;
+
+/**
+ * Allows issuing find in page related requests for a given WebContents.
+ */
+public class FindInPageBridge {
+ private final WebContents mWebContents;
+ private final long mFindInPageBridge;
Ted C 2014/10/07 20:49:49 I would try to include either the word Native or P
aurimas (slooooooooow) 2014/10/07 23:28:25 Done.
+
+ public FindInPageBridge(WebContents webContents) {
+ mWebContents = webContents;
+ mFindInPageBridge = nativeInit(webContents);
+ }
+
+ /**
+ * Destroys this instance so no further calls can be executed.
+ */
+ public void destroy() {
+ if (mFindInPageBridge != 0) nativeDestroy(mFindInPageBridge);
Ted C 2014/10/07 20:49:49 You might want to make mFindInPageBridge non-final
aurimas (slooooooooow) 2014/10/07 23:28:25 Done.
+ }
+
+ /**
+ * @return True, if the ChromeTab currently has a page that supports finding.
+ */
+ public boolean supportsFinding() {
+ return mWebContents != null;
Ted C 2014/10/07 20:49:49 I don't think we should ever support a null web co
aurimas (slooooooooow) 2014/10/07 23:28:25 Already fixed in patchset 2
+ }
+
+ /**
+ * Starts the find operation by calling StartFinding on the ChromeTab.
+ * This function does not block while a search is in progress.
+ * Set a listener using setFindResultListener to receive the results.
+ */
+ public void startFinding(String searchString, boolean forwardDirection, boolean caseSensitive) {
+ assert mFindInPageBridge != 0;
+ nativeStartFinding(mFindInPageBridge, searchString, forwardDirection, caseSensitive);
+ }
+
+ /** Stops the current find operation. */
+ public void stopFinding() {
+ assert mFindInPageBridge != 0;
+ nativeStopFinding(mFindInPageBridge);
+ }
+
+ /** Returns the most recent find text before the current one. */
+ public String getPreviousFindText() {
+ assert mFindInPageBridge != 0;
+ return nativeGetPreviousFindText(mFindInPageBridge);
+ }
+
+ /** Asks the renderer to send the bounding boxes of current find matches. */
+ public void requestFindMatchRects(int currentVersion) {
+ assert mFindInPageBridge != 0;
+ nativeRequestFindMatchRects(mFindInPageBridge, currentVersion);
+ }
+
+ /**
+ * Selects and zooms to the nearest find result to the point (x,y),
+ * where x and y are fractions of the content document's width and height.
+ */
+ public void activateNearestFindResult(float x, float y) {
+ assert mFindInPageBridge != 0;
+ nativeActivateNearestFindResult(mFindInPageBridge, x, y);
+ }
+
+ private native long nativeInit(WebContents webContents);
+
+ private native void nativeDestroy(long nativeFindInPageBridge);
+
+ private native void nativeStartFinding(long nativeFindInPageBridge, String searchString,
+ boolean forwardDirection, boolean caseSensitive);
+
+ private native void nativeStopFinding(long nativeFindInPageBridge);
+
+ private native String nativeGetPreviousFindText(long nativeFindInPageBridge);
+
+ private native void nativeRequestFindMatchRects(
+ long nativeFindInPageBridge, int currentVersion);
+
+ private native void nativeActivateNearestFindResult(
+ long nativeFindInPageBridge, float x, float y);
+
+}

Powered by Google App Engine
This is Rietveld 408576698