OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/web/net/request_tracker_impl.h" | 5 #include "ios/web/net/request_tracker_impl.h" |
6 | 6 |
7 #include <pthread.h> | 7 #include <pthread.h> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 // TODO(noyau): In iOS there is no notion of resource type. The insecure | 281 // TODO(noyau): In iOS there is no notion of resource type. The insecure |
282 // content could be an image (DISPLAYED_INSECURE_CONTENT) or a script | 282 // content could be an image (DISPLAYED_INSECURE_CONTENT) or a script |
283 // (RAN_INSECURE_CONTENT). The status of the page is different for both, but | 283 // (RAN_INSECURE_CONTENT). The status of the page is different for both, but |
284 // there is not enough information from UIWebView to differentiate the two | 284 // there is not enough information from UIWebView to differentiate the two |
285 // cases. | 285 // cases. |
286 status_.content_status = web::SSLStatus::DISPLAYED_INSECURE_CONTENT; | 286 status_.content_status = web::SSLStatus::DISPLAYED_INSECURE_CONTENT; |
287 } else { | 287 } else { |
288 status_.content_status = web::SSLStatus::NORMAL_CONTENT; | 288 status_.content_status = web::SSLStatus::NORMAL_CONTENT; |
289 } | 289 } |
290 | 290 |
291 if (!url_.SchemeIsSecure()) { | 291 if (!url_.SchemeIsCryptographic()) { |
292 // Should not happen as the sslInfo is valid. | 292 // Should not happen as the sslInfo is valid. |
293 NOTREACHED(); | 293 NOTREACHED(); |
294 status_.security_style = web::SECURITY_STYLE_UNAUTHENTICATED; | 294 status_.security_style = web::SECURITY_STYLE_UNAUTHENTICATED; |
295 } else if (net::IsCertStatusError(status_.cert_status) && | 295 } else if (net::IsCertStatusError(status_.cert_status) && |
296 !net::IsCertStatusMinorError(status_.cert_status)) { | 296 !net::IsCertStatusMinorError(status_.cert_status)) { |
297 // Minor errors don't lower the security style to | 297 // Minor errors don't lower the security style to |
298 // SECURITY_STYLE_AUTHENTICATION_BROKEN. | 298 // SECURITY_STYLE_AUTHENTICATION_BROKEN. |
299 status_.security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN; | 299 status_.security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN; |
300 } else { | 300 } else { |
301 // This page is secure. | 301 // This page is secure. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 // calculation. | 488 // calculation. |
489 counts_by_request_.clear(); | 489 counts_by_request_.clear(); |
490 estimate_start_index_ = counts_.size(); | 490 estimate_start_index_ = counts_.size(); |
491 new_estimate_round_ = false; | 491 new_estimate_round_ = false; |
492 } | 492 } |
493 const GURL& url = request->original_url(); | 493 const GURL& url = request->original_url(); |
494 TrackerCounts* counts = new TrackerCounts( | 494 TrackerCounts* counts = new TrackerCounts( |
495 GURLByRemovingRefFromGURL(url), request); | 495 GURLByRemovingRefFromGURL(url), request); |
496 counts_.push_back(counts); | 496 counts_.push_back(counts); |
497 counts_by_request_[request] = counts; | 497 counts_by_request_[request] = counts; |
498 if (page_url_.SchemeIsSecure() && !url.SchemeIsSecure()) | 498 if (page_url_.SchemeIsCryptographic() && !url.SchemeIsCryptographic()) |
499 has_mixed_content_ = true; | 499 has_mixed_content_ = true; |
500 Notify(); | 500 Notify(); |
501 } | 501 } |
502 | 502 |
503 void RequestTrackerImpl::CaptureHeaders(net::URLRequest* request) { | 503 void RequestTrackerImpl::CaptureHeaders(net::URLRequest* request) { |
504 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); | 504 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); |
505 if (is_closing_) | 505 if (is_closing_) |
506 return; | 506 return; |
507 | 507 |
508 if (!request->response_headers()) | 508 if (!request->response_headers()) |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 } | 804 } |
805 | 805 |
806 void RequestTrackerImpl::SSLNotify() { | 806 void RequestTrackerImpl::SSLNotify() { |
807 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); | 807 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); |
808 if (is_closing_) | 808 if (is_closing_) |
809 return; | 809 return; |
810 | 810 |
811 if (!counts_.size()) | 811 if (!counts_.size()) |
812 return; // Nothing yet to notify. | 812 return; // Nothing yet to notify. |
813 | 813 |
814 if (!page_url_.SchemeIsSecure()) | 814 if (!page_url_.SchemeIsCryptographic()) |
815 return; | 815 return; |
816 | 816 |
817 const GURL page_origin = page_url_.GetOrigin(); | 817 const GURL page_origin = page_url_.GetOrigin(); |
818 ScopedVector<TrackerCounts>::iterator it; | 818 ScopedVector<TrackerCounts>::iterator it; |
819 for (it = counts_.begin(); it != counts_.end(); ++it) { | 819 for (it = counts_.begin(); it != counts_.end(); ++it) { |
820 if (!(*it)->ssl_info.is_valid()) | 820 if (!(*it)->ssl_info.is_valid()) |
821 continue; // No SSL info at this point in time on this tracker. | 821 continue; // No SSL info at this point in time on this tracker. |
822 | 822 |
823 GURL request_origin = (*it)->url.GetOrigin(); | 823 GURL request_origin = (*it)->url.GetOrigin(); |
824 if (request_origin != page_origin) | 824 if (request_origin != page_origin) |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 previous_estimate_ += maxBump; | 1096 previous_estimate_ += maxBump; |
1097 } | 1097 } |
1098 | 1098 |
1099 return previous_estimate_; | 1099 return previous_estimate_; |
1100 } | 1100 } |
1101 | 1101 |
1102 void RequestTrackerImpl::RecomputeMixedContent( | 1102 void RequestTrackerImpl::RecomputeMixedContent( |
1103 const TrackerCounts* split_position) { | 1103 const TrackerCounts* split_position) { |
1104 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); | 1104 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); |
1105 // Check if the mixed content before trimming was correct. | 1105 // Check if the mixed content before trimming was correct. |
1106 if (page_url_.SchemeIsSecure() && has_mixed_content_) { | 1106 if (page_url_.SchemeIsCryptographic() && has_mixed_content_) { |
1107 bool old_url_has_mixed_content = false; | 1107 bool old_url_has_mixed_content = false; |
1108 const GURL origin = page_url_.GetOrigin(); | 1108 const GURL origin = page_url_.GetOrigin(); |
1109 ScopedVector<TrackerCounts>::iterator it = counts_.begin(); | 1109 ScopedVector<TrackerCounts>::iterator it = counts_.begin(); |
1110 while (it != counts_.end() && *it != split_position) { | 1110 while (it != counts_.end() && *it != split_position) { |
1111 if (!(*it)->url.SchemeIsSecure() && | 1111 if (!(*it)->url.SchemeIsCryptographic() && |
1112 origin == (*it)->first_party_for_cookies_origin) { | 1112 origin == (*it)->first_party_for_cookies_origin) { |
1113 old_url_has_mixed_content = true; | 1113 old_url_has_mixed_content = true; |
1114 break; | 1114 break; |
1115 } | 1115 } |
1116 ++it; | 1116 ++it; |
1117 } | 1117 } |
1118 if (!old_url_has_mixed_content) { | 1118 if (!old_url_has_mixed_content) { |
1119 // We marked the previous page with incorrect data about its mixed | 1119 // We marked the previous page with incorrect data about its mixed |
1120 // content. Turns out that the elements that triggered that condition | 1120 // content. Turns out that the elements that triggered that condition |
1121 // where in fact in a subsequent page. Duh. | 1121 // where in fact in a subsequent page. Duh. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 } | 1161 } |
1162 } | 1162 } |
1163 | 1163 |
1164 void RequestTrackerImpl::TrimToURL(const GURL& full_url, id user_info) { | 1164 void RequestTrackerImpl::TrimToURL(const GURL& full_url, id user_info) { |
1165 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); | 1165 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO); |
1166 | 1166 |
1167 GURL url = GURLByRemovingRefFromGURL(full_url); | 1167 GURL url = GURLByRemovingRefFromGURL(full_url); |
1168 | 1168 |
1169 // Locate the request with this url, if present. | 1169 // Locate the request with this url, if present. |
1170 bool new_url_has_mixed_content = false; | 1170 bool new_url_has_mixed_content = false; |
1171 bool url_scheme_is_secure = url.SchemeIsSecure(); | 1171 bool url_scheme_is_secure = url.SchemeIsCryptographic(); |
1172 ScopedVector<TrackerCounts>::const_reverse_iterator rit = counts_.rbegin(); | 1172 ScopedVector<TrackerCounts>::const_reverse_iterator rit = counts_.rbegin(); |
1173 while (rit != counts_.rend() && (*rit)->url != url) { | 1173 while (rit != counts_.rend() && (*rit)->url != url) { |
1174 if (url_scheme_is_secure && !(*rit)->url.SchemeIsSecure() && | 1174 if (url_scheme_is_secure && !(*rit)->url.SchemeIsCryptographic() && |
1175 (*rit)->first_party_for_cookies_origin == url.GetOrigin()) { | 1175 (*rit)->first_party_for_cookies_origin == url.GetOrigin()) { |
1176 new_url_has_mixed_content = true; | 1176 new_url_has_mixed_content = true; |
1177 } | 1177 } |
1178 ++rit; | 1178 ++rit; |
1179 } | 1179 } |
1180 | 1180 |
1181 // |split_position| will be set to the count for the passed url if it exists. | 1181 // |split_position| will be set to the count for the passed url if it exists. |
1182 TrackerCounts* split_position = NULL; | 1182 TrackerCounts* split_position = NULL; |
1183 if (rit != counts_.rend()) { | 1183 if (rit != counts_.rend()) { |
1184 split_position = (*rit); | 1184 split_position = (*rit); |
1185 } else { | 1185 } else { |
1186 // The URL was not found, everything will be trimmed. The mixed content | 1186 // The URL was not found, everything will be trimmed. The mixed content |
1187 // calculation is invalid. | 1187 // calculation is invalid. |
1188 new_url_has_mixed_content = false; | 1188 new_url_has_mixed_content = false; |
1189 | 1189 |
1190 // In the case of a page loaded via a HTML5 manifest there is no page | 1190 // In the case of a page loaded via a HTML5 manifest there is no page |
1191 // boundary to be found. However the latest count is a request for a | 1191 // boundary to be found. However the latest count is a request for a |
1192 // manifest. This tries to detect this peculiar case. | 1192 // manifest. This tries to detect this peculiar case. |
1193 // This is important as if this request for the manifest is on the same | 1193 // This is important as if this request for the manifest is on the same |
1194 // domain as the page itself this will allow retrieval of the SSL | 1194 // domain as the page itself this will allow retrieval of the SSL |
1195 // information. | 1195 // information. |
1196 if (url_scheme_is_secure && counts_.size()) { | 1196 if (url_scheme_is_secure && counts_.size()) { |
1197 TrackerCounts* back = counts_.back(); | 1197 TrackerCounts* back = counts_.back(); |
1198 const GURL& back_url = back->url; | 1198 const GURL& back_url = back->url; |
1199 if (back_url.SchemeIsSecure() && | 1199 if (back_url.SchemeIsCryptographic() && |
1200 back_url.GetOrigin() == url.GetOrigin() && | 1200 back_url.GetOrigin() == url.GetOrigin() && !back->is_subrequest) { |
1201 !back->is_subrequest) { | |
1202 split_position = back; | 1201 split_position = back; |
1203 } | 1202 } |
1204 } | 1203 } |
1205 } | 1204 } |
1206 RecomputeMixedContent(split_position); | 1205 RecomputeMixedContent(split_position); |
1207 RecomputeCertificatePolicy(split_position); | 1206 RecomputeCertificatePolicy(split_position); |
1208 | 1207 |
1209 // Trim up to that element. | 1208 // Trim up to that element. |
1210 ScopedVector<TrackerCounts>::iterator it = counts_.begin(); | 1209 ScopedVector<TrackerCounts>::iterator it = counts_.begin(); |
1211 while (it != counts_.end() && *it != split_position) { | 1210 while (it != counts_.end() && *it != split_position) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 })); | 1298 })); |
1300 } | 1299 } |
1301 } | 1300 } |
1302 | 1301 |
1303 void RequestTrackerImpl::SetCertificatePolicyCacheForTest( | 1302 void RequestTrackerImpl::SetCertificatePolicyCacheForTest( |
1304 web::CertificatePolicyCache* cache) { | 1303 web::CertificatePolicyCache* cache) { |
1305 policy_cache_ = cache; | 1304 policy_cache_ = cache; |
1306 } | 1305 } |
1307 | 1306 |
1308 } // namespace web | 1307 } // namespace web |
OLD | NEW |