| 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& saved_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 saved_domain_(saved_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(); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void PasswordProtectionRequest::Start() { | 44 void PasswordProtectionRequest::Start() { |
| 43 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 45 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 44 CheckWhitelistOnUIThread(); | 46 CheckWhitelistOnUIThread(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void PasswordProtectionRequest::CheckWhitelistOnUIThread() { | 49 void PasswordProtectionRequest::CheckWhitelistOnUIThread() { |
| 48 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 49 bool* match_whitelist = new bool(false); | 51 bool* match_whitelist = new bool(false); |
| 52 // TODO(jialiul): Move CheckCsdWhitelistOnIOThread to |
| 53 // PasswordProtectionRequest class, since PasswordProtectionService no longer |
| 54 // need it. |
| 50 tracker_.PostTaskAndReply( | 55 tracker_.PostTaskAndReply( |
| 51 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(), FROM_HERE, | 56 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(), FROM_HERE, |
| 52 base::Bind(&PasswordProtectionService::CheckCsdWhitelistOnIOThread, | 57 base::Bind(&PasswordProtectionService::CheckCsdWhitelistOnIOThread, |
| 53 base::Unretained(password_protection_service_), | 58 base::Unretained(password_protection_service_), |
| 54 main_frame_url_, match_whitelist), | 59 main_frame_url_, match_whitelist), |
| 55 base::Bind(&PasswordProtectionRequest::OnWhitelistCheckDone, this, | 60 base::Bind(&PasswordProtectionRequest::OnWhitelistCheckDone, this, |
| 56 base::Owned(match_whitelist))); | 61 base::Owned(match_whitelist))); |
| 57 } | 62 } |
| 58 | 63 |
| 59 void PasswordProtectionRequest::OnWhitelistCheckDone( | 64 void PasswordProtectionRequest::OnWhitelistCheckDone( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 90 password_protection_service_->FillUserPopulation(request_type_, | 95 password_protection_service_->FillUserPopulation(request_type_, |
| 91 request_proto_.get()); | 96 request_proto_.get()); |
| 92 request_proto_->set_stored_verdict_cnt( | 97 request_proto_->set_stored_verdict_cnt( |
| 93 password_protection_service_->GetStoredVerdictCount()); | 98 password_protection_service_->GetStoredVerdictCount()); |
| 94 LoginReputationClientRequest::Frame* main_frame = | 99 LoginReputationClientRequest::Frame* main_frame = |
| 95 request_proto_->add_frames(); | 100 request_proto_->add_frames(); |
| 96 main_frame->set_url(main_frame_url_.spec()); | 101 main_frame->set_url(main_frame_url_.spec()); |
| 97 main_frame->set_frame_index(0 /* main frame */); | 102 main_frame->set_frame_index(0 /* main frame */); |
| 98 password_protection_service_->FillReferrerChain( | 103 password_protection_service_->FillReferrerChain( |
| 99 main_frame_url_, -1 /* tab id not available */, main_frame); | 104 main_frame_url_, -1 /* tab id not available */, main_frame); |
| 100 LoginReputationClientRequest::Frame::Form* password_form; | 105 |
| 101 if (password_form_frame_url_ == main_frame_url_) { | 106 switch (request_type_) { |
| 102 main_frame->set_has_password_field(true); | 107 case LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE: { |
| 103 password_form = main_frame->add_forms(); | 108 LoginReputationClientRequest::Frame::Form* password_form; |
| 104 } else { | 109 if (password_form_frame_url_ == main_frame_url_) { |
| 105 LoginReputationClientRequest::Frame* password_frame = | 110 main_frame->set_has_password_field(true); |
| 106 request_proto_->add_frames(); | 111 password_form = main_frame->add_forms(); |
| 107 password_frame->set_url(password_form_frame_url_.spec()); | 112 } else { |
| 108 password_frame->set_has_password_field(true); | 113 LoginReputationClientRequest::Frame* password_frame = |
| 109 // TODO(jialiul): Add referrer chain for subframes later. | 114 request_proto_->add_frames(); |
| 110 password_form = password_frame->add_forms(); | 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 // TODO(jialiul): Fill more frame specific info when Safe Browsing backend |
| 122 // is ready to handle these pieces of information. |
| 123 break; |
| 124 } |
| 125 case LoginReputationClientRequest::PASSWORD_REUSE_EVENT: { |
| 126 if (password_protection_service_->IsExtendedReporting() && |
| 127 !password_protection_service_->IsIncognito()) { |
| 128 LoginReputationClientRequest::PasswordReuseEvent* password_reuse = |
| 129 request_proto_->mutable_password_reuse_event(); |
| 130 password_reuse->add_password_reused_original_origins(saved_domain_); |
| 131 } |
| 132 // TODO(jialiul): Fill more password_reuse information. |
| 133 break; |
| 134 } |
| 135 default: |
| 136 NOTREACHED(); |
| 111 } | 137 } |
| 112 password_form->set_action_url(password_form_action_.spec()); | |
| 113 password_form->set_has_password_field(true); | |
| 114 // TODO(jialiul): Fill more frame specific info when Safe Browsing backend | |
| 115 // is ready to handle these pieces of information. | |
| 116 } | 138 } |
| 117 | 139 |
| 118 void PasswordProtectionRequest::SendRequest() { | 140 void PasswordProtectionRequest::SendRequest() { |
| 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 120 FillRequestProto(); | 142 FillRequestProto(); |
| 121 | 143 |
| 122 std::string serialized_request; | 144 std::string serialized_request; |
| 123 if (!request_proto_->SerializeToString(&serialized_request)) { | 145 if (!request_proto_->SerializeToString(&serialized_request)) { |
| 124 Finish(PasswordProtectionService::REQUEST_MALFORMED, nullptr); | 146 Finish(PasswordProtectionService::REQUEST_MALFORMED, nullptr); |
| 125 return; | 147 return; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 void PasswordProtectionRequest::Cancel(bool timed_out) { | 247 void PasswordProtectionRequest::Cancel(bool timed_out) { |
| 226 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 248 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 227 fetcher_.reset(); | 249 fetcher_.reset(); |
| 228 | 250 |
| 229 Finish(timed_out ? PasswordProtectionService::TIMEDOUT | 251 Finish(timed_out ? PasswordProtectionService::TIMEDOUT |
| 230 : PasswordProtectionService::CANCELED, | 252 : PasswordProtectionService::CANCELED, |
| 231 nullptr); | 253 nullptr); |
| 232 } | 254 } |
| 233 | 255 |
| 234 } // namespace safe_browsing | 256 } // namespace safe_browsing |
| OLD | NEW |