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

Side by Side Diff: components/safe_browsing/password_protection/password_protection_service.cc

Issue 2959443003: Fix GetHostNameWithHTTPScheme for IPv6 addresses (Closed)
Patch Set: fix unittest Created 3 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
« no previous file with comments | « no previous file | components/safe_browsing/password_protection/password_protection_service_unittest.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/safe_browsing/password_protection/password_protection_servi ce.h" 5 #include "components/safe_browsing/password_protection/password_protection_servi ce.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // Returns the number of path segments in |cache_expression_path|. 52 // Returns the number of path segments in |cache_expression_path|.
53 // For example, return 0 for "/", since there is no path after the leading 53 // For example, return 0 for "/", since there is no path after the leading
54 // slash; return 3 for "/abc/def/gh.html". 54 // slash; return 3 for "/abc/def/gh.html".
55 size_t GetPathDepth(const std::string& cache_expression_path) { 55 size_t GetPathDepth(const std::string& cache_expression_path) {
56 return base::SplitString(base::StringPiece(cache_expression_path), "/", 56 return base::SplitString(base::StringPiece(cache_expression_path), "/",
57 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY) 57 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)
58 .size(); 58 .size();
59 } 59 }
60 60
61 // Given a URL of either http or https scheme, return its scheme://hostname. 61 // Given a URL of either http or https scheme, return its http://hostname.
62 // e.g., "https://www.foo.com:80/bar/test.cgi" -> "http://www.foo.com". 62 // e.g., "https://www.foo.com:80/bar/test.cgi" -> "http://www.foo.com".
63 GURL GetHostNameWithHTTPScheme(const GURL& url) { 63 GURL GetHostNameWithHTTPScheme(const GURL& url) {
64 DCHECK(url.SchemeIsHTTPOrHTTPS()); 64 DCHECK(url.SchemeIsHTTPOrHTTPS());
65 std::string result(url::kHttpScheme); 65 std::string result(url::kHttpScheme);
66 result.append(url::kStandardSchemeSeparator).append(url.HostNoBrackets()); 66 result.append(url::kStandardSchemeSeparator).append(url.host());
67 return GURL(result); 67 return GURL(result);
68 } 68 }
69 69
70 } // namespace 70 } // namespace
71 71
72 const base::Feature kPasswordFieldOnFocusPinging{ 72 const base::Feature kPasswordFieldOnFocusPinging{
73 "PasswordFieldOnFocusPinging", base::FEATURE_DISABLED_BY_DEFAULT}; 73 "PasswordFieldOnFocusPinging", base::FEATURE_DISABLED_BY_DEFAULT};
74 74
75 const base::Feature kProtectedPasswordEntryPinging{ 75 const base::Feature kProtectedPasswordEntryPinging{
76 "ProtectedPasswordEntryPinging", base::FEATURE_DISABLED_BY_DEFAULT}; 76 "ProtectedPasswordEntryPinging", base::FEATURE_DISABLED_BY_DEFAULT};
(...skipping 26 matching lines...) Expand all
103 tracker_.TryCancelAll(); 103 tracker_.TryCancelAll();
104 CancelPendingRequests(); 104 CancelPendingRequests();
105 history_service_observer_.RemoveAll(); 105 history_service_observer_.RemoveAll();
106 weak_factory_.InvalidateWeakPtrs(); 106 weak_factory_.InvalidateWeakPtrs();
107 } 107 }
108 108
109 bool PasswordProtectionService::CanGetReputationOfURL(const GURL& url) { 109 bool PasswordProtectionService::CanGetReputationOfURL(const GURL& url) {
110 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) 110 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS())
111 return false; 111 return false;
112 112
113 const std::string& hostname = url.HostNoBrackets(); 113 const std::string hostname = url.HostNoBrackets();
114 return !net::IsLocalhost(hostname) && !net::IsHostnameNonUnique(hostname) && 114 return !net::IsLocalhost(hostname) && !net::IsHostnameNonUnique(hostname) &&
115 hostname.find('.') != std::string::npos; 115 hostname.find('.') != std::string::npos;
116 } 116 }
117 117
118 LoginReputationClientResponse::VerdictType 118 LoginReputationClientResponse::VerdictType
119 PasswordProtectionService::GetCachedVerdict( 119 PasswordProtectionService::GetCachedVerdict(
120 const GURL& url, 120 const GURL& url,
121 LoginReputationClientResponse* out_response) { 121 LoginReputationClientResponse* out_response) {
122 if (!url.is_valid()) 122 if (!url.is_valid())
123 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED; 123 return LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED;
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 if (is_password_entry_ping) { 578 if (is_password_entry_ping) {
579 UMA_HISTOGRAM_ENUMERATION(kPasswordEntryRequestOutcomeHistogramName, reason, 579 UMA_HISTOGRAM_ENUMERATION(kPasswordEntryRequestOutcomeHistogramName, reason,
580 MAX_OUTCOME); 580 MAX_OUTCOME);
581 } else { 581 } else {
582 UMA_HISTOGRAM_ENUMERATION(kPasswordOnFocusRequestOutcomeHistogramName, 582 UMA_HISTOGRAM_ENUMERATION(kPasswordOnFocusRequestOutcomeHistogramName,
583 reason, MAX_OUTCOME); 583 reason, MAX_OUTCOME);
584 } 584 }
585 } 585 }
586 586
587 } // namespace safe_browsing 587 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | components/safe_browsing/password_protection/password_protection_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698