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 #include "net/traffic_annotation/network_traffic_annotation.h" |
15 | 16 |
16 using content::BrowserThread; | 17 using content::BrowserThread; |
17 | 18 |
18 namespace safe_browsing { | 19 namespace safe_browsing { |
19 | 20 |
20 PasswordProtectionRequest::PasswordProtectionRequest( | 21 PasswordProtectionRequest::PasswordProtectionRequest( |
21 const GURL& main_frame_url, | 22 const GURL& main_frame_url, |
22 const GURL& password_form_action, | 23 const GURL& password_form_action, |
23 const GURL& password_form_frame_url, | 24 const GURL& password_form_frame_url, |
24 LoginReputationClientRequest::TriggerType type, | 25 LoginReputationClientRequest::TriggerType type, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 FillRequestProto(); | 120 FillRequestProto(); |
120 | 121 |
121 std::string serialized_request; | 122 std::string serialized_request; |
122 if (!request_proto_->SerializeToString(&serialized_request)) { | 123 if (!request_proto_->SerializeToString(&serialized_request)) { |
123 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); | 124 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); |
124 return; | 125 return; |
125 } | 126 } |
126 | 127 |
127 // In case the request take too long, we set a timer to cancel this request. | 128 // In case the request take too long, we set a timer to cancel this request. |
128 StartTimeout(); | 129 StartTimeout(); |
129 | 130 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 131 net::DefineNetworkTrafficAnnotation("password_protection_request", R"( |
| 132 semantics { |
| 133 sender: "Safe Browsing" |
| 134 description: |
| 135 "When the user is about to log in to a new, uncommon site, Chrome " |
| 136 "will send a request to Safe Browsing to determine if the page is " |
| 137 "phishing. It'll then show a warning if the page poses a risk of " |
| 138 "phishing." |
| 139 trigger: |
| 140 "When a user focuses on a password field on a page that they " |
| 141 "haven't visited before and that isn't popular or known to be safe." |
| 142 data: |
| 143 "URL and referrer of the current page, password form action, and " |
| 144 "iframe structure." |
| 145 destination: GOOGLE_OWNED_SERVICE |
| 146 } |
| 147 policy { |
| 148 cookies_allowed: true |
| 149 cookies_store: "Safe Browsing Cookie Store" |
| 150 setting: |
| 151 "Users can control this feature via 'Protect you and your device " |
| 152 "from dangerous sites' or 'Automatically report details of " |
| 153 "possible security incidents to Google' setting under 'Privacy'. " |
| 154 "By default, the first setting is enabled and the second is not." |
| 155 chrome_policy { |
| 156 SafeBrowsingExtendedReportingOptInAllowed { |
| 157 policy_options {mode: MANDATORY} |
| 158 SafeBrowsingExtendedReportingOptInAllowed: false |
| 159 } |
| 160 } |
| 161 })"); |
130 fetcher_ = net::URLFetcher::Create( | 162 fetcher_ = net::URLFetcher::Create( |
131 0, PasswordProtectionService::GetPasswordProtectionRequestUrl(), | 163 0, PasswordProtectionService::GetPasswordProtectionRequestUrl(), |
132 net::URLFetcher::POST, this); | 164 net::URLFetcher::POST, this, traffic_annotation); |
133 data_use_measurement::DataUseUserData::AttachToFetcher( | 165 data_use_measurement::DataUseUserData::AttachToFetcher( |
134 fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); | 166 fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); |
135 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 167 fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
136 fetcher_->SetAutomaticallyRetryOn5xx(false); | 168 fetcher_->SetAutomaticallyRetryOn5xx(false); |
137 fetcher_->SetRequestContext( | 169 fetcher_->SetRequestContext( |
138 password_protection_service_->request_context_getter().get()); | 170 password_protection_service_->request_context_getter().get()); |
139 fetcher_->SetUploadData("application/octet-stream", serialized_request); | 171 fetcher_->SetUploadData("application/octet-stream", serialized_request); |
140 request_start_time_ = base::TimeTicks::Now(); | 172 request_start_time_ = base::TimeTicks::Now(); |
141 fetcher_->Start(); | 173 fetcher_->Start(); |
142 } | 174 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 249 } |
218 | 250 |
219 void PasswordProtectionRequest::Cancel(bool timed_out) { | 251 void PasswordProtectionRequest::Cancel(bool timed_out) { |
220 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 252 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
221 fetcher_.reset(); | 253 fetcher_.reset(); |
222 | 254 |
223 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); | 255 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); |
224 } | 256 } |
225 | 257 |
226 } // namespace safe_browsing | 258 } // namespace safe_browsing |
OLD | NEW |