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

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

Issue 320253004: Componentize URLFixerUpper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win64 fix 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/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 "components/url_fixer/url_fixer.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 "url/url_canon_ip.h" 15 #include "url/url_canon_ip.h"
16 #include "url/url_util.h" 16 #include "url/url_util.h"
17 17
18 namespace { 18 namespace {
19 19
20 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, 20 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed,
21 size_t* cursor_position) { 21 size_t* cursor_position) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return metrics::OmniboxInputType::FORCED_QUERY; 140 return metrics::OmniboxInputType::FORCED_QUERY;
141 } 141 }
142 142
143 // Ask our parsing back-end to help us understand what the user typed. We 143 // Ask our parsing back-end to help us understand what the user typed. We
144 // use the URLFixerUpper here because we want to be smart about what we 144 // use the URLFixerUpper here because we want to be smart about what we
145 // consider a scheme. For example, we shouldn't consider www.google.com:80 145 // consider a scheme. For example, we shouldn't consider www.google.com:80
146 // to have a scheme. 146 // to have a scheme.
147 url::Parsed local_parts; 147 url::Parsed local_parts;
148 if (!parts) 148 if (!parts)
149 parts = &local_parts; 149 parts = &local_parts;
150 const base::string16 parsed_scheme(URLFixerUpper::SegmentURL(text, parts)); 150 const base::string16 parsed_scheme(url_fixer::SegmentURL(text, parts));
151 if (scheme) 151 if (scheme)
152 *scheme = parsed_scheme; 152 *scheme = parsed_scheme;
153 153
154 // If we can't canonicalize the user's input, the rest of the autocomplete 154 // If we can't canonicalize the user's input, the rest of the autocomplete
155 // system isn't going to be able to produce a navigable URL match for it. 155 // system isn't going to be able to produce a navigable URL match for it.
156 // So we just return QUERY immediately in these cases. 156 // So we just return QUERY immediately in these cases.
157 GURL placeholder_canonicalized_url; 157 GURL placeholder_canonicalized_url;
158 if (!canonicalized_url) 158 if (!canonicalized_url)
159 canonicalized_url = &placeholder_canonicalized_url; 159 canonicalized_url = &placeholder_canonicalized_url;
160 *canonicalized_url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), 160 *canonicalized_url = url_fixer::FixupURL(base::UTF16ToUTF8(text),
161 base::UTF16ToUTF8(desired_tld)); 161 base::UTF16ToUTF8(desired_tld));
162 if (!canonicalized_url->is_valid()) 162 if (!canonicalized_url->is_valid())
163 return metrics::OmniboxInputType::QUERY; 163 return metrics::OmniboxInputType::QUERY;
164 164
165 if (LowerCaseEqualsASCII(parsed_scheme, url::kFileScheme)) { 165 if (LowerCaseEqualsASCII(parsed_scheme, url::kFileScheme)) {
166 // A user might or might not type a scheme when entering a file URL. In 166 // A user might or might not type a scheme when entering a file URL. In
167 // either case, |parsed_scheme| will tell us that this is a file URL, but 167 // either case, |parsed_scheme| will tell us that this is a file URL, but
168 // |parts->scheme| might be empty, e.g. if the user typed "C:\foo". 168 // |parts->scheme| might be empty, e.g. if the user typed "C:\foo".
169 return metrics::OmniboxInputType::URL; 169 return metrics::OmniboxInputType::URL;
170 } 170 }
171 171
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 url::Component* components[] = { 234 url::Component* components[] = {
235 &http_parts.username, 235 &http_parts.username,
236 &http_parts.password, 236 &http_parts.password,
237 &http_parts.host, 237 &http_parts.host,
238 &http_parts.port, 238 &http_parts.port,
239 &http_parts.path, 239 &http_parts.path,
240 &http_parts.query, 240 &http_parts.query,
241 &http_parts.ref, 241 &http_parts.ref,
242 }; 242 };
243 for (size_t i = 0; i < arraysize(components); ++i) { 243 for (size_t i = 0; i < arraysize(components); ++i) {
244 URLFixerUpper::OffsetComponent( 244 url_fixer::OffsetComponent(
245 -static_cast<int>(http_scheme_prefix.length()), components[i]); 245 -static_cast<int>(http_scheme_prefix.length()), components[i]);
246 } 246 }
247 247
248 *parts = http_parts; 248 *parts = http_parts;
249 if (scheme) 249 if (scheme)
250 scheme->clear(); 250 scheme->clear();
251 *canonicalized_url = http_canonicalized_url; 251 *canonicalized_url = http_canonicalized_url;
252 252
253 return metrics::OmniboxInputType::URL; 253 return metrics::OmniboxInputType::URL;
254 } 254 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 current_page_classification_ = AutocompleteInput::INVALID_SPEC; 533 current_page_classification_ = AutocompleteInput::INVALID_SPEC;
534 type_ = metrics::OmniboxInputType::INVALID; 534 type_ = metrics::OmniboxInputType::INVALID;
535 parts_ = url::Parsed(); 535 parts_ = url::Parsed();
536 scheme_.clear(); 536 scheme_.clear();
537 canonicalized_url_ = GURL(); 537 canonicalized_url_ = GURL();
538 prevent_inline_autocomplete_ = false; 538 prevent_inline_autocomplete_ = false;
539 prefer_keyword_ = false; 539 prefer_keyword_ = false;
540 allow_exact_keyword_match_ = false; 540 allow_exact_keyword_match_ = false;
541 want_asynchronous_matches_ = true; 541 want_asynchronous_matches_ = true;
542 } 542 }
OLDNEW
« no previous file with comments | « chrome/browser/android/url_utilities.cc ('k') | chrome/browser/autocomplete/autocomplete_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698