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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 | 159 |
160 base::android::ScopedJavaLocalRef<jstring> | 160 base::android::ScopedJavaLocalRef<jstring> |
161 TemplateUrlServiceAndroid::GetUrlForVoiceSearchQuery(JNIEnv* env, | 161 TemplateUrlServiceAndroid::GetUrlForVoiceSearchQuery(JNIEnv* env, |
162 jobject obj, | 162 jobject obj, |
163 jstring jquery) { | 163 jstring jquery) { |
164 base::string16 query(ConvertJavaStringToUTF16(env, jquery)); | 164 base::string16 query(ConvertJavaStringToUTF16(env, jquery)); |
165 std::string url; | 165 std::string url; |
166 | 166 |
167 if (!query.empty()) { | 167 if (!query.empty()) { |
168 GURL gurl = GetDefaultSearchURLForSearchTerms(GetOriginalProfile(), query); | 168 GURL gurl(GetDefaultSearchURLForSearchTerms(GetOriginalProfile(), query)); |
169 if (google_util::IsGoogleSearchUrl(gurl)) | 169 if (google_util::IsGoogleSearchUrl(gurl)) |
170 gurl = net::AppendQueryParameter(gurl, "inm", "vs"); | 170 gurl = net::AppendQueryParameter(gurl, "inm", "vs"); |
171 url = gurl.spec(); | 171 url = gurl.spec(); |
172 } | 172 } |
173 | 173 |
174 return ConvertUTF8ToJavaString(env, url); | 174 return ConvertUTF8ToJavaString(env, url); |
175 } | 175 } |
176 | 176 |
177 base::android::ScopedJavaLocalRef<jstring> | 177 base::android::ScopedJavaLocalRef<jstring> |
178 TemplateUrlServiceAndroid::ReplaceSearchTermsInUrl(JNIEnv* env, | 178 TemplateUrlServiceAndroid::ReplaceSearchTermsInUrl(JNIEnv* env, |
179 jobject obj, | 179 jobject obj, |
180 jstring jquery, | 180 jstring jquery, |
181 jstring jcurrent_url) { | 181 jstring jcurrent_url) { |
182 TemplateURL* default_provider = | 182 TemplateURL* default_provider = |
183 template_url_service_->GetDefaultSearchProvider(); | 183 template_url_service_->GetDefaultSearchProvider(); |
184 | 184 |
185 base::string16 query(ConvertJavaStringToUTF16(env, jquery)); | 185 base::string16 query(ConvertJavaStringToUTF16(env, jquery)); |
186 GURL current_url(ConvertJavaStringToUTF16(env, jcurrent_url)); | 186 GURL current_url(ConvertJavaStringToUTF16(env, jcurrent_url)); |
187 GURL destination_url(current_url); | 187 GURL destination_url(current_url); |
188 if (default_provider && !query.empty()) { | 188 if (default_provider && !query.empty()) { |
189 bool refined_query = default_provider->ReplaceSearchTermsInURL(current_url, | 189 bool refined_query = default_provider->ReplaceSearchTermsInURL(current_url, |
190 TemplateURLRef::SearchTermsArgs(query), &destination_url); | 190 TemplateURLRef::SearchTermsArgs(query), &destination_url); |
191 if (refined_query) | 191 if (refined_query) |
192 return ConvertUTF8ToJavaString(env, destination_url.spec()); | 192 return ConvertUTF8ToJavaString(env, destination_url.spec()); |
193 } | 193 } |
194 return base::android::ScopedJavaLocalRef<jstring>(env, NULL); | 194 return base::android::ScopedJavaLocalRef<jstring>(env, NULL); |
195 } | 195 } |
196 | 196 |
| 197 base::android::ScopedJavaLocalRef<jstring> |
| 198 TemplateUrlServiceAndroid::GetUrlForContextualSearchQuery(JNIEnv* env, |
| 199 jobject obj, |
| 200 jstring jquery) { |
| 201 base::string16 query(ConvertJavaStringToUTF16(env, jquery)); |
| 202 std::string url; |
| 203 |
| 204 if (!query.empty()) { |
| 205 GURL gurl(GetDefaultSearchURLForSearchTerms(GetOriginalProfile(), query)); |
| 206 if (google_util::IsGoogleSearchUrl(gurl)) |
| 207 gurl = net::AppendQueryParameter(gurl, "ctxs", "1"); |
| 208 url = gurl.spec(); |
| 209 } |
| 210 |
| 211 return ConvertUTF8ToJavaString(env, url); |
| 212 } |
| 213 |
197 static jlong Init(JNIEnv* env, jobject obj) { | 214 static jlong Init(JNIEnv* env, jobject obj) { |
198 TemplateUrlServiceAndroid* template_url_service_android = | 215 TemplateUrlServiceAndroid* template_url_service_android = |
199 new TemplateUrlServiceAndroid(env, obj); | 216 new TemplateUrlServiceAndroid(env, obj); |
200 return reinterpret_cast<intptr_t>(template_url_service_android); | 217 return reinterpret_cast<intptr_t>(template_url_service_android); |
201 } | 218 } |
202 | 219 |
203 // static | 220 // static |
204 bool TemplateUrlServiceAndroid::Register(JNIEnv* env) { | 221 bool TemplateUrlServiceAndroid::Register(JNIEnv* env) { |
205 return RegisterNativesImpl(env); | 222 return RegisterNativesImpl(env); |
206 } | 223 } |
OLD | NEW |