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

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

Issue 178193033: Android: support http referrers for context menu navigations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
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 "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "content/public/browser/android/content_view_core.h" 9 #include "content/public/browser/android/content_view_core.h"
10 #include "content/public/browser/android/download_controller_android.h" 10 #include "content/public/browser/android/download_controller_android.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 60
61 void ContextMenuHelper::SetPopulator(jobject jpopulator) { 61 void ContextMenuHelper::SetPopulator(jobject jpopulator) {
62 JNIEnv* env = base::android::AttachCurrentThread(); 62 JNIEnv* env = base::android::AttachCurrentThread();
63 Java_ContextMenuHelper_setPopulator(env, java_obj_.obj(), jpopulator); 63 Java_ContextMenuHelper_setPopulator(env, java_obj_.obj(), jpopulator);
64 } 64 }
65 65
66 base::android::ScopedJavaLocalRef<jobject> 66 base::android::ScopedJavaLocalRef<jobject>
67 ContextMenuHelper::CreateJavaContextMenuParams( 67 ContextMenuHelper::CreateJavaContextMenuParams(
68 const content::ContextMenuParams& params) { 68 const content::ContextMenuParams& params) {
69 GURL sanitizedReferrer = SanitizeReferrer(
70 params.frame_url.is_empty() ? params.page_url : params.frame_url);
71
69 JNIEnv* env = base::android::AttachCurrentThread(); 72 JNIEnv* env = base::android::AttachCurrentThread();
70 base::android::ScopedJavaLocalRef<jobject> jmenu_info = 73 base::android::ScopedJavaLocalRef<jobject> jmenu_info =
71 ContextMenuParamsAndroid::Java_ContextMenuParams_create( 74 ContextMenuParamsAndroid::Java_ContextMenuParams_create(
72 env, 75 env,
73 params.media_type, 76 params.media_type,
74 ConvertUTF8ToJavaString(env, params.link_url.spec()).obj(), 77 ConvertUTF8ToJavaString(env, params.link_url.spec()).obj(),
75 ConvertUTF16ToJavaString(env, params.link_text).obj(), 78 ConvertUTF16ToJavaString(env, params.link_text).obj(),
76 ConvertUTF8ToJavaString(env, params.unfiltered_link_url.spec()).obj(), 79 ConvertUTF8ToJavaString(env, params.unfiltered_link_url.spec()).obj(),
77 ConvertUTF8ToJavaString(env, params.src_url.spec()).obj(), 80 ConvertUTF8ToJavaString(env, params.src_url.spec()).obj(),
78 ConvertUTF16ToJavaString(env, params.selection_text).obj(), 81 ConvertUTF16ToJavaString(env, params.selection_text).obj(),
79 params.is_editable); 82 params.is_editable,
83 ConvertUTF8ToJavaString(env, sanitizedReferrer.spec()).obj(),
84 params.referrer_policy);
80 85
81 std::vector<content::MenuItem>::const_iterator i; 86 std::vector<content::MenuItem>::const_iterator i;
82 for (i = params.custom_items.begin(); i != params.custom_items.end(); ++i) { 87 for (i = params.custom_items.begin(); i != params.custom_items.end(); ++i) {
83 ContextMenuParamsAndroid::Java_ContextMenuParams_addCustomItem( 88 ContextMenuParamsAndroid::Java_ContextMenuParams_addCustomItem(
84 env, 89 env,
85 jmenu_info.obj(), 90 jmenu_info.obj(),
86 ConvertUTF16ToJavaString(env, i->label).obj(), 91 ConvertUTF16ToJavaString(env, i->label).obj(),
87 i->action); 92 i->action);
88 } 93 }
89 94
90 return jmenu_info; 95 return jmenu_info;
91 } 96 }
92 97
98 GURL ContextMenuHelper::SanitizeReferrer(const GURL& referring_url) {
99 // This mirrors sanitization done on Desktop in RenderViewContextMenu.
100 // TODO(ppi): consider extracting into a helper method in GURL?
ppi 2014/03/05 20:01:45 As for this TODO - I also sent https://codereview.
Ted C 2014/03/05 22:20:53 I would say that if the other review doesn't go th
ppi 2014/03/06 11:41:04 Agreed. I will remove it already and include this
101 if (referring_url.is_valid() && (referring_url.has_ref() ||
102 referring_url.has_username() || referring_url.has_password())) {
103 GURL::Replacements referrer_mods;
104 referrer_mods.ClearRef();
105 referrer_mods.ClearUsername();
106 referrer_mods.ClearPassword();
107 return referring_url.ReplaceComponents(referrer_mods);
108 }
109 return referring_url;
110 }
111
93 void ContextMenuHelper::OnCustomItemSelected(JNIEnv* env, 112 void ContextMenuHelper::OnCustomItemSelected(JNIEnv* env,
94 jobject obj, 113 jobject obj,
95 jint action) { 114 jint action) {
96 if (!context_menu_callback_.is_null()) { 115 if (!context_menu_callback_.is_null()) {
97 context_menu_callback_.Run(action); 116 context_menu_callback_.Run(action);
98 context_menu_callback_.Reset(); 117 context_menu_callback_.Reset();
99 } 118 }
100 } 119 }
101 120
102 void ContextMenuHelper::OnStartDownload(JNIEnv* env, 121 void ContextMenuHelper::OnStartDownload(JNIEnv* env,
103 jobject obj, 122 jobject obj,
104 jboolean jis_link) { 123 jboolean jis_link) {
105 content::DownloadControllerAndroid::Get()->StartContextMenuDownload( 124 content::DownloadControllerAndroid::Get()->StartContextMenuDownload(
106 context_menu_params_, 125 context_menu_params_,
107 web_contents_, 126 web_contents_,
108 jis_link); 127 jis_link);
109 } 128 }
110 129
111 bool RegisterContextMenuHelper(JNIEnv* env) { 130 bool RegisterContextMenuHelper(JNIEnv* env) {
112 return RegisterNativesImpl(env) && 131 return RegisterNativesImpl(env) &&
113 ContextMenuParamsAndroid::RegisterNativesImpl(env); 132 ContextMenuParamsAndroid::RegisterNativesImpl(env);
114 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698