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