| 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 "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/browser/search_engines/template_url_service.h" | 29 #include "chrome/browser/search_engines/template_url_service.h" |
| 30 #include "chrome/browser/search_engines/template_url_service_factory.h" | 30 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 31 #include "chrome/browser/sessions/session_id.h" | 31 #include "chrome/browser/sessions/session_id.h" |
| 32 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | 32 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
| 33 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 33 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 34 #include "chrome/common/autocomplete_match_type.h" | 34 #include "chrome/common/autocomplete_match_type.h" |
| 35 #include "chrome/common/instant_types.h" | 35 #include "chrome/common/instant_types.h" |
| 36 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 37 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 38 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 38 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 39 #include "components/metrics/proto/omnibox_event.pb.h" |
| 39 #include "content/public/browser/notification_details.h" | 40 #include "content/public/browser/notification_details.h" |
| 40 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
| 41 #include "content/public/browser/notification_source.h" | 42 #include "content/public/browser/notification_source.h" |
| 42 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/common/url_constants.h" | 44 #include "content/public/common/url_constants.h" |
| 44 #include "jni/AutocompleteController_jni.h" | 45 #include "jni/AutocompleteController_jni.h" |
| 45 #include "net/base/escape.h" | 46 #include "net/base/escape.h" |
| 46 #include "net/base/net_util.h" | 47 #include "net/base/net_util.h" |
| 47 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 48 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 48 #include "ui/base/resource/resource_bundle.h" | 49 #include "ui/base/resource/resource_bundle.h" |
| 49 | 50 |
| 50 using base::android::AttachCurrentThread; | 51 using base::android::AttachCurrentThread; |
| 51 using base::android::ConvertJavaStringToUTF16; | 52 using base::android::ConvertJavaStringToUTF16; |
| 52 using base::android::ConvertUTF8ToJavaString; | 53 using base::android::ConvertUTF8ToJavaString; |
| 53 using base::android::ConvertUTF16ToJavaString; | 54 using base::android::ConvertUTF16ToJavaString; |
| 55 using metrics::OmniboxEventProto; |
| 54 | 56 |
| 55 namespace { | 57 namespace { |
| 56 | 58 |
| 57 const int kAndroidAutocompleteProviders = | 59 const int kAndroidAutocompleteProviders = |
| 58 AutocompleteClassifier::kDefaultOmniboxProviders; | 60 AutocompleteClassifier::kDefaultOmniboxProviders; |
| 59 | 61 |
| 60 /** | 62 /** |
| 61 * A prefetcher class responsible for triggering zero suggest prefetch. | 63 * A prefetcher class responsible for triggering zero suggest prefetch. |
| 62 * The prefetch occurs as a side-effect of calling StartZeroSuggest() on | 64 * The prefetch occurs as a side-effect of calling StartZeroSuggest() on |
| 63 * the AutocompleteController object. | 65 * the AutocompleteController object. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 82 AutocompleteProvider::TYPE_ZERO_SUGGEST)) { | 84 AutocompleteProvider::TYPE_ZERO_SUGGEST)) { |
| 83 // Creating an arbitrary fake_request_source to avoid passing in an invalid | 85 // Creating an arbitrary fake_request_source to avoid passing in an invalid |
| 84 // AutocompleteInput object. | 86 // AutocompleteInput object. |
| 85 base::string16 fake_request_source(base::ASCIIToUTF16( | 87 base::string16 fake_request_source(base::ASCIIToUTF16( |
| 86 "http://www.foobarbazblah.com")); | 88 "http://www.foobarbazblah.com")); |
| 87 controller_->StartZeroSuggest(AutocompleteInput( | 89 controller_->StartZeroSuggest(AutocompleteInput( |
| 88 fake_request_source, | 90 fake_request_source, |
| 89 base::string16::npos, | 91 base::string16::npos, |
| 90 base::string16(), | 92 base::string16(), |
| 91 GURL(fake_request_source), | 93 GURL(fake_request_source), |
| 92 AutocompleteInput::INVALID_SPEC, | 94 OmniboxEventProto::INVALID_SPEC, |
| 93 false, | 95 false, |
| 94 false, | 96 false, |
| 95 true, | 97 true, |
| 96 true)); | 98 true)); |
| 97 // Delete ourselves after 10s. This is enough time to cache results or | 99 // Delete ourselves after 10s. This is enough time to cache results or |
| 98 // give up if the results haven't been received. | 100 // give up if the results haven't been received. |
| 99 expire_timer_.Start(FROM_HERE, | 101 expire_timer_.Start(FROM_HERE, |
| 100 base::TimeDelta::FromMilliseconds(10000), | 102 base::TimeDelta::FromMilliseconds(10000), |
| 101 this, &ZeroSuggestPrefetcher::SelfDestruct); | 103 this, &ZeroSuggestPrefetcher::SelfDestruct); |
| 102 } | 104 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if (!autocomplete_controller_) | 137 if (!autocomplete_controller_) |
| 136 return; | 138 return; |
| 137 | 139 |
| 138 base::string16 desired_tld; | 140 base::string16 desired_tld; |
| 139 GURL current_url; | 141 GURL current_url; |
| 140 if (j_current_url != NULL) | 142 if (j_current_url != NULL) |
| 141 current_url = GURL(ConvertJavaStringToUTF16(env, j_current_url)); | 143 current_url = GURL(ConvertJavaStringToUTF16(env, j_current_url)); |
| 142 if (j_desired_tld != NULL) | 144 if (j_desired_tld != NULL) |
| 143 desired_tld = ConvertJavaStringToUTF16(env, j_desired_tld); | 145 desired_tld = ConvertJavaStringToUTF16(env, j_desired_tld); |
| 144 base::string16 text = ConvertJavaStringToUTF16(env, j_text); | 146 base::string16 text = ConvertJavaStringToUTF16(env, j_text); |
| 145 AutocompleteInput::PageClassification page_classification = | 147 OmniboxEventProto::PageClassification page_classification = |
| 146 AutocompleteInput::OTHER; | 148 OmniboxEventProto::OTHER; |
| 147 input_ = AutocompleteInput(text, | 149 input_ = AutocompleteInput(text, |
| 148 base::string16::npos, | 150 base::string16::npos, |
| 149 desired_tld, | 151 desired_tld, |
| 150 current_url, | 152 current_url, |
| 151 page_classification, | 153 page_classification, |
| 152 prevent_inline_autocomplete, | 154 prevent_inline_autocomplete, |
| 153 prefer_keyword, | 155 prefer_keyword, |
| 154 allow_exact_keyword_match, | 156 allow_exact_keyword_match, |
| 155 want_asynchronous_matches); | 157 want_asynchronous_matches); |
| 156 autocomplete_controller_->Start(input_); | 158 autocomplete_controller_->Start(input_); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 JNIEnv* env, | 207 JNIEnv* env, |
| 206 jobject obj, | 208 jobject obj, |
| 207 jint selected_index, | 209 jint selected_index, |
| 208 jstring j_current_url, | 210 jstring j_current_url, |
| 209 jboolean is_query_in_omnibox, | 211 jboolean is_query_in_omnibox, |
| 210 jboolean focused_from_fakebox, | 212 jboolean focused_from_fakebox, |
| 211 jlong elapsed_time_since_first_modified, | 213 jlong elapsed_time_since_first_modified, |
| 212 jobject j_web_contents) { | 214 jobject j_web_contents) { |
| 213 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url); | 215 base::string16 url = ConvertJavaStringToUTF16(env, j_current_url); |
| 214 const GURL current_url = GURL(url); | 216 const GURL current_url = GURL(url); |
| 215 AutocompleteInput::PageClassification current_page_classification = | 217 OmniboxEventProto::PageClassification current_page_classification = |
| 216 ClassifyPage(current_url, is_query_in_omnibox, focused_from_fakebox); | 218 ClassifyPage(current_url, is_query_in_omnibox, focused_from_fakebox); |
| 217 const base::TimeTicks& now(base::TimeTicks::Now()); | 219 const base::TimeTicks& now(base::TimeTicks::Now()); |
| 218 content::WebContents* web_contents = | 220 content::WebContents* web_contents = |
| 219 content::WebContents::FromJavaWebContents(j_web_contents); | 221 content::WebContents::FromJavaWebContents(j_web_contents); |
| 220 | 222 |
| 221 OmniboxLog log( | 223 OmniboxLog log( |
| 222 input_.text(), | 224 input_.text(), |
| 223 false, /* don't know */ | 225 false, /* don't know */ |
| 224 input_.type(), | 226 input_.type(), |
| 225 true, | 227 true, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 ConvertUTF16ToJavaString(env, inline_autocomplete_text); | 392 ConvertUTF16ToJavaString(env, inline_autocomplete_text); |
| 391 jlong j_autocomplete_result = | 393 jlong j_autocomplete_result = |
| 392 reinterpret_cast<intptr_t>(&(autocomplete_result)); | 394 reinterpret_cast<intptr_t>(&(autocomplete_result)); |
| 393 Java_AutocompleteController_onSuggestionsReceived(env, | 395 Java_AutocompleteController_onSuggestionsReceived(env, |
| 394 java_bridge.obj(), | 396 java_bridge.obj(), |
| 395 suggestion_list_obj.obj(), | 397 suggestion_list_obj.obj(), |
| 396 inline_text.obj(), | 398 inline_text.obj(), |
| 397 j_autocomplete_result); | 399 j_autocomplete_result); |
| 398 } | 400 } |
| 399 | 401 |
| 400 AutocompleteInput::PageClassification | 402 OmniboxEventProto::PageClassification |
| 401 AutocompleteControllerAndroid::ClassifyPage(const GURL& gurl, | 403 AutocompleteControllerAndroid::ClassifyPage(const GURL& gurl, |
| 402 bool is_query_in_omnibox, | 404 bool is_query_in_omnibox, |
| 403 bool focused_from_fakebox) const { | 405 bool focused_from_fakebox) const { |
| 404 if (!gurl.is_valid()) | 406 if (!gurl.is_valid()) |
| 405 return AutocompleteInput::INVALID_SPEC; | 407 return OmniboxEventProto::INVALID_SPEC; |
| 406 | 408 |
| 407 const std::string& url = gurl.spec(); | 409 const std::string& url = gurl.spec(); |
| 408 | 410 |
| 409 if (gurl.SchemeIs(content::kChromeUIScheme) && | 411 if (gurl.SchemeIs(content::kChromeUIScheme) && |
| 410 gurl.host() == chrome::kChromeUINewTabHost) { | 412 gurl.host() == chrome::kChromeUINewTabHost) { |
| 411 return AutocompleteInput::NTP; | 413 return OmniboxEventProto::NTP; |
| 412 } | 414 } |
| 413 | 415 |
| 414 if (url == chrome::kChromeUINativeNewTabURL) { | 416 if (url == chrome::kChromeUINativeNewTabURL) { |
| 415 return focused_from_fakebox ? | 417 return focused_from_fakebox ? |
| 416 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS : | 418 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS : |
| 417 AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS; | 419 OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS; |
| 418 } | 420 } |
| 419 | 421 |
| 420 if (url == url::kAboutBlankURL) | 422 if (url == url::kAboutBlankURL) |
| 421 return AutocompleteInput::BLANK; | 423 return OmniboxEventProto::BLANK; |
| 422 | 424 |
| 423 if (url == profile_->GetPrefs()->GetString(prefs::kHomePage)) | 425 if (url == profile_->GetPrefs()->GetString(prefs::kHomePage)) |
| 424 return AutocompleteInput::HOME_PAGE; | 426 return OmniboxEventProto::HOME_PAGE; |
| 425 | 427 |
| 426 if (is_query_in_omnibox) | 428 if (is_query_in_omnibox) |
| 427 return AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT; | 429 return OmniboxEventProto::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT; |
| 428 | 430 |
| 429 bool is_search_url = TemplateURLServiceFactory::GetForProfile(profile_)-> | 431 bool is_search_url = TemplateURLServiceFactory::GetForProfile(profile_)-> |
| 430 IsSearchResultsPageFromDefaultSearchProvider(gurl); | 432 IsSearchResultsPageFromDefaultSearchProvider(gurl); |
| 431 if (is_search_url) | 433 if (is_search_url) |
| 432 return AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT; | 434 return OmniboxEventProto::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT; |
| 433 | 435 |
| 434 return AutocompleteInput::OTHER; | 436 return OmniboxEventProto::OTHER; |
| 435 } | 437 } |
| 436 | 438 |
| 437 ScopedJavaLocalRef<jobject> | 439 ScopedJavaLocalRef<jobject> |
| 438 AutocompleteControllerAndroid::BuildOmniboxSuggestion( | 440 AutocompleteControllerAndroid::BuildOmniboxSuggestion( |
| 439 JNIEnv* env, | 441 JNIEnv* env, |
| 440 const AutocompleteMatch& match) { | 442 const AutocompleteMatch& match) { |
| 441 ScopedJavaLocalRef<jstring> contents = | 443 ScopedJavaLocalRef<jstring> contents = |
| 442 ConvertUTF16ToJavaString(env, match.contents); | 444 ConvertUTF16ToJavaString(env, match.contents); |
| 443 ScopedJavaLocalRef<jstring> description = | 445 ScopedJavaLocalRef<jstring> description = |
| 444 ConvertUTF16ToJavaString(env, match.description); | 446 ConvertUTF16ToJavaString(env, match.description); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 JNIEnv* env, jclass clazz, jstring jquery) { | 525 JNIEnv* env, jclass clazz, jstring jquery) { |
| 524 Profile* profile = ProfileManager::GetActiveUserProfile(); | 526 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 525 if (!profile) | 527 if (!profile) |
| 526 return NULL; | 528 return NULL; |
| 527 AutocompleteMatch match; | 529 AutocompleteMatch match; |
| 528 base::string16 query_string(ConvertJavaStringToUTF16(env, jquery)); | 530 base::string16 query_string(ConvertJavaStringToUTF16(env, jquery)); |
| 529 AutocompleteClassifierFactory::GetForProfile(profile)->Classify( | 531 AutocompleteClassifierFactory::GetForProfile(profile)->Classify( |
| 530 query_string, | 532 query_string, |
| 531 false, | 533 false, |
| 532 false, | 534 false, |
| 533 AutocompleteInput::INVALID_SPEC, | 535 OmniboxEventProto::INVALID_SPEC, |
| 534 &match, | 536 &match, |
| 535 NULL); | 537 NULL); |
| 536 if (!match.destination_url.is_valid()) | 538 if (!match.destination_url.is_valid()) |
| 537 return NULL; | 539 return NULL; |
| 538 | 540 |
| 539 // Only return a URL if the match is a URL type. | 541 // Only return a URL if the match is a URL type. |
| 540 if (match.type != AutocompleteMatchType::URL_WHAT_YOU_TYPED && | 542 if (match.type != AutocompleteMatchType::URL_WHAT_YOU_TYPED && |
| 541 match.type != AutocompleteMatchType::HISTORY_URL && | 543 match.type != AutocompleteMatchType::HISTORY_URL && |
| 542 match.type != AutocompleteMatchType::NAVSUGGEST) | 544 match.type != AutocompleteMatchType::NAVSUGGEST) |
| 543 return NULL; | 545 return NULL; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 555 return; | 557 return; |
| 556 | 558 |
| 557 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. | 559 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. |
| 558 new ZeroSuggestPrefetcher(profile); | 560 new ZeroSuggestPrefetcher(profile); |
| 559 } | 561 } |
| 560 | 562 |
| 561 // Register native methods | 563 // Register native methods |
| 562 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { | 564 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { |
| 563 return RegisterNativesImpl(env); | 565 return RegisterNativesImpl(env); |
| 564 } | 566 } |
| OLD | NEW |