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

Side by Side Diff: components/omnibox/browser/autocomplete_input.cc

Issue 1171333003: Move net::FormatUrl and friends outside of //net and into //components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase again now that CQ is fixed Created 5 years, 4 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
« no previous file with comments | « components/omnibox/browser/DEPS ('k') | components/omnibox/browser/autocomplete_match.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/omnibox/browser/autocomplete_input.h" 5 #include "components/omnibox/browser/autocomplete_input.h"
6 6
7 #include "base/strings/string_split.h" 7 #include "base/strings/string_split.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 "components/metrics/proto/omnibox_event.pb.h" 10 #include "components/metrics/proto/omnibox_event.pb.h"
11 #include "components/omnibox/browser/autocomplete_scheme_classifier.h" 11 #include "components/omnibox/browser/autocomplete_scheme_classifier.h"
12 #include "components/omnibox/browser/omnibox_field_trial.h" 12 #include "components/omnibox/browser/omnibox_field_trial.h"
13 #include "components/url_fixer/url_fixer.h" 13 #include "components/url_formatter/url_fixer.h"
14 #include "components/url_formatter/url_formatter.h"
14 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
15 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
16 #include "url/url_canon_ip.h" 17 #include "url/url_canon_ip.h"
17 #include "url/url_util.h" 18 #include "url/url_util.h"
18 19
19 namespace { 20 namespace {
20 21
21 // Hardcode constant to avoid any dependencies on content/. 22 // Hardcode constant to avoid any dependencies on content/.
22 const char kViewSourceScheme[] = "view-source"; 23 const char kViewSourceScheme[] = "view-source";
23 24
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return metrics::OmniboxInputType::FORCED_QUERY; 182 return metrics::OmniboxInputType::FORCED_QUERY;
182 } 183 }
183 184
184 // Ask our parsing back-end to help us understand what the user typed. We 185 // Ask our parsing back-end to help us understand what the user typed. We
185 // use the URLFixerUpper here because we want to be smart about what we 186 // use the URLFixerUpper here because we want to be smart about what we
186 // consider a scheme. For example, we shouldn't consider www.google.com:80 187 // consider a scheme. For example, we shouldn't consider www.google.com:80
187 // to have a scheme. 188 // to have a scheme.
188 url::Parsed local_parts; 189 url::Parsed local_parts;
189 if (!parts) 190 if (!parts)
190 parts = &local_parts; 191 parts = &local_parts;
191 const base::string16 parsed_scheme(url_fixer::SegmentURL(text, parts)); 192 const base::string16 parsed_scheme(url_formatter::SegmentURL(text, parts));
192 if (scheme) 193 if (scheme)
193 *scheme = parsed_scheme; 194 *scheme = parsed_scheme;
194 const std::string parsed_scheme_utf8(base::UTF16ToUTF8(parsed_scheme)); 195 const std::string parsed_scheme_utf8(base::UTF16ToUTF8(parsed_scheme));
195 196
196 // If we can't canonicalize the user's input, the rest of the autocomplete 197 // If we can't canonicalize the user's input, the rest of the autocomplete
197 // system isn't going to be able to produce a navigable URL match for it. 198 // system isn't going to be able to produce a navigable URL match for it.
198 // So we just return QUERY immediately in these cases. 199 // So we just return QUERY immediately in these cases.
199 GURL placeholder_canonicalized_url; 200 GURL placeholder_canonicalized_url;
200 if (!canonicalized_url) 201 if (!canonicalized_url)
201 canonicalized_url = &placeholder_canonicalized_url; 202 canonicalized_url = &placeholder_canonicalized_url;
202 *canonicalized_url = 203 *canonicalized_url =
203 url_fixer::FixupURL(base::UTF16ToUTF8(text), desired_tld); 204 url_formatter::FixupURL(base::UTF16ToUTF8(text), desired_tld);
204 if (!canonicalized_url->is_valid()) 205 if (!canonicalized_url->is_valid())
205 return metrics::OmniboxInputType::QUERY; 206 return metrics::OmniboxInputType::QUERY;
206 207
207 if (base::LowerCaseEqualsASCII(parsed_scheme_utf8, url::kFileScheme)) { 208 if (base::LowerCaseEqualsASCII(parsed_scheme_utf8, url::kFileScheme)) {
208 // A user might or might not type a scheme when entering a file URL. In 209 // A user might or might not type a scheme when entering a file URL. In
209 // either case, |parsed_scheme_utf8| will tell us that this is a file URL, 210 // either case, |parsed_scheme_utf8| will tell us that this is a file URL,
210 // but |parts->scheme| might be empty, e.g. if the user typed "C:\foo". 211 // but |parts->scheme| might be empty, e.g. if the user typed "C:\foo".
211 return metrics::OmniboxInputType::URL; 212 return metrics::OmniboxInputType::URL;
212 } 213 }
213 214
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 url::Component* components[] = { 249 url::Component* components[] = {
249 &http_parts.username, 250 &http_parts.username,
250 &http_parts.password, 251 &http_parts.password,
251 &http_parts.host, 252 &http_parts.host,
252 &http_parts.port, 253 &http_parts.port,
253 &http_parts.path, 254 &http_parts.path,
254 &http_parts.query, 255 &http_parts.query,
255 &http_parts.ref, 256 &http_parts.ref,
256 }; 257 };
257 for (size_t i = 0; i < arraysize(components); ++i) { 258 for (size_t i = 0; i < arraysize(components); ++i) {
258 url_fixer::OffsetComponent( 259 url_formatter::OffsetComponent(
259 -static_cast<int>(http_scheme_prefix.length()), components[i]); 260 -static_cast<int>(http_scheme_prefix.length()), components[i]);
260 } 261 }
261 262
262 *parts = http_parts; 263 *parts = http_parts;
263 if (scheme) 264 if (scheme)
264 scheme->clear(); 265 scheme->clear();
265 *canonicalized_url = http_canonicalized_url; 266 *canonicalized_url = http_canonicalized_url;
266 267
267 return metrics::OmniboxInputType::URL; 268 return metrics::OmniboxInputType::URL;
268 } 269 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { 498 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) {
498 *host = parts.inner_parsed()->host; 499 *host = parts.inner_parsed()->host;
499 } 500 }
500 } 501 }
501 502
502 // static 503 // static
503 base::string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( 504 base::string16 AutocompleteInput::FormattedStringWithEquivalentMeaning(
504 const GURL& url, 505 const GURL& url,
505 const base::string16& formatted_url, 506 const base::string16& formatted_url,
506 const AutocompleteSchemeClassifier& scheme_classifier) { 507 const AutocompleteSchemeClassifier& scheme_classifier) {
507 if (!net::CanStripTrailingSlash(url)) 508 if (!url_formatter::CanStripTrailingSlash(url))
508 return formatted_url; 509 return formatted_url;
509 const base::string16 url_with_path(formatted_url + base::char16('/')); 510 const base::string16 url_with_path(formatted_url + base::char16('/'));
510 return (AutocompleteInput::Parse(formatted_url, std::string(), 511 return (AutocompleteInput::Parse(formatted_url, std::string(),
511 scheme_classifier, NULL, NULL, NULL) == 512 scheme_classifier, NULL, NULL, NULL) ==
512 AutocompleteInput::Parse(url_with_path, std::string(), 513 AutocompleteInput::Parse(url_with_path, std::string(),
513 scheme_classifier, NULL, NULL, NULL)) ? 514 scheme_classifier, NULL, NULL, NULL)) ?
514 formatted_url : url_with_path; 515 formatted_url : url_with_path;
515 } 516 }
516 517
517 // static 518 // static
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 parts_ = url::Parsed(); 565 parts_ = url::Parsed();
565 scheme_.clear(); 566 scheme_.clear();
566 canonicalized_url_ = GURL(); 567 canonicalized_url_ = GURL();
567 prevent_inline_autocomplete_ = false; 568 prevent_inline_autocomplete_ = false;
568 prefer_keyword_ = false; 569 prefer_keyword_ = false;
569 allow_exact_keyword_match_ = false; 570 allow_exact_keyword_match_ = false;
570 want_asynchronous_matches_ = true; 571 want_asynchronous_matches_ = true;
571 from_omnibox_focus_ = false; 572 from_omnibox_focus_ = false;
572 terms_prefixed_by_http_or_https_.clear(); 573 terms_prefixed_by_http_or_https_.clear();
573 } 574 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/DEPS ('k') | components/omnibox/browser/autocomplete_match.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698