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

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

Issue 185133005: Move referrer stripping into GURL::GetAsReferrer(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore the behavior of setting the referrer when it's invalid in URLRequest::SetReferrer. 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
« no previous file with comments | « chrome/browser/ui/android/context_menu_helper.h ('k') | net/url_request/url_request.cc » ('j') | 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 "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( 69 GURL sanitizedReferrer = (params.frame_url.is_empty() ?
70 params.frame_url.is_empty() ? params.page_url : params.frame_url); 70 params.page_url : params.frame_url).GetAsReferrer();
71 71
72 JNIEnv* env = base::android::AttachCurrentThread(); 72 JNIEnv* env = base::android::AttachCurrentThread();
73 base::android::ScopedJavaLocalRef<jobject> jmenu_info = 73 base::android::ScopedJavaLocalRef<jobject> jmenu_info =
74 ContextMenuParamsAndroid::Java_ContextMenuParams_create( 74 ContextMenuParamsAndroid::Java_ContextMenuParams_create(
75 env, 75 env,
76 params.media_type, 76 params.media_type,
77 ConvertUTF8ToJavaString(env, params.link_url.spec()).obj(), 77 ConvertUTF8ToJavaString(env, params.link_url.spec()).obj(),
78 ConvertUTF16ToJavaString(env, params.link_text).obj(), 78 ConvertUTF16ToJavaString(env, params.link_text).obj(),
79 ConvertUTF8ToJavaString(env, params.unfiltered_link_url.spec()).obj(), 79 ConvertUTF8ToJavaString(env, params.unfiltered_link_url.spec()).obj(),
80 ConvertUTF8ToJavaString(env, params.src_url.spec()).obj(), 80 ConvertUTF8ToJavaString(env, params.src_url.spec()).obj(),
81 ConvertUTF16ToJavaString(env, params.selection_text).obj(), 81 ConvertUTF16ToJavaString(env, params.selection_text).obj(),
82 params.is_editable, 82 params.is_editable,
83 ConvertUTF8ToJavaString(env, sanitizedReferrer.spec()).obj(), 83 ConvertUTF8ToJavaString(env, sanitizedReferrer.spec()).obj(),
84 params.referrer_policy); 84 params.referrer_policy);
85 85
86 std::vector<content::MenuItem>::const_iterator i; 86 std::vector<content::MenuItem>::const_iterator i;
87 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) {
88 ContextMenuParamsAndroid::Java_ContextMenuParams_addCustomItem( 88 ContextMenuParamsAndroid::Java_ContextMenuParams_addCustomItem(
89 env, 89 env,
90 jmenu_info.obj(), 90 jmenu_info.obj(),
91 ConvertUTF16ToJavaString(env, i->label).obj(), 91 ConvertUTF16ToJavaString(env, i->label).obj(),
92 i->action); 92 i->action);
93 } 93 }
94 94
95 return jmenu_info; 95 return jmenu_info;
96 } 96 }
97 97
98 GURL ContextMenuHelper::SanitizeReferrer(const GURL& referring_url) {
99 // This mirrors sanitization done on Desktop in RenderViewContextMenu.
100 if (referring_url.is_valid() && (referring_url.has_ref() ||
101 referring_url.has_username() || referring_url.has_password())) {
102 GURL::Replacements referrer_mods;
103 referrer_mods.ClearRef();
104 referrer_mods.ClearUsername();
105 referrer_mods.ClearPassword();
106 return referring_url.ReplaceComponents(referrer_mods);
107 }
108 return referring_url;
109 }
110
111 void ContextMenuHelper::OnCustomItemSelected(JNIEnv* env, 98 void ContextMenuHelper::OnCustomItemSelected(JNIEnv* env,
112 jobject obj, 99 jobject obj,
113 jint action) { 100 jint action) {
114 if (!context_menu_callback_.is_null()) { 101 if (!context_menu_callback_.is_null()) {
115 context_menu_callback_.Run(action); 102 context_menu_callback_.Run(action);
116 context_menu_callback_.Reset(); 103 context_menu_callback_.Reset();
117 } 104 }
118 } 105 }
119 106
120 void ContextMenuHelper::OnStartDownload(JNIEnv* env, 107 void ContextMenuHelper::OnStartDownload(JNIEnv* env,
121 jobject obj, 108 jobject obj,
122 jboolean jis_link) { 109 jboolean jis_link) {
123 content::DownloadControllerAndroid::Get()->StartContextMenuDownload( 110 content::DownloadControllerAndroid::Get()->StartContextMenuDownload(
124 context_menu_params_, 111 context_menu_params_,
125 web_contents_, 112 web_contents_,
126 jis_link); 113 jis_link);
127 } 114 }
128 115
129 bool RegisterContextMenuHelper(JNIEnv* env) { 116 bool RegisterContextMenuHelper(JNIEnv* env) {
130 return RegisterNativesImpl(env) && 117 return RegisterNativesImpl(env) &&
131 ContextMenuParamsAndroid::RegisterNativesImpl(env); 118 ContextMenuParamsAndroid::RegisterNativesImpl(env);
132 } 119 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/android/context_menu_helper.h ('k') | net/url_request/url_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698