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

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

Issue 1098843004: Omnibox - Do Not Allow HTTP/HTTPS Equivalence if User Explicitly Entered A Scheme (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revise test cases to be correct Created 5 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
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/autocomplete_input.h" 5 #include "components/omnibox/autocomplete_input.h"
6 6
7 #include "base/strings/string_split.h"
7 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "components/metrics/proto/omnibox_event.pb.h" 10 #include "components/metrics/proto/omnibox_event.pb.h"
10 #include "components/omnibox/autocomplete_scheme_classifier.h" 11 #include "components/omnibox/autocomplete_scheme_classifier.h"
11 #include "components/omnibox/omnibox_field_trial.h" 12 #include "components/omnibox/omnibox_field_trial.h"
12 #include "components/url_fixer/url_fixer.h" 13 #include "components/url_fixer/url_fixer.h"
13 #include "net/base/net_util.h" 14 #include "net/base/net_util.h"
14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 15 #include "net/base/registry_controlled_domains/registry_controlled_domain.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 // Hardcode constant to avoid any dependencies on content/. 21 // Hardcode constant to avoid any dependencies on content/.
21 const char kViewSourceScheme[] = "view-source"; 22 const char kViewSourceScheme[] = "view-source";
22 23
23 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, 24 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed,
24 size_t* cursor_position) { 25 size_t* cursor_position) {
25 if (*cursor_position == base::string16::npos) 26 if (*cursor_position == base::string16::npos)
26 return; 27 return;
27 if (num_leading_chars_removed < *cursor_position) 28 if (num_leading_chars_removed < *cursor_position)
28 *cursor_position -= num_leading_chars_removed; 29 *cursor_position -= num_leading_chars_removed;
29 else 30 else
30 *cursor_position = 0; 31 *cursor_position = 0;
31 } 32 }
32 33
34 // Finds all terms in |text| that start with http:// or https:// plus at least
35 // one more character and puts the text after the prefix in
36 // |terms_prefixed_by_http_or_https|.
37 void PopulateTermsPrefixedByHttpOrHttps(
38 const std::string& text,
39 std::vector<std::string>* terms_prefixed_by_http_or_https) {
40 std::vector<std::string> terms;
41 // Split on whitespace rather than use ICU's word iterator because, for
42 // example, ICU's iterator may break on punctuation (such as ://) or decide
43 // to split a single term in a hostname (if it seems to think that the
44 // hostname is multiple words). Neither of these behaviors is desirable.
45 base::SplitString(text, ' ', &terms);
46 const std::string separator(url::kStandardSchemeSeparator);
47 for (const auto& term : terms) {
48 LOG(INFO) << "checking term: " << term;
49 static const char* kSchemes[2] = { url::kHttpScheme, url::kHttpsScheme };
50 for (const char* scheme : kSchemes) {
51 const std::string prefix(scheme + separator);
52 if (base::StartsWith(term, prefix,
53 base::CompareCase::INSENSITIVE_ASCII) &&
54 (term.length() > prefix.length())) {
55 LOG(INFO) << "adding term: " << term.substr(prefix.length());
56 terms_prefixed_by_http_or_https->push_back(
57 term.substr(prefix.length()));
58 }
59 }
60 }
61 }
62
33 } // namespace 63 } // namespace
34 64
35 AutocompleteInput::AutocompleteInput() 65 AutocompleteInput::AutocompleteInput()
36 : cursor_position_(base::string16::npos), 66 : cursor_position_(base::string16::npos),
37 current_page_classification_(metrics::OmniboxEventProto::INVALID_SPEC), 67 current_page_classification_(metrics::OmniboxEventProto::INVALID_SPEC),
38 type_(metrics::OmniboxInputType::INVALID), 68 type_(metrics::OmniboxInputType::INVALID),
39 prevent_inline_autocomplete_(false), 69 prevent_inline_autocomplete_(false),
40 prefer_keyword_(false), 70 prefer_keyword_(false),
41 allow_exact_keyword_match_(true), 71 allow_exact_keyword_match_(true),
42 want_asynchronous_matches_(true), 72 want_asynchronous_matches_(true),
(...skipping 26 matching lines...) Expand all
69 // None of the providers care about leading white space so we always trim it. 99 // None of the providers care about leading white space so we always trim it.
70 // Providers that care about trailing white space handle trimming themselves. 100 // Providers that care about trailing white space handle trimming themselves.
71 if ((base::TrimWhitespace(text, base::TRIM_LEADING, &text_) & 101 if ((base::TrimWhitespace(text, base::TRIM_LEADING, &text_) &
72 base::TRIM_LEADING) != 0) 102 base::TRIM_LEADING) != 0)
73 AdjustCursorPositionIfNecessary(text.length() - text_.length(), 103 AdjustCursorPositionIfNecessary(text.length() - text_.length(),
74 &cursor_position_); 104 &cursor_position_);
75 105
76 GURL canonicalized_url; 106 GURL canonicalized_url;
77 type_ = Parse(text_, desired_tld, scheme_classifier, &parts_, &scheme_, 107 type_ = Parse(text_, desired_tld, scheme_classifier, &parts_, &scheme_,
78 &canonicalized_url); 108 &canonicalized_url);
109 PopulateTermsPrefixedByHttpOrHttps(base::UTF16ToUTF8(text_),
110 &terms_prefixed_by_http_or_https_);
79 111
80 if (type_ == metrics::OmniboxInputType::INVALID) 112 if (type_ == metrics::OmniboxInputType::INVALID)
81 return; 113 return;
82 114
83 if (((type_ == metrics::OmniboxInputType::UNKNOWN) || 115 if (((type_ == metrics::OmniboxInputType::UNKNOWN) ||
84 (type_ == metrics::OmniboxInputType::URL)) && 116 (type_ == metrics::OmniboxInputType::URL)) &&
85 canonicalized_url.is_valid() && 117 canonicalized_url.is_valid() &&
86 (!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() || 118 (!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() ||
87 canonicalized_url.SchemeIsFileSystem() || 119 canonicalized_url.SchemeIsFileSystem() ||
88 !canonicalized_url.host().empty())) 120 !canonicalized_url.host().empty()))
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 current_page_classification_ = metrics::OmniboxEventProto::INVALID_SPEC; 563 current_page_classification_ = metrics::OmniboxEventProto::INVALID_SPEC;
532 type_ = metrics::OmniboxInputType::INVALID; 564 type_ = metrics::OmniboxInputType::INVALID;
533 parts_ = url::Parsed(); 565 parts_ = url::Parsed();
534 scheme_.clear(); 566 scheme_.clear();
535 canonicalized_url_ = GURL(); 567 canonicalized_url_ = GURL();
536 prevent_inline_autocomplete_ = false; 568 prevent_inline_autocomplete_ = false;
537 prefer_keyword_ = false; 569 prefer_keyword_ = false;
538 allow_exact_keyword_match_ = false; 570 allow_exact_keyword_match_ = false;
539 want_asynchronous_matches_ = true; 571 want_asynchronous_matches_ = true;
540 from_omnibox_focus_ = false; 572 from_omnibox_focus_ = false;
573 terms_prefixed_by_http_or_https_.clear();
541 } 574 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698