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

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

Issue 254763005: Move some content url constants to /url. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address some style nits. Created 6 years, 7 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
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/autocomplete_input.h" 5 #include "chrome/browser/autocomplete/autocomplete_input.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/external_protocol/external_protocol_handler.h" 9 #include "chrome/browser/external_protocol/external_protocol_handler.h"
10 #include "chrome/browser/profiles/profile_io_data.h" 10 #include "chrome/browser/profiles/profile_io_data.h"
11 #include "chrome/common/net/url_fixer_upper.h" 11 #include "chrome/common/net/url_fixer_upper.h"
12 #include "content/public/common/url_constants.h" 12 #include "content/public/common/url_constants.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
15 #include "net/base/url_constants.h"
15 #include "url/url_canon_ip.h" 16 #include "url/url_canon_ip.h"
16 #include "url/url_util.h" 17 #include "url/url_util.h"
17 18
18 namespace { 19 namespace {
19 20
20 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, 21 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed,
21 size_t* cursor_position) { 22 size_t* cursor_position) {
22 if (*cursor_position == base::string16::npos) 23 if (*cursor_position == base::string16::npos)
23 return; 24 return;
24 if (num_leading_chars_removed < *cursor_position) 25 if (num_leading_chars_removed < *cursor_position)
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 return URL; 169 return URL;
169 } 170 }
170 171
171 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it 172 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it
172 // well enough that we can fall through to the heuristics below. If it's 173 // well enough that we can fall through to the heuristics below. If it's
173 // something else, we can just determine our action based on what we do with 174 // something else, we can just determine our action based on what we do with
174 // any input of this scheme. In theory we could do better with some schemes 175 // any input of this scheme. In theory we could do better with some schemes
175 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that 176 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that
176 // until I run into some cases that really need it. 177 // until I run into some cases that really need it.
177 if (parts->scheme.is_nonempty() && 178 if (parts->scheme.is_nonempty() &&
178 !LowerCaseEqualsASCII(parsed_scheme, content::kHttpScheme) && 179 !LowerCaseEqualsASCII(parsed_scheme, net::kHttpScheme) &&
179 !LowerCaseEqualsASCII(parsed_scheme, content::kHttpsScheme)) { 180 !LowerCaseEqualsASCII(parsed_scheme, net::kHttpsScheme)) {
180 // See if we know how to handle the URL internally. There are some schemes 181 // See if we know how to handle the URL internally. There are some schemes
181 // that we convert to other things before they reach the renderer or else 182 // that we convert to other things before they reach the renderer or else
182 // the renderer handles internally without reaching the net::URLRequest 183 // the renderer handles internally without reaching the net::URLRequest
183 // logic. They thus won't be listed as "handled protocols", but we should 184 // logic. They thus won't be listed as "handled protocols", but we should
184 // still claim to handle them. 185 // still claim to handle them.
185 if (ProfileIOData::IsHandledProtocol(base::UTF16ToASCII(parsed_scheme)) || 186 if (ProfileIOData::IsHandledProtocol(base::UTF16ToASCII(parsed_scheme)) ||
186 LowerCaseEqualsASCII(parsed_scheme, content::kViewSourceScheme) || 187 LowerCaseEqualsASCII(parsed_scheme, content::kViewSourceScheme) ||
187 LowerCaseEqualsASCII(parsed_scheme, content::kJavaScriptScheme) || 188 LowerCaseEqualsASCII(parsed_scheme, content::kJavaScriptScheme) ||
188 LowerCaseEqualsASCII(parsed_scheme, content::kDataScheme)) 189 LowerCaseEqualsASCII(parsed_scheme, content::kDataScheme))
189 return URL; 190 return URL;
(...skipping 15 matching lines...) Expand all
205 return URL; 206 return URL;
206 207
207 case ExternalProtocolHandler::BLOCK: 208 case ExternalProtocolHandler::BLOCK:
208 // If we don't want the user to open the URL, don't let it be navigated 209 // If we don't want the user to open the URL, don't let it be navigated
209 // to at all. 210 // to at all.
210 return QUERY; 211 return QUERY;
211 212
212 default: { 213 default: {
213 // We don't know about this scheme. It might be that the user typed a 214 // We don't know about this scheme. It might be that the user typed a
214 // URL of the form "username:password@foo.com". 215 // URL of the form "username:password@foo.com".
215 const base::string16 http_scheme_prefix = 216 const base::string16 http_scheme_prefix = base::ASCIIToUTF16(
216 base::ASCIIToUTF16(std::string(content::kHttpScheme) + 217 std::string(net::kHttpScheme) + content::kStandardSchemeSeparator);
217 content::kStandardSchemeSeparator);
218 url_parse::Parsed http_parts; 218 url_parse::Parsed http_parts;
219 base::string16 http_scheme; 219 base::string16 http_scheme;
220 GURL http_canonicalized_url; 220 GURL http_canonicalized_url;
221 Type http_type = Parse(http_scheme_prefix + text, desired_tld, 221 Type http_type = Parse(http_scheme_prefix + text, desired_tld,
222 &http_parts, &http_scheme, 222 &http_parts, &http_scheme,
223 &http_canonicalized_url); 223 &http_canonicalized_url);
224 DCHECK_EQ(std::string(content::kHttpScheme), 224 DCHECK_EQ(std::string(net::kHttpScheme),
225 base::UTF16ToUTF8(http_scheme)); 225 base::UTF16ToUTF8(http_scheme));
226 226
227 if ((http_type == URL) && http_parts.username.is_nonempty() && 227 if ((http_type == URL) && http_parts.username.is_nonempty() &&
228 http_parts.password.is_nonempty()) { 228 http_parts.password.is_nonempty()) {
229 // Manually re-jigger the parsed parts to match |text| (without the 229 // Manually re-jigger the parsed parts to match |text| (without the
230 // http scheme added). 230 // http scheme added).
231 http_parts.scheme.reset(); 231 http_parts.scheme.reset();
232 url_parse::Component* components[] = { 232 url_parse::Component* components[] = {
233 &http_parts.username, 233 &http_parts.username,
234 &http_parts.password, 234 &http_parts.password,
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 return num_nonhost_components; 499 return num_nonhost_components;
500 } 500 }
501 501
502 // static 502 // static
503 bool AutocompleteInput::HasHTTPScheme(const base::string16& input) { 503 bool AutocompleteInput::HasHTTPScheme(const base::string16& input) {
504 std::string utf8_input(base::UTF16ToUTF8(input)); 504 std::string utf8_input(base::UTF16ToUTF8(input));
505 url_parse::Component scheme; 505 url_parse::Component scheme;
506 if (url_util::FindAndCompareScheme(utf8_input, content::kViewSourceScheme, 506 if (url_util::FindAndCompareScheme(utf8_input, content::kViewSourceScheme,
507 &scheme)) 507 &scheme))
508 utf8_input.erase(0, scheme.end() + 1); 508 utf8_input.erase(0, scheme.end() + 1);
509 return url_util::FindAndCompareScheme(utf8_input, content::kHttpScheme, NULL); 509 return url_util::FindAndCompareScheme(utf8_input, net::kHttpScheme, NULL);
510 } 510 }
511 511
512 void AutocompleteInput::UpdateText(const base::string16& text, 512 void AutocompleteInput::UpdateText(const base::string16& text,
513 size_t cursor_position, 513 size_t cursor_position,
514 const url_parse::Parsed& parts) { 514 const url_parse::Parsed& parts) {
515 DCHECK(cursor_position <= text.length() || 515 DCHECK(cursor_position <= text.length() ||
516 cursor_position == base::string16::npos) 516 cursor_position == base::string16::npos)
517 << "Text: '" << text << "', cp: " << cursor_position; 517 << "Text: '" << text << "', cp: " << cursor_position;
518 text_ = text; 518 text_ = text;
519 cursor_position_ = cursor_position; 519 cursor_position_ = cursor_position;
520 parts_ = parts; 520 parts_ = parts;
521 } 521 }
522 522
523 void AutocompleteInput::Clear() { 523 void AutocompleteInput::Clear() {
524 text_.clear(); 524 text_.clear();
525 cursor_position_ = base::string16::npos; 525 cursor_position_ = base::string16::npos;
526 current_url_ = GURL(); 526 current_url_ = GURL();
527 current_page_classification_ = AutocompleteInput::INVALID_SPEC; 527 current_page_classification_ = AutocompleteInput::INVALID_SPEC;
528 type_ = INVALID; 528 type_ = INVALID;
529 parts_ = url_parse::Parsed(); 529 parts_ = url_parse::Parsed();
530 scheme_.clear(); 530 scheme_.clear();
531 canonicalized_url_ = GURL(); 531 canonicalized_url_ = GURL();
532 prevent_inline_autocomplete_ = false; 532 prevent_inline_autocomplete_ = false;
533 prefer_keyword_ = false; 533 prefer_keyword_ = false;
534 allow_exact_keyword_match_ = false; 534 allow_exact_keyword_match_ = false;
535 want_asynchronous_matches_ = true; 535 want_asynchronous_matches_ = true;
536 } 536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698