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

Side by Side Diff: chrome/browser/ui/android/context_menu_helper.cc

Issue 2945903002: Rendering the image in the sandbox for security (Closed)
Patch Set: comments Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/android/context_menu_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/android/callback_android.h" 11 #include "base/android/callback_android.h"
12 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "chrome/browser/android/download/download_controller_base.h" 15 #include "chrome/browser/android/download/download_controller_base.h"
16 #include "chrome/browser/image_decoder.h"
16 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 17 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
17 #include "chrome/common/thumbnail_capturer.mojom.h" 18 #include "chrome/common/thumbnail_capturer.mojom.h"
18 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
19 #include "content/public/browser/android/content_view_core.h" 20 #include "content/public/browser/android/content_view_core.h"
20 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
22 #include "content/public/common/context_menu_params.h" 23 #include "content/public/common/context_menu_params.h"
23 #include "jni/ContextMenuHelper_jni.h" 24 #include "jni/ContextMenuHelper_jni.h"
24 #include "jni/ContextMenuParams_jni.h" 25 #include "jni/ContextMenuParams_jni.h"
25 #include "services/service_manager/public/cpp/interface_provider.h" 26 #include "services/service_manager/public/cpp/interface_provider.h"
26 #include "third_party/WebKit/public/web/WebContextMenuData.h" 27 #include "third_party/WebKit/public/web/WebContextMenuData.h"
28 #include "ui/gfx/android/java_bitmap.h"
27 #include "ui/gfx/geometry/point.h" 29 #include "ui/gfx/geometry/point.h"
28 #include "ui/gfx/geometry/size.h" 30 #include "ui/gfx/geometry/size.h"
29 31
30 using base::android::ConvertJavaStringToUTF8; 32 using base::android::ConvertJavaStringToUTF8;
31 using base::android::ConvertUTF8ToJavaString; 33 using base::android::ConvertUTF8ToJavaString;
32 using base::android::ConvertUTF16ToJavaString; 34 using base::android::ConvertUTF16ToJavaString;
33 using base::android::JavaParamRef; 35 using base::android::JavaParamRef;
34 36
35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ContextMenuHelper); 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ContextMenuHelper);
36 38
37 const char kDataReductionProxyPassthroughHeader[] = 39 const char kDataReductionProxyPassthroughHeader[] =
38 "Chrome-Proxy-Accept-Transform: identity\r\n"; 40 "Chrome-Proxy-Accept-Transform: identity\r\n";
39 41
40 namespace { 42 namespace {
41 43
42 void OnRetrieveImage(chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer, 44 class ContextMenuHelperImageRequest : public ImageDecoder::ImageRequest {
43 const base::android::JavaRef<jobject>& jcallback, 45 public:
44 const std::vector<uint8_t>& thumbnail_data, 46 static void Start(const base::android::JavaRef<jobject>& jcallback,
45 const gfx::Size& original_size) { 47 const std::vector<uint8_t>& thumbnail_data) {
48 ContextMenuHelperImageRequest* request =
49 new ContextMenuHelperImageRequest(jcallback);
50 ImageDecoder::Start(request, thumbnail_data);
51 }
52
53 protected:
54 void OnImageDecoded(const SkBitmap& decoded_image) override {
55 base::android::RunCallbackAndroid(jcallback_,
56 gfx::ConvertToJavaBitmap(&decoded_image));
57 delete this;
58 }
59
60 void OnDecodeImageFailed() override {
61 base::android::ScopedJavaLocalRef<jobject> j_bitmap;
62 base::android::RunCallbackAndroid(jcallback_, j_bitmap);
63 delete this;
64 }
65
66 private:
67 ContextMenuHelperImageRequest(
68 const base::android::JavaRef<jobject>& jcallback)
69 : jcallback_(jcallback) {}
70
71 const base::android::ScopedJavaGlobalRef<jobject> jcallback_;
72
73 DISALLOW_IMPLICIT_CONSTRUCTORS(ContextMenuHelperImageRequest);
74 };
75
76 void OnRetrieveImageForShare(
77 chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer,
78 const base::android::JavaRef<jobject>& jcallback,
79 const std::vector<uint8_t>& thumbnail_data,
80 const gfx::Size& original_size) {
46 base::android::RunCallbackAndroid(jcallback, thumbnail_data); 81 base::android::RunCallbackAndroid(jcallback, thumbnail_data);
47 } 82 }
48 83
84 void OnRetrieveImageForContextMenu(
85 chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer,
86 const base::android::JavaRef<jobject>& jcallback,
87 const std::vector<uint8_t>& thumbnail_data,
88 const gfx::Size& original_size) {
89 ContextMenuHelperImageRequest::Start(jcallback, thumbnail_data);
90 }
91
49 } // namespace 92 } // namespace
50 93
51 ContextMenuHelper::ContextMenuHelper(content::WebContents* web_contents) 94 ContextMenuHelper::ContextMenuHelper(content::WebContents* web_contents)
52 : web_contents_(web_contents) { 95 : web_contents_(web_contents) {
53 JNIEnv* env = base::android::AttachCurrentThread(); 96 JNIEnv* env = base::android::AttachCurrentThread();
54 java_obj_.Reset( 97 java_obj_.Reset(
55 env, 98 env,
56 Java_ContextMenuHelper_create(env, reinterpret_cast<long>(this)).obj()); 99 Java_ContextMenuHelper_create(env, reinterpret_cast<long>(this)).obj());
57 DCHECK(!java_obj_.is_null()); 100 DCHECK(!java_obj_.is_null());
58 } 101 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const JavaParamRef<jobject>& obj) { 197 const JavaParamRef<jobject>& obj) {
155 content::RenderFrameHost* render_frame_host = 198 content::RenderFrameHost* render_frame_host =
156 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); 199 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
157 if (!render_frame_host) 200 if (!render_frame_host)
158 return; 201 return;
159 202
160 CoreTabHelper::FromWebContents(web_contents_)->SearchByImageInNewTab( 203 CoreTabHelper::FromWebContents(web_contents_)->SearchByImageInNewTab(
161 render_frame_host, context_menu_params_.src_url); 204 render_frame_host, context_menu_params_.src_url);
162 } 205 }
163 206
164 void ContextMenuHelper::RetrieveImage(JNIEnv* env, 207 void ContextMenuHelper::RetrieveImageForShare(
165 const JavaParamRef<jobject>& obj, 208 JNIEnv* env,
166 const JavaParamRef<jobject>& jcallback, 209 const JavaParamRef<jobject>& obj,
167 jint max_dimen_px) { 210 const JavaParamRef<jobject>& jcallback,
211 jint max_dimen_px) {
212 RetrieveImageInternal(env, base::Bind(&OnRetrieveImageForShare), jcallback,
213 max_dimen_px);
214 }
215
216 void ContextMenuHelper::RetrieveImageForContextMenu(
217 JNIEnv* env,
218 const JavaParamRef<jobject>& obj,
219 const JavaParamRef<jobject>& jcallback,
220 jint max_dimen_px) {
221 RetrieveImageInternal(env, base::Bind(&OnRetrieveImageForContextMenu),
222 jcallback, max_dimen_px);
223 }
224
225 void ContextMenuHelper::RetrieveImageInternal(
226 JNIEnv* env,
227 const ImageRetrieveCallback& retrieve_callback,
228 const JavaParamRef<jobject>& jcallback,
229 jint max_dimen_px) {
168 content::RenderFrameHost* render_frame_host = 230 content::RenderFrameHost* render_frame_host =
169 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); 231 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
170 if (!render_frame_host) 232 if (!render_frame_host)
171 return; 233 return;
172 234
173 chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer; 235 chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer;
174 render_frame_host->GetRemoteInterfaces()->GetInterface(&thumbnail_capturer); 236 render_frame_host->GetRemoteInterfaces()->GetInterface(&thumbnail_capturer);
175 // Bind the InterfacePtr into the callback so that it's kept alive until 237 // Bind the InterfacePtr into the callback so that it's kept alive
176 // there's either a connection error or a response. 238 // until there's either a connection error or a response.
177 auto* thumbnail_capturer_proxy = thumbnail_capturer.get(); 239 auto* thumbnail_capturer_proxy = thumbnail_capturer.get();
178 thumbnail_capturer_proxy->RequestThumbnailForContextNode( 240 thumbnail_capturer_proxy->RequestThumbnailForContextNode(
179 0, gfx::Size(max_dimen_px, max_dimen_px), 241 0, gfx::Size(max_dimen_px, max_dimen_px),
180 base::Bind(&OnRetrieveImage, base::Passed(&thumbnail_capturer), 242 base::Bind(retrieve_callback, base::Passed(&thumbnail_capturer),
181 base::android::ScopedJavaGlobalRef<jobject>(env, jcallback))); 243 base::android::ScopedJavaGlobalRef<jobject>(env, jcallback)));
182 } 244 }
183 245
184 bool RegisterContextMenuHelper(JNIEnv* env) { 246 bool RegisterContextMenuHelper(JNIEnv* env) {
185 return RegisterNativesImpl(env); 247 return RegisterNativesImpl(env);
186 } 248 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/android/context_menu_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698