OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/loader/resource_loader.h" | 5 #include "content/browser/loader/resource_loader.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 #include "net/http/http_response_headers.h" | 39 #include "net/http/http_response_headers.h" |
40 #include "net/nqe/effective_connection_type.h" | 40 #include "net/nqe/effective_connection_type.h" |
41 #include "net/nqe/network_quality_estimator.h" | 41 #include "net/nqe/network_quality_estimator.h" |
42 #include "net/ssl/client_cert_store.h" | 42 #include "net/ssl/client_cert_store.h" |
43 #include "net/ssl/ssl_platform_key.h" | 43 #include "net/ssl/ssl_platform_key.h" |
44 #include "net/ssl/ssl_private_key.h" | 44 #include "net/ssl/ssl_private_key.h" |
45 #include "net/url_request/redirect_info.h" | 45 #include "net/url_request/redirect_info.h" |
46 #include "net/url_request/url_request_context.h" | 46 #include "net/url_request/url_request_context.h" |
47 #include "net/url_request/url_request_status.h" | 47 #include "net/url_request/url_request_status.h" |
48 | 48 |
49 | |
50 #include "content/browser/frame_host/frame_tree.h" | |
51 #include "content/browser/frame_host/frame_tree_node.h" | |
52 #include "content/browser/frame_host/render_frame_host_impl.h" | |
53 #include "content/browser/frame_host/render_frame_host_manager.h" | |
54 #include "content/browser/web_contents/web_contents_impl.h" | |
55 #include "content/public/browser/navigation_controller.h" | |
56 #include "content/public/browser/navigation_entry.h" | |
57 | |
49 using base::TimeDelta; | 58 using base::TimeDelta; |
50 using base::TimeTicks; | 59 using base::TimeTicks; |
51 | 60 |
52 namespace content { | 61 namespace content { |
53 namespace { | 62 namespace { |
54 | 63 |
55 void GetSSLStatusForRequest(const GURL& url, | 64 void SetSSLStatus(const base::Callback<WebContents*(void)>& wc_getter, |
56 const net::SSLInfo& ssl_info, | 65 const GURL& url, |
57 int child_id, | 66 const SSLStatus& ssl_status) { |
58 CertStore* cert_store, | 67 WebContentsImpl* web_contents = |
59 SSLStatus* ssl_status) { | 68 static_cast<WebContentsImpl*>(wc_getter.Run()); |
60 DCHECK(ssl_info.cert); | 69 if (!web_contents) |
61 int cert_id = cert_store->StoreCert(ssl_info.cert.get(), child_id); | 70 return; |
71 NavigationEntry* pending_entry = | |
72 web_contents->GetController().GetPendingEntry(); | |
73 if (!pending_entry) | |
74 return; | |
62 | 75 |
63 *ssl_status = SSLStatus(SSLPolicy::GetSecurityStyleForResource( | 76 // First check the pending entry. This is the case for the normal navigation |
64 url, cert_id, ssl_info.cert_status), | 77 // case without redirect. |
65 cert_id, ssl_info); | 78 if (pending_entry->GetURL() == url) { |
79 pending_entry->GetSSL() = ssl_status; | |
estark
2016/08/15 08:14:08
Does this change the behavior of the omnibox durin
jam
2016/08/15 19:23:58
I just tried adding breakpoints and looking at the
| |
80 return; | |
81 } | |
82 | |
83 // Handle redirect case since url won't match now. So cache the SSLStatus | |
84 // along with the url which we'll check when the commit happens. | |
85 RenderFrameHostImpl* rfh = | |
86 web_contents->GetFrameTree()->root()->render_manager()-> | |
87 current_frame_host(); | |
88 if (rfh) | |
89 rfh->SetSSLStatusForPendingNavigate(url, ssl_status); | |
66 } | 90 } |
67 | 91 |
68 void PopulateResourceResponse(ResourceRequestInfoImpl* info, | 92 void PopulateResourceResponse(ResourceRequestInfoImpl* info, |
69 net::URLRequest* request, | 93 net::URLRequest* request, |
70 CertStore* cert_store, | 94 CertStore* cert_store, |
71 ResourceResponse* response) { | 95 ResourceResponse* response) { |
72 response->head.request_time = request->request_time(); | 96 response->head.request_time = request->request_time(); |
73 response->head.response_time = request->response_time(); | 97 response->head.response_time = request->response_time(); |
74 response->head.headers = request->response_headers(); | 98 response->head.headers = request->response_headers(); |
75 request->GetCharset(&response->head.charset); | 99 request->GetCharset(&response->head.charset); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 if (service_worker_info) | 131 if (service_worker_info) |
108 service_worker_info->GetExtraResponseInfo(&response->head); | 132 service_worker_info->GetExtraResponseInfo(&response->head); |
109 AppCacheInterceptor::GetExtraResponseInfo( | 133 AppCacheInterceptor::GetExtraResponseInfo( |
110 request, &response->head.appcache_id, | 134 request, &response->head.appcache_id, |
111 &response->head.appcache_manifest_url); | 135 &response->head.appcache_manifest_url); |
112 if (info->is_load_timing_enabled()) | 136 if (info->is_load_timing_enabled()) |
113 request->GetLoadTimingInfo(&response->head.load_timing); | 137 request->GetLoadTimingInfo(&response->head.load_timing); |
114 | 138 |
115 if (request->ssl_info().cert.get()) { | 139 if (request->ssl_info().cert.get()) { |
116 SSLStatus ssl_status; | 140 SSLStatus ssl_status; |
117 GetSSLStatusForRequest(request->url(), request->ssl_info(), | 141 ResourceLoader::GetSSLStatusForRequest( |
118 info->GetChildID(), cert_store, &ssl_status); | 142 request->url(), request->ssl_info(), info->GetChildID(), |
143 cert_store, &ssl_status); | |
144 | |
145 if (info->IsMainFrame()) { | |
estark
2016/08/15 08:14:08
1. The comment on ResourceRequestInfo::IsMainFrame
jam
2016/08/15 19:23:58
ah, thanks, yes that's what I wanted. fixed.
| |
146 // Store the SSLStatus in the pending NavigationEntry so that if it's | |
147 // committed we can store it in the SSLManager. | |
148 BrowserThread::PostTask(BrowserThread::UI, | |
149 FROM_HERE, | |
150 base::Bind(SetSSLStatus, | |
151 info->GetWebContentsGetterForRequest(), | |
152 request->url(), | |
153 ssl_status)); | |
154 } | |
119 response->head.security_info = SerializeSecurityInfo(ssl_status); | 155 response->head.security_info = SerializeSecurityInfo(ssl_status); |
120 response->head.has_major_certificate_errors = | 156 response->head.has_major_certificate_errors = |
121 net::IsCertStatusError(ssl_status.cert_status) && | 157 net::IsCertStatusError(ssl_status.cert_status) && |
122 !net::IsCertStatusMinorError(ssl_status.cert_status); | 158 !net::IsCertStatusMinorError(ssl_status.cert_status); |
123 if (info->ShouldReportRawHeaders()) { | 159 if (info->ShouldReportRawHeaders()) { |
124 // Only pass the Signed Certificate Timestamps (SCTs) when the network | 160 // Only pass the Signed Certificate Timestamps (SCTs) when the network |
125 // panel of the DevTools is open, i.e. ShouldReportRawHeaders() is set. | 161 // panel of the DevTools is open, i.e. ShouldReportRawHeaders() is set. |
126 // These data are used to populate the requests in the security panel too. | 162 // These data are used to populate the requests in the security panel too. |
127 response->head.signed_certificate_timestamps = | 163 response->head.signed_certificate_timestamps = |
128 request->ssl_info().signed_certificate_timestamps; | 164 request->ssl_info().signed_certificate_timestamps; |
129 } | 165 } |
130 } else { | 166 } else { |
131 // We should not have any SSL state. | 167 // We should not have any SSL state. |
132 DCHECK(!request->ssl_info().cert_status); | 168 DCHECK(!request->ssl_info().cert_status); |
133 DCHECK_EQ(request->ssl_info().security_bits, -1); | 169 DCHECK_EQ(request->ssl_info().security_bits, -1); |
134 DCHECK_EQ(request->ssl_info().key_exchange_info, 0); | 170 DCHECK_EQ(request->ssl_info().key_exchange_info, 0); |
135 DCHECK(!request->ssl_info().connection_status); | 171 DCHECK(!request->ssl_info().connection_status); |
136 } | 172 } |
137 } | 173 } |
138 | 174 |
139 } // namespace | 175 } // namespace |
140 | 176 |
177 void ResourceLoader::GetSSLStatusForRequest(const GURL& url, | |
178 const net::SSLInfo& ssl_info, | |
179 int child_id, | |
180 CertStore* cert_store, | |
181 SSLStatus* ssl_status) { | |
182 DCHECK(ssl_info.cert); | |
183 int cert_id = cert_store->StoreCert(ssl_info.cert.get(), child_id); | |
184 | |
185 *ssl_status = SSLStatus(SSLPolicy::GetSecurityStyleForResource( | |
186 url, cert_id, ssl_info.cert_status), | |
187 cert_id, ssl_info); | |
188 } | |
189 | |
141 ResourceLoader::ResourceLoader(std::unique_ptr<net::URLRequest> request, | 190 ResourceLoader::ResourceLoader(std::unique_ptr<net::URLRequest> request, |
142 std::unique_ptr<ResourceHandler> handler, | 191 std::unique_ptr<ResourceHandler> handler, |
143 CertStore* cert_store, | 192 CertStore* cert_store, |
144 ResourceLoaderDelegate* delegate) | 193 ResourceLoaderDelegate* delegate) |
145 : deferred_stage_(DEFERRED_NONE), | 194 : deferred_stage_(DEFERRED_NONE), |
146 request_(std::move(request)), | 195 request_(std::move(request)), |
147 handler_(std::move(handler)), | 196 handler_(std::move(handler)), |
148 delegate_(delegate), | 197 delegate_(delegate), |
149 is_transferring_(false), | 198 is_transferring_(false), |
150 times_cancelled_before_request_start_(0), | 199 times_cancelled_before_request_start_(0), |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 } | 787 } |
739 | 788 |
740 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); | 789 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); |
741 } else if (request_->response_info().unused_since_prefetch) { | 790 } else if (request_->response_info().unused_since_prefetch) { |
742 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time(); | 791 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time(); |
743 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time); | 792 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time); |
744 } | 793 } |
745 } | 794 } |
746 | 795 |
747 } // namespace content | 796 } // namespace content |
OLD | NEW |