Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/autocomplete/history_quick_provider.cc

Issue 222783006: Omnibox: Fix HQP Crash on Bad FormatURL and can_inline Interaction (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revise comment Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), 270 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(),
271 net::FormatUrlWithOffsets(info.url(), languages_, format_types, 271 net::FormatUrlWithOffsets(info.url(), languages_, format_types,
272 net::UnescapeRule::SPACES, NULL, NULL, &offsets)); 272 net::UnescapeRule::SPACES, NULL, NULL, &offsets));
273 history::TermMatches new_matches = 273 history::TermMatches new_matches =
274 ReplaceOffsetsInTermMatches(history_match.url_matches(), offsets); 274 ReplaceOffsetsInTermMatches(history_match.url_matches(), offsets);
275 match.contents = net::FormatUrl(info.url(), languages_, format_types, 275 match.contents = net::FormatUrl(info.url(), languages_, format_types,
276 net::UnescapeRule::SPACES, NULL, NULL, NULL); 276 net::UnescapeRule::SPACES, NULL, NULL, NULL);
277 match.contents_class = 277 match.contents_class =
278 SpansFromTermMatch(new_matches, match.contents.length(), true); 278 SpansFromTermMatch(new_matches, match.contents.length(), true);
279 279
280 if (history_match.can_inline()) { 280 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible.
281 // The second part of this test can happen if the only match(es) of the user's
282 // term occur in places FormatUrl() decides to omit in the formatted url.
283 // In these cases, it's impossible to set |inline_autocompletion| correctly
284 // and hence the match cannot be the default match. I (mpearson@) believe
285 // this is likely caused by the mismatch that offsets are originally
286 // computed with respect to the cleaned-up URL yet then applied and
287 // updated by FormatUrl() as if they applied to the original string.
288 // See crbug.com/252630.
289 // TODO(mpearson): try removing the second clause after fixing 252630.
Peter Kasting 2014/04/14 22:13:21 Nit: removing the second clause -> replacing the s
Mark P 2014/04/14 23:34:20 Done.
290 if (history_match.can_inline() && !new_matches.empty()) {
281 DCHECK(!new_matches.empty()); 291 DCHECK(!new_matches.empty());
282 size_t inline_autocomplete_offset = new_matches[0].offset + 292 size_t inline_autocomplete_offset = new_matches[0].offset +
283 new_matches[0].length; 293 new_matches[0].length;
284 // |inline_autocomplete_offset| may be beyond the end of the 294 // |inline_autocomplete_offset| may be beyond the end of the
285 // |fill_into_edit| if the user has typed an URL with a scheme and the 295 // |fill_into_edit| if the user has typed an URL with a scheme and the
286 // last character typed is a slash. That slash is removed by the 296 // last character typed is a slash. That slash is removed by the
287 // FormatURLWithOffsets call above. 297 // FormatURLWithOffsets call above.
288 if (inline_autocomplete_offset < match.fill_into_edit.length()) { 298 if (inline_autocomplete_offset < match.fill_into_edit.length()) {
289 match.inline_autocompletion = 299 match.inline_autocompletion =
290 match.fill_into_edit.substr(inline_autocomplete_offset); 300 match.fill_into_edit.substr(inline_autocomplete_offset);
(...skipping 18 matching lines...) Expand all
309 if (index_for_testing_.get()) 319 if (index_for_testing_.get())
310 return index_for_testing_.get(); 320 return index_for_testing_.get();
311 321
312 HistoryService* const history_service = 322 HistoryService* const history_service =
313 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 323 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
314 if (!history_service) 324 if (!history_service)
315 return NULL; 325 return NULL;
316 326
317 return history_service->InMemoryIndex(); 327 return history_service->InMemoryIndex();
318 } 328 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698