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

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

Issue 55049: Add the ability to specify a default MIME type when loading a resource. We'l... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 8 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
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 "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/mime_sniffer.h" 9 #include "net/base/mime_sniffer.h"
10 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" 10 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 return false; 173 return false;
174 174
175 // Today, the only reason to buffer the request is to fix the doctype decoding 175 // Today, the only reason to buffer the request is to fix the doctype decoding
176 // performed by webkit: if there is not enough data it will go to quirks mode. 176 // performed by webkit: if there is not enough data it will go to quirks mode.
177 // We only expect the doctype check to apply to html documents. 177 // We only expect the doctype check to apply to html documents.
178 return mime_type == "text/html"; 178 return mime_type == "text/html";
179 } 179 }
180 180
181 bool BufferedResourceHandler::KeepBuffering(int bytes_read) { 181 bool BufferedResourceHandler::KeepBuffering(int bytes_read) {
182 DCHECK(read_buffer_); 182 DCHECK(read_buffer_);
183
184 ResourceDispatcherHost::ExtraRequestInfo* info =
185 ResourceDispatcherHost::ExtraInfoForRequest(request_);
186 DCHECK(info);
187
183 if (my_buffer_) { 188 if (my_buffer_) {
184 // We are using our own buffer to read, update the main buffer. 189 // We are using our own buffer to read, update the main buffer.
185 CHECK(bytes_read + bytes_read_ < read_buffer_size_); 190 CHECK(bytes_read + bytes_read_ < read_buffer_size_);
186 memcpy(read_buffer_->data() + bytes_read_, my_buffer_->data(), bytes_read); 191 memcpy(read_buffer_->data() + bytes_read_, my_buffer_->data(), bytes_read);
187 my_buffer_ = NULL; 192 my_buffer_ = NULL;
188 } 193 }
189 bytes_read_ += bytes_read; 194 bytes_read_ += bytes_read;
190 finished_ = (bytes_read == 0); 195 finished_ = (bytes_read == 0);
191 196
192 if (sniff_content_) { 197 if (sniff_content_) {
193 std::string type_hint, new_type; 198 std::string type_hint, new_type;
194 request_->GetMimeType(&type_hint); 199 request_->GetMimeType(&type_hint);
195 200
201 if (type_hint.empty())
202 type_hint = info->default_mime_type;
203
196 if (!net::SniffMimeType(read_buffer_->data(), bytes_read_, 204 if (!net::SniffMimeType(read_buffer_->data(), bytes_read_,
197 request_->url(), type_hint, &new_type)) { 205 request_->url(), type_hint, &new_type)) {
198 // SniffMimeType() returns false if there is not enough data to determine 206 // SniffMimeType() returns false if there is not enough data to determine
199 // the mime type. However, even if it returns false, it returns a new type 207 // the mime type. However, even if it returns false, it returns a new type
200 // that is probably better than the current one. 208 // that is probably better than the current one.
201 DCHECK(bytes_read_ < kMaxBytesToSniff); 209 DCHECK(bytes_read_ < kMaxBytesToSniff);
202 if (!finished_) { 210 if (!finished_) {
203 buffering_ = true; 211 buffering_ = true;
204 return true; 212 return true;
205 } 213 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 real_handler_ = download_handler; 288 real_handler_ = download_handler;
281 } 289 }
282 return real_handler_->OnResponseStarted(request_id, response_); 290 return real_handler_->OnResponseStarted(request_id, response_);
283 } 291 }
284 292
285 bool BufferedResourceHandler::DidBufferEnough(int bytes_read) { 293 bool BufferedResourceHandler::DidBufferEnough(int bytes_read) {
286 const int kRequiredLength = 256; 294 const int kRequiredLength = 256;
287 295
288 return bytes_read >= kRequiredLength; 296 return bytes_read >= kRequiredLength;
289 } 297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698