| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/omnibox/omnibox_ui_handler.h" | 5 #include "chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 16 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 17 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_match.h" | 18 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 19 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 21 #include "chrome/browser/history/history_service.h" | 22 #include "chrome/browser/history/history_service.h" |
| 22 #include "chrome/browser/history/history_service_factory.h" | 23 #include "chrome/browser/history/history_service_factory.h" |
| 23 #include "chrome/browser/search/search.h" | 24 #include "chrome/browser/search/search.h" |
| 24 #include "chrome/browser/search_engines/template_url_service_factory.h" | 25 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 26 #include "components/bookmarks/browser/bookmark_model.h" |
| 25 #include "components/history/core/browser/url_database.h" | 27 #include "components/history/core/browser/url_database.h" |
| 26 #include "components/metrics/proto/omnibox_event.pb.h" | 28 #include "components/metrics/proto/omnibox_event.pb.h" |
| 27 #include "components/search_engines/template_url.h" | 29 #include "components/search_engines/template_url.h" |
| 28 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 29 #include "mojo/common/common_type_converters.h" | 31 #include "mojo/common/common_type_converters.h" |
| 30 | 32 |
| 31 namespace mojo { | 33 namespace mojo { |
| 32 | 34 |
| 33 template <> | 35 template <> |
| 34 class TypeConverter<mojo::Array<AutocompleteAdditionalInfoPtr>, | 36 class TypeConverter<mojo::Array<AutocompleteAdditionalInfoPtr>, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 result->transition = input.transition; | 77 result->transition = input.transition; |
| 76 result->is_history_what_you_typed_match = | 78 result->is_history_what_you_typed_match = |
| 77 input.is_history_what_you_typed_match; | 79 input.is_history_what_you_typed_match; |
| 78 result->allowed_to_be_default_match = input.allowed_to_be_default_match; | 80 result->allowed_to_be_default_match = input.allowed_to_be_default_match; |
| 79 result->type = AutocompleteMatchType::ToString(input.type); | 81 result->type = AutocompleteMatchType::ToString(input.type); |
| 80 if (input.associated_keyword.get() != NULL) { | 82 if (input.associated_keyword.get() != NULL) { |
| 81 result->associated_keyword = | 83 result->associated_keyword = |
| 82 mojo::String::From(input.associated_keyword->keyword); | 84 mojo::String::From(input.associated_keyword->keyword); |
| 83 } | 85 } |
| 84 result->keyword = mojo::String::From(input.keyword); | 86 result->keyword = mojo::String::From(input.keyword); |
| 85 result->starred = input.starred; | |
| 86 result->duplicates = static_cast<int32>(input.duplicate_matches.size()); | 87 result->duplicates = static_cast<int32>(input.duplicate_matches.size()); |
| 87 result->from_previous = input.from_previous; | 88 result->from_previous = input.from_previous; |
| 88 | 89 |
| 89 result->additional_info = | 90 result->additional_info = |
| 90 mojo::Array<AutocompleteAdditionalInfoPtr>::From(input.additional_info); | 91 mojo::Array<AutocompleteAdditionalInfoPtr>::From(input.additional_info); |
| 91 return result.Pass(); | 92 return result.Pass(); |
| 92 } | 93 } |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 template <> | 96 template <> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // Copy to an ACMatches to make conversion easier. Since this isn't | 135 // Copy to an ACMatches to make conversion easier. Since this isn't |
| 135 // performance critical we don't worry about the cost here. | 136 // performance critical we don't worry about the cost here. |
| 136 ACMatches matches(controller_->result().begin(), | 137 ACMatches matches(controller_->result().begin(), |
| 137 controller_->result().end()); | 138 controller_->result().end()); |
| 138 result->combined_results = | 139 result->combined_results = |
| 139 mojo::Array<AutocompleteMatchMojoPtr>::From(matches); | 140 mojo::Array<AutocompleteMatchMojoPtr>::From(matches); |
| 140 } | 141 } |
| 141 result->results_by_provider = | 142 result->results_by_provider = |
| 142 mojo::Array<AutocompleteResultsForProviderMojoPtr>::From( | 143 mojo::Array<AutocompleteResultsForProviderMojoPtr>::From( |
| 143 controller_->providers()); | 144 controller_->providers()); |
| 145 |
| 146 // Fill AutocompleteMatchMojo::starred. |
| 147 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); |
| 148 if (bookmark_model) { |
| 149 for (size_t i = 0; i < result->combined_results.size(); ++i) { |
| 150 result->combined_results[i]->starred = bookmark_model->IsBookmarked( |
| 151 GURL(result->combined_results[i]->destination_url)); |
| 152 } |
| 153 for (size_t i = 0; i < result->results_by_provider.size(); ++i) { |
| 154 const AutocompleteResultsForProviderMojo& result_by_provider = |
| 155 *result->results_by_provider[i]; |
| 156 for (size_t j = 0; j < result_by_provider.results.size(); ++j) { |
| 157 result_by_provider.results[j]->starred = bookmark_model->IsBookmarked( |
| 158 GURL(result_by_provider.results[j]->destination_url)); |
| 159 } |
| 160 } |
| 161 } |
| 162 |
| 144 client()->HandleNewAutocompleteResult(result.Pass()); | 163 client()->HandleNewAutocompleteResult(result.Pass()); |
| 145 } | 164 } |
| 146 | 165 |
| 147 bool OmniboxUIHandler::LookupIsTypedHost(const base::string16& host, | 166 bool OmniboxUIHandler::LookupIsTypedHost(const base::string16& host, |
| 148 bool* is_typed_host) const { | 167 bool* is_typed_host) const { |
| 149 HistoryService* const history_service = | 168 HistoryService* const history_service = |
| 150 HistoryServiceFactory::GetForProfile(profile_, | 169 HistoryServiceFactory::GetForProfile(profile_, |
| 151 Profile::EXPLICIT_ACCESS); | 170 Profile::EXPLICIT_ACCESS); |
| 152 if (!history_service) | 171 if (!history_service) |
| 153 return false; | 172 return false; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 179 ChromeAutocompleteSchemeClassifier(profile_)); | 198 ChromeAutocompleteSchemeClassifier(profile_)); |
| 180 controller_->Start(input_); | 199 controller_->Start(input_); |
| 181 } | 200 } |
| 182 | 201 |
| 183 void OmniboxUIHandler::ResetController() { | 202 void OmniboxUIHandler::ResetController() { |
| 184 controller_.reset(new AutocompleteController(profile_, | 203 controller_.reset(new AutocompleteController(profile_, |
| 185 TemplateURLServiceFactory::GetForProfile(profile_), | 204 TemplateURLServiceFactory::GetForProfile(profile_), |
| 186 this, | 205 this, |
| 187 AutocompleteClassifier::kDefaultOmniboxProviders)); | 206 AutocompleteClassifier::kDefaultOmniboxProviders)); |
| 188 } | 207 } |
| OLD | NEW |