| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/bookmarks/bookmarks_bridge.h" | 5 #include "chrome/browser/android/bookmarks/bookmarks_bridge.h" |
| 6 | 6 |
| 7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/containers/stack_container.h" | 9 #include "base/containers/stack_container.h" |
| 10 #include "base/i18n/string_compare.h" | 10 #include "base/i18n/string_compare.h" |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 const BookmarkNode* node = folder; | 587 const BookmarkNode* node = folder; |
| 588 while (node) { | 588 while (node) { |
| 589 ExtractBookmarkNodeInformation(node, j_result_obj); | 589 ExtractBookmarkNodeInformation(node, j_result_obj); |
| 590 node = GetParentNode(node); | 590 node = GetParentNode(node); |
| 591 } | 591 } |
| 592 | 592 |
| 593 Java_BookmarksCallback_onBookmarksFolderHierarchyAvailable( | 593 Java_BookmarksCallback_onBookmarksFolderHierarchyAvailable( |
| 594 env, j_callback_obj, j_folder_id_obj, j_result_obj); | 594 env, j_callback_obj, j_folder_id_obj, j_result_obj); |
| 595 } | 595 } |
| 596 | 596 |
| 597 void BookmarksBridge::SearchBookmarks(JNIEnv* env, |
| 598 jobject obj, |
| 599 jobject j_list, |
| 600 jstring j_query, |
| 601 jint max_results) { |
| 602 DCHECK(bookmark_model_->loaded()); |
| 603 |
| 604 std::vector<bookmarks::BookmarkMatch> results; |
| 605 bookmark_model_->GetBookmarksMatching( |
| 606 base::android::ConvertJavaStringToUTF16(env, j_query), |
| 607 max_results, |
| 608 query_parser::MatchingAlgorithm::ALWAYS_PREFIX_SEARCH, |
| 609 &results); |
| 610 for (const bookmarks::BookmarkMatch& match : results) { |
| 611 const BookmarkNode* node = match.node; |
| 612 |
| 613 std::vector<int> title_match_start_positions; |
| 614 std::vector<int> title_match_end_positions; |
| 615 for (auto position : match.title_match_positions) { |
| 616 title_match_start_positions.push_back(position.first); |
| 617 title_match_end_positions.push_back(position.second); |
| 618 } |
| 619 |
| 620 std::vector<int> url_match_start_positions; |
| 621 std::vector<int> url_match_end_positions; |
| 622 for (auto position : match.url_match_positions) { |
| 623 url_match_start_positions.push_back(position.first); |
| 624 url_match_end_positions.push_back(position.second); |
| 625 } |
| 626 |
| 627 Java_BookmarksBridge_addToBookmarkMatchList( |
| 628 env, j_list, node->id(), node->type(), |
| 629 ToJavaIntArray(env, title_match_start_positions).obj(), |
| 630 ToJavaIntArray(env, title_match_end_positions).obj(), |
| 631 ToJavaIntArray(env, url_match_start_positions).obj(), |
| 632 ToJavaIntArray(env, url_match_end_positions).obj()); |
| 633 } |
| 634 } |
| 635 |
| 597 ScopedJavaLocalRef<jobject> BookmarksBridge::AddFolder(JNIEnv* env, | 636 ScopedJavaLocalRef<jobject> BookmarksBridge::AddFolder(JNIEnv* env, |
| 598 jobject obj, | 637 jobject obj, |
| 599 jobject j_parent_id_obj, | 638 jobject j_parent_id_obj, |
| 600 jint index, | 639 jint index, |
| 601 jstring j_title) { | 640 jstring j_title) { |
| 602 DCHECK(IsLoaded()); | 641 DCHECK(IsLoaded()); |
| 603 long bookmark_id = JavaBookmarkIdGetId(env, j_parent_id_obj); | 642 long bookmark_id = JavaBookmarkIdGetId(env, j_parent_id_obj); |
| 604 int type = JavaBookmarkIdGetType(env, j_parent_id_obj); | 643 int type = JavaBookmarkIdGetType(env, j_parent_id_obj); |
| 605 const BookmarkNode* parent = GetNodeByID(bookmark_id, type); | 644 const BookmarkNode* parent = GetNodeByID(bookmark_id, type); |
| 606 | 645 |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 BookmarkModelChanged(); | 1054 BookmarkModelChanged(); |
| 1016 } | 1055 } |
| 1017 | 1056 |
| 1018 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { | 1057 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { |
| 1019 NotifyIfDoneLoading(); | 1058 NotifyIfDoneLoading(); |
| 1020 } | 1059 } |
| 1021 | 1060 |
| 1022 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { | 1061 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { |
| 1023 partner_bookmarks_shim_ = NULL; | 1062 partner_bookmarks_shim_ = NULL; |
| 1024 } | 1063 } |
| OLD | NEW |