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/appcache/appcache_update_job.h" | 5 #include "content/browser/appcache/appcache_update_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 | 154 |
155 void AppCacheUpdateJob::URLFetcher::OnResponseStarted( | 155 void AppCacheUpdateJob::URLFetcher::OnResponseStarted( |
156 net::URLRequest *request) { | 156 net::URLRequest *request) { |
157 DCHECK(request == request_); | 157 DCHECK(request == request_); |
158 int response_code = -1; | 158 int response_code = -1; |
159 if (request->status().is_success()) { | 159 if (request->status().is_success()) { |
160 response_code = request->GetResponseCode(); | 160 response_code = request->GetResponseCode(); |
161 job_->MadeProgress(); | 161 job_->MadeProgress(); |
162 } | 162 } |
163 if ((response_code / 100) == 2) { | |
164 | 163 |
165 // See http://code.google.com/p/chromium/issues/detail?id=69594 | 164 if ((response_code / 100) != 2) { |
166 // We willfully violate the HTML5 spec at this point in order | |
167 // to support the appcaching of cross-origin HTTPS resources. | |
168 // We've opted for a milder constraint and allow caching unless | |
169 // the resource has a "no-store" header. A spec change has been | |
170 // requested on the whatwg list. | |
171 // TODO(michaeln): Consider doing this for cross-origin HTTP resources too. | |
172 if (url_.SchemeIsSecure() && | |
173 url_.GetOrigin() != job_->manifest_url_.GetOrigin()) { | |
174 if (request->response_headers()-> | |
175 HasHeaderValue("cache-control", "no-store")) { | |
176 DCHECK_EQ(-1, redirect_response_code_); | |
177 request->Cancel(); | |
178 result_ = SERVER_ERROR; // Not the best match? | |
179 OnResponseCompleted(); | |
180 return; | |
181 } | |
182 } | |
183 | |
184 // Write response info to storage for URL fetches. Wait for async write | |
185 // completion before reading any response data. | |
186 if (fetch_type_ == URL_FETCH || fetch_type_ == MASTER_ENTRY_FETCH) { | |
187 response_writer_.reset(job_->CreateResponseWriter()); | |
188 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer( | |
189 new HttpResponseInfoIOBuffer( | |
190 new net::HttpResponseInfo(request->response_info()))); | |
191 response_writer_->WriteInfo( | |
192 io_buffer.get(), | |
193 base::Bind(&URLFetcher::OnWriteComplete, base::Unretained(this))); | |
194 } else { | |
195 ReadResponseData(); | |
196 } | |
197 } else { | |
198 if (response_code > 0) | 165 if (response_code > 0) |
199 result_ = SERVER_ERROR; | 166 result_ = SERVER_ERROR; |
200 else | 167 else |
201 result_ = NETWORK_ERROR; | 168 result_ = NETWORK_ERROR; |
202 OnResponseCompleted(); | 169 OnResponseCompleted(); |
| 170 return; |
| 171 } |
| 172 |
| 173 if (url_.SchemeIsSecure()) { |
| 174 // Do not cache content with cert errors. |
| 175 // Also, we willfully violate the HTML5 spec at this point in order |
| 176 // to support the appcaching of cross-origin HTTPS resources. |
| 177 // We've opted for a milder constraint and allow caching unless |
| 178 // the resource has a "no-store" header. A spec change has been |
| 179 // requested on the whatwg list. |
| 180 // See http://code.google.com/p/chromium/issues/detail?id=69594 |
| 181 // TODO(michaeln): Consider doing this for cross-origin HTTP too. |
| 182 if (net::IsCertStatusError(request->ssl_info().cert_status) || |
| 183 (url_.GetOrigin() != job_->manifest_url_.GetOrigin() && |
| 184 request->response_headers()-> |
| 185 HasHeaderValue("cache-control", "no-store"))) { |
| 186 DCHECK_EQ(-1, redirect_response_code_); |
| 187 request->Cancel(); |
| 188 result_ = SECURITY_ERROR; |
| 189 OnResponseCompleted(); |
| 190 return; |
| 191 } |
| 192 } |
| 193 |
| 194 // Write response info to storage for URL fetches. Wait for async write |
| 195 // completion before reading any response data. |
| 196 if (fetch_type_ == URL_FETCH || fetch_type_ == MASTER_ENTRY_FETCH) { |
| 197 response_writer_.reset(job_->CreateResponseWriter()); |
| 198 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer( |
| 199 new HttpResponseInfoIOBuffer( |
| 200 new net::HttpResponseInfo(request->response_info()))); |
| 201 response_writer_->WriteInfo( |
| 202 io_buffer.get(), |
| 203 base::Bind(&URLFetcher::OnWriteComplete, base::Unretained(this))); |
| 204 } else { |
| 205 ReadResponseData(); |
203 } | 206 } |
204 } | 207 } |
205 | 208 |
206 void AppCacheUpdateJob::URLFetcher::OnReadCompleted( | 209 void AppCacheUpdateJob::URLFetcher::OnReadCompleted( |
207 net::URLRequest* request, int bytes_read) { | 210 net::URLRequest* request, int bytes_read) { |
208 DCHECK(request_ == request); | 211 DCHECK(request_ == request); |
209 bool data_consumed = true; | 212 bool data_consumed = true; |
210 if (request->status().is_success() && bytes_read > 0) { | 213 if (request->status().is_success() && bytes_read > 0) { |
211 job_->MadeProgress(); | 214 job_->MadeProgress(); |
212 data_consumed = ConsumeResponseData(bytes_read); | 215 data_consumed = ConsumeResponseData(bytes_read); |
(...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 | 1607 |
1605 // Break the connection with the group so the group cannot call delete | 1608 // Break the connection with the group so the group cannot call delete |
1606 // on this object after we've posted a task to delete ourselves. | 1609 // on this object after we've posted a task to delete ourselves. |
1607 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); | 1610 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); |
1608 group_ = NULL; | 1611 group_ = NULL; |
1609 | 1612 |
1610 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1613 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1611 } | 1614 } |
1612 | 1615 |
1613 } // namespace content | 1616 } // namespace content |
OLD | NEW |