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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_
8 #include "base/android/jni_weak_ref.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "components/search_engines/template_url_service.h"
12 #include "components/search_engines/template_url_service_observer.h"
17 // Android wrapper of the TemplateUrlService which provides access from the Java
18 // layer. Note that on Android, there's only a single profile, and therefore
19 // a single instance of this wrapper.
20 class TemplateUrlServiceAndroid
: public TemplateURLServiceObserver
{
22 TemplateUrlServiceAndroid(JNIEnv
* env
, jobject obj
);
24 void Load(JNIEnv
* env
, jobject obj
);
25 void SetUserSelectedDefaultSearchProvider(JNIEnv
* env
,
28 jint
GetDefaultSearchProvider(JNIEnv
* env
, jobject obj
);
29 jint
GetTemplateUrlCount(JNIEnv
* env
, jobject obj
);
30 jboolean
IsLoaded(JNIEnv
* env
, jobject obj
);
31 base::android::ScopedJavaLocalRef
<jobject
>
32 GetPrepopulatedTemplateUrlAt(JNIEnv
* env
, jobject obj
, jint index
);
33 jboolean
IsSearchProviderManaged(JNIEnv
* env
, jobject obj
);
34 jboolean
IsSearchByImageAvailable(JNIEnv
* env
, jobject obj
);
35 jboolean
IsDefaultSearchEngineGoogle(JNIEnv
* env
, jobject obj
);
36 base::android::ScopedJavaLocalRef
<jstring
> GetUrlForSearchQuery(
40 base::android::ScopedJavaLocalRef
<jstring
> GetUrlForVoiceSearchQuery(
44 base::android::ScopedJavaLocalRef
<jstring
> ReplaceSearchTermsInUrl(
48 jstring jcurrent_url
);
49 base::android::ScopedJavaLocalRef
<jstring
> GetUrlForContextualSearchQuery(
53 jstring jalternate_term
,
54 jboolean jshould_prefetch
);
55 base::android::ScopedJavaLocalRef
<jstring
> GetSearchEngineUrlFromTemplateUrl(
60 static bool Register(JNIEnv
* env
);
63 ~TemplateUrlServiceAndroid() override
;
65 bool IsPrepopulatedTemplate(TemplateURL
* url
);
67 void OnTemplateURLServiceLoaded();
69 // TemplateUrlServiceObserver:
70 void OnTemplateURLServiceChanged() override
;
72 JavaObjectWeakGlobalRef weak_java_obj_
;
74 // Pointer to the TemplateUrlService for the main profile.
75 TemplateURLService
* template_url_service_
;
77 scoped_ptr
<TemplateURLService::Subscription
> template_url_subscription_
;
79 DISALLOW_COPY_AND_ASSIGN(TemplateUrlServiceAndroid
);
82 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_