Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Unified Diff: chrome/browser/ui/android/context_menu_helper.cc

Issue 2777773002: Show the image header for the Context Menu (Closed)
Patch Set: Fixed based of tedchoc's comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/android/context_menu_helper.cc
diff --git a/chrome/browser/ui/android/context_menu_helper.cc b/chrome/browser/ui/android/context_menu_helper.cc
index f4ed7f8256c3df2acc3d29686fadecb093c13164..1db8593bf4a7434e8687a03140ae37dd8d3fd012 100644
--- a/chrome/browser/ui/android/context_menu_helper.cc
+++ b/chrome/browser/ui/android/context_menu_helper.cc
@@ -34,6 +34,8 @@ using base::android::JavaParamRef;
DEFINE_WEB_CONTENTS_USER_DATA_KEY(ContextMenuHelper);
+const int kHeaderImageMaxWidth = 864; // max size (216dp) * max density
Ted C 2017/03/31 18:48:32 remove these two lines
+const int kHeaderImageMaxHeight = 864;
const int kShareImageMaxWidth = 2048;
const int kShareImageMaxHeight = 2048;
@@ -188,6 +190,51 @@ void ContextMenuHelper::OnShareImage(
j_bytes);
}
+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.
+ JNIEnv* env,
+ const JavaParamRef<jobject>& obj,
+ jint j_max_size_px) {
+ content::RenderFrameHost* render_frame_host =
+ content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
+
+ if (!render_frame_host)
+ return;
+
+ chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer;
+ render_frame_host->GetRemoteInterfaces()->GetInterface(&thumbnail_capturer);
+ // Bind the InterfacePtr into the callback so that it's kept alive until
+ // there's either a connection error or a response.
+ auto* thumbnail_capturer_proxy = thumbnail_capturer.get();
+ thumbnail_capturer_proxy->RequestThumbnailForContextNode(
+ 0, gfx::Size(j_max_size_px, j_max_size_px),
+ base::Bind(&ContextMenuHelper::OnHeaderThumbnailReceived,
+ weak_factory_.GetWeakPtr(),
+ base::Passed(&thumbnail_capturer)));
+}
+
+void ContextMenuHelper::OnHeaderThumbnailReceived(
+ chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer,
+ const std::vector<uint8_t>& thumbnail_data,
+ const gfx::Size& original_size) {
+ content::ContentViewCore* content_view_core =
+ content::ContentViewCore::FromWebContents(web_contents_);
+ if (!content_view_core)
+ return;
+
+ base::android::ScopedJavaLocalRef<jobject> jwindow_android(
+ content_view_core->GetWindowAndroid()->GetJavaObject());
+
+ if (jwindow_android.is_null())
+ return;
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ base::android::ScopedJavaLocalRef<jbyteArray> j_bytes =
+ base::android::ToJavaByteArray(env, thumbnail_data);
+
+ Java_ContextMenuHelper_onHeaderThumbnailReceived(env, java_obj_,
+ jwindow_android, j_bytes);
+}
+
bool RegisterContextMenuHelper(JNIEnv* env) {
return RegisterNativesImpl(env);
}

Powered by Google App Engine
This is Rietveld 408576698