| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/android/omnibox/autocomplete_controller_android.h" | 5 #include "chrome/browser/android/omnibox/autocomplete_controller_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 : controller_(new AutocompleteController( | 91 : controller_(new AutocompleteController( |
| 92 base::MakeUnique<ChromeAutocompleteProviderClient>(profile), | 92 base::MakeUnique<ChromeAutocompleteProviderClient>(profile), |
| 93 this, | 93 this, |
| 94 AutocompleteProvider::TYPE_ZERO_SUGGEST)) { | 94 AutocompleteProvider::TYPE_ZERO_SUGGEST)) { |
| 95 // Creating an arbitrary fake_request_source to avoid passing in an invalid | 95 // Creating an arbitrary fake_request_source to avoid passing in an invalid |
| 96 // AutocompleteInput object. | 96 // AutocompleteInput object. |
| 97 base::string16 fake_request_source(base::ASCIIToUTF16( | 97 base::string16 fake_request_source(base::ASCIIToUTF16( |
| 98 "http://www.foobarbazblah.com")); | 98 "http://www.foobarbazblah.com")); |
| 99 controller_->Start(AutocompleteInput( | 99 controller_->Start(AutocompleteInput( |
| 100 fake_request_source, base::string16::npos, std::string(), | 100 fake_request_source, base::string16::npos, std::string(), |
| 101 GURL(fake_request_source), OmniboxEventProto::INVALID_SPEC, false, false, | 101 GURL(fake_request_source), base::string16(), |
| 102 true, true, true, ChromeAutocompleteSchemeClassifier(profile))); | 102 OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, |
| 103 ChromeAutocompleteSchemeClassifier(profile))); |
| 103 // Delete ourselves after 10s. This is enough time to cache results or | 104 // Delete ourselves after 10s. This is enough time to cache results or |
| 104 // give up if the results haven't been received. | 105 // give up if the results haven't been received. |
| 105 expire_timer_.Start(FROM_HERE, | 106 expire_timer_.Start(FROM_HERE, |
| 106 base::TimeDelta::FromMilliseconds(10000), | 107 base::TimeDelta::FromMilliseconds(10000), |
| 107 this, &ZeroSuggestPrefetcher::SelfDestruct); | 108 this, &ZeroSuggestPrefetcher::SelfDestruct); |
| 108 } | 109 } |
| 109 | 110 |
| 110 ZeroSuggestPrefetcher::~ZeroSuggestPrefetcher() { | 111 ZeroSuggestPrefetcher::~ZeroSuggestPrefetcher() { |
| 111 } | 112 } |
| 112 | 113 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 std::string desired_tld; | 148 std::string desired_tld; |
| 148 GURL current_url; | 149 GURL current_url; |
| 149 if (!j_current_url.is_null()) | 150 if (!j_current_url.is_null()) |
| 150 current_url = GURL(ConvertJavaStringToUTF16(env, j_current_url)); | 151 current_url = GURL(ConvertJavaStringToUTF16(env, j_current_url)); |
| 151 if (!j_desired_tld.is_null()) | 152 if (!j_desired_tld.is_null()) |
| 152 desired_tld = base::android::ConvertJavaStringToUTF8(env, j_desired_tld); | 153 desired_tld = base::android::ConvertJavaStringToUTF8(env, j_desired_tld); |
| 153 base::string16 text = ConvertJavaStringToUTF16(env, j_text); | 154 base::string16 text = ConvertJavaStringToUTF16(env, j_text); |
| 154 OmniboxEventProto::PageClassification page_classification = | 155 OmniboxEventProto::PageClassification page_classification = |
| 155 OmniboxEventProto::OTHER; | 156 OmniboxEventProto::OTHER; |
| 156 size_t cursor_pos = j_cursor_pos == -1 ? base::string16::npos : j_cursor_pos; | 157 size_t cursor_pos = j_cursor_pos == -1 ? base::string16::npos : j_cursor_pos; |
| 157 input_ = AutocompleteInput(text, cursor_pos, desired_tld, current_url, | 158 input_ = AutocompleteInput( |
| 158 page_classification, prevent_inline_autocomplete, | 159 text, cursor_pos, desired_tld, current_url, base::string16(), |
| 159 prefer_keyword, allow_exact_keyword_match, | 160 page_classification, prevent_inline_autocomplete, prefer_keyword, |
| 160 want_asynchronous_matches, false, | 161 allow_exact_keyword_match, want_asynchronous_matches, false, |
| 161 ChromeAutocompleteSchemeClassifier(profile_)); | 162 ChromeAutocompleteSchemeClassifier(profile_)); |
| 162 autocomplete_controller_->Start(input_); | 163 autocomplete_controller_->Start(input_); |
| 163 } | 164 } |
| 164 | 165 |
| 165 ScopedJavaLocalRef<jobject> AutocompleteControllerAndroid::Classify( | 166 ScopedJavaLocalRef<jobject> AutocompleteControllerAndroid::Classify( |
| 166 JNIEnv* env, | 167 JNIEnv* env, |
| 167 const JavaParamRef<jobject>& obj, | 168 const JavaParamRef<jobject>& obj, |
| 168 const JavaParamRef<jstring>& j_text) { | 169 const JavaParamRef<jstring>& j_text) { |
| 169 return GetTopSynchronousResult(env, obj, j_text, true); | 170 return GetTopSynchronousResult(env, obj, j_text, true); |
| 170 } | 171 } |
| 171 | 172 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 184 | 185 |
| 185 // If omnibox text is empty, set it to the current URL for the purposes of | 186 // If omnibox text is empty, set it to the current URL for the purposes of |
| 186 // populating the verbatim match. | 187 // populating the verbatim match. |
| 187 if (omnibox_text.empty() && | 188 if (omnibox_text.empty() && |
| 188 !current_url.SchemeIs(content::kChromeUIScheme) && | 189 !current_url.SchemeIs(content::kChromeUIScheme) && |
| 189 !current_url.SchemeIs(chrome::kChromeUINativeScheme)) | 190 !current_url.SchemeIs(chrome::kChromeUINativeScheme)) |
| 190 omnibox_text = url; | 191 omnibox_text = url; |
| 191 | 192 |
| 192 input_ = AutocompleteInput( | 193 input_ = AutocompleteInput( |
| 193 omnibox_text, base::string16::npos, std::string(), current_url, | 194 omnibox_text, base::string16::npos, std::string(), current_url, |
| 194 ClassifyPage(current_url, focused_from_fakebox), | 195 base::string16(), ClassifyPage(current_url, focused_from_fakebox), false, |
| 195 false, false, true, true, true, | 196 false, true, true, true, ChromeAutocompleteSchemeClassifier(profile_)); |
| 196 ChromeAutocompleteSchemeClassifier(profile_)); | |
| 197 autocomplete_controller_->Start(input_); | 197 autocomplete_controller_->Start(input_); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void AutocompleteControllerAndroid::Stop(JNIEnv* env, | 200 void AutocompleteControllerAndroid::Stop(JNIEnv* env, |
| 201 const JavaParamRef<jobject>& obj, | 201 const JavaParamRef<jobject>& obj, |
| 202 bool clear_results) { | 202 bool clear_results) { |
| 203 if (autocomplete_controller_ != nullptr) | 203 if (autocomplete_controller_ != nullptr) |
| 204 autocomplete_controller_->Stop(clear_results); | 204 autocomplete_controller_->Stop(clear_results); |
| 205 } | 205 } |
| 206 | 206 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 return; | 602 return; |
| 603 | 603 |
| 604 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. | 604 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. |
| 605 new ZeroSuggestPrefetcher(profile); | 605 new ZeroSuggestPrefetcher(profile); |
| 606 } | 606 } |
| 607 | 607 |
| 608 // Register native methods | 608 // Register native methods |
| 609 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { | 609 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { |
| 610 return RegisterNativesImpl(env); | 610 return RegisterNativesImpl(env); |
| 611 } | 611 } |
| OLD | NEW |