Home | History | Annotate | Download | only in search_engines
      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.
      4 
      5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_
      6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_
      7 
      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 
     13 class TemplateURL;
     14 
     15 
     16 // Android wrapper of the TemplateUrlService which provides access from the Java
     17 // layer. Note that on Android, there's only a single profile, and therefore
     18 // a single instance of this wrapper.
     19 class TemplateUrlServiceAndroid {
     20  public:
     21   TemplateUrlServiceAndroid(JNIEnv* env, jobject obj);
     22 
     23   void Load(JNIEnv* env, jobject obj);
     24   void SetUserSelectedDefaultSearchProvider(JNIEnv* env,
     25                                             jobject obj,
     26                                             jint selected_index);
     27   jint GetDefaultSearchProvider(JNIEnv* env, jobject obj);
     28   jint GetTemplateUrlCount(JNIEnv* env, jobject obj);
     29   jboolean IsLoaded(JNIEnv* env, jobject obj);
     30   base::android::ScopedJavaLocalRef<jobject>
     31       GetPrepopulatedTemplateUrlAt(JNIEnv* env, jobject obj, jint index);
     32   jboolean IsSearchProviderManaged(JNIEnv* env, jobject obj);
     33   jboolean IsSearchByImageAvailable(JNIEnv* env, jobject obj);
     34   jboolean IsDefaultSearchEngineGoogle(JNIEnv* env, jobject obj);
     35   base::android::ScopedJavaLocalRef<jstring> GetUrlForSearchQuery(
     36       JNIEnv* env,
     37       jobject obj,
     38       jstring jquery);
     39   base::android::ScopedJavaLocalRef<jstring> GetUrlForVoiceSearchQuery(
     40       JNIEnv* env,
     41       jobject obj,
     42       jstring jquery);
     43   base::android::ScopedJavaLocalRef<jstring> ReplaceSearchTermsInUrl(
     44       JNIEnv* env,
     45       jobject obj,
     46       jstring jquery,
     47       jstring jcurrent_url);
     48   base::android::ScopedJavaLocalRef<jstring> GetUrlForContextualSearchQuery(
     49       JNIEnv* env,
     50       jobject obj,
     51       jstring jquery,
     52       jstring jalternate_term,
     53       jboolean jshould_prefetch);
     54 
     55   static bool Register(JNIEnv* env);
     56 
     57  private:
     58   ~TemplateUrlServiceAndroid();
     59 
     60   bool IsPrepopulatedTemplate(TemplateURL* url);
     61 
     62   void OnTemplateURLServiceLoaded();
     63 
     64   JavaObjectWeakGlobalRef weak_java_obj_;
     65 
     66   // Pointer to the TemplateUrlService for the main profile.
     67   TemplateURLService* template_url_service_;
     68 
     69   scoped_ptr<TemplateURLService::Subscription> template_url_subscription_;
     70 
     71   DISALLOW_COPY_AND_ASSIGN(TemplateUrlServiceAndroid);
     72 };
     73 
     74 #endif  // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_ANDROID_H_
     75