Index: chrome/android/java/src/org/chromium/chrome/browser/BookmarksBridge.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/BookmarksBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/BookmarksBridge.java |
index 9c31845e4c4622e3e04292d751efa2064727106e..66cdbdabbc05c032a99330771f026791a4ccb7a3 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/BookmarksBridge.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/BookmarksBridge.java |
@@ -4,11 +4,14 @@ |
package org.chromium.chrome.browser; |
+import android.util.Pair; |
+ |
import org.chromium.base.ObserverList; |
import org.chromium.base.VisibleForTesting; |
import org.chromium.base.annotations.CalledByNative; |
import org.chromium.chrome.browser.profiles.Profile; |
import org.chromium.components.bookmarks.BookmarkId; |
+import org.chromium.components.bookmarks.BookmarkMatch; |
import org.chromium.components.bookmarks.BookmarkType; |
import java.util.ArrayList; |
@@ -378,6 +381,19 @@ public class BookmarksBridge { |
} |
/** |
+ * Synchronously gets a list of bookmarks that match the specified search query. |
+ * @param query Keyword used for searching bookmarks. |
+ * @param maxNumberOfResult Maximum number of result to fetch. |
+ * @return List of bookmarks that are related to the given query. |
+ */ |
Kibeom Kim (inactive)
2015/08/10 07:47:38
Wasn't this async API before?
|
+ public List<BookmarkMatch> searchBookmarks(String query, int maxNumberOfResult) { |
+ List<BookmarkMatch> bookmarkMatches = new ArrayList<BookmarkMatch>(); |
+ nativeSearchBookmarks(mNativeBookmarksBridge, bookmarkMatches, query, |
+ maxNumberOfResult); |
+ return bookmarkMatches; |
+ } |
+ |
+ /** |
* Set title of the given bookmark. |
*/ |
public void setBookmarkTitle(BookmarkId id, String title) { |
@@ -660,6 +676,24 @@ public class BookmarksBridge { |
} |
@CalledByNative |
+ private static void addToBookmarkMatchList(List<BookmarkMatch> bookmarkMatchList, |
+ long id, int type, int[] titleMatchStartPositions, |
+ int[] titleMatchEndPositions, int[] urlMatchStartPositions, |
+ int[] urlMatchEndPositions) { |
+ bookmarkMatchList.add(new BookmarkMatch(new BookmarkId(id, type), |
+ createPairsList(titleMatchStartPositions, titleMatchEndPositions), |
+ createPairsList(urlMatchStartPositions, urlMatchEndPositions))); |
+ } |
+ |
+ private static List<Pair<Integer, Integer>> createPairsList(int[] left, int[] right) { |
+ List<Pair<Integer, Integer>> pairList = new ArrayList<Pair<Integer, Integer>>(); |
+ for (int i = 0; i < left.length; i++) { |
+ pairList.add(new Pair<Integer, Integer>(left[i], right[i])); |
+ } |
+ return pairList; |
+ } |
+ |
+ @CalledByNative |
private static void addToBookmarkIdListWithDepth(List<BookmarkId> folderList, long id, |
int type, List<Integer> depthList, int depth) { |
folderList.add(new BookmarkId(id, type)); |
@@ -703,6 +737,8 @@ public class BookmarksBridge { |
private native void nativeDeleteBookmark(long nativeBookmarksBridge, BookmarkId bookmarkId); |
private native void nativeMoveBookmark(long nativeBookmarksBridge, BookmarkId bookmarkId, |
BookmarkId newParentId, int index); |
+ private native void nativeSearchBookmarks(long nativeBookmarksBridge, |
+ List<BookmarkMatch> bookmarkMatches, String query, int maxNumber); |
private native BookmarkId nativeAddBookmark(long nativeBookmarksBridge, BookmarkId parent, |
int index, String title, String url); |
private native void nativeUndo(long nativeBookmarksBridge); |