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/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/search_engines/search_terms_data.h" | 14 #include "chrome/browser/search_engines/search_terms_data.h" |
15 #include "chrome/browser/search_engines/template_url.h" | 15 #include "chrome/browser/search_engines/template_url.h" |
16 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 16 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
17 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
20 #include "jni/TemplateUrlService_jni.h" | 20 #include "jni/TemplateUrlService_jni.h" |
21 | 21 |
22 using base::android::ConvertJavaStringToUTF16; | |
22 using base::android::ConvertUTF16ToJavaString; | 23 using base::android::ConvertUTF16ToJavaString; |
24 using base::android::ConvertUTF8ToJavaString; | |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 Profile* GetOriginalProfile() { | 28 Profile* GetOriginalProfile() { |
27 return g_browser_process->profile_manager()->GetDefaultProfile()-> | 29 return g_browser_process->profile_manager()->GetDefaultProfile()-> |
28 GetOriginalProfile(); | 30 GetOriginalProfile(); |
29 } | 31 } |
30 | 32 |
31 } // namespace | 33 } // namespace |
32 | 34 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 env, | 133 env, |
132 index, | 134 index, |
133 ConvertUTF16ToJavaString(env, template_url->short_name()).obj(), | 135 ConvertUTF16ToJavaString(env, template_url->short_name()).obj(), |
134 ConvertUTF16ToJavaString(env, template_url->keyword()).obj()); | 136 ConvertUTF16ToJavaString(env, template_url->keyword()).obj()); |
135 } | 137 } |
136 | 138 |
137 bool TemplateUrlServiceAndroid::IsPrepopulatedTemplate(TemplateURL* url) { | 139 bool TemplateUrlServiceAndroid::IsPrepopulatedTemplate(TemplateURL* url) { |
138 return url->prepopulate_id() > 0; | 140 return url->prepopulate_id() > 0; |
139 } | 141 } |
140 | 142 |
143 static jstring GetUrlForSearchQuery(JNIEnv* env, jclass, jstring jquery) { | |
Ted C
2013/09/10 16:05:06
here and below, I thought chrome was against name
David Trainor- moved to gerrit
2013/09/10 22:35:46
Done.
| |
144 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); | |
145 const TemplateURL* default_provider = | |
146 TemplateURLServiceFactory::GetForProfile(profile)-> | |
Yaron
2013/09/10 16:31:46
You already have a template_url_service_ member. M
David Trainor- moved to gerrit
2013/09/10 22:35:46
Done.
| |
147 GetDefaultSearchProvider(); | |
148 | |
149 string16 query(ConvertJavaStringToUTF16(env, jquery)); | |
150 | |
151 std::string url; | |
152 if (default_provider && | |
153 default_provider->url_ref().SupportsReplacement() && !query.empty()) { | |
154 url = default_provider->url_ref().ReplaceSearchTerms( | |
155 TemplateURLRef::SearchTermsArgs(query)); | |
156 } | |
157 | |
158 // OK to release, JNI binding. | |
159 return ConvertUTF8ToJavaString(env, url).Release(); | |
160 } | |
161 | |
162 static jstring ReplaceSearchTermsInUrl(JNIEnv* env, | |
163 jclass, | |
Ted C
2013/09/10 16:05:06
alignment is off
David Trainor- moved to gerrit
2013/09/10 22:35:46
Done.
| |
164 jstring jquery, | |
165 jstring jcurrent_url) { | |
166 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); | |
Yaron
2013/09/10 16:31:46
same here
David Trainor- moved to gerrit
2013/09/10 22:35:46
Done.
| |
167 TemplateURL* default_provider = | |
168 TemplateURLServiceFactory::GetForProfile(profile)-> | |
169 GetDefaultSearchProvider(); | |
170 | |
171 string16 query(ConvertJavaStringToUTF16(env, jquery)); | |
172 GURL current_url(ConvertJavaStringToUTF16(env, jcurrent_url)); | |
173 GURL destination_url(current_url); | |
174 if (default_provider && !query.empty()) { | |
175 bool refinedQuery = default_provider->ReplaceSearchTermsInURL(current_url, | |
Yaron
2013/09/10 16:31:46
refined_query
David Trainor- moved to gerrit
2013/09/10 22:35:46
Moving methods wholesale ftl :(. Sorry.
| |
176 TemplateURLRef::SearchTermsArgs(query), &destination_url); | |
177 if (refinedQuery) { | |
Ted C
2013/09/10 16:05:06
no braces needed
David Trainor- moved to gerrit
2013/09/10 22:35:46
Done.
| |
178 return ConvertUTF8ToJavaString(env, destination_url.spec()).Release(); | |
179 } | |
180 } | |
181 return NULL; | |
182 } | |
183 | |
141 static jint Init(JNIEnv* env, jobject obj) { | 184 static jint Init(JNIEnv* env, jobject obj) { |
142 TemplateUrlServiceAndroid* template_url_service_android = | 185 TemplateUrlServiceAndroid* template_url_service_android = |
143 new TemplateUrlServiceAndroid(env, obj); | 186 new TemplateUrlServiceAndroid(env, obj); |
144 return reinterpret_cast<jint>(template_url_service_android); | 187 return reinterpret_cast<jint>(template_url_service_android); |
145 } | 188 } |
146 | 189 |
147 // static | 190 // static |
148 bool TemplateUrlServiceAndroid::Register(JNIEnv* env) { | 191 bool TemplateUrlServiceAndroid::Register(JNIEnv* env) { |
149 return RegisterNativesImpl(env); | 192 return RegisterNativesImpl(env); |
150 } | 193 } |
OLD | NEW |