OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/search_engines/template_url_service_android.h" | 5 #include "chrome/browser/search_engines/template_url_service_android.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 GURL destination_url(current_url); | 189 GURL destination_url(current_url); |
190 if (default_provider && !query.empty()) { | 190 if (default_provider && !query.empty()) { |
191 bool refined_query = default_provider->ReplaceSearchTermsInURL(current_url, | 191 bool refined_query = default_provider->ReplaceSearchTermsInURL(current_url, |
192 TemplateURLRef::SearchTermsArgs(query), &destination_url); | 192 TemplateURLRef::SearchTermsArgs(query), &destination_url); |
193 if (refined_query) | 193 if (refined_query) |
194 return ConvertUTF8ToJavaString(env, destination_url.spec()); | 194 return ConvertUTF8ToJavaString(env, destination_url.spec()); |
195 } | 195 } |
196 return base::android::ScopedJavaLocalRef<jstring>(env, NULL); | 196 return base::android::ScopedJavaLocalRef<jstring>(env, NULL); |
197 } | 197 } |
198 | 198 |
| 199 base::android::ScopedJavaLocalRef<jstring> |
| 200 TemplateUrlServiceAndroid::GetUrlForContextualSearchQuery(JNIEnv* env, |
| 201 jobject obj, |
| 202 jstring jquery) { |
| 203 base::string16 query(ConvertJavaStringToUTF16(env, jquery)); |
| 204 std::string url; |
| 205 |
| 206 if (!query.empty()) { |
| 207 GURL gurl = GetDefaultSearchURLForSearchTerms(GetOriginalProfile(), query); |
| 208 if (google_util::IsGoogleSearchUrl(gurl)) |
| 209 gurl = net::AppendQueryParameter(gurl, "ctxs", "1"); |
| 210 url = gurl.spec(); |
| 211 } |
| 212 |
| 213 return ConvertUTF8ToJavaString(env, url); |
| 214 } |
| 215 |
199 static jlong Init(JNIEnv* env, jobject obj) { | 216 static jlong Init(JNIEnv* env, jobject obj) { |
200 TemplateUrlServiceAndroid* template_url_service_android = | 217 TemplateUrlServiceAndroid* template_url_service_android = |
201 new TemplateUrlServiceAndroid(env, obj); | 218 new TemplateUrlServiceAndroid(env, obj); |
202 return reinterpret_cast<intptr_t>(template_url_service_android); | 219 return reinterpret_cast<intptr_t>(template_url_service_android); |
203 } | 220 } |
204 | 221 |
205 // static | 222 // static |
206 bool TemplateUrlServiceAndroid::Register(JNIEnv* env) { | 223 bool TemplateUrlServiceAndroid::Register(JNIEnv* env) { |
207 return RegisterNativesImpl(env); | 224 return RegisterNativesImpl(env); |
208 } | 225 } |
OLD | NEW |