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 "components/omnibox/browser/bookmark_provider.h" | 5 #include "components/omnibox/browser/bookmark_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "components/bookmarks/browser/bookmark_match.h" | 14 #include "components/bookmarks/browser/bookmark_match.h" |
15 #include "components/bookmarks/browser/bookmark_model.h" | 15 #include "components/bookmarks/browser/bookmark_model.h" |
16 #include "components/metrics/proto/omnibox_input_type.pb.h" | 16 #include "components/metrics/proto/omnibox_input_type.pb.h" |
17 #include "components/omnibox/browser/autocomplete_provider_client.h" | 17 #include "components/omnibox/browser/autocomplete_provider_client.h" |
18 #include "components/omnibox/browser/autocomplete_result.h" | 18 #include "components/omnibox/browser/autocomplete_result.h" |
19 #include "components/omnibox/browser/history_provider.h" | 19 #include "components/omnibox/browser/history_provider.h" |
20 #include "components/omnibox/browser/url_prefix.h" | 20 #include "components/omnibox/browser/url_prefix.h" |
21 #include "net/base/net_util.h" | 21 #include "components/url_formatter/url_formatter.h" |
22 #include "url/url_constants.h" | 22 #include "url/url_constants.h" |
23 | 23 |
24 using bookmarks::BookmarkMatch; | 24 using bookmarks::BookmarkMatch; |
25 using bookmarks::BookmarkNode; | 25 using bookmarks::BookmarkNode; |
26 | 26 |
27 typedef std::vector<BookmarkMatch> BookmarkMatches; | 27 typedef std::vector<BookmarkMatch> BookmarkMatches; |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Removes leading spaces from |title| before displaying, otherwise it looks | 31 // Removes leading spaces from |title| before displaying, otherwise it looks |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 0 : bookmark_match.url_match_positions[0].first; | 181 0 : bookmark_match.url_match_positions[0].first; |
182 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()) && | 182 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()) && |
183 ((match_start == base::string16::npos) || (match_start != 0)); | 183 ((match_start == base::string16::npos) || (match_start != 0)); |
184 std::vector<size_t> offsets = BookmarkMatch::OffsetsFromMatchPositions( | 184 std::vector<size_t> offsets = BookmarkMatch::OffsetsFromMatchPositions( |
185 bookmark_match.url_match_positions); | 185 bookmark_match.url_match_positions); |
186 // In addition to knowing how |offsets| is transformed, we need to know how | 186 // In addition to knowing how |offsets| is transformed, we need to know how |
187 // |inline_autocomplete_offset| is transformed. We add it to the end of | 187 // |inline_autocomplete_offset| is transformed. We add it to the end of |
188 // |offsets|, compute how everything is transformed, then remove it from the | 188 // |offsets|, compute how everything is transformed, then remove it from the |
189 // end. | 189 // end. |
190 offsets.push_back(inline_autocomplete_offset); | 190 offsets.push_back(inline_autocomplete_offset); |
191 match.contents = net::FormatUrlWithOffsets(url, languages_, | 191 match.contents = url_formatter::FormatUrlWithOffsets( |
192 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP), | 192 url, languages_, url_formatter::kFormatUrlOmitAll & |
193 net::UnescapeRule::SPACES, NULL, NULL, &offsets); | 193 ~(trim_http ? 0 : url_formatter::kFormatUrlOmitHTTP), |
| 194 net::UnescapeRule::SPACES, nullptr, nullptr, &offsets); |
194 inline_autocomplete_offset = offsets.back(); | 195 inline_autocomplete_offset = offsets.back(); |
195 offsets.pop_back(); | 196 offsets.pop_back(); |
196 BookmarkMatch::MatchPositions new_url_match_positions = | 197 BookmarkMatch::MatchPositions new_url_match_positions = |
197 BookmarkMatch::ReplaceOffsetsInMatchPositions( | 198 BookmarkMatch::ReplaceOffsetsInMatchPositions( |
198 bookmark_match.url_match_positions, offsets); | 199 bookmark_match.url_match_positions, offsets); |
199 match.contents_class = | 200 match.contents_class = |
200 ClassificationsFromMatch(new_url_match_positions, | 201 ClassificationsFromMatch(new_url_match_positions, |
201 match.contents.size(), | 202 match.contents.size(), |
202 true); | 203 true); |
203 match.fill_into_edit = | 204 match.fill_into_edit = |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 i != positions.end(); | 336 i != positions.end(); |
336 ++i) { | 337 ++i) { |
337 AutocompleteMatch::ACMatchClassifications new_class; | 338 AutocompleteMatch::ACMatchClassifications new_class; |
338 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first, | 339 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first, |
339 text_length, url_style, &new_class); | 340 text_length, url_style, &new_class); |
340 classifications = AutocompleteMatch::MergeClassifications( | 341 classifications = AutocompleteMatch::MergeClassifications( |
341 classifications, new_class); | 342 classifications, new_class); |
342 } | 343 } |
343 return classifications; | 344 return classifications; |
344 } | 345 } |
OLD | NEW |