Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/buffered_resource_handler.h" | 5 #include "chrome/browser/renderer_host/buffered_resource_handler.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/mime_sniffer.h" | 10 #include "net/base/mime_sniffer.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 bool BufferedResourceHandler::DelayResponse() { | 144 bool BufferedResourceHandler::DelayResponse() { |
| 145 std::string mime_type; | 145 std::string mime_type; |
| 146 request_->GetMimeType(&mime_type); | 146 request_->GetMimeType(&mime_type); |
| 147 | 147 |
| 148 std::string content_type_options; | 148 std::string content_type_options; |
| 149 request_->GetResponseHeaderByName("x-content-type-options", | 149 request_->GetResponseHeaderByName("x-content-type-options", |
| 150 &content_type_options); | 150 &content_type_options); |
| 151 | 151 |
| 152 const bool sniffing_blocked = | 152 const bool sniffing_blocked = |
| 153 LowerCaseEqualsASCII(content_type_options, "nosniff"); | 153 LowerCaseEqualsASCII(content_type_options, "nosniff"); |
| 154 const bool no_data = | |
| 155 response_->response_head.headers && // Can be NULL if FTP. | |
| 156 (response_->response_head.headers->response_code() == 304 || | |
|
eroman
2009/09/01 03:30:58
I'm not sure that it is appropriate to put HTTP-co
| |
| 157 response_->response_head.headers->response_code() == 204); | |
| 154 const bool we_would_like_to_sniff = | 158 const bool we_would_like_to_sniff = |
| 155 net::ShouldSniffMimeType(request_->url(), mime_type); | 159 no_data ? false : net::ShouldSniffMimeType(request_->url(), mime_type); |
| 156 | 160 |
| 157 RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type); | 161 RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type); |
| 158 | 162 |
| 159 if (!sniffing_blocked && we_would_like_to_sniff) { | 163 if (!sniffing_blocked && we_would_like_to_sniff) { |
| 160 // We're going to look at the data before deciding what the content type | 164 // We're going to look at the data before deciding what the content type |
| 161 // is. That means we need to delay sending the ResponseStarted message | 165 // is. That means we need to delay sending the ResponseStarted message |
| 162 // over the IPC channel. | 166 // over the IPC channel. |
| 163 sniff_content_ = true; | 167 sniff_content_ = true; |
| 164 LOG(INFO) << "To buffer: " << request_->url().spec(); | 168 LOG(INFO) << "To buffer: " << request_->url().spec(); |
| 165 return true; | 169 return true; |
| 166 } | 170 } |
| 167 | 171 |
| 168 if (sniffing_blocked && mime_type.empty()) { | 172 if (sniffing_blocked && mime_type.empty() && !no_data) { |
| 169 // Ugg. The server told us not to sniff the content but didn't give us a | 173 // Ugg. The server told us not to sniff the content but didn't give us a |
| 170 // mime type. What's a browser to do? Turns out, we're supposed to treat | 174 // mime type. What's a browser to do? Turns out, we're supposed to treat |
| 171 // the response as "text/plain". This is the most secure option. | 175 // the response as "text/plain". This is the most secure option. |
| 172 mime_type.assign("text/plain"); | 176 mime_type.assign("text/plain"); |
| 173 response_->response_head.mime_type.assign(mime_type); | 177 response_->response_head.mime_type.assign(mime_type); |
| 174 } | 178 } |
| 175 | 179 |
| 176 if (ShouldBuffer(request_->url(), mime_type)) { | 180 if (ShouldBuffer(request_->url(), mime_type)) { |
| 177 // This is a temporary fix for the fact that webkit expects to have | 181 // This is a temporary fix for the fact that webkit expects to have |
| 178 // enough data to decode the doctype in order to select the rendering | 182 // enough data to decode the doctype in order to select the rendering |
| 179 // mode. | 183 // mode. |
| 180 should_buffer_ = true; | 184 should_buffer_ = true; |
| 181 LOG(INFO) << "To buffer: " << request_->url().spec(); | 185 LOG(INFO) << "To buffer: " << request_->url().spec(); |
| 182 return true; | 186 return true; |
| 183 } | 187 } |
| 184 | 188 |
| 185 if (ShouldWaitForPlugins()) { | 189 if (!no_data && ShouldWaitForPlugins()) { |
| 186 wait_for_plugins_ = true; | 190 wait_for_plugins_ = true; |
| 187 return true; | 191 return true; |
| 188 } | 192 } |
| 189 | 193 |
| 190 return false; | 194 return false; |
| 191 } | 195 } |
| 192 | 196 |
| 193 bool BufferedResourceHandler::ShouldBuffer(const GURL& url, | 197 bool BufferedResourceHandler::ShouldBuffer(const GURL& url, |
| 194 const std::string& mime_type) { | 198 const std::string& mime_type) { |
| 195 // We are willing to buffer for HTTP and HTTPS. | 199 // We are willing to buffer for HTTP and HTTPS. |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 428 wait_for_plugins_ = false; | 432 wait_for_plugins_ = false; |
| 429 if (request_) { | 433 if (request_) { |
| 430 ResourceDispatcherHost::ExtraRequestInfo* info = | 434 ResourceDispatcherHost::ExtraRequestInfo* info = |
| 431 ResourceDispatcherHost::ExtraInfoForRequest(request_); | 435 ResourceDispatcherHost::ExtraInfoForRequest(request_); |
| 432 host_->PauseRequest(info->process_id, info->request_id, false); | 436 host_->PauseRequest(info->process_id, info->request_id, false); |
| 433 if (!CompleteResponseStarted(info->request_id, false)) | 437 if (!CompleteResponseStarted(info->request_id, false)) |
| 434 host_->CancelRequest(info->process_id, info->request_id, false); | 438 host_->CancelRequest(info->process_id, info->request_id, false); |
| 435 } | 439 } |
| 436 Release(); | 440 Release(); |
| 437 } | 441 } |
| OLD | NEW |