| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp/ntp_snippets_bridge.h" | 5 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // URL for the article. This will also be used to find the favicon for the | 130 // URL for the article. This will also be used to find the favicon for the |
| 131 // article. | 131 // article. |
| 132 std::vector<std::string> urls; | 132 std::vector<std::string> urls; |
| 133 // URL for the AMP version of the article if it exists. This will be used as | 133 // URL for the AMP version of the article if it exists. This will be used as |
| 134 // the URL to direct the user to on tap. | 134 // the URL to direct the user to on tap. |
| 135 std::vector<std::string> amp_urls; | 135 std::vector<std::string> amp_urls; |
| 136 std::vector<std::string> thumbnail_urls; | 136 std::vector<std::string> thumbnail_urls; |
| 137 std::vector<std::string> snippets; | 137 std::vector<std::string> snippets; |
| 138 std::vector<int64_t> timestamps; | 138 std::vector<int64_t> timestamps; |
| 139 std::vector<std::string> publishers; | 139 std::vector<std::string> publishers; |
| 140 for (const ntp_snippets::NTPSnippet& snippet : *ntp_snippets_service_) { | 140 for (const std::unique_ptr<ntp_snippets::NTPSnippet>& snippet : |
| 141 ntp_snippets_service_->snippets()) { |
| 141 // The url from source_info is a url for a site that is one of the | 142 // The url from source_info is a url for a site that is one of the |
| 142 // HOST_RESTRICT parameters, so this is preferred. | 143 // HOST_RESTRICT parameters, so this is preferred. |
| 143 urls.push_back(snippet.best_source().url.spec()); | 144 urls.push_back(snippet->best_source().url.spec()); |
| 144 amp_urls.push_back(snippet.best_source().amp_url.spec()); | 145 amp_urls.push_back(snippet->best_source().amp_url.spec()); |
| 145 titles.push_back(snippet.title()); | 146 titles.push_back(snippet->title()); |
| 146 thumbnail_urls.push_back(snippet.salient_image_url().spec()); | 147 thumbnail_urls.push_back(snippet->salient_image_url().spec()); |
| 147 snippets.push_back(snippet.snippet()); | 148 snippets.push_back(snippet->snippet()); |
| 148 timestamps.push_back(snippet.publish_date().ToJavaTime()); | 149 timestamps.push_back(snippet->publish_date().ToJavaTime()); |
| 149 publishers.push_back(snippet.best_source().publisher_name); | 150 publishers.push_back(snippet->best_source().publisher_name); |
| 150 } | 151 } |
| 151 | 152 |
| 152 JNIEnv* env = base::android::AttachCurrentThread(); | 153 JNIEnv* env = base::android::AttachCurrentThread(); |
| 153 Java_SnippetsBridge_onSnippetsAvailable( | 154 Java_SnippetsBridge_onSnippetsAvailable( |
| 154 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), | 155 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), |
| 155 ToJavaArrayOfStrings(env, urls).obj(), | 156 ToJavaArrayOfStrings(env, urls).obj(), |
| 156 ToJavaArrayOfStrings(env, amp_urls).obj(), | 157 ToJavaArrayOfStrings(env, amp_urls).obj(), |
| 157 ToJavaArrayOfStrings(env, thumbnail_urls).obj(), | 158 ToJavaArrayOfStrings(env, thumbnail_urls).obj(), |
| 158 ToJavaArrayOfStrings(env, snippets).obj(), | 159 ToJavaArrayOfStrings(env, snippets).obj(), |
| 159 ToJavaLongArray(env, timestamps).obj(), | 160 ToJavaLongArray(env, timestamps).obj(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 175 j_bitmap = gfx::ConvertToJavaBitmap(bitmap); | 176 j_bitmap = gfx::ConvertToJavaBitmap(bitmap); |
| 176 | 177 |
| 177 Java_FetchSnippetImageCallback_onSnippetImageAvailable(env, callback.obj(), | 178 Java_FetchSnippetImageCallback_onSnippetImageAvailable(env, callback.obj(), |
| 178 j_bitmap.obj()); | 179 j_bitmap.obj()); |
| 179 } | 180 } |
| 180 | 181 |
| 181 // static | 182 // static |
| 182 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 183 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 183 return RegisterNativesImpl(env); | 184 return RegisterNativesImpl(env); |
| 184 } | 185 } |
| OLD | NEW |