| 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_page_handler.h" | 5 #include "chrome/browser/ui/webui/omnibox/omnibox_page_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "components/bookmarks/browser/bookmark_model.h" | 26 #include "components/bookmarks/browser/bookmark_model.h" |
| 27 #include "components/history/core/browser/history_service.h" | 27 #include "components/history/core/browser/history_service.h" |
| 28 #include "components/history/core/browser/url_database.h" | 28 #include "components/history/core/browser/url_database.h" |
| 29 #include "components/metrics/proto/omnibox_event.pb.h" | 29 #include "components/metrics/proto/omnibox_event.pb.h" |
| 30 #include "components/omnibox/browser/autocomplete_classifier.h" | 30 #include "components/omnibox/browser/autocomplete_classifier.h" |
| 31 #include "components/omnibox/browser/autocomplete_controller.h" | 31 #include "components/omnibox/browser/autocomplete_controller.h" |
| 32 #include "components/omnibox/browser/autocomplete_match.h" | 32 #include "components/omnibox/browser/autocomplete_match.h" |
| 33 #include "components/omnibox/browser/autocomplete_provider.h" | 33 #include "components/omnibox/browser/autocomplete_provider.h" |
| 34 #include "components/search_engines/template_url.h" | 34 #include "components/search_engines/template_url.h" |
| 35 #include "content/public/browser/web_ui.h" | 35 #include "content/public/browser/web_ui.h" |
| 36 #include "mojo/common/common_type_converters.h" | |
| 37 | 36 |
| 38 using bookmarks::BookmarkModel; | 37 using bookmarks::BookmarkModel; |
| 39 | 38 |
| 40 namespace mojo { | 39 namespace mojo { |
| 41 | 40 |
| 42 template <> | 41 template <> |
| 43 struct TypeConverter<mojo::Array<mojom::AutocompleteAdditionalInfoPtr>, | 42 struct TypeConverter<std::vector<mojom::AutocompleteAdditionalInfoPtr>, |
| 44 AutocompleteMatch::AdditionalInfo> { | 43 AutocompleteMatch::AdditionalInfo> { |
| 45 static mojo::Array<mojom::AutocompleteAdditionalInfoPtr> Convert( | 44 static std::vector<mojom::AutocompleteAdditionalInfoPtr> Convert( |
| 46 const AutocompleteMatch::AdditionalInfo& input) { | 45 const AutocompleteMatch::AdditionalInfo& input) { |
| 47 mojo::Array<mojom::AutocompleteAdditionalInfoPtr> array(input.size()); | 46 std::vector<mojom::AutocompleteAdditionalInfoPtr> array(input.size()); |
| 48 size_t index = 0; | 47 size_t index = 0; |
| 49 for (AutocompleteMatch::AdditionalInfo::const_iterator i = input.begin(); | 48 for (AutocompleteMatch::AdditionalInfo::const_iterator i = input.begin(); |
| 50 i != input.end(); ++i, index++) { | 49 i != input.end(); ++i, index++) { |
| 51 mojom::AutocompleteAdditionalInfoPtr item( | 50 mojom::AutocompleteAdditionalInfoPtr item( |
| 52 mojom::AutocompleteAdditionalInfo::New()); | 51 mojom::AutocompleteAdditionalInfo::New()); |
| 53 item->key = i->first; | 52 item->key = i->first; |
| 54 item->value = i->second; | 53 item->value = i->second; |
| 55 array[index] = std::move(item); | 54 array[index] = std::move(item); |
| 56 } | 55 } |
| 57 return array; | 56 return array; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 85 result->type = AutocompleteMatchType::ToString(input.type); | 84 result->type = AutocompleteMatchType::ToString(input.type); |
| 86 if (input.associated_keyword.get() != NULL) { | 85 if (input.associated_keyword.get() != NULL) { |
| 87 result->associated_keyword = | 86 result->associated_keyword = |
| 88 base::UTF16ToUTF8(input.associated_keyword->keyword); | 87 base::UTF16ToUTF8(input.associated_keyword->keyword); |
| 89 } | 88 } |
| 90 result->keyword = base::UTF16ToUTF8(input.keyword); | 89 result->keyword = base::UTF16ToUTF8(input.keyword); |
| 91 result->duplicates = static_cast<int32_t>(input.duplicate_matches.size()); | 90 result->duplicates = static_cast<int32_t>(input.duplicate_matches.size()); |
| 92 result->from_previous = input.from_previous; | 91 result->from_previous = input.from_previous; |
| 93 | 92 |
| 94 result->additional_info = | 93 result->additional_info = |
| 95 mojo::Array<mojom::AutocompleteAdditionalInfoPtr>::From( | 94 mojo::ConvertTo<std::vector<mojom::AutocompleteAdditionalInfoPtr>>( |
| 96 input.additional_info) | 95 input.additional_info); |
| 97 .PassStorage(); | |
| 98 return result; | 96 return result; |
| 99 } | 97 } |
| 100 }; | 98 }; |
| 101 | 99 |
| 102 template <> | 100 template <> |
| 103 struct TypeConverter<mojom::AutocompleteResultsForProviderPtr, | 101 struct TypeConverter<mojom::AutocompleteResultsForProviderPtr, |
| 104 scoped_refptr<AutocompleteProvider>> { | 102 scoped_refptr<AutocompleteProvider>> { |
| 105 static mojom::AutocompleteResultsForProviderPtr Convert( | 103 static mojom::AutocompleteResultsForProviderPtr Convert( |
| 106 const scoped_refptr<AutocompleteProvider>& input) { | 104 const scoped_refptr<AutocompleteProvider>& input) { |
| 107 mojom::AutocompleteResultsForProviderPtr result( | 105 mojom::AutocompleteResultsForProviderPtr result( |
| 108 mojom::AutocompleteResultsForProvider::New()); | 106 mojom::AutocompleteResultsForProvider::New()); |
| 109 result->provider_name = input->GetName(); | 107 result->provider_name = input->GetName(); |
| 110 result->results = | 108 result->results = mojo::ConvertTo<std::vector<mojom::AutocompleteMatchPtr>>( |
| 111 mojo::Array<mojom::AutocompleteMatchPtr>::From(input->matches()) | 109 input->matches()); |
| 112 .PassStorage(); | |
| 113 return result; | 110 return result; |
| 114 } | 111 } |
| 115 }; | 112 }; |
| 116 | 113 |
| 117 } // namespace mojo | 114 } // namespace mojo |
| 118 | 115 |
| 119 OmniboxPageHandler::OmniboxPageHandler( | 116 OmniboxPageHandler::OmniboxPageHandler( |
| 120 Profile* profile, | 117 Profile* profile, |
| 121 mojo::InterfaceRequest<mojom::OmniboxPageHandler> request) | 118 mojo::InterfaceRequest<mojom::OmniboxPageHandler> request) |
| 122 : profile_(profile), binding_(this, std::move(request)) { | 119 : profile_(profile), binding_(this, std::move(request)) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 137 if (!LookupIsTypedHost(host, &is_typed_host)) | 134 if (!LookupIsTypedHost(host, &is_typed_host)) |
| 138 is_typed_host = false; | 135 is_typed_host = false; |
| 139 result->is_typed_host = is_typed_host; | 136 result->is_typed_host = is_typed_host; |
| 140 | 137 |
| 141 { | 138 { |
| 142 // Copy to an ACMatches to make conversion easier. Since this isn't | 139 // Copy to an ACMatches to make conversion easier. Since this isn't |
| 143 // performance critical we don't worry about the cost here. | 140 // performance critical we don't worry about the cost here. |
| 144 ACMatches matches(controller_->result().begin(), | 141 ACMatches matches(controller_->result().begin(), |
| 145 controller_->result().end()); | 142 controller_->result().end()); |
| 146 result->combined_results = | 143 result->combined_results = |
| 147 mojo::Array<mojom::AutocompleteMatchPtr>::From(matches).PassStorage(); | 144 mojo::ConvertTo<std::vector<mojom::AutocompleteMatchPtr>>(matches); |
| 148 } | 145 } |
| 149 result->results_by_provider = | 146 result->results_by_provider = |
| 150 mojo::Array<mojom::AutocompleteResultsForProviderPtr>::From( | 147 mojo::ConvertTo<std::vector<mojom::AutocompleteResultsForProviderPtr>>( |
| 151 controller_->providers()) | 148 controller_->providers()); |
| 152 .PassStorage(); | |
| 153 | 149 |
| 154 // Fill AutocompleteMatch::starred. | 150 // Fill AutocompleteMatch::starred. |
| 155 BookmarkModel* bookmark_model = | 151 BookmarkModel* bookmark_model = |
| 156 BookmarkModelFactory::GetForBrowserContext(profile_); | 152 BookmarkModelFactory::GetForBrowserContext(profile_); |
| 157 if (bookmark_model) { | 153 if (bookmark_model) { |
| 158 for (size_t i = 0; i < result->combined_results.size(); ++i) { | 154 for (size_t i = 0; i < result->combined_results.size(); ++i) { |
| 159 result->combined_results[i]->starred = bookmark_model->IsBookmarked( | 155 result->combined_results[i]->starred = bookmark_model->IsBookmarked( |
| 160 GURL(result->combined_results[i]->destination_url)); | 156 GURL(result->combined_results[i]->destination_url)); |
| 161 } | 157 } |
| 162 for (size_t i = 0; i < result->results_by_provider.size(); ++i) { | 158 for (size_t i = 0; i < result->results_by_provider.size(); ++i) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 prevent_inline_autocomplete, prefer_keyword, true, true, false, | 205 prevent_inline_autocomplete, prefer_keyword, true, true, false, |
| 210 ChromeAutocompleteSchemeClassifier(profile_)); | 206 ChromeAutocompleteSchemeClassifier(profile_)); |
| 211 controller_->Start(input_); | 207 controller_->Start(input_); |
| 212 } | 208 } |
| 213 | 209 |
| 214 void OmniboxPageHandler::ResetController() { | 210 void OmniboxPageHandler::ResetController() { |
| 215 controller_.reset(new AutocompleteController( | 211 controller_.reset(new AutocompleteController( |
| 216 base::MakeUnique<ChromeAutocompleteProviderClient>(profile_), this, | 212 base::MakeUnique<ChromeAutocompleteProviderClient>(profile_), this, |
| 217 AutocompleteClassifier::kDefaultOmniboxProviders)); | 213 AutocompleteClassifier::kDefaultOmniboxProviders)); |
| 218 } | 214 } |
| OLD | NEW |