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

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: Resolve a merge conflict. 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"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 return URL; 168 return URL;
169 } 169 }
170 170
171 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it 171 // 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 172 // 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 173 // 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 174 // 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 175 // (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. 176 // until I run into some cases that really need it.
177 if (parts->scheme.is_nonempty() && 177 if (parts->scheme.is_nonempty() &&
178 !LowerCaseEqualsASCII(parsed_scheme, content::kHttpScheme) && 178 !LowerCaseEqualsASCII(parsed_scheme, url::kHttpScheme) &&
179 !LowerCaseEqualsASCII(parsed_scheme, content::kHttpsScheme)) { 179 !LowerCaseEqualsASCII(parsed_scheme, url::kHttpsScheme)) {
180 // See if we know how to handle the URL internally. There are some schemes 180 // 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 181 // that we convert to other things before they reach the renderer or else
182 // the renderer handles internally without reaching the net::URLRequest 182 // the renderer handles internally without reaching the net::URLRequest
183 // logic. They thus won't be listed as "handled protocols", but we should 183 // logic. They thus won't be listed as "handled protocols", but we should
184 // still claim to handle them. 184 // still claim to handle them.
185 if (ProfileIOData::IsHandledProtocol(base::UTF16ToASCII(parsed_scheme)) || 185 if (ProfileIOData::IsHandledProtocol(base::UTF16ToASCII(parsed_scheme)) ||
186 LowerCaseEqualsASCII(parsed_scheme, content::kViewSourceScheme) || 186 LowerCaseEqualsASCII(parsed_scheme, content::kViewSourceScheme) ||
187 LowerCaseEqualsASCII(parsed_scheme, content::kJavaScriptScheme) || 187 LowerCaseEqualsASCII(parsed_scheme, content::kJavaScriptScheme) ||
188 LowerCaseEqualsASCII(parsed_scheme, content::kDataScheme)) 188 LowerCaseEqualsASCII(parsed_scheme, content::kDataScheme))
189 return URL; 189 return URL;
(...skipping 16 matching lines...) Expand all
206 206
207 case ExternalProtocolHandler::BLOCK: 207 case ExternalProtocolHandler::BLOCK:
208 // If we don't want the user to open the URL, don't let it be navigated 208 // If we don't want the user to open the URL, don't let it be navigated
209 // to at all. 209 // to at all.
210 return QUERY; 210 return QUERY;
211 211
212 default: { 212 default: {
213 // We don't know about this scheme. It might be that the user typed a 213 // We don't know about this scheme. It might be that the user typed a
214 // URL of the form "username:password@foo.com". 214 // URL of the form "username:password@foo.com".
215 const base::string16 http_scheme_prefix = 215 const base::string16 http_scheme_prefix =
216 base::ASCIIToUTF16(std::string(content::kHttpScheme) + 216 base::ASCIIToUTF16(std::string(url::kHttpScheme) +
217 content::kStandardSchemeSeparator); 217 content::kStandardSchemeSeparator);
218 url::Parsed http_parts; 218 url::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(url::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::Component* components[] = { 232 url::Component* components[] = {
233 &http_parts.username, 233 &http_parts.username,
234 &http_parts.password, 234 &http_parts.password,
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 497 }
498 498
499 // static 499 // static
500 bool AutocompleteInput::HasHTTPScheme(const base::string16& input) { 500 bool AutocompleteInput::HasHTTPScheme(const base::string16& input) {
501 std::string utf8_input(base::UTF16ToUTF8(input)); 501 std::string utf8_input(base::UTF16ToUTF8(input));
502 url::Component scheme; 502 url::Component scheme;
503 if (url::FindAndCompareScheme(utf8_input, content::kViewSourceScheme, 503 if (url::FindAndCompareScheme(utf8_input, content::kViewSourceScheme,
504 &scheme)) { 504 &scheme)) {
505 utf8_input.erase(0, scheme.end() + 1); 505 utf8_input.erase(0, scheme.end() + 1);
506 } 506 }
507 return url::FindAndCompareScheme(utf8_input, content::kHttpScheme, NULL); 507 return url::FindAndCompareScheme(utf8_input, url::kHttpScheme, NULL);
508 } 508 }
509 509
510 void AutocompleteInput::UpdateText(const base::string16& text, 510 void AutocompleteInput::UpdateText(const base::string16& text,
511 size_t cursor_position, 511 size_t cursor_position,
512 const url::Parsed& parts) { 512 const url::Parsed& parts) {
513 DCHECK(cursor_position <= text.length() || 513 DCHECK(cursor_position <= text.length() ||
514 cursor_position == base::string16::npos) 514 cursor_position == base::string16::npos)
515 << "Text: '" << text << "', cp: " << cursor_position; 515 << "Text: '" << text << "', cp: " << cursor_position;
516 text_ = text; 516 text_ = text;
517 cursor_position_ = cursor_position; 517 cursor_position_ = cursor_position;
518 parts_ = parts; 518 parts_ = parts;
519 } 519 }
520 520
521 void AutocompleteInput::Clear() { 521 void AutocompleteInput::Clear() {
522 text_.clear(); 522 text_.clear();
523 cursor_position_ = base::string16::npos; 523 cursor_position_ = base::string16::npos;
524 current_url_ = GURL(); 524 current_url_ = GURL();
525 current_page_classification_ = AutocompleteInput::INVALID_SPEC; 525 current_page_classification_ = AutocompleteInput::INVALID_SPEC;
526 type_ = INVALID; 526 type_ = INVALID;
527 parts_ = url::Parsed(); 527 parts_ = url::Parsed();
528 scheme_.clear(); 528 scheme_.clear();
529 canonicalized_url_ = GURL(); 529 canonicalized_url_ = GURL();
530 prevent_inline_autocomplete_ = false; 530 prevent_inline_autocomplete_ = false;
531 prefer_keyword_ = false; 531 prefer_keyword_ = false;
532 allow_exact_keyword_match_ = false; 532 allow_exact_keyword_match_ = false;
533 want_asynchronous_matches_ = true; 533 want_asynchronous_matches_ = true;
534 } 534 }
OLDNEW
« no previous file with comments | « android_webview/renderer/aw_content_renderer_client.cc ('k') | chrome/browser/autocomplete/autocomplete_match.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698