Chromium Code Reviews| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 GURL destination_url(current_url); | 188 GURL destination_url(current_url); |
| 189 if (default_provider && !query.empty()) { | 189 if (default_provider && !query.empty()) { |
| 190 bool refined_query = default_provider->ReplaceSearchTermsInURL(current_url, | 190 bool refined_query = default_provider->ReplaceSearchTermsInURL(current_url, |
| 191 TemplateURLRef::SearchTermsArgs(query), &destination_url); | 191 TemplateURLRef::SearchTermsArgs(query), &destination_url); |
| 192 if (refined_query) | 192 if (refined_query) |
| 193 return ConvertUTF8ToJavaString(env, destination_url.spec()); | 193 return ConvertUTF8ToJavaString(env, destination_url.spec()); |
| 194 } | 194 } |
| 195 return base::android::ScopedJavaLocalRef<jstring>(env, NULL); | 195 return base::android::ScopedJavaLocalRef<jstring>(env, NULL); |
| 196 } | 196 } |
| 197 | 197 |
| 198 base::android::ScopedJavaLocalRef<jstring> | |
| 199 TemplateUrlServiceAndroid::GetUrlForContextualSearchQuery(JNIEnv* env, | |
| 200 jobject obj, | |
| 201 jstring jquery) { | |
| 202 base::string16 query(ConvertJavaStringToUTF16(env, jquery)); | |
| 203 std::string url; | |
| 204 | |
| 205 if (!query.empty()) { | |
| 206 GURL gurl = GetDefaultSearchURLForSearchTerms(GetOriginalProfile(), query); | |
|
Peter Kasting
2014/06/06 17:51:33
Nit: Consider using () instead of = to construct n
jeremycho
2014/06/06 21:51:45
Done.
| |
| 207 if (google_util::IsGoogleSearchUrl(gurl)) | |
| 208 gurl = net::AppendQueryParameter(gurl, "ctxs", "1"); | |
| 209 url = gurl.spec(); | |
| 210 } | |
| 211 | |
| 212 return ConvertUTF8ToJavaString(env, url); | |
| 213 } | |
| 214 | |
| 198 static jlong Init(JNIEnv* env, jobject obj) { | 215 static jlong Init(JNIEnv* env, jobject obj) { |
| 199 TemplateUrlServiceAndroid* template_url_service_android = | 216 TemplateUrlServiceAndroid* template_url_service_android = |
| 200 new TemplateUrlServiceAndroid(env, obj); | 217 new TemplateUrlServiceAndroid(env, obj); |
| 201 return reinterpret_cast<intptr_t>(template_url_service_android); | 218 return reinterpret_cast<intptr_t>(template_url_service_android); |
| 202 } | 219 } |
| 203 | 220 |
| 204 // static | 221 // static |
| 205 bool TemplateUrlServiceAndroid::Register(JNIEnv* env) { | 222 bool TemplateUrlServiceAndroid::Register(JNIEnv* env) { |
| 206 return RegisterNativesImpl(env); | 223 return RegisterNativesImpl(env); |
| 207 } | 224 } |
| OLD | NEW |