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

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: 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 void BuiltinProvider::Start(const AutocompleteInput& input, 64 void BuiltinProvider::Start(const AutocompleteInput& input,
65 bool minimal_changes) { 65 bool minimal_changes) {
66 matches_.clear(); 66 matches_.clear();
67 if ((input.type() == AutocompleteInput::INVALID) || 67 if ((input.type() == AutocompleteInput::INVALID) ||
68 (input.type() == AutocompleteInput::FORCED_QUERY) || 68 (input.type() == AutocompleteInput::FORCED_QUERY) ||
69 (input.type() == AutocompleteInput::QUERY)) 69 (input.type() == AutocompleteInput::QUERY))
70 return; 70 return;
71 71
72 const size_t kAboutSchemeLength = strlen(content::kAboutScheme); 72 const size_t kAboutSchemeLength = strlen(url::kAboutScheme);
73 const base::string16 kAbout = base::ASCIIToUTF16(content::kAboutScheme) + 73 const base::string16 kAbout = base::ASCIIToUTF16(url::kAboutScheme) +
74 base::ASCIIToUTF16(content::kStandardSchemeSeparator); 74 base::ASCIIToUTF16(content::kStandardSchemeSeparator);
75 const base::string16 kChrome = base::ASCIIToUTF16(content::kChromeUIScheme) + 75 const base::string16 kChrome = base::ASCIIToUTF16(content::kChromeUIScheme) +
76 base::ASCIIToUTF16(content::kStandardSchemeSeparator); 76 base::ASCIIToUTF16(content::kStandardSchemeSeparator);
77 77
78 const int kUrl = ACMatchClassification::URL; 78 const int kUrl = ACMatchClassification::URL;
79 const int kMatch = kUrl | ACMatchClassification::MATCH; 79 const int kMatch = kUrl | ACMatchClassification::MATCH;
80 80
81 base::string16 text = input.text(); 81 base::string16 text = input.text();
82 bool starting_chrome = StartsWith(kChrome, text, false); 82 bool starting_chrome = StartsWith(kChrome, text, false);
83 if (starting_chrome || StartsWith(kAbout, text, false)) { 83 if (starting_chrome || StartsWith(kAbout, text, false)) {
(...skipping 18 matching lines...) Expand all
102 // Match input about: or chrome: URL input against builtin chrome URLs. 102 // Match input about: or chrome: URL input against builtin chrome URLs.
103 GURL url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), std::string()); 103 GURL url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), std::string());
104 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment 104 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment
105 // extensions to chrome: URLs. 105 // extensions to chrome: URLs.
106 if (url.SchemeIs(content::kChromeUIScheme) && url.has_host() && 106 if (url.SchemeIs(content::kChromeUIScheme) && url.has_host() &&
107 !url.has_query() && !url.has_ref()) { 107 !url.has_query() && !url.has_ref()) {
108 // Suggest about:blank for substrings, taking URL fixup into account. 108 // Suggest about:blank for substrings, taking URL fixup into account.
109 // Chrome does not support trailing slashes or paths for about:blank. 109 // Chrome does not support trailing slashes or paths for about:blank.
110 const base::string16 blank_host = base::ASCIIToUTF16("blank"); 110 const base::string16 blank_host = base::ASCIIToUTF16("blank");
111 const base::string16 host = base::UTF8ToUTF16(url.host()); 111 const base::string16 host = base::UTF8ToUTF16(url.host());
112 if (StartsWith(text, base::ASCIIToUTF16(content::kAboutScheme), false) && 112 if (StartsWith(text, base::ASCIIToUTF16(url::kAboutScheme), false) &&
113 StartsWith(blank_host, host, false) && (url.path().length() <= 1) && 113 StartsWith(blank_host, host, false) && (url.path().length() <= 1) &&
114 !EndsWith(text, base::ASCIIToUTF16("/"), false)) { 114 !EndsWith(text, base::ASCIIToUTF16("/"), false)) {
115 ACMatchClassifications styles; 115 ACMatchClassifications styles;
116 styles.push_back(ACMatchClassification(0, kMatch)); 116 styles.push_back(ACMatchClassification(0, kMatch));
117 base::string16 match = base::ASCIIToUTF16(content::kAboutBlankURL); 117 base::string16 match = base::ASCIIToUTF16(url::kAboutBlankURL);
118 // Measure the length of the matching host after the "about:" scheme. 118 // Measure the length of the matching host after the "about:" scheme.
119 const size_t corrected_length = kAboutSchemeLength + 1 + host.length(); 119 const size_t corrected_length = kAboutSchemeLength + 1 + host.length();
120 if (blank_host.length() > host.length()) 120 if (blank_host.length() > host.length())
121 styles.push_back(ACMatchClassification(corrected_length, kUrl)); 121 styles.push_back(ACMatchClassification(corrected_length, kUrl));
122 AddMatch(match, match.substr(corrected_length), styles); 122 AddMatch(match, match.substr(corrected_length), styles);
123 } 123 }
124 124
125 // Include the path for sub-pages (e.g. "chrome://settings/browser"). 125 // Include the path for sub-pages (e.g. "chrome://settings/browser").
126 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path()); 126 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path());
127 base::TrimString(host_and_path, base::ASCIIToUTF16("/"), &host_and_path); 127 base::TrimString(host_and_path, base::ASCIIToUTF16("/"), &host_and_path);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const ACMatchClassifications& styles) { 160 const ACMatchClassifications& styles) {
161 AutocompleteMatch match(this, kRelevance, false, 161 AutocompleteMatch match(this, kRelevance, false,
162 AutocompleteMatchType::NAVSUGGEST); 162 AutocompleteMatchType::NAVSUGGEST);
163 match.fill_into_edit = match_string; 163 match.fill_into_edit = match_string;
164 match.inline_autocompletion = inline_completion; 164 match.inline_autocompletion = inline_completion;
165 match.destination_url = GURL(match_string); 165 match.destination_url = GURL(match_string);
166 match.contents = match_string; 166 match.contents = match_string;
167 match.contents_class = styles; 167 match.contents_class = styles;
168 matches_.push_back(match); 168 matches_.push_back(match);
169 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698