| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 14 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 15 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 16 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 16 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_match.h" | 17 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 18 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 18 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 19 #include "chrome/browser/autocomplete/search_provider.h" | 19 #include "chrome/browser/autocomplete/search_provider.h" |
| 20 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 20 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
| 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
| 23 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 24 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 24 #include "chrome/browser/omnibox/omnibox_log.h" | 25 #include "chrome/browser/omnibox/omnibox_log.h" |
| 25 #include "chrome/browser/profiles/incognito_helpers.h" | 26 #include "chrome/browser/profiles/incognito_helpers.h" |
| 26 #include "chrome/browser/profiles/profile_android.h" | 27 #include "chrome/browser/profiles/profile_android.h" |
| 27 #include "chrome/browser/profiles/profile_manager.h" | 28 #include "chrome/browser/profiles/profile_manager.h" |
| 28 #include "chrome/browser/search/search.h" | 29 #include "chrome/browser/search/search.h" |
| 29 #include "chrome/browser/search_engines/template_url_service_factory.h" | 30 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 30 #include "chrome/browser/sessions/session_id.h" | 31 #include "chrome/browser/sessions/session_id.h" |
| 31 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | 32 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
| 32 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 33 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 33 #include "chrome/common/instant_types.h" | 34 #include "chrome/common/instant_types.h" |
| 34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
| 36 #include "components/autocomplete/autocomplete_input.h" | 37 #include "components/autocomplete/autocomplete_input.h" |
| 37 #include "components/autocomplete/autocomplete_match_type.h" | 38 #include "components/autocomplete/autocomplete_match_type.h" |
| 39 #include "components/bookmarks/browser/bookmark_model.h" |
| 38 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 40 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 39 #include "components/metrics/proto/omnibox_event.pb.h" | 41 #include "components/metrics/proto/omnibox_event.pb.h" |
| 40 #include "components/search/search.h" | 42 #include "components/search/search.h" |
| 41 #include "components/search_engines/template_url_service.h" | 43 #include "components/search_engines/template_url_service.h" |
| 42 #include "content/public/browser/notification_details.h" | 44 #include "content/public/browser/notification_details.h" |
| 43 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
| 44 #include "content/public/browser/notification_source.h" | 46 #include "content/public/browser/notification_source.h" |
| 45 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
| 46 #include "content/public/common/url_constants.h" | 48 #include "content/public/common/url_constants.h" |
| 47 #include "jni/AutocompleteController_jni.h" | 49 #include "jni/AutocompleteController_jni.h" |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 ConvertUTF16ToJavaString(env, match.answer_contents); | 443 ConvertUTF16ToJavaString(env, match.answer_contents); |
| 442 ScopedJavaLocalRef<jstring> answer_type = | 444 ScopedJavaLocalRef<jstring> answer_type = |
| 443 ConvertUTF16ToJavaString(env, match.answer_type); | 445 ConvertUTF16ToJavaString(env, match.answer_type); |
| 444 ScopedJavaLocalRef<jstring> fill_into_edit = | 446 ScopedJavaLocalRef<jstring> fill_into_edit = |
| 445 ConvertUTF16ToJavaString(env, match.fill_into_edit); | 447 ConvertUTF16ToJavaString(env, match.fill_into_edit); |
| 446 ScopedJavaLocalRef<jstring> destination_url = | 448 ScopedJavaLocalRef<jstring> destination_url = |
| 447 ConvertUTF8ToJavaString(env, match.destination_url.spec()); | 449 ConvertUTF8ToJavaString(env, match.destination_url.spec()); |
| 448 // Note that we are also removing 'www' host from formatted url. | 450 // Note that we are also removing 'www' host from formatted url. |
| 449 ScopedJavaLocalRef<jstring> formatted_url = ConvertUTF16ToJavaString(env, | 451 ScopedJavaLocalRef<jstring> formatted_url = ConvertUTF16ToJavaString(env, |
| 450 FormatURLUsingAcceptLanguages(match.stripped_destination_url)); | 452 FormatURLUsingAcceptLanguages(match.stripped_destination_url)); |
| 453 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); |
| 451 return Java_AutocompleteController_buildOmniboxSuggestion( | 454 return Java_AutocompleteController_buildOmniboxSuggestion( |
| 452 env, | 455 env, |
| 453 match.type, | 456 match.type, |
| 454 match.relevance, | 457 match.relevance, |
| 455 match.transition, | 458 match.transition, |
| 456 contents.obj(), | 459 contents.obj(), |
| 457 description.obj(), | 460 description.obj(), |
| 458 answer_contents.obj(), | 461 answer_contents.obj(), |
| 459 answer_type.obj(), | 462 answer_type.obj(), |
| 460 fill_into_edit.obj(), | 463 fill_into_edit.obj(), |
| 461 destination_url.obj(), | 464 destination_url.obj(), |
| 462 formatted_url.obj(), | 465 formatted_url.obj(), |
| 463 match.starred, | 466 bookmark_model && bookmark_model->IsBookmarked(match.destination_url), |
| 464 match.SupportsDeletion()); | 467 match.SupportsDeletion()); |
| 465 } | 468 } |
| 466 | 469 |
| 467 base::string16 AutocompleteControllerAndroid::FormatURLUsingAcceptLanguages( | 470 base::string16 AutocompleteControllerAndroid::FormatURLUsingAcceptLanguages( |
| 468 GURL url) { | 471 GURL url) { |
| 469 if (profile_ == NULL) | 472 if (profile_ == NULL) |
| 470 return base::string16(); | 473 return base::string16(); |
| 471 | 474 |
| 472 std::string languages( | 475 std::string languages( |
| 473 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 476 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 return; | 553 return; |
| 551 | 554 |
| 552 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. | 555 // ZeroSuggestPrefetcher deletes itself after it's done prefetching. |
| 553 new ZeroSuggestPrefetcher(profile); | 556 new ZeroSuggestPrefetcher(profile); |
| 554 } | 557 } |
| 555 | 558 |
| 556 // Register native methods | 559 // Register native methods |
| 557 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { | 560 bool RegisterAutocompleteControllerAndroid(JNIEnv* env) { |
| 558 return RegisterNativesImpl(env); | 561 return RegisterNativesImpl(env); |
| 559 } | 562 } |
| OLD | NEW |