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

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

Issue 2833193002: Trigger Password Protection ping on username/password field on focus (Closed)
Patch Set: nit Created 3 years, 7 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 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/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // e.g., "https://www.foo.com:80/bar/test.cgi" -> "http://www.foo.com". 56 // e.g., "https://www.foo.com:80/bar/test.cgi" -> "http://www.foo.com".
57 GURL GetHostNameWithHTTPScheme(const GURL& url) { 57 GURL GetHostNameWithHTTPScheme(const GURL& url) {
58 DCHECK(url.SchemeIsHTTPOrHTTPS()); 58 DCHECK(url.SchemeIsHTTPOrHTTPS());
59 std::string result(url::kHttpScheme); 59 std::string result(url::kHttpScheme);
60 result.append(url::kStandardSchemeSeparator).append(url.HostNoBrackets()); 60 result.append(url::kStandardSchemeSeparator).append(url.HostNoBrackets());
61 return GURL(result); 61 return GURL(result);
62 } 62 }
63 63
64 } // namespace 64 } // namespace
65 65
66 PasswordProtectionFrame::~PasswordProtectionFrame() = default;
67
68 PasswordProtectionService::PasswordProtectionService( 66 PasswordProtectionService::PasswordProtectionService(
69 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, 67 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
70 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 68 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
71 HistoryService* history_service, 69 HistoryService* history_service,
72 HostContentSettingsMap* host_content_settings_map) 70 HostContentSettingsMap* host_content_settings_map)
73 : stored_verdict_count_(-1), 71 : stored_verdict_count_(-1),
74 database_manager_(database_manager), 72 database_manager_(database_manager),
75 request_context_getter_(request_context_getter), 73 request_context_getter_(request_context_getter),
76 history_service_observer_(this), 74 history_service_observer_(this),
77 content_settings_(host_content_settings_map), 75 content_settings_(host_content_settings_map),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // override it. 189 // override it.
192 verdict_dictionary->SetWithoutPathExpansion(verdict->cache_expression(), 190 verdict_dictionary->SetWithoutPathExpansion(verdict->cache_expression(),
193 std::move(verdict_entry)); 191 std::move(verdict_entry));
194 content_settings_->SetWebsiteSettingDefaultScope( 192 content_settings_->SetWebsiteSettingDefaultScope(
195 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, 193 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION,
196 std::string(), std::move(verdict_dictionary)); 194 std::string(), std::move(verdict_dictionary));
197 } 195 }
198 196
199 void PasswordProtectionService::StartRequest( 197 void PasswordProtectionService::StartRequest(
200 const GURL& main_frame_url, 198 const GURL& main_frame_url,
201 LoginReputationClientRequest::TriggerType type, 199 const GURL& password_form_action,
202 std::unique_ptr<PasswordProtectionFrameList> password_frames) { 200 LoginReputationClientRequest::TriggerType type) {
203 DCHECK_CURRENTLY_ON(BrowserThread::UI); 201 DCHECK_CURRENTLY_ON(BrowserThread::UI);
204 scoped_refptr<PasswordProtectionRequest> request( 202 scoped_refptr<PasswordProtectionRequest> request(
205 new PasswordProtectionRequest(main_frame_url, type, 203 new PasswordProtectionRequest(main_frame_url, password_form_action, type,
206 std::move(password_frames), this, 204 this, GetRequestTimeoutInMS()));
207 GetRequestTimeoutInMS()));
208 DCHECK(request); 205 DCHECK(request);
209 request->Start(); 206 request->Start();
210 requests_.insert(std::move(request)); 207 requests_.insert(std::move(request));
211 } 208 }
212 209
213 void PasswordProtectionService::MaybeStartLowReputationRequest( 210 void PasswordProtectionService::MaybeStartLowReputationRequest(
214 const GURL& main_frame_url, 211 const GURL& main_frame_url,
215 std::unique_ptr<PasswordProtectionFrameList> password_frames) { 212 const GURL& password_form_action) {
216 DCHECK_CURRENTLY_ON(BrowserThread::UI); 213 DCHECK_CURRENTLY_ON(BrowserThread::UI);
217 if (!IsPingingEnabled()) 214 if (!IsPingingEnabled())
218 return; 215 return;
219 216
220 // Skip URLs that we can't get a reliable reputation for. 217 // Skip URLs that we can't get a reliable reputation for.
221 if (!main_frame_url.is_valid() || !main_frame_url.SchemeIsHTTPOrHTTPS()) { 218 if (!main_frame_url.is_valid() || !main_frame_url.SchemeIsHTTPOrHTTPS()) {
222 return; 219 return;
223 } 220 }
224 221
225 StartRequest(main_frame_url, 222 StartRequest(main_frame_url, password_form_action,
226 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, 223 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE);
227 std::move(password_frames));
228 } 224 }
229 225
230 void PasswordProtectionService::RequestFinished( 226 void PasswordProtectionService::RequestFinished(
231 PasswordProtectionRequest* request, 227 PasswordProtectionRequest* request,
232 std::unique_ptr<LoginReputationClientResponse> response) { 228 std::unique_ptr<LoginReputationClientResponse> response) {
233 DCHECK_CURRENTLY_ON(BrowserThread::UI); 229 DCHECK_CURRENTLY_ON(BrowserThread::UI);
234 230
235 DCHECK(request); 231 DCHECK(request);
236 // TODO(jialiul): We don't cache verdict for incognito mode for now. 232 // TODO(jialiul): We don't cache verdict for incognito mode for now.
237 // Later we may consider temporarily caching verdict. 233 // Later we may consider temporarily caching verdict.
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 const std::vector<char> verdict_blob(serialized_proto.begin(), 443 const std::vector<char> verdict_blob(serialized_proto.begin(),
448 serialized_proto.end()); 444 serialized_proto.end());
449 std::unique_ptr<base::Value> binary_value = 445 std::unique_ptr<base::Value> binary_value =
450 base::MakeUnique<base::Value>(verdict_blob); 446 base::MakeUnique<base::Value>(verdict_blob);
451 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); 447 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type());
452 result->Set(kVerdictProto, std::move(binary_value)); 448 result->Set(kVerdictProto, std::move(binary_value));
453 return result; 449 return result;
454 } 450 }
455 451
456 } // namespace safe_browsing 452 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698