default-to-https-scheme.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Default to https for (non-standard) URLs without scheme.
  2. #
  3. # This patch handles URLs like user:pass@example.com and trims scheme in suggestions if it is implicit.
  4. # URLs entered in md_bookmarks (chrome://bookmarks) will also get https:// prefix.
  5. #
  6. # Note that there is a small hack in AutocompleteInput::HasHTTPScheme: we check kHttpsScheme instead.
  7. # All other changes in omnibox were made to preserve old behavior.
  8. --- a/chrome/browser/resources/bookmarks/edit_dialog.js
  9. +++ b/chrome/browser/resources/bookmarks/edit_dialog.js
  10. @@ -111,7 +111,7 @@ Polymer({
  11. /**
  12. * Validates the value of the URL field, returning true if it is a valid URL.
  13. - * May modify the value by prepending 'http://' in order to make it valid.
  14. + * May modify the value by prepending 'https://' in order to make it valid.
  15. * @return {boolean}
  16. * @private
  17. */
  18. @@ -123,7 +123,7 @@ Polymer({
  19. return true;
  20. }
  21. - this.urlValue_ = 'http://' + originalValue;
  22. + this.urlValue_ = 'https://' + originalValue;
  23. if (urlInput.validate()) {
  24. return true;
  25. --- a/components/omnibox/browser/autocomplete_input.cc
  26. +++ b/components/omnibox/browser/autocomplete_input.cc
  27. @@ -228,7 +228,7 @@ metrics::OmniboxInputType AutocompleteIn
  28. // We don't know about this scheme. It might be that the user typed a
  29. // URL of the form "username:password@foo.com".
  30. const base::string16 http_scheme_prefix =
  31. - base::ASCIIToUTF16(std::string(url::kHttpScheme) +
  32. + base::ASCIIToUTF16(std::string(url::kHttpsScheme) +
  33. url::kStandardSchemeSeparator);
  34. url::Parsed http_parts;
  35. base::string16 http_scheme;
  36. @@ -236,7 +236,7 @@ metrics::OmniboxInputType AutocompleteIn
  37. metrics::OmniboxInputType http_type =
  38. Parse(http_scheme_prefix + text, desired_tld, scheme_classifier,
  39. &http_parts, &http_scheme, &http_canonicalized_url);
  40. - DCHECK_EQ(std::string(url::kHttpScheme),
  41. + DCHECK_EQ(std::string(url::kHttpsScheme),
  42. base::UTF16ToUTF8(http_scheme));
  43. if ((http_type == metrics::OmniboxInputType::URL) &&
  44. @@ -566,7 +566,7 @@ bool AutocompleteInput::HasHTTPScheme(co
  45. } else if (url::FindAndCompareScheme(utf8_input, kViewSourceScheme, &scheme)) {
  46. utf8_input.erase(0, scheme.end() + 1);
  47. }
  48. - return url::FindAndCompareScheme(utf8_input, url::kHttpScheme, nullptr);
  49. + return url::FindAndCompareScheme(utf8_input, url::kHttpsScheme, nullptr);
  50. }
  51. void AutocompleteInput::UpdateText(const base::string16& text,
  52. --- a/components/omnibox/browser/autocomplete_provider.cc
  53. +++ b/components/omnibox/browser/autocomplete_provider.cc
  54. @@ -239,11 +239,11 @@ size_t AutocompleteProvider::TrimHttpPre
  55. if (!AutocompleteInput::HasHTTPScheme(*url))
  56. return 0;
  57. size_t scheme_pos =
  58. - url->find(base::ASCIIToUTF16(url::kHttpScheme) + base::char16(':'));
  59. + url->find(base::ASCIIToUTF16(url::kHttpsScheme) + base::char16(':'));
  60. DCHECK_NE(base::string16::npos, scheme_pos);
  61. // Erase scheme plus up to two slashes.
  62. - size_t prefix_end = scheme_pos + strlen(url::kHttpScheme) + 1;
  63. + size_t prefix_end = scheme_pos + strlen(url::kHttpsScheme) + 1;
  64. const size_t after_slashes = std::min(url->length(), prefix_end + 2);
  65. while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/'))
  66. ++prefix_end;
  67. --- a/components/url_formatter/url_fixer.cc
  68. +++ b/components/url_formatter/url_fixer.cc
  69. @@ -451,9 +451,9 @@ std::string SegmentURLInternal(std::stri
  70. (*text)[semicolon] = ';';
  71. }
  72. if (!found_scheme) {
  73. - // Couldn't determine the scheme, so just default to http.
  74. + // Couldn't determine the scheme, so just default to https.
  75. parts->scheme.reset();
  76. - scheme = url::kHttpScheme;
  77. + scheme = url::kHttpsScheme;
  78. }
  79. }