| 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 | 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 Loading... |
| 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 Loading... |
| 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 const GURL& password_form_frame_url, |
| 201 LoginReputationClientRequest::TriggerType type) { |
| 203 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 202 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 204 scoped_refptr<PasswordProtectionRequest> request( | 203 scoped_refptr<PasswordProtectionRequest> request( |
| 205 new PasswordProtectionRequest(main_frame_url, type, | 204 new PasswordProtectionRequest(main_frame_url, password_form_action, |
| 206 std::move(password_frames), this, | 205 password_form_frame_url, type, this, |
| 207 GetRequestTimeoutInMS())); | 206 GetRequestTimeoutInMS())); |
| 208 DCHECK(request); | 207 DCHECK(request); |
| 209 request->Start(); | 208 request->Start(); |
| 210 requests_.insert(std::move(request)); | 209 requests_.insert(std::move(request)); |
| 211 } | 210 } |
| 212 | 211 |
| 213 void PasswordProtectionService::MaybeStartLowReputationRequest( | 212 void PasswordProtectionService::MaybeStartLowReputationRequest( |
| 214 const GURL& main_frame_url, | 213 const GURL& main_frame_url, |
| 215 std::unique_ptr<PasswordProtectionFrameList> password_frames) { | 214 const GURL& password_form_action, |
| 215 const GURL& password_form_frame_url) { |
| 216 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 216 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 217 if (!IsPingingEnabled()) | 217 if (!IsPingingEnabled()) |
| 218 return; | 218 return; |
| 219 | 219 |
| 220 // Skip URLs that we can't get a reliable reputation for. | 220 // Skip URLs that we can't get a reliable reputation for. |
| 221 if (!main_frame_url.is_valid() || !main_frame_url.SchemeIsHTTPOrHTTPS()) { | 221 if (!main_frame_url.is_valid() || !main_frame_url.SchemeIsHTTPOrHTTPS()) { |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 StartRequest(main_frame_url, | 225 StartRequest(main_frame_url, password_form_action, password_form_frame_url, |
| 226 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, | 226 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE); |
| 227 std::move(password_frames)); | |
| 228 } | 227 } |
| 229 | 228 |
| 230 void PasswordProtectionService::RequestFinished( | 229 void PasswordProtectionService::RequestFinished( |
| 231 PasswordProtectionRequest* request, | 230 PasswordProtectionRequest* request, |
| 232 std::unique_ptr<LoginReputationClientResponse> response) { | 231 std::unique_ptr<LoginReputationClientResponse> response) { |
| 233 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 232 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 234 | 233 |
| 235 DCHECK(request); | 234 DCHECK(request); |
| 236 // TODO(jialiul): We don't cache verdict for incognito mode for now. | 235 // TODO(jialiul): We don't cache verdict for incognito mode for now. |
| 237 // Later we may consider temporarily caching verdict. | 236 // Later we may consider temporarily caching verdict. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 const std::vector<char> verdict_blob(serialized_proto.begin(), | 446 const std::vector<char> verdict_blob(serialized_proto.begin(), |
| 448 serialized_proto.end()); | 447 serialized_proto.end()); |
| 449 std::unique_ptr<base::Value> binary_value = | 448 std::unique_ptr<base::Value> binary_value = |
| 450 base::MakeUnique<base::Value>(verdict_blob); | 449 base::MakeUnique<base::Value>(verdict_blob); |
| 451 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); | 450 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); |
| 452 result->Set(kVerdictProto, std::move(binary_value)); | 451 result->Set(kVerdictProto, std::move(binary_value)); |
| 453 return result; | 452 return result; |
| 454 } | 453 } |
| 455 | 454 |
| 456 } // namespace safe_browsing | 455 } // namespace safe_browsing |
| OLD | NEW |