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

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

Issue 274075: Sniff 204 responses as text/plain to avoid creating unwanted downloads.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 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 | chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc » ('j') | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <vector> 7 #include <vector>
8 8
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 bool BufferedResourceHandler::DelayResponse() { 147 bool BufferedResourceHandler::DelayResponse() {
148 std::string mime_type; 148 std::string mime_type;
149 request_->GetMimeType(&mime_type); 149 request_->GetMimeType(&mime_type);
150 150
151 std::string content_type_options; 151 std::string content_type_options;
152 request_->GetResponseHeaderByName("x-content-type-options", 152 request_->GetResponseHeaderByName("x-content-type-options",
153 &content_type_options); 153 &content_type_options);
154 154
155 const bool sniffing_blocked = 155 const bool sniffing_blocked =
156 LowerCaseEqualsASCII(content_type_options, "nosniff"); 156 LowerCaseEqualsASCII(content_type_options, "nosniff");
157 const bool no_data = 157 const bool not_modified_status =
158 response_->response_head.headers && // Can be NULL if FTP. 158 response_->response_head.headers &&
159 (response_->response_head.headers->response_code() == 304 || 159 response_->response_head.headers->response_code() == 304;
160 response_->response_head.headers->response_code() == 204); 160 const bool we_would_like_to_sniff = not_modified_status ?
161 const bool we_would_like_to_sniff = 161 false : net::ShouldSniffMimeType(request_->url(), mime_type);
162 no_data ? false : net::ShouldSniffMimeType(request_->url(), mime_type);
163 162
164 RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type); 163 RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type);
165 164
166 if (!sniffing_blocked && we_would_like_to_sniff) { 165 if (!sniffing_blocked && we_would_like_to_sniff) {
167 // We're going to look at the data before deciding what the content type 166 // We're going to look at the data before deciding what the content type
168 // is. That means we need to delay sending the ResponseStarted message 167 // is. That means we need to delay sending the ResponseStarted message
169 // over the IPC channel. 168 // over the IPC channel.
170 sniff_content_ = true; 169 sniff_content_ = true;
171 LOG(INFO) << "To buffer: " << request_->url().spec(); 170 LOG(INFO) << "To buffer: " << request_->url().spec();
172 return true; 171 return true;
173 } 172 }
174 173
175 if (sniffing_blocked && mime_type.empty() && !no_data) { 174 if (sniffing_blocked && mime_type.empty() && !not_modified_status) {
176 // Ugg. The server told us not to sniff the content but didn't give us a 175 // Ugg. The server told us not to sniff the content but didn't give us a
177 // mime type. What's a browser to do? Turns out, we're supposed to treat 176 // mime type. What's a browser to do? Turns out, we're supposed to treat
178 // the response as "text/plain". This is the most secure option. 177 // the response as "text/plain". This is the most secure option.
179 mime_type.assign("text/plain"); 178 mime_type.assign("text/plain");
180 response_->response_head.mime_type.assign(mime_type); 179 response_->response_head.mime_type.assign(mime_type);
181 } 180 }
182 181
183 if (mime_type == "application/rss+xml" || 182 if (mime_type == "application/rss+xml" ||
184 mime_type == "application/atom+xml") { 183 mime_type == "application/atom+xml") {
185 // Sad face. The server told us that they wanted us to treat the response 184 // Sad face. The server told us that they wanted us to treat the response
186 // as RSS or Atom. Unfortunately, we don't have a built-in feed previewer 185 // as RSS or Atom. Unfortunately, we don't have a built-in feed previewer
187 // like other browsers. We can't just render the content as XML because 186 // like other browsers. We can't just render the content as XML because
188 // web sites let third parties inject arbitrary script into their RSS 187 // web sites let third parties inject arbitrary script into their RSS
189 // feeds. That leaves us with little choice but to practically ignore the 188 // feeds. That leaves us with little choice but to practically ignore the
190 // response. In the future, when we have an RSS feed previewer, we can 189 // response. In the future, when we have an RSS feed previewer, we can
191 // remove this logic. 190 // remove this logic.
192 mime_type.assign("text/plain"); 191 mime_type.assign("text/plain");
193 response_->response_head.mime_type.assign(mime_type); 192 response_->response_head.mime_type.assign(mime_type);
194 } 193 }
195 194
196 if (ShouldBuffer(request_->url(), mime_type)) { 195 if (ShouldBuffer(request_->url(), mime_type)) {
197 // This is a temporary fix for the fact that webkit expects to have 196 // This is a temporary fix for the fact that webkit expects to have
198 // enough data to decode the doctype in order to select the rendering 197 // enough data to decode the doctype in order to select the rendering
199 // mode. 198 // mode.
200 should_buffer_ = true; 199 should_buffer_ = true;
201 LOG(INFO) << "To buffer: " << request_->url().spec(); 200 LOG(INFO) << "To buffer: " << request_->url().spec();
202 return true; 201 return true;
203 } 202 }
204 203
205 if (!no_data && ShouldWaitForPlugins()) { 204 if (!not_modified_status && ShouldWaitForPlugins()) {
206 wait_for_plugins_ = true; 205 wait_for_plugins_ = true;
207 return true; 206 return true;
208 } 207 }
209 208
210 return false; 209 return false;
211 } 210 }
212 211
213 bool BufferedResourceHandler::ShouldBuffer(const GURL& url, 212 bool BufferedResourceHandler::ShouldBuffer(const GURL& url,
214 const std::string& mime_type) { 213 const std::string& mime_type) {
215 // We are willing to buffer for HTTP and HTTPS. 214 // We are willing to buffer for HTTP and HTTPS.
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 wait_for_plugins_ = false; 447 wait_for_plugins_ = false;
449 if (request_) { 448 if (request_) {
450 ResourceDispatcherHostRequestInfo* info = 449 ResourceDispatcherHostRequestInfo* info =
451 ResourceDispatcherHost::InfoForRequest(request_); 450 ResourceDispatcherHost::InfoForRequest(request_);
452 host_->PauseRequest(info->child_id(), info->request_id(), false); 451 host_->PauseRequest(info->child_id(), info->request_id(), false);
453 if (!CompleteResponseStarted(info->request_id(), false)) 452 if (!CompleteResponseStarted(info->request_id(), false))
454 host_->CancelRequest(info->child_id(), info->request_id(), false); 453 host_->CancelRequest(info->child_id(), info->request_id(), false);
455 } 454 }
456 Release(); 455 Release();
457 } 456 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698