| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h" | 5 #include "chrome/browser/enhanced_bookmarks/android/enhanced_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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/enhanced_bookmarks/android/bookmark_image_service_andro
id.h" | 10 #include "chrome/browser/enhanced_bookmarks/android/bookmark_image_service_andro
id.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 void EnhancedBookmarksBridge::FetchImageForTab(JNIEnv* env, | 90 void EnhancedBookmarksBridge::FetchImageForTab(JNIEnv* env, |
| 91 jobject obj, | 91 jobject obj, |
| 92 jobject j_web_contents) { | 92 jobject j_web_contents) { |
| 93 WebContents* web_contents = WebContents::FromJavaWebContents(j_web_contents); | 93 WebContents* web_contents = WebContents::FromJavaWebContents(j_web_contents); |
| 94 bookmark_image_service_->RetrieveSalientImageFromContext( | 94 bookmark_image_service_->RetrieveSalientImageFromContext( |
| 95 web_contents, web_contents->GetURL(), true); | 95 web_contents, web_contents->GetURL(), true); |
| 96 } | 96 } |
| 97 | 97 |
| 98 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( | |
| 99 JNIEnv* env, jobject obj, jlong id, jint type) { | |
| 100 DCHECK(enhanced_bookmark_model_->loaded()); | |
| 101 if (type != BookmarkType::BOOKMARK_TYPE_NORMAL) { | |
| 102 return base::android::ConvertUTF8ToJavaString(env, std::string()); | |
| 103 } | |
| 104 | |
| 105 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( | |
| 106 enhanced_bookmark_model_->bookmark_model(), static_cast<int64>(id)); | |
| 107 | |
| 108 return node ? base::android::ConvertUTF8ToJavaString( | |
| 109 env, enhanced_bookmark_model_->GetDescription(node)) | |
| 110 : ScopedJavaLocalRef<jstring>(); | |
| 111 } | |
| 112 | |
| 113 void EnhancedBookmarksBridge::SetBookmarkDescription(JNIEnv* env, | |
| 114 jobject obj, | |
| 115 jlong id, | |
| 116 jint type, | |
| 117 jstring description) { | |
| 118 DCHECK(enhanced_bookmark_model_->loaded()); | |
| 119 DCHECK_EQ(type, BookmarkType::BOOKMARK_TYPE_NORMAL); | |
| 120 | |
| 121 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( | |
| 122 enhanced_bookmark_model_->bookmark_model(), static_cast<int64>(id)); | |
| 123 | |
| 124 enhanced_bookmark_model_->SetDescription( | |
| 125 node, base::android::ConvertJavaStringToUTF8(env, description)); | |
| 126 } | |
| 127 | |
| 128 ScopedJavaLocalRef<jobject> EnhancedBookmarksBridge::AddFolder(JNIEnv* env, | 98 ScopedJavaLocalRef<jobject> EnhancedBookmarksBridge::AddFolder(JNIEnv* env, |
| 129 jobject obj, | 99 jobject obj, |
| 130 jobject j_parent_id_obj, | 100 jobject j_parent_id_obj, |
| 131 jint index, | 101 jint index, |
| 132 jstring j_title) { | 102 jstring j_title) { |
| 133 DCHECK(enhanced_bookmark_model_->loaded()); | 103 DCHECK(enhanced_bookmark_model_->loaded()); |
| 134 long bookmark_id = JavaBookmarkIdGetId(env, j_parent_id_obj); | 104 long bookmark_id = JavaBookmarkIdGetId(env, j_parent_id_obj); |
| 135 const BookmarkNode* parent = bookmarks::GetBookmarkNodeByID( | 105 const BookmarkNode* parent = bookmarks::GetBookmarkNodeByID( |
| 136 enhanced_bookmark_model_->bookmark_model(), | 106 enhanced_bookmark_model_->bookmark_model(), |
| 137 static_cast<int64>(bookmark_id)); | 107 static_cast<int64>(bookmark_id)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( | 184 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( |
| 215 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); | 185 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); |
| 216 } | 186 } |
| 217 | 187 |
| 218 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { | 188 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { |
| 219 return RegisterNativesImpl(env); | 189 return RegisterNativesImpl(env); |
| 220 } | 190 } |
| 221 | 191 |
| 222 } // namespace android | 192 } // namespace android |
| 223 } // namespace enhanced_bookmarks | 193 } // namespace enhanced_bookmarks |
| OLD | NEW |