| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 const JavaParamRef<jobject>& obj, | 170 const JavaParamRef<jobject>& obj, |
| 171 const JavaParamRef<jstring>& j_text) { | 171 const JavaParamRef<jstring>& j_text) { |
| 172 return GetTopSynchronousResult(env, obj, j_text, true); | 172 return GetTopSynchronousResult(env, obj, j_text, true); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void AutocompleteControllerAndroid::OnOmniboxFocused( | 175 void AutocompleteControllerAndroid::OnOmniboxFocused( |
| 176 JNIEnv* env, | 176 JNIEnv* env, |
| 177 const JavaParamRef<jobject>& obj, | 177 const JavaParamRef<jobject>& obj, |
| 178 const JavaParamRef<jstring>& j_omnibox_text, | 178 const JavaParamRef<jstring>& j_omnibox_text, |
| 179 const JavaParamRef<jstring>& j_current_url, | 179 const JavaParamRef<jstring>& j_current_url, |
| 180 jboolean is_query_in_omnibox, | |
| 181 jboolean focused_from_fakebox) { | 180 jboolean focused_from_fakebox) { |
| 182 if (!autocomplete_controller_) | 181 if (!autocomplete_controller_) |
| 183 return; | 182 return; |
| 184 | 183 |
| 185 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url); | 184 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url); |
| 186 const GURL current_url = GURL(url); | 185 const GURL current_url = GURL(url); |
| 187 base::string16 omnibox_text = ConvertJavaStringToUTF16(env, j_omnibox_text); | 186 base::string16 omnibox_text = ConvertJavaStringToUTF16(env, j_omnibox_text); |
| 188 | 187 |
| 189 // If omnibox text is empty, set it to the current URL for the purposes of | 188 // If omnibox text is empty, set it to the current URL for the purposes of |
| 190 // populating the verbatim match. | 189 // populating the verbatim match. |
| 191 if (omnibox_text.empty()) | 190 if (omnibox_text.empty()) |
| 192 omnibox_text = url; | 191 omnibox_text = url; |
| 193 | 192 |
| 194 input_ = AutocompleteInput( | 193 input_ = AutocompleteInput( |
| 195 omnibox_text, base::string16::npos, std::string(), current_url, | 194 omnibox_text, base::string16::npos, std::string(), current_url, |
| 196 ClassifyPage(current_url, is_query_in_omnibox, focused_from_fakebox), | 195 ClassifyPage(current_url, focused_from_fakebox), |
| 197 false, false, true, true, true, | 196 false, false, true, true, true, |
| 198 ChromeAutocompleteSchemeClassifier(profile_)); | 197 ChromeAutocompleteSchemeClassifier(profile_)); |
| 199 autocomplete_controller_->Start(input_); | 198 autocomplete_controller_->Start(input_); |
| 200 } | 199 } |
| 201 | 200 |
| 202 void AutocompleteControllerAndroid::Stop(JNIEnv* env, | 201 void AutocompleteControllerAndroid::Stop(JNIEnv* env, |
| 203 const JavaParamRef<jobject>& obj, | 202 const JavaParamRef<jobject>& obj, |
| 204 bool clear_results) { | 203 bool clear_results) { |
| 205 if (autocomplete_controller_ != NULL) | 204 if (autocomplete_controller_ != NULL) |
| 206 autocomplete_controller_->Stop(clear_results); | 205 autocomplete_controller_->Stop(clear_results); |
| 207 } | 206 } |
| 208 | 207 |
| 209 void AutocompleteControllerAndroid::ResetSession( | 208 void AutocompleteControllerAndroid::ResetSession( |
| 210 JNIEnv* env, | 209 JNIEnv* env, |
| 211 const JavaParamRef<jobject>& obj) { | 210 const JavaParamRef<jobject>& obj) { |
| 212 if (autocomplete_controller_ != NULL) | 211 if (autocomplete_controller_ != NULL) |
| 213 autocomplete_controller_->ResetSession(); | 212 autocomplete_controller_->ResetSession(); |
| 214 } | 213 } |
| 215 | 214 |
| 216 void AutocompleteControllerAndroid::OnSuggestionSelected( | 215 void AutocompleteControllerAndroid::OnSuggestionSelected( |
| 217 JNIEnv* env, | 216 JNIEnv* env, |
| 218 const JavaParamRef<jobject>& obj, | 217 const JavaParamRef<jobject>& obj, |
| 219 jint selected_index, | 218 jint selected_index, |
| 220 const JavaParamRef<jstring>& j_current_url, | 219 const JavaParamRef<jstring>& j_current_url, |
| 221 jboolean is_query_in_omnibox, | |
| 222 jboolean focused_from_fakebox, | 220 jboolean focused_from_fakebox, |
| 223 jlong elapsed_time_since_first_modified, | 221 jlong elapsed_time_since_first_modified, |
| 224 jint completed_length, | 222 jint completed_length, |
| 225 const JavaParamRef<jobject>& j_web_contents) { | 223 const JavaParamRef<jobject>& j_web_contents) { |
| 226 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url); | 224 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url); |
| 227 const GURL current_url = GURL(url); | 225 const GURL current_url = GURL(url); |
| 228 OmniboxEventProto::PageClassification current_page_classification = | 226 OmniboxEventProto::PageClassification current_page_classification = |
| 229 ClassifyPage(current_url, is_query_in_omnibox, focused_from_fakebox); | 227 ClassifyPage(current_url, focused_from_fakebox); |
| 230 const base::TimeTicks& now(base::TimeTicks::Now()); | 228 const base::TimeTicks& now(base::TimeTicks::Now()); |
| 231 content::WebContents* web_contents = | 229 content::WebContents* web_contents = |
| 232 content::WebContents::FromJavaWebContents(j_web_contents); | 230 content::WebContents::FromJavaWebContents(j_web_contents); |
| 233 | 231 |
| 234 OmniboxLog log( | 232 OmniboxLog log( |
| 235 // For zero suggest, record an empty input string instead of the | 233 // For zero suggest, record an empty input string instead of the |
| 236 // current URL. | 234 // current URL. |
| 237 input_.from_omnibox_focus() ? base::string16() : input_.text(), | 235 input_.from_omnibox_focus() ? base::string16() : input_.text(), |
| 238 false, /* don't know */ | 236 false, /* don't know */ |
| 239 input_.type(), | 237 input_.type(), |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 reinterpret_cast<intptr_t>(&(autocomplete_result)); | 399 reinterpret_cast<intptr_t>(&(autocomplete_result)); |
| 402 Java_AutocompleteController_onSuggestionsReceived(env, | 400 Java_AutocompleteController_onSuggestionsReceived(env, |
| 403 java_bridge.obj(), | 401 java_bridge.obj(), |
| 404 suggestion_list_obj.obj(), | 402 suggestion_list_obj.obj(), |
| 405 inline_text.obj(), | 403 inline_text.obj(), |
| 406 j_autocomplete_result); | 404 j_autocomplete_result); |
| 407 } | 405 } |
| 408 | 406 |
| 409 OmniboxEventProto::PageClassification | 407 OmniboxEventProto::PageClassification |
| 410 AutocompleteControllerAndroid::ClassifyPage(const GURL& gurl, | 408 AutocompleteControllerAndroid::ClassifyPage(const GURL& gurl, |
| 411 bool is_query_in_omnibox, | |
| 412 bool focused_from_fakebox) const { | 409 bool focused_from_fakebox) const { |
| 413 if (!gurl.is_valid()) | 410 if (!gurl.is_valid()) |
| 414 return OmniboxEventProto::INVALID_SPEC; | 411 return OmniboxEventProto::INVALID_SPEC; |
| 415 | 412 |
| 416 const std::string& url = gurl.spec(); | 413 const std::string& url = gurl.spec(); |
| 417 | 414 |
| 418 if (gurl.SchemeIs(content::kChromeUIScheme) && | 415 if (gurl.SchemeIs(content::kChromeUIScheme) && |
| 419 gurl.host_piece() == chrome::kChromeUINewTabHost) { | 416 gurl.host_piece() == chrome::kChromeUINewTabHost) { |
| 420 return OmniboxEventProto::NTP; | 417 return OmniboxEventProto::NTP; |
| 421 } | 418 } |
| 422 | 419 |
| 423 if (url == chrome::kChromeUINativeNewTabURL) { | 420 if (url == chrome::kChromeUINativeNewTabURL) { |
| 424 return focused_from_fakebox ? | 421 return focused_from_fakebox ? |
| 425 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS : | 422 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS : |
| 426 OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS; | 423 OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS; |
| 427 } | 424 } |
| 428 | 425 |
| 429 if (url == url::kAboutBlankURL) | 426 if (url == url::kAboutBlankURL) |
| 430 return OmniboxEventProto::BLANK; | 427 return OmniboxEventProto::BLANK; |
| 431 | 428 |
| 432 if (url == profile_->GetPrefs()->GetString(prefs::kHomePage)) | 429 if (url == profile_->GetPrefs()->GetString(prefs::kHomePage)) |
| 433 return OmniboxEventProto::HOME_PAGE; | 430 return OmniboxEventProto::HOME_PAGE; |
| 434 | 431 |
| 435 if (is_query_in_omnibox) | |
| 436 return OmniboxEventProto::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT; | |
| 437 | |
| 438 bool is_search_url = TemplateURLServiceFactory::GetForProfile(profile_)-> | 432 bool is_search_url = TemplateURLServiceFactory::GetForProfile(profile_)-> |
| 439 IsSearchResultsPageFromDefaultSearchProvider(gurl); | 433 IsSearchResultsPageFromDefaultSearchProvider(gurl); |
| 440 if (is_search_url) | 434 if (is_search_url) |
| 441 return OmniboxEventProto::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT; | 435 return OmniboxEventProto::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT; |
| 442 | 436 |
| 443 return OmniboxEventProto::OTHER; | 437 return OmniboxEventProto::OTHER; |
| 444 } | 438 } |
| 445 | 439 |
| 446 namespace { | 440 namespace { |
| 447 | 441 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 return; | 630 return; |
| 637 | 631 |
| 638 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. | 632 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. |
| 639 new ZeroSuggestPrefetcher(profile); | 633 new ZeroSuggestPrefetcher(profile); |
| 640 } | 634 } |
| 641 | 635 |
| 642 // Register native methods | 636 // Register native methods |
| 643 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { | 637 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { |
| 644 return RegisterNativesImpl(env); | 638 return RegisterNativesImpl(env); |
| 645 } | 639 } |
| OLD | NEW |