Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 const GURL& password_form_action, |
| 23 const GURL& password_form_frame_url, | 23 const GURL& password_form_frame_url, |
| 24 const std::string& legitimate_domain, | |
| 24 LoginReputationClientRequest::TriggerType type, | 25 LoginReputationClientRequest::TriggerType type, |
| 25 PasswordProtectionService* pps, | 26 PasswordProtectionService* pps, |
| 26 int request_timeout_in_ms) | 27 int request_timeout_in_ms) |
| 27 : main_frame_url_(main_frame_url), | 28 : main_frame_url_(main_frame_url), |
| 28 password_form_action_(password_form_action), | 29 password_form_action_(password_form_action), |
| 29 password_form_frame_url_(password_form_frame_url), | 30 password_form_frame_url_(password_form_frame_url), |
| 31 legitimate_domain_(legitimate_domain), | |
| 30 request_type_(type), | 32 request_type_(type), |
| 31 password_protection_service_(pps), | 33 password_protection_service_(pps), |
| 32 database_manager_(password_protection_service_->database_manager()), | 34 database_manager_(password_protection_service_->database_manager()), |
| 33 request_timeout_in_ms_(request_timeout_in_ms), | 35 request_timeout_in_ms_(request_timeout_in_ms), |
| 34 weakptr_factory_(this) { | 36 weakptr_factory_(this) { |
| 35 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 37 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 36 } | 38 } |
| 37 | 39 |
| 38 PasswordProtectionRequest::~PasswordProtectionRequest() { | 40 PasswordProtectionRequest::~PasswordProtectionRequest() { |
| 39 weakptr_factory_.InvalidateWeakPtrs(); | 41 weakptr_factory_.InvalidateWeakPtrs(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 std::unique_ptr<LoginReputationClientResponse> cached_response = | 77 std::unique_ptr<LoginReputationClientResponse> cached_response = |
| 76 base::MakeUnique<LoginReputationClientResponse>(); | 78 base::MakeUnique<LoginReputationClientResponse>(); |
| 77 auto verdict = password_protection_service_->GetCachedVerdict( | 79 auto verdict = password_protection_service_->GetCachedVerdict( |
| 78 main_frame_url_, cached_response.get()); | 80 main_frame_url_, cached_response.get()); |
| 79 if (verdict != LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED) | 81 if (verdict != LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED) |
| 80 Finish(RequestOutcome::RESPONSE_ALREADY_CACHED, std::move(cached_response)); | 82 Finish(RequestOutcome::RESPONSE_ALREADY_CACHED, std::move(cached_response)); |
| 81 else | 83 else |
| 82 SendRequest(); | 84 SendRequest(); |
| 83 } | 85 } |
| 84 | 86 |
| 85 void PasswordProtectionRequest::FillRequestProto() { | 87 void PasswordProtectionRequest::FillRequestProto() { |
|
Nathan Parker
2017/05/12 22:27:59
Are there tests for this function?
Jialiu Lin
2017/05/13 00:24:12
Done. Added 2 unit tests to verify request proto.
| |
| 86 request_proto_ = base::MakeUnique<LoginReputationClientRequest>(); | 88 request_proto_ = base::MakeUnique<LoginReputationClientRequest>(); |
| 87 request_proto_->set_page_url(main_frame_url_.spec()); | 89 request_proto_->set_page_url(main_frame_url_.spec()); |
| 88 request_proto_->set_trigger_type(request_type_); | 90 request_proto_->set_trigger_type(request_type_); |
| 89 password_protection_service_->FillUserPopulation(request_type_, | 91 password_protection_service_->FillUserPopulation(request_type_, |
| 90 request_proto_.get()); | 92 request_proto_.get()); |
| 91 request_proto_->set_stored_verdict_cnt( | 93 request_proto_->set_stored_verdict_cnt( |
| 92 password_protection_service_->GetStoredVerdictCount()); | 94 password_protection_service_->GetStoredVerdictCount()); |
| 93 LoginReputationClientRequest::Frame* main_frame = | 95 LoginReputationClientRequest::Frame* main_frame = |
| 94 request_proto_->add_frames(); | 96 request_proto_->add_frames(); |
| 95 main_frame->set_url(main_frame_url_.spec()); | 97 main_frame->set_url(main_frame_url_.spec()); |
| 96 main_frame->set_frame_index(0 /* main frame */); | 98 main_frame->set_frame_index(0 /* main frame */); |
| 97 password_protection_service_->FillReferrerChain( | 99 password_protection_service_->FillReferrerChain( |
| 98 main_frame_url_, -1 /* tab id not available */, main_frame); | 100 main_frame_url_, -1 /* tab id not available */, main_frame); |
| 99 LoginReputationClientRequest::Frame::Form* password_form; | 101 |
| 100 if (password_form_frame_url_ == main_frame_url_) { | 102 switch (request_type_) { |
| 101 main_frame->set_has_password_field(true); | 103 case LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE: { |
| 102 password_form = main_frame->add_forms(); | 104 LoginReputationClientRequest::Frame::Form* password_form; |
| 103 } else { | 105 if (password_form_frame_url_ == main_frame_url_) { |
| 104 LoginReputationClientRequest::Frame* password_frame = | 106 main_frame->set_has_password_field(true); |
|
Nathan Parker
2017/05/12 22:27:59
I think all this form/frame info should be filled
Jialiu Lin
2017/05/13 00:24:12
This is temporary. password form, password_form_fr
| |
| 105 request_proto_->add_frames(); | 107 password_form = main_frame->add_forms(); |
| 106 password_frame->set_url(password_form_frame_url_.spec()); | 108 } else { |
| 107 password_frame->set_has_password_field(true); | 109 LoginReputationClientRequest::Frame* password_frame = |
| 108 // TODO(jialiul): Add referrer chain for subframes later. | 110 request_proto_->add_frames(); |
| 109 password_form = password_frame->add_forms(); | 111 password_frame->set_url(password_form_frame_url_.spec()); |
| 112 password_frame->set_has_password_field(true); | |
|
Nathan Parker
2017/05/12 22:27:59
So do we need to set_has_password_field on both th
Jialiu Lin
2017/05/13 00:24:12
Agree. It is redundant. remove the filling of has_
| |
| 113 // TODO(jialiul): Add referrer chain for subframes later. | |
| 114 password_form = password_frame->add_forms(); | |
| 115 } | |
| 116 password_form->set_action_url(password_form_action_.spec()); | |
| 117 password_form->set_has_password_field(true); | |
| 118 // TODO(jialiul): Fill more frame specific info when Safe Browsing backend | |
| 119 // is ready to handle these pieces of information. | |
| 120 break; | |
| 121 } | |
| 122 case LoginReputationClientRequest::PASSWORD_REUSE_EVENT: { | |
| 123 LoginReputationClientRequest::PasswordReuseEvent* password_reuse = | |
| 124 request_proto_->mutable_password_reuse_event(); | |
| 125 password_reuse->add_password_reused_original_origins(legitimate_domain_); | |
|
Nathan Parker
2017/05/12 22:27:59
This one should only be filled for SBER. That's t
Jialiu Lin
2017/05/13 00:24:12
Yes, thanks for catching this.
| |
| 126 // TODO(jialiul): Fill more password_reuse information. | |
| 127 break; | |
| 128 } | |
| 129 default: | |
| 130 NOTREACHED(); | |
| 110 } | 131 } |
| 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. | |
| 115 } | 132 } |
| 116 | 133 |
| 117 void PasswordProtectionRequest::SendRequest() { | 134 void PasswordProtectionRequest::SendRequest() { |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 119 FillRequestProto(); | 136 FillRequestProto(); |
| 120 | 137 |
| 121 std::string serialized_request; | 138 std::string serialized_request; |
| 122 if (!request_proto_->SerializeToString(&serialized_request)) { | 139 if (!request_proto_->SerializeToString(&serialized_request)) { |
| 123 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); | 140 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); |
| 124 return; | 141 return; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 } | 234 } |
| 218 | 235 |
| 219 void PasswordProtectionRequest::Cancel(bool timed_out) { | 236 void PasswordProtectionRequest::Cancel(bool timed_out) { |
| 220 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 237 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 221 fetcher_.reset(); | 238 fetcher_.reset(); |
| 222 | 239 |
| 223 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); | 240 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); |
| 224 } | 241 } |
| 225 | 242 |
| 226 } // namespace safe_browsing | 243 } // namespace safe_browsing |
| OLD | NEW |