Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 #include "ui/android/window_android.h" | 27 #include "ui/android/window_android.h" |
| 28 #include "ui/gfx/geometry/point.h" | 28 #include "ui/gfx/geometry/point.h" |
| 29 | 29 |
| 30 using base::android::ConvertJavaStringToUTF8; | 30 using base::android::ConvertJavaStringToUTF8; |
| 31 using base::android::ConvertUTF8ToJavaString; | 31 using base::android::ConvertUTF8ToJavaString; |
| 32 using base::android::ConvertUTF16ToJavaString; | 32 using base::android::ConvertUTF16ToJavaString; |
| 33 using base::android::JavaParamRef; | 33 using base::android::JavaParamRef; |
| 34 | 34 |
| 35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ContextMenuHelper); | 35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ContextMenuHelper); |
| 36 | 36 |
| 37 const int kHeaderImageMaxWidth = 864; // max size (216dp) * max density | |
|
Ted C
2017/03/31 18:48:32
remove these two lines
| |
| 38 const int kHeaderImageMaxHeight = 864; | |
| 37 const int kShareImageMaxWidth = 2048; | 39 const int kShareImageMaxWidth = 2048; |
| 38 const int kShareImageMaxHeight = 2048; | 40 const int kShareImageMaxHeight = 2048; |
| 39 | 41 |
| 40 const char kDataReductionProxyPassthroughHeader[] = | 42 const char kDataReductionProxyPassthroughHeader[] = |
| 41 "Chrome-Proxy: pass-through\r\n"; | 43 "Chrome-Proxy: pass-through\r\n"; |
| 42 | 44 |
| 43 ContextMenuHelper::ContextMenuHelper(content::WebContents* web_contents) | 45 ContextMenuHelper::ContextMenuHelper(content::WebContents* web_contents) |
| 44 : web_contents_(web_contents), weak_factory_(this) { | 46 : web_contents_(web_contents), weak_factory_(this) { |
| 45 JNIEnv* env = base::android::AttachCurrentThread(); | 47 JNIEnv* env = base::android::AttachCurrentThread(); |
| 46 java_obj_.Reset( | 48 java_obj_.Reset( |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 return; | 183 return; |
| 182 | 184 |
| 183 JNIEnv* env = base::android::AttachCurrentThread(); | 185 JNIEnv* env = base::android::AttachCurrentThread(); |
| 184 base::android::ScopedJavaLocalRef<jbyteArray> j_bytes = | 186 base::android::ScopedJavaLocalRef<jbyteArray> j_bytes = |
| 185 base::android::ToJavaByteArray(env, thumbnail_data); | 187 base::android::ToJavaByteArray(env, thumbnail_data); |
| 186 | 188 |
| 187 Java_ContextMenuHelper_onShareImageReceived(env, java_obj_, jwindow_android, | 189 Java_ContextMenuHelper_onShareImageReceived(env, java_obj_, jwindow_android, |
| 188 j_bytes); | 190 j_bytes); |
| 189 } | 191 } |
| 190 | 192 |
| 193 void ContextMenuHelper::RetrieveHeaderThumbnail( | |
|
Ted C
2017/03/31 18:48:32
missing todo here to combine
JJ
2017/03/31 19:01:20
100% certain I did this. Whoops.
| |
| 194 JNIEnv* env, | |
| 195 const JavaParamRef<jobject>& obj, | |
| 196 jint j_max_size_px) { | |
| 197 content::RenderFrameHost* render_frame_host = | |
| 198 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); | |
| 199 | |
| 200 if (!render_frame_host) | |
| 201 return; | |
| 202 | |
| 203 chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer; | |
| 204 render_frame_host->GetRemoteInterfaces()->GetInterface(&thumbnail_capturer); | |
| 205 // Bind the InterfacePtr into the callback so that it's kept alive until | |
| 206 // there's either a connection error or a response. | |
| 207 auto* thumbnail_capturer_proxy = thumbnail_capturer.get(); | |
| 208 thumbnail_capturer_proxy->RequestThumbnailForContextNode( | |
| 209 0, gfx::Size(j_max_size_px, j_max_size_px), | |
| 210 base::Bind(&ContextMenuHelper::OnHeaderThumbnailReceived, | |
| 211 weak_factory_.GetWeakPtr(), | |
| 212 base::Passed(&thumbnail_capturer))); | |
| 213 } | |
| 214 | |
| 215 void ContextMenuHelper::OnHeaderThumbnailReceived( | |
| 216 chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer, | |
| 217 const std::vector<uint8_t>& thumbnail_data, | |
| 218 const gfx::Size& original_size) { | |
| 219 content::ContentViewCore* content_view_core = | |
| 220 content::ContentViewCore::FromWebContents(web_contents_); | |
| 221 if (!content_view_core) | |
| 222 return; | |
| 223 | |
| 224 base::android::ScopedJavaLocalRef<jobject> jwindow_android( | |
| 225 content_view_core->GetWindowAndroid()->GetJavaObject()); | |
| 226 | |
| 227 if (jwindow_android.is_null()) | |
| 228 return; | |
| 229 | |
| 230 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 231 base::android::ScopedJavaLocalRef<jbyteArray> j_bytes = | |
| 232 base::android::ToJavaByteArray(env, thumbnail_data); | |
| 233 | |
| 234 Java_ContextMenuHelper_onHeaderThumbnailReceived(env, java_obj_, | |
| 235 jwindow_android, j_bytes); | |
| 236 } | |
| 237 | |
| 191 bool RegisterContextMenuHelper(JNIEnv* env) { | 238 bool RegisterContextMenuHelper(JNIEnv* env) { |
| 192 return RegisterNativesImpl(env); | 239 return RegisterNativesImpl(env); |
| 193 } | 240 } |
| OLD | NEW |