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/autocomplete/history_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 AutocompleteMatch match( | 240 AutocompleteMatch match( |
241 this, score, !!info.visit_count(), | 241 this, score, !!info.visit_count(), |
242 history_match.url_matches().empty() ? | 242 history_match.url_matches().empty() ? |
243 AutocompleteMatchType::HISTORY_TITLE : | 243 AutocompleteMatchType::HISTORY_TITLE : |
244 AutocompleteMatchType::HISTORY_URL); | 244 AutocompleteMatchType::HISTORY_URL); |
245 match.typed_count = info.typed_count(); | 245 match.typed_count = info.typed_count(); |
246 match.destination_url = info.url(); | 246 match.destination_url = info.url(); |
247 DCHECK(match.destination_url.is_valid()); | 247 DCHECK(match.destination_url.is_valid()); |
248 | 248 |
249 // Format the URL autocomplete presentation. | 249 // Format the URL autocomplete presentation. |
250 std::vector<size_t> offsets = | |
251 OffsetsFromTermMatches(history_match.url_matches()); | |
252 const net::FormatUrlTypes format_types = net::kFormatUrlOmitAll & | 250 const net::FormatUrlTypes format_types = net::kFormatUrlOmitAll & |
253 ~(!history_match.match_in_scheme ? 0 : net::kFormatUrlOmitHTTP); | 251 ~(!history_match.match_in_scheme ? 0 : net::kFormatUrlOmitHTTP); |
254 match.fill_into_edit = | 252 match.fill_into_edit = |
255 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), | 253 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), |
Peter Kasting
2014/04/23 23:18:01
Nit: Move this onto the next line so all lines of
Mark P
2014/04/24 14:05:02
Done. Also adjusted FormatUrl() spacing around he
| |
256 net::FormatUrlWithOffsets(info.url(), languages_, format_types, | 254 net::FormatUrl(info.url(), languages_, format_types, |
257 net::UnescapeRule::SPACES, NULL, NULL, &offsets)); | 255 net::UnescapeRule::SPACES, NULL, NULL, NULL)); |
256 std::vector<size_t> offsets = | |
257 OffsetsFromTermMatches(history_match.url_matches()); | |
258 base::OffsetAdjuster::Adjustments adjustments; | |
259 match.contents = net::FormatUrlWithAdjustments( | |
260 info.url(), languages_, format_types, net::UnescapeRule::SPACES, NULL, | |
261 NULL, &adjustments); | |
262 base::OffsetAdjuster::AdjustOffsets(adjustments, &offsets); | |
258 history::TermMatches new_matches = | 263 history::TermMatches new_matches = |
259 ReplaceOffsetsInTermMatches(history_match.url_matches(), offsets); | 264 ReplaceOffsetsInTermMatches(history_match.url_matches(), offsets); |
260 match.contents = net::FormatUrl(info.url(), languages_, format_types, | |
261 net::UnescapeRule::SPACES, NULL, NULL, NULL); | |
262 match.contents_class = | 265 match.contents_class = |
263 SpansFromTermMatch(new_matches, match.contents.length(), true); | 266 SpansFromTermMatch(new_matches, match.contents.length(), true); |
264 | 267 |
265 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. | 268 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. |
266 // The second part of this test can happen if the only match(es) of the user's | 269 if (history_match.can_inline()) { |
267 // term occur in places FormatUrl() decides to omit in the formatted url. | 270 DCHECK(!new_matches.empty()); |
268 // In these cases, it's impossible to set |inline_autocompletion| correctly | |
269 // and hence the match cannot be the default match. I (mpearson@) believe | |
270 // this is likely caused by the mismatch that offsets are originally | |
271 // computed with respect to the cleaned-up URL yet then applied and | |
272 // updated by FormatUrl() as if they applied to the original string. | |
273 // See crbug.com/252630. | |
274 // TODO(mpearson): replacing the second clause with a DCHECK after fixing | |
275 // 252630. | |
276 if (history_match.can_inline() && !new_matches.empty()) { | |
277 size_t inline_autocomplete_offset = new_matches[0].offset + | 271 size_t inline_autocomplete_offset = new_matches[0].offset + |
278 new_matches[0].length; | 272 new_matches[0].length; |
279 // |inline_autocomplete_offset| may be beyond the end of the | 273 // |inline_autocomplete_offset| may be beyond the end of the |
280 // |fill_into_edit| if the user has typed an URL with a scheme and the | 274 // |fill_into_edit| if the user has typed an URL with a scheme and the |
281 // last character typed is a slash. That slash is removed by the | 275 // last character typed is a slash. That slash is removed by the |
282 // FormatURLWithOffsets call above. | 276 // FormatURLWithOffsets call above. |
283 if (inline_autocomplete_offset < match.fill_into_edit.length()) { | 277 if (inline_autocomplete_offset < match.fill_into_edit.length()) { |
284 match.inline_autocompletion = | 278 match.inline_autocompletion = |
285 match.fill_into_edit.substr(inline_autocomplete_offset); | 279 match.fill_into_edit.substr(inline_autocomplete_offset); |
286 } | 280 } |
(...skipping 17 matching lines...) Expand all Loading... | |
304 if (index_for_testing_.get()) | 298 if (index_for_testing_.get()) |
305 return index_for_testing_.get(); | 299 return index_for_testing_.get(); |
306 | 300 |
307 HistoryService* const history_service = | 301 HistoryService* const history_service = |
308 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 302 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
309 if (!history_service) | 303 if (!history_service) |
310 return NULL; | 304 return NULL; |
311 | 305 |
312 return history_service->InMemoryIndex(); | 306 return history_service->InMemoryIndex(); |
313 } | 307 } |
OLD | NEW |