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

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

Issue 184663002: Omnibox: Make URLs of Bookmarks Searchable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pkasting and tfarina's comments 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
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/url_prefix.h" 5 #include "chrome/browser/autocomplete/url_prefix.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_input.h" 10 #include "chrome/browser/autocomplete/autocomplete_input.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 71
72 // static 72 // static
73 bool URLPrefix::PrefixMatch(const URLPrefix& prefix, 73 bool URLPrefix::PrefixMatch(const URLPrefix& prefix,
74 const base::string16& text, 74 const base::string16& text,
75 const base::string16& prefix_suffix) { 75 const base::string16& prefix_suffix) {
76 return StartsWith(text, prefix.prefix + prefix_suffix, false); 76 return StartsWith(text, prefix.prefix + prefix_suffix, false);
77 } 77 }
78 78
79 // static 79 // static
80 void URLPrefix::ComputeMatchStartAndInlineAutocompleteOffset( 80 size_t URLPrefix::GetInlineAutocompleteOffset(
81 const AutocompleteInput& input, 81 const AutocompleteInput& input,
82 const AutocompleteInput& fixed_up_input, 82 const AutocompleteInput& fixed_up_input,
83 const bool allow_www_prefix_without_scheme, 83 const bool allow_www_prefix_without_scheme,
84 const base::string16& text, 84 const base::string16& text) {
85 size_t* match_start,
86 size_t* inline_autocomplete_offset) {
87 const URLPrefix* best_prefix = allow_www_prefix_without_scheme ? 85 const URLPrefix* best_prefix = allow_www_prefix_without_scheme ?
88 BestURLPrefixWithWWWCase(text, input.text()) : 86 BestURLPrefixWithWWWCase(text, input.text()) :
89 BestURLPrefix(text, input.text()); 87 BestURLPrefix(text, input.text());
90 const base::string16* matching_string = &input.text(); 88 const base::string16* matching_string = &input.text();
91 // If we failed to find a best_prefix initially, try again using a fixed-up 89 // If we failed to find a best_prefix initially, try again using a fixed-up
92 // version of the user input. This is especially useful to get about: URLs 90 // version of the user input. This is especially useful to get about: URLs
93 // to inline against chrome:// shortcuts. (about: URLs are fixed up to the 91 // to inline against chrome:// shortcuts. (about: URLs are fixed up to the
94 // chrome:// scheme.) 92 // chrome:// scheme.)
95 if ((best_prefix == NULL) && !fixed_up_input.text().empty() && 93 if ((best_prefix == NULL) && !fixed_up_input.text().empty() &&
96 (fixed_up_input.text() != input.text())) { 94 (fixed_up_input.text() != input.text())) {
97 best_prefix = allow_www_prefix_without_scheme ? 95 best_prefix = allow_www_prefix_without_scheme ?
98 BestURLPrefixWithWWWCase(text, fixed_up_input.text()) : 96 BestURLPrefixWithWWWCase(text, fixed_up_input.text()) :
99 BestURLPrefix(text, fixed_up_input.text()); 97 BestURLPrefix(text, fixed_up_input.text());
100 matching_string = &fixed_up_input.text(); 98 matching_string = &fixed_up_input.text();
101 } 99 }
102 if (best_prefix != NULL) { 100 return (best_prefix != NULL) ?
103 *match_start = best_prefix->prefix.length(); 101 (best_prefix->prefix.length() + matching_string->length()) :
104 *inline_autocomplete_offset = 102 base::string16::npos;
105 best_prefix->prefix.length() + matching_string->length();
106 } else {
107 *match_start = base::string16::npos;
108 *inline_autocomplete_offset = base::string16::npos;
109 }
110 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698