Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(901)

Side by Side Diff: chrome/browser/renderer_host/buffered_resource_handler.cc

Issue 18549: When the server says "nosniff" but then doesn't give us a Content-Type we now... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/base/mime_sniffer.h" 8 #include "net/base/mime_sniffer.h"
9 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" 9 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h"
10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 110
111 bool BufferedResourceHandler::DelayResponse() { 111 bool BufferedResourceHandler::DelayResponse() {
112 std::string mime_type; 112 std::string mime_type;
113 request_->GetMimeType(&mime_type); 113 request_->GetMimeType(&mime_type);
114 114
115 std::string content_type_options; 115 std::string content_type_options;
116 request_->GetResponseHeaderByName("x-content-type-options", 116 request_->GetResponseHeaderByName("x-content-type-options",
117 &content_type_options); 117 &content_type_options);
118 118
119 const bool sniffing_blocked = (content_type_options == "nosniff"); 119 const bool sniffing_blocked =
120 LowerCaseEqualsASCII(content_type_options, "nosniff");
darin (slow to review) 2009/01/23 15:59:05 good fix
120 const bool we_would_like_to_sniff = 121 const bool we_would_like_to_sniff =
121 net::ShouldSniffMimeType(request_->url(), mime_type); 122 net::ShouldSniffMimeType(request_->url(), mime_type);
122 123
123 RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type); 124 RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type);
124 125
125 if (!sniffing_blocked && we_would_like_to_sniff) { 126 if (!sniffing_blocked && we_would_like_to_sniff) {
126 // We're going to look at the data before deciding what the content type 127 // We're going to look at the data before deciding what the content type
127 // is. That means we need to delay sending the ResponseStarted message 128 // is. That means we need to delay sending the ResponseStarted message
128 // over the IPC channel. 129 // over the IPC channel.
129 sniff_content_ = true; 130 sniff_content_ = true;
130 LOG(INFO) << "To buffer: " << request_->url().spec(); 131 LOG(INFO) << "To buffer: " << request_->url().spec();
131 return true; 132 return true;
132 } 133 }
133 134
135 if (sniffing_blocked && mime_type.empty()) {
136 // Ugg. The server told us not to sniff the content but didn't give us a
137 // mime type. What's a browser to do? Turns out, we're supposed to treat
138 // the response as "text/plain". This is the most secure option.
139 mime_type.assign("text/plain");
140 response_->response_head.mime_type.assign(mime_type);
141 }
142
134 if (ShouldBuffer(request_->url(), mime_type)) { 143 if (ShouldBuffer(request_->url(), mime_type)) {
135 // This is a temporary fix for the fact that webkit expects to have 144 // This is a temporary fix for the fact that webkit expects to have
136 // enough data to decode the doctype in order to select the rendering 145 // enough data to decode the doctype in order to select the rendering
137 // mode. 146 // mode.
138 should_buffer_ = true; 147 should_buffer_ = true;
139 LOG(INFO) << "To buffer: " << request_->url().spec(); 148 LOG(INFO) << "To buffer: " << request_->url().spec();
140 return true; 149 return true;
141 } 150 }
142 return false; 151 return false;
143 } 152 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 real_handler_ = download_handler; 257 real_handler_ = download_handler;
249 } 258 }
250 return real_handler_->OnResponseStarted(request_id, response_); 259 return real_handler_->OnResponseStarted(request_id, response_);
251 } 260 }
252 261
253 bool BufferedResourceHandler::DidBufferEnough(int bytes_read) { 262 bool BufferedResourceHandler::DidBufferEnough(int bytes_read) {
254 const int kRequiredLength = 256; 263 const int kRequiredLength = 256;
255 264
256 return bytes_read >= kRequiredLength; 265 return bytes_read >= kRequiredLength;
257 } 266 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698