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( |
256 net::FormatUrlWithOffsets(info.url(), languages_, format_types, | 254 info.url(), |
257 net::UnescapeRule::SPACES, NULL, NULL, &offsets)); | 255 net::FormatUrl(info.url(), languages_, format_types, |
| 256 net::UnescapeRule::SPACES, NULL, NULL, NULL)); |
| 257 std::vector<size_t> offsets = |
| 258 OffsetsFromTermMatches(history_match.url_matches()); |
| 259 base::OffsetAdjuster::Adjustments adjustments; |
| 260 match.contents = net::FormatUrlWithAdjustments( |
| 261 info.url(), languages_, format_types, net::UnescapeRule::SPACES, NULL, |
| 262 NULL, &adjustments); |
| 263 base::OffsetAdjuster::AdjustOffsets(adjustments, &offsets); |
258 history::TermMatches new_matches = | 264 history::TermMatches new_matches = |
259 ReplaceOffsetsInTermMatches(history_match.url_matches(), offsets); | 265 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 = | 266 match.contents_class = |
263 SpansFromTermMatch(new_matches, match.contents.length(), true); | 267 SpansFromTermMatch(new_matches, match.contents.length(), true); |
264 | 268 |
265 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. | 269 // 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 | 270 if (history_match.can_inline()) { |
267 // term occur in places FormatUrl() decides to omit in the formatted url. | 271 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 + | 272 size_t inline_autocomplete_offset = new_matches[0].offset + |
278 new_matches[0].length; | 273 new_matches[0].length; |
279 // |inline_autocomplete_offset| may be beyond the end of the | 274 // |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 | 275 // |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 | 276 // last character typed is a slash. That slash is removed by the |
282 // FormatURLWithOffsets call above. | 277 // FormatURLWithOffsets call above. |
283 if (inline_autocomplete_offset < match.fill_into_edit.length()) { | 278 if (inline_autocomplete_offset < match.fill_into_edit.length()) { |
284 match.inline_autocompletion = | 279 match.inline_autocompletion = |
285 match.fill_into_edit.substr(inline_autocomplete_offset); | 280 match.fill_into_edit.substr(inline_autocomplete_offset); |
286 } | 281 } |
(...skipping 17 matching lines...) Expand all Loading... |
304 if (index_for_testing_.get()) | 299 if (index_for_testing_.get()) |
305 return index_for_testing_.get(); | 300 return index_for_testing_.get(); |
306 | 301 |
307 HistoryService* const history_service = | 302 HistoryService* const history_service = |
308 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 303 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
309 if (!history_service) | 304 if (!history_service) |
310 return NULL; | 305 return NULL; |
311 | 306 |
312 return history_service->InMemoryIndex(); | 307 return history_service->InMemoryIndex(); |
313 } | 308 } |
OLD | NEW |