| 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 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 if (!IsEditable(node)) { | 650 if (!IsEditable(node)) { |
| 651 NOTREACHED(); | 651 NOTREACHED(); |
| 652 return; | 652 return; |
| 653 } | 653 } |
| 654 bookmark_id = JavaBookmarkIdGetId(env, j_parent_id_obj); | 654 bookmark_id = JavaBookmarkIdGetId(env, j_parent_id_obj); |
| 655 type = JavaBookmarkIdGetType(env, j_parent_id_obj); | 655 type = JavaBookmarkIdGetType(env, j_parent_id_obj); |
| 656 const BookmarkNode* new_parent_node = GetNodeByID(bookmark_id, type); | 656 const BookmarkNode* new_parent_node = GetNodeByID(bookmark_id, type); |
| 657 bookmark_model_->Move(node, new_parent_node, index); | 657 bookmark_model_->Move(node, new_parent_node, index); |
| 658 } | 658 } |
| 659 | 659 |
| 660 void BookmarksBridge::SearchBookmarks(JNIEnv* env, |
| 661 jobject obj, |
| 662 jobject j_list, |
| 663 jstring j_query, |
| 664 jint max_results) { |
| 665 DCHECK(bookmark_model_->loaded()); |
| 666 |
| 667 std::vector<bookmarks::BookmarkMatch> results; |
| 668 bookmark_model_->GetBookmarksMatching( |
| 669 base::android::ConvertJavaStringToUTF16(env, j_query), |
| 670 max_results, |
| 671 query_parser::MatchingAlgorithm::ALWAYS_PREFIX_SEARCH, |
| 672 &results); |
| 673 for (const bookmarks::BookmarkMatch& match : results) { |
| 674 const BookmarkNode* node = match.node; |
| 675 |
| 676 std::vector<int> title_match_start_positions; |
| 677 std::vector<int> title_match_end_positions; |
| 678 for (auto position : match.title_match_positions) { |
| 679 title_match_start_positions.push_back(position.first); |
| 680 title_match_end_positions.push_back(position.second); |
| 681 } |
| 682 |
| 683 std::vector<int> url_match_start_positions; |
| 684 std::vector<int> url_match_end_positions; |
| 685 for (auto position : match.url_match_positions) { |
| 686 url_match_start_positions.push_back(position.first); |
| 687 url_match_end_positions.push_back(position.second); |
| 688 } |
| 689 |
| 690 Java_BookmarksBridge_addToBookmarkMatchList( |
| 691 env, j_list, node->id(), node->type(), |
| 692 ToJavaIntArray(env, title_match_start_positions).obj(), |
| 693 ToJavaIntArray(env, title_match_end_positions).obj(), |
| 694 ToJavaIntArray(env, url_match_start_positions).obj(), |
| 695 ToJavaIntArray(env, url_match_end_positions).obj()); |
| 696 } |
| 697 } |
| 698 |
| 660 ScopedJavaLocalRef<jobject> BookmarksBridge::AddBookmark( | 699 ScopedJavaLocalRef<jobject> BookmarksBridge::AddBookmark( |
| 661 JNIEnv* env, | 700 JNIEnv* env, |
| 662 jobject obj, | 701 jobject obj, |
| 663 jobject j_parent_id_obj, | 702 jobject j_parent_id_obj, |
| 664 jint index, | 703 jint index, |
| 665 jstring j_title, | 704 jstring j_title, |
| 666 jstring j_url) { | 705 jstring j_url) { |
| 667 DCHECK(IsLoaded()); | 706 DCHECK(IsLoaded()); |
| 668 long bookmark_id = JavaBookmarkIdGetId(env, j_parent_id_obj); | 707 long bookmark_id = JavaBookmarkIdGetId(env, j_parent_id_obj); |
| 669 int type = JavaBookmarkIdGetType(env, j_parent_id_obj); | 708 int type = JavaBookmarkIdGetType(env, j_parent_id_obj); |
| (...skipping 345 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 |