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

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

Issue 2833193002: Trigger Password Protection ping on username/password field on focus (Closed)
Patch Set: nit Created 3 years, 8 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 #include "components/safe_browsing/password_protection/password_protection_reque st.h" 4 #include "components/safe_browsing/password_protection/password_protection_reque st.h"
5 5
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "components/data_use_measurement/core/data_use_user_data.h" 9 #include "components/data_use_measurement/core/data_use_user_data.h"
10 #include "components/safe_browsing_db/database_manager.h" 10 #include "components/safe_browsing_db/database_manager.h"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 #include "net/base/load_flags.h" 12 #include "net/base/load_flags.h"
13 #include "net/base/url_util.h" 13 #include "net/base/url_util.h"
14 #include "net/http/http_status_code.h" 14 #include "net/http/http_status_code.h"
15 15
16 using content::BrowserThread; 16 using content::BrowserThread;
17 17
18 namespace safe_browsing { 18 namespace safe_browsing {
19 19
20 PasswordProtectionRequest::PasswordProtectionRequest( 20 PasswordProtectionRequest::PasswordProtectionRequest(
21 const GURL& main_frame_url, 21 const GURL& main_frame_url,
22 const GURL& password_form_action,
22 LoginReputationClientRequest::TriggerType type, 23 LoginReputationClientRequest::TriggerType type,
23 std::unique_ptr<PasswordProtectionFrameList> password_frames,
24 PasswordProtectionService* pps, 24 PasswordProtectionService* pps,
25 int request_timeout_in_ms) 25 int request_timeout_in_ms)
26 : main_frame_url_(main_frame_url), 26 : main_frame_url_(main_frame_url),
27 password_form_action_(password_form_action),
27 request_type_(type), 28 request_type_(type),
28 password_frames_(std::move(password_frames)),
29 password_protection_service_(pps), 29 password_protection_service_(pps),
30 database_manager_(password_protection_service_->database_manager()), 30 database_manager_(password_protection_service_->database_manager()),
31 request_timeout_in_ms_(request_timeout_in_ms), 31 request_timeout_in_ms_(request_timeout_in_ms),
32 weakptr_factory_(this) { 32 weakptr_factory_(this) {
33 DCHECK_CURRENTLY_ON(BrowserThread::UI); 33 DCHECK_CURRENTLY_ON(BrowserThread::UI);
34 } 34 }
35 35
36 PasswordProtectionRequest::~PasswordProtectionRequest() { 36 PasswordProtectionRequest::~PasswordProtectionRequest() {
37 weakptr_factory_.InvalidateWeakPtrs(); 37 weakptr_factory_.InvalidateWeakPtrs();
38 } 38 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 request_proto_->set_trigger_type(request_type_); 97 request_proto_->set_trigger_type(request_type_);
98 request_proto_->set_stored_verdict_cnt( 98 request_proto_->set_stored_verdict_cnt(
99 password_protection_service_->GetStoredVerdictCount()); 99 password_protection_service_->GetStoredVerdictCount());
100 LoginReputationClientRequest::Frame* main_frame = 100 LoginReputationClientRequest::Frame* main_frame =
101 request_proto_->add_frames(); 101 request_proto_->add_frames();
102 main_frame->set_url(main_frame_url_.spec()); 102 main_frame->set_url(main_frame_url_.spec());
103 main_frame->set_frame_index(0 /* main frame */); 103 main_frame->set_frame_index(0 /* main frame */);
104 main_frame->set_has_password_field(true); 104 main_frame->set_has_password_field(true);
105 password_protection_service_->FillReferrerChain( 105 password_protection_service_->FillReferrerChain(
106 main_frame_url_, -1 /* tab id not available */, main_frame); 106 main_frame_url_, -1 /* tab id not available */, main_frame);
107 107 // TODO(jialiul): Put the password form in the main frame for now, even if it
108 // TODO(jialiul): Fill more password form related info based on 108 // is actually in a subframe.
109 // |password_frame_map_| when Safe Browsing backend is ready to handle these 109 LoginReputationClientRequest::Frame::Form* password_form =
110 // pieces of information. 110 main_frame->add_forms();
111 password_form->set_action_url(password_form_action_.spec());
112 password_form->set_has_password_field(true);
113 // TODO(jialiul): Fill more frame specific info when Safe Browsing backend
114 // is ready to handle these pieces of information.
111 } 115 }
112 116
113 void PasswordProtectionRequest::SendRequest() { 117 void PasswordProtectionRequest::SendRequest() {
114 DCHECK_CURRENTLY_ON(BrowserThread::UI); 118 DCHECK_CURRENTLY_ON(BrowserThread::UI);
115 FillRequestProto(); 119 FillRequestProto();
116 120
117 std::string serialized_request; 121 std::string serialized_request;
118 if (!request_proto_->SerializeToString(&serialized_request)) { 122 if (!request_proto_->SerializeToString(&serialized_request)) {
119 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); 123 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr);
120 return; 124 return;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 217 }
214 218
215 void PasswordProtectionRequest::Cancel(bool timed_out) { 219 void PasswordProtectionRequest::Cancel(bool timed_out) {
216 DCHECK_CURRENTLY_ON(BrowserThread::UI); 220 DCHECK_CURRENTLY_ON(BrowserThread::UI);
217 fetcher_.reset(); 221 fetcher_.reset();
218 222
219 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); 223 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr);
220 } 224 }
221 225
222 } // namespace safe_browsing 226 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698