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/ui/android/context_menu_helper.h" | 5 #include "chrome/browser/ui/android/context_menu_helper.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 return; | 181 return; |
182 | 182 |
183 JNIEnv* env = base::android::AttachCurrentThread(); | 183 JNIEnv* env = base::android::AttachCurrentThread(); |
184 base::android::ScopedJavaLocalRef<jbyteArray> j_bytes = | 184 base::android::ScopedJavaLocalRef<jbyteArray> j_bytes = |
185 base::android::ToJavaByteArray(env, thumbnail_data); | 185 base::android::ToJavaByteArray(env, thumbnail_data); |
186 | 186 |
187 Java_ContextMenuHelper_onShareImageReceived(env, java_obj_, jwindow_android, | 187 Java_ContextMenuHelper_onShareImageReceived(env, java_obj_, jwindow_android, |
188 j_bytes); | 188 j_bytes); |
189 } | 189 } |
190 | 190 |
| 191 // TODO(tedchoc): Unify RetrieveHeaderThumbnail and ShareImage. |
| 192 void ContextMenuHelper::RetrieveHeaderThumbnail( |
| 193 JNIEnv* env, |
| 194 const JavaParamRef<jobject>& obj, |
| 195 jint j_max_size_px) { |
| 196 content::RenderFrameHost* render_frame_host = |
| 197 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); |
| 198 |
| 199 if (!render_frame_host) |
| 200 return; |
| 201 |
| 202 chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer; |
| 203 render_frame_host->GetRemoteInterfaces()->GetInterface(&thumbnail_capturer); |
| 204 // Bind the InterfacePtr into the callback so that it's kept alive until |
| 205 // there's either a connection error or a response. |
| 206 auto* thumbnail_capturer_proxy = thumbnail_capturer.get(); |
| 207 thumbnail_capturer_proxy->RequestThumbnailForContextNode( |
| 208 0, gfx::Size(j_max_size_px, j_max_size_px), |
| 209 base::Bind(&ContextMenuHelper::OnHeaderThumbnailReceived, |
| 210 weak_factory_.GetWeakPtr(), |
| 211 base::Passed(&thumbnail_capturer))); |
| 212 } |
| 213 |
| 214 void ContextMenuHelper::OnHeaderThumbnailReceived( |
| 215 chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer, |
| 216 const std::vector<uint8_t>& thumbnail_data, |
| 217 const gfx::Size& original_size) { |
| 218 content::ContentViewCore* content_view_core = |
| 219 content::ContentViewCore::FromWebContents(web_contents_); |
| 220 if (!content_view_core) |
| 221 return; |
| 222 |
| 223 base::android::ScopedJavaLocalRef<jobject> jwindow_android( |
| 224 content_view_core->GetWindowAndroid()->GetJavaObject()); |
| 225 |
| 226 if (jwindow_android.is_null()) |
| 227 return; |
| 228 |
| 229 JNIEnv* env = base::android::AttachCurrentThread(); |
| 230 base::android::ScopedJavaLocalRef<jbyteArray> j_bytes = |
| 231 base::android::ToJavaByteArray(env, thumbnail_data); |
| 232 |
| 233 Java_ContextMenuHelper_onHeaderThumbnailReceived(env, java_obj_, |
| 234 jwindow_android, j_bytes); |
| 235 } |
| 236 |
191 bool RegisterContextMenuHelper(JNIEnv* env) { | 237 bool RegisterContextMenuHelper(JNIEnv* env) { |
192 return RegisterNativesImpl(env); | 238 return RegisterNativesImpl(env); |
193 } | 239 } |
OLD | NEW |