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/builtin_provider.cc

Issue 325443002: Move about://-related constants from //content to //url (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Android ifx Created 6 years, 6 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/builtin_provider.h" 5 #include "chrome/browser/autocomplete/builtin_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 void BuiltinProvider::Start(const AutocompleteInput& input, 65 void BuiltinProvider::Start(const AutocompleteInput& input,
66 bool minimal_changes) { 66 bool minimal_changes) {
67 matches_.clear(); 67 matches_.clear();
68 if ((input.type() == metrics::OmniboxInputType::INVALID) || 68 if ((input.type() == metrics::OmniboxInputType::INVALID) ||
69 (input.type() == metrics::OmniboxInputType::FORCED_QUERY) || 69 (input.type() == metrics::OmniboxInputType::FORCED_QUERY) ||
70 (input.type() == metrics::OmniboxInputType::QUERY)) 70 (input.type() == metrics::OmniboxInputType::QUERY))
71 return; 71 return;
72 72
73 const size_t kAboutSchemeLength = strlen(content::kAboutScheme); 73 const size_t kAboutSchemeLength = strlen(url::kAboutScheme);
74 const base::string16 kAbout = base::ASCIIToUTF16(content::kAboutScheme) + 74 const base::string16 kAbout =
75 base::ASCIIToUTF16(url::kAboutScheme) +
75 base::ASCIIToUTF16(url::kStandardSchemeSeparator); 76 base::ASCIIToUTF16(url::kStandardSchemeSeparator);
76 const base::string16 kChrome = base::ASCIIToUTF16(content::kChromeUIScheme) + 77 const base::string16 kChrome = base::ASCIIToUTF16(content::kChromeUIScheme) +
77 base::ASCIIToUTF16(url::kStandardSchemeSeparator); 78 base::ASCIIToUTF16(url::kStandardSchemeSeparator);
78 79
79 const int kUrl = ACMatchClassification::URL; 80 const int kUrl = ACMatchClassification::URL;
80 const int kMatch = kUrl | ACMatchClassification::MATCH; 81 const int kMatch = kUrl | ACMatchClassification::MATCH;
81 82
82 base::string16 text = input.text(); 83 base::string16 text = input.text();
83 bool starting_chrome = StartsWith(kChrome, text, false); 84 bool starting_chrome = StartsWith(kChrome, text, false);
84 if (starting_chrome || StartsWith(kAbout, text, false)) { 85 if (starting_chrome || StartsWith(kAbout, text, false)) {
(...skipping 18 matching lines...) Expand all
103 // Match input about: or chrome: URL input against builtin chrome URLs. 104 // Match input about: or chrome: URL input against builtin chrome URLs.
104 GURL url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), std::string()); 105 GURL url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), std::string());
105 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment 106 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment
106 // extensions to chrome: URLs. 107 // extensions to chrome: URLs.
107 if (url.SchemeIs(content::kChromeUIScheme) && url.has_host() && 108 if (url.SchemeIs(content::kChromeUIScheme) && url.has_host() &&
108 !url.has_query() && !url.has_ref()) { 109 !url.has_query() && !url.has_ref()) {
109 // Suggest about:blank for substrings, taking URL fixup into account. 110 // Suggest about:blank for substrings, taking URL fixup into account.
110 // Chrome does not support trailing slashes or paths for about:blank. 111 // Chrome does not support trailing slashes or paths for about:blank.
111 const base::string16 blank_host = base::ASCIIToUTF16("blank"); 112 const base::string16 blank_host = base::ASCIIToUTF16("blank");
112 const base::string16 host = base::UTF8ToUTF16(url.host()); 113 const base::string16 host = base::UTF8ToUTF16(url.host());
113 if (StartsWith(text, base::ASCIIToUTF16(content::kAboutScheme), false) && 114 if (StartsWith(text, base::ASCIIToUTF16(url::kAboutScheme), false) &&
114 StartsWith(blank_host, host, false) && (url.path().length() <= 1) && 115 StartsWith(blank_host, host, false) && (url.path().length() <= 1) &&
115 !EndsWith(text, base::ASCIIToUTF16("/"), false)) { 116 !EndsWith(text, base::ASCIIToUTF16("/"), false)) {
116 ACMatchClassifications styles; 117 ACMatchClassifications styles;
117 styles.push_back(ACMatchClassification(0, kMatch)); 118 styles.push_back(ACMatchClassification(0, kMatch));
118 base::string16 match = base::ASCIIToUTF16(content::kAboutBlankURL); 119 base::string16 match = base::ASCIIToUTF16(url::kAboutBlankURL);
119 // Measure the length of the matching host after the "about:" scheme. 120 // Measure the length of the matching host after the "about:" scheme.
120 const size_t corrected_length = kAboutSchemeLength + 1 + host.length(); 121 const size_t corrected_length = kAboutSchemeLength + 1 + host.length();
121 if (blank_host.length() > host.length()) 122 if (blank_host.length() > host.length())
122 styles.push_back(ACMatchClassification(corrected_length, kUrl)); 123 styles.push_back(ACMatchClassification(corrected_length, kUrl));
123 AddMatch(match, match.substr(corrected_length), styles); 124 AddMatch(match, match.substr(corrected_length), styles);
124 } 125 }
125 126
126 // Include the path for sub-pages (e.g. "chrome://settings/browser"). 127 // Include the path for sub-pages (e.g. "chrome://settings/browser").
127 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path()); 128 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path());
128 base::TrimString(host_and_path, base::ASCIIToUTF16("/"), &host_and_path); 129 base::TrimString(host_and_path, base::ASCIIToUTF16("/"), &host_and_path);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 const ACMatchClassifications& styles) { 162 const ACMatchClassifications& styles) {
162 AutocompleteMatch match(this, kRelevance, false, 163 AutocompleteMatch match(this, kRelevance, false,
163 AutocompleteMatchType::NAVSUGGEST); 164 AutocompleteMatchType::NAVSUGGEST);
164 match.fill_into_edit = match_string; 165 match.fill_into_edit = match_string;
165 match.inline_autocompletion = inline_completion; 166 match.inline_autocompletion = inline_completion;
166 match.destination_url = GURL(match_string); 167 match.destination_url = GURL(match_string);
167 match.contents = match_string; 168 match.contents = match_string;
168 match.contents_class = styles; 169 match.contents_class = styles;
169 matches_.push_back(match); 170 matches_.push_back(match);
170 } 171 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_browsertest.cc ('k') | chrome/browser/autocomplete/builtin_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698