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