OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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_ANDROID_OMNIBOX_AUTOCOMPLETE_CONTROLLER_ANDROID_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OMNIBOX_AUTOCOMPLETE_CONTROLLER_ANDROID_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/android/jni_weak_ref.h" |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/singleton.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 16 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
| 17 #include "components/keyed_service/core/keyed_service.h" |
| 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/notification_service.h" |
| 21 |
| 22 class AutocompleteController; |
| 23 struct AutocompleteMatch; |
| 24 class AutocompleteResult; |
| 25 class Profile; |
| 26 class Tab; |
| 27 |
| 28 // The native part of the Java AutocompleteController class. |
| 29 class AutocompleteControllerAndroid : public AutocompleteControllerDelegate, |
| 30 public KeyedService { |
| 31 public: |
| 32 explicit AutocompleteControllerAndroid(Profile* profile); |
| 33 |
| 34 // Methods that forward to AutocompleteController: |
| 35 void Start(JNIEnv* env, |
| 36 jobject obj, |
| 37 jstring j_text, |
| 38 jstring j_desired_tld, |
| 39 jstring j_current_url, |
| 40 bool prevent_inline_autocomplete, |
| 41 bool prefer_keyword, |
| 42 bool allow_exact_keyword_match, |
| 43 bool best_match_only); |
| 44 base::android::ScopedJavaLocalRef<jobject> Classify(JNIEnv* env, |
| 45 jobject obj, |
| 46 jstring j_text); |
| 47 void StartZeroSuggest(JNIEnv* env, |
| 48 jobject obj, |
| 49 jstring j_omnibox_text, |
| 50 jstring j_current_url, |
| 51 jboolean is_query_in_omnibox, |
| 52 jboolean focused_from_fakebox); |
| 53 void Stop(JNIEnv* env, jobject obj, bool clear_result); |
| 54 void ResetSession(JNIEnv* env, jobject obj); |
| 55 void OnSuggestionSelected(JNIEnv* env, |
| 56 jobject obj, |
| 57 jint selected_index, |
| 58 jstring j_current_url, |
| 59 jboolean is_query_in_omnibox, |
| 60 jboolean focused_from_fakebox, |
| 61 jlong elapsed_time_since_first_modified, |
| 62 jobject j_web_contents); |
| 63 void DeleteSuggestion(JNIEnv* env, jobject obj, int selected_index); |
| 64 base::android::ScopedJavaLocalRef<jstring> UpdateMatchDestinationURL( |
| 65 JNIEnv* env, |
| 66 jobject obj, |
| 67 jint selected_index, |
| 68 jlong elapsed_time_since_input_change); |
| 69 |
| 70 // KeyedService: |
| 71 virtual void Shutdown() OVERRIDE; |
| 72 |
| 73 class Factory : public BrowserContextKeyedServiceFactory { |
| 74 public: |
| 75 static AutocompleteControllerAndroid* GetForProfile(Profile* profile, |
| 76 JNIEnv* env, |
| 77 jobject obj); |
| 78 |
| 79 static Factory* GetInstance(); |
| 80 |
| 81 protected: |
| 82 virtual content::BrowserContext* GetBrowserContextToUse( |
| 83 content::BrowserContext* context) const OVERRIDE; |
| 84 |
| 85 private: |
| 86 friend struct DefaultSingletonTraits<Factory>; |
| 87 |
| 88 Factory(); |
| 89 virtual ~Factory(); |
| 90 |
| 91 // BrowserContextKeyedServiceFactory |
| 92 virtual KeyedService* BuildServiceInstanceFor( |
| 93 content::BrowserContext* profile) const OVERRIDE; |
| 94 }; |
| 95 |
| 96 private: |
| 97 virtual ~AutocompleteControllerAndroid(); |
| 98 void InitJNI(JNIEnv* env, jobject obj); |
| 99 |
| 100 // AutocompleteControllerDelegate implementation. |
| 101 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; |
| 102 |
| 103 // Notifies the Java AutocompleteController that suggestions were received |
| 104 // based on the text the user typed in last. |
| 105 void NotifySuggestionsReceived( |
| 106 const AutocompleteResult& autocomplete_result); |
| 107 |
| 108 // Classifies the type of page we are on. |
| 109 AutocompleteInput::PageClassification ClassifyPage( |
| 110 const GURL& gurl, |
| 111 bool is_query_in_omnibox, |
| 112 bool focused_from_fakebox) const; |
| 113 |
| 114 base::android::ScopedJavaLocalRef<jobject> BuildOmniboxSuggestion( |
| 115 JNIEnv* env, const AutocompleteMatch& match); |
| 116 |
| 117 // Converts destination_url (which is in its canonical form or punycode) to a |
| 118 // user-friendly URL by looking up accept languages of the current profile. |
| 119 // e.g. http://xn--6q8b.kr/ --> 한.kr |
| 120 base::string16 FormatURLUsingAcceptLanguages(GURL url); |
| 121 |
| 122 scoped_ptr<AutocompleteController> autocomplete_controller_; |
| 123 |
| 124 // Last input we sent to the autocomplete controller. |
| 125 AutocompleteInput input_; |
| 126 |
| 127 // Whether we're currently inside a call to Classify(). |
| 128 bool inside_classify_; |
| 129 |
| 130 JavaObjectWeakGlobalRef weak_java_autocomplete_controller_android_; |
| 131 Profile* profile_; |
| 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(AutocompleteControllerAndroid); |
| 134 }; |
| 135 |
| 136 // Registers the LocationBar native method. |
| 137 bool RegisterAutocompleteControllerAndroid(JNIEnv* env); |
| 138 |
| 139 #endif // CHROME_BROWSER_ANDROID_OMNIBOX_AUTOCOMPLETE_CONTROLLER_ANDROID_H_ |
OLD | NEW |