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

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, 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 #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,
23 const GURL& password_form_frame_url,
22 LoginReputationClientRequest::TriggerType type, 24 LoginReputationClientRequest::TriggerType type,
23 std::unique_ptr<PasswordProtectionFrameList> password_frames,
24 PasswordProtectionService* pps, 25 PasswordProtectionService* pps,
25 int request_timeout_in_ms) 26 int request_timeout_in_ms)
26 : main_frame_url_(main_frame_url), 27 : main_frame_url_(main_frame_url),
28 password_form_action_(password_form_action),
29 password_form_frame_url_(password_form_frame_url),
27 request_type_(type), 30 request_type_(type),
28 password_frames_(std::move(password_frames)),
29 password_protection_service_(pps), 31 password_protection_service_(pps),
30 database_manager_(password_protection_service_->database_manager()), 32 database_manager_(password_protection_service_->database_manager()),
31 request_timeout_in_ms_(request_timeout_in_ms), 33 request_timeout_in_ms_(request_timeout_in_ms),
32 weakptr_factory_(this) { 34 weakptr_factory_(this) {
33 DCHECK_CURRENTLY_ON(BrowserThread::UI); 35 DCHECK_CURRENTLY_ON(BrowserThread::UI);
34 } 36 }
35 37
36 PasswordProtectionRequest::~PasswordProtectionRequest() { 38 PasswordProtectionRequest::~PasswordProtectionRequest() {
37 weakptr_factory_.InvalidateWeakPtrs(); 39 weakptr_factory_.InvalidateWeakPtrs();
38 } 40 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void PasswordProtectionRequest::FillRequestProto() { 96 void PasswordProtectionRequest::FillRequestProto() {
95 request_proto_ = base::MakeUnique<LoginReputationClientRequest>(); 97 request_proto_ = base::MakeUnique<LoginReputationClientRequest>();
96 request_proto_->set_page_url(main_frame_url_.spec()); 98 request_proto_->set_page_url(main_frame_url_.spec());
97 request_proto_->set_trigger_type(request_type_); 99 request_proto_->set_trigger_type(request_type_);
98 request_proto_->set_stored_verdict_cnt( 100 request_proto_->set_stored_verdict_cnt(
99 password_protection_service_->GetStoredVerdictCount()); 101 password_protection_service_->GetStoredVerdictCount());
100 LoginReputationClientRequest::Frame* main_frame = 102 LoginReputationClientRequest::Frame* main_frame =
101 request_proto_->add_frames(); 103 request_proto_->add_frames();
102 main_frame->set_url(main_frame_url_.spec()); 104 main_frame->set_url(main_frame_url_.spec());
103 main_frame->set_frame_index(0 /* main frame */); 105 main_frame->set_frame_index(0 /* main frame */);
104 main_frame->set_has_password_field(true);
105 password_protection_service_->FillReferrerChain( 106 password_protection_service_->FillReferrerChain(
106 main_frame_url_, -1 /* tab id not available */, main_frame); 107 main_frame_url_, -1 /* tab id not available */, main_frame);
107 108 LoginReputationClientRequest::Frame::Form* password_form;
108 // TODO(jialiul): Fill more password form related info based on 109 if (password_form_frame_url_ == main_frame_url_) {
109 // |password_frame_map_| when Safe Browsing backend is ready to handle these 110 main_frame->set_has_password_field(true);
110 // pieces of information. 111 password_form = main_frame->add_forms();
112 } else {
113 LoginReputationClientRequest::Frame* password_frame =
114 request_proto_->add_frames();
115 password_frame->set_url(password_form_frame_url_.spec());
116 password_frame->set_has_password_field(true);
117 // TODO(jialiul): Add referrer chain for subframes later.
118 password_form = password_frame->add_forms();
119 }
120 password_form->set_action_url(password_form_action_.spec());
121 password_form->set_has_password_field(true);
122 // TODO(jialiul): Fill more frame specific info when Safe Browsing backend
123 // is ready to handle these pieces of information.
111 } 124 }
112 125
113 void PasswordProtectionRequest::SendRequest() { 126 void PasswordProtectionRequest::SendRequest() {
114 DCHECK_CURRENTLY_ON(BrowserThread::UI); 127 DCHECK_CURRENTLY_ON(BrowserThread::UI);
115 FillRequestProto(); 128 FillRequestProto();
116 129
117 std::string serialized_request; 130 std::string serialized_request;
118 if (!request_proto_->SerializeToString(&serialized_request)) { 131 if (!request_proto_->SerializeToString(&serialized_request)) {
119 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); 132 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr);
120 return; 133 return;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 226 }
214 227
215 void PasswordProtectionRequest::Cancel(bool timed_out) { 228 void PasswordProtectionRequest::Cancel(bool timed_out) {
216 DCHECK_CURRENTLY_ON(BrowserThread::UI); 229 DCHECK_CURRENTLY_ON(BrowserThread::UI);
217 fetcher_.reset(); 230 fetcher_.reset();
218 231
219 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); 232 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr);
220 } 233 }
221 234
222 } // namespace safe_browsing 235 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698