blob: d7c115d0615fee9e39a96f60bff74c797d54c3e8 [file] [log] [blame]
[email protected]0a0b2542012-01-03 08:25:221// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]e3c404b2008-12-23 01:07:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]678c0362012-12-05 08:02:445#include "content/browser/loader/buffered_resource_handler.h"
[email protected]e3c404b2008-12-23 01:07:326
[email protected]dd9b5462009-09-25 17:22:237#include <vector>
8
[email protected]d33e7cc2011-09-23 01:43:569#include "base/bind.h"
[email protected]5203e6002009-07-29 03:42:0010#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3811#include "base/metrics/histogram.h"
[email protected]319d9e6f2009-02-18 19:47:2112#include "base/string_util.h"
[email protected]254ed742011-08-16 18:45:2713#include "content/browser/download/download_resource_handler.h"
[email protected]14365e32012-01-24 01:12:2214#include "content/browser/download/download_stats.h"
[email protected]3b455502012-12-11 18:22:5815#include "content/browser/loader/certificate_resource_handler.h"
[email protected]678c0362012-12-05 08:02:4416#include "content/browser/loader/resource_dispatcher_host_impl.h"
17#include "content/browser/loader/resource_request_info_impl.h"
[email protected]e67385f2011-12-21 06:00:5618#include "content/browser/plugin_service_impl.h"
[email protected]87f3c082011-10-19 18:07:4419#include "content/public/browser/content_browser_client.h"
[email protected]8d68a3e02013-01-12 15:57:1020#include "content/public/browser/download_id.h"
[email protected]29a5ffc82012-03-13 19:35:5821#include "content/public/browser/download_save_info.h"
[email protected]ce967862012-02-09 22:47:0522#include "content/public/browser/resource_context.h"
[email protected]1bd0ef12011-10-20 05:24:1723#include "content/public/browser/resource_dispatcher_host_delegate.h"
[email protected]2336ffe2011-11-24 01:23:3424#include "content/public/common/resource_response.h"
[email protected]dd9b5462009-09-25 17:22:2325#include "net/base/io_buffer.h"
[email protected]9dea9e1f2009-01-29 00:30:4726#include "net/base/mime_sniffer.h"
[email protected]35fa6a22009-08-15 00:04:0127#include "net/base/mime_util.h"
[email protected]dd9b5462009-09-25 17:22:2328#include "net/base/net_errors.h"
[email protected]28ca9fb2012-01-28 14:50:2429#include "net/http/http_content_disposition.h"
[email protected]319d9e6f2009-02-18 19:47:2130#include "net/http/http_response_headers.h"
[email protected]d33e7cc2011-09-23 01:43:5631#include "webkit/plugins/webplugininfo.h"
[email protected]e3c404b2008-12-23 01:07:3232
[email protected]d18720a2012-01-06 09:53:5533namespace content {
34
[email protected]306291392009-01-17 19:15:3635namespace {
36
37void RecordSnifferMetrics(bool sniffing_blocked,
38 bool we_would_like_to_sniff,
39 const std::string& mime_type) {
[email protected]de415552013-01-23 04:12:1740 static base::HistogramBase* nosniff_usage(NULL);
[email protected]81ce9f3b2011-04-05 04:48:5341 if (!nosniff_usage)
42 nosniff_usage = base::BooleanHistogram::FactoryGet(
[email protected]de415552013-01-23 04:12:1743 "nosniff.usage", base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]e8829a192009-12-06 00:09:3744 nosniff_usage->AddBoolean(sniffing_blocked);
[email protected]306291392009-01-17 19:15:3645
46 if (sniffing_blocked) {
[email protected]de415552013-01-23 04:12:1747 static base::HistogramBase* nosniff_otherwise(NULL);
[email protected]81ce9f3b2011-04-05 04:48:5348 if (!nosniff_otherwise)
49 nosniff_otherwise = base::BooleanHistogram::FactoryGet(
[email protected]de415552013-01-23 04:12:1750 "nosniff.otherwise", base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]e8829a192009-12-06 00:09:3751 nosniff_otherwise->AddBoolean(we_would_like_to_sniff);
[email protected]306291392009-01-17 19:15:3652
[email protected]de415552013-01-23 04:12:1753 static base::HistogramBase* nosniff_empty_mime_type(NULL);
[email protected]81ce9f3b2011-04-05 04:48:5354 if (!nosniff_empty_mime_type)
55 nosniff_empty_mime_type = base::BooleanHistogram::FactoryGet(
56 "nosniff.empty_mime_type",
[email protected]de415552013-01-23 04:12:1757 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]e8829a192009-12-06 00:09:3758 nosniff_empty_mime_type->AddBoolean(mime_type.empty());
[email protected]306291392009-01-17 19:15:3659 }
60}
61
[email protected]926360f2012-06-29 04:45:0262// Used to write into an existing IOBuffer at a given offset.
63class DependentIOBuffer : public net::WrappedIOBuffer {
64 public:
65 DependentIOBuffer(net::IOBuffer* buf, int offset)
66 : net::WrappedIOBuffer(buf->data() + offset),
67 buf_(buf) {
68 }
69
70 private:
[email protected]c3e35892013-02-12 02:08:0171 virtual ~DependentIOBuffer() {}
[email protected]926360f2012-06-29 04:45:0272
73 scoped_refptr<net::IOBuffer> buf_;
74};
75
[email protected]306291392009-01-17 19:15:3676} // namespace
77
[email protected]ea114722012-03-12 01:11:2578BufferedResourceHandler::BufferedResourceHandler(
[email protected]d651cbc2012-05-31 21:33:0579 scoped_ptr<ResourceHandler> next_handler,
[email protected]ea114722012-03-12 01:11:2580 ResourceDispatcherHostImpl* host,
81 net::URLRequest* request)
[email protected]d651cbc2012-05-31 21:33:0582 : LayeredResourceHandler(next_handler.Pass()),
[email protected]926360f2012-06-29 04:45:0283 state_(STATE_STARTING),
[email protected]e3c404b2008-12-23 01:07:3284 host_(host),
85 request_(request),
[email protected]dd9b5462009-09-25 17:22:2386 read_buffer_size_(0),
[email protected]e3c404b2008-12-23 01:07:3287 bytes_read_(0),
[email protected]926360f2012-06-29 04:45:0288 must_download_(false),
[email protected]5c1d3e52012-08-01 05:14:2789 must_download_is_set_(false),
90 weak_ptr_factory_(this) {
[email protected]926360f2012-06-29 04:45:0291}
92
93BufferedResourceHandler::~BufferedResourceHandler() {
94}
95
96void BufferedResourceHandler::SetController(ResourceController* controller) {
97 ResourceHandler::SetController(controller);
98
99 // Downstream handlers see us as their ResourceController, which allows us to
100 // consume part or all of the resource response, and then later replay it to
101 // downstream handler.
102 DCHECK(next_handler_.get());
103 next_handler_->SetController(this);
[email protected]e3c404b2008-12-23 01:07:32104}
105
[email protected]2336ffe2011-11-24 01:23:34106bool BufferedResourceHandler::OnResponseStarted(
107 int request_id,
[email protected]22b305442012-05-21 18:02:59108 ResourceResponse* response,
109 bool* defer) {
[email protected]e3c404b2008-12-23 01:07:32110 response_ = response;
[email protected]22b305442012-05-21 18:02:59111
[email protected]926360f2012-06-29 04:45:02112 // TODO(darin): It is very odd to special-case 304 responses at this level.
113 // We do so only because the code always has, see r24977 and r29355. The
114 // fact that 204 is no longer special-cased this way suggests that 304 need
115 // not be special-cased either.
116 //
117 // The network stack only forwards 304 responses that were not received in
118 // response to a conditional request (i.e., If-Modified-Since). Other 304
119 // responses end up being translated to 200 or whatever the cached response
120 // code happens to be. It should be very rare to see a 304 at this level.
[email protected]22b305442012-05-21 18:02:59121
[email protected]fc72bb12013-06-02 21:13:46122 if (!(response_->head.headers.get() &&
[email protected]926360f2012-06-29 04:45:02123 response_->head.headers->response_code() == 304)) {
124 if (ShouldSniffContent()) {
125 state_ = STATE_BUFFERING;
126 return true;
127 }
128
129 if (response_->head.mime_type.empty()) {
130 // Ugg. The server told us not to sniff the content but didn't give us
131 // a mime type. What's a browser to do? Turns out, we're supposed to
132 // treat the response as "text/plain". This is the most secure option.
133 response_->head.mime_type.assign("text/plain");
134 }
[email protected]3ff679262012-10-12 23:40:05135
136 // Treat feed types as text/plain.
137 if (response_->head.mime_type == "application/rss+xml" ||
138 response_->head.mime_type == "application/atom+xml") {
139 response_->head.mime_type.assign("text/plain");
140 }
[email protected]22b305442012-05-21 18:02:59141 }
[email protected]926360f2012-06-29 04:45:02142
143 state_ = STATE_PROCESSING;
144 return ProcessResponse(defer);
[email protected]e3c404b2008-12-23 01:07:32145}
146
[email protected]e3c404b2008-12-23 01:07:32147// We'll let the original event handler provide a buffer, and reuse it for
148// subsequent reads until we're done buffering.
[email protected]9dea9e1f2009-01-29 00:30:47149bool BufferedResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf,
150 int* buf_size, int min_size) {
[email protected]926360f2012-06-29 04:45:02151 if (state_ == STATE_STREAMING)
152 return next_handler_->OnWillRead(request_id, buf, buf_size, min_size);
153
154 DCHECK_EQ(-1, min_size);
155
[email protected]fc72bb12013-06-02 21:13:46156 if (read_buffer_.get()) {
[email protected]926360f2012-06-29 04:45:02157 CHECK_LT(bytes_read_, read_buffer_size_);
[email protected]fc72bb12013-06-02 21:13:46158 *buf = new DependentIOBuffer(read_buffer_.get(), bytes_read_);
[email protected]926360f2012-06-29 04:45:02159 *buf_size = read_buffer_size_ - bytes_read_;
160 } else {
161 if (!next_handler_->OnWillRead(request_id, buf, buf_size, min_size))
162 return false;
163
164 read_buffer_ = *buf;
165 read_buffer_size_ = *buf_size;
166 DCHECK_GE(read_buffer_size_, net::kMaxBytesToSniff * 2);
[email protected]e3c404b2008-12-23 01:07:32167 }
[email protected]67199052009-06-12 21:15:33168 return true;
[email protected]e3c404b2008-12-23 01:07:32169}
170
[email protected]926360f2012-06-29 04:45:02171bool BufferedResourceHandler::OnReadCompleted(int request_id, int bytes_read,
[email protected]22b305442012-05-21 18:02:59172 bool* defer) {
[email protected]926360f2012-06-29 04:45:02173 if (state_ == STATE_STREAMING)
174 return next_handler_->OnReadCompleted(request_id, bytes_read, defer);
[email protected]e3c404b2008-12-23 01:07:32175
[email protected]926360f2012-06-29 04:45:02176 DCHECK_EQ(state_, STATE_BUFFERING);
177 bytes_read_ += bytes_read;
[email protected]e3c404b2008-12-23 01:07:32178
[email protected]926360f2012-06-29 04:45:02179 if (!DetermineMimeType() && (bytes_read > 0))
180 return true; // Needs more data, so keep buffering.
181
182 state_ = STATE_PROCESSING;
183 return ProcessResponse(defer);
184}
185
186bool BufferedResourceHandler::OnResponseCompleted(
187 int request_id,
188 const net::URLRequestStatus& status,
189 const std::string& security_info) {
190 // Upon completion, act like a pass-through handler in case the downstream
191 // handler defers OnResponseCompleted.
192 state_ = STATE_STREAMING;
193
194 return next_handler_->OnResponseCompleted(request_id, status, security_info);
195}
196
197void BufferedResourceHandler::Resume() {
198 switch (state_) {
199 case STATE_BUFFERING:
200 case STATE_PROCESSING:
201 NOTREACHED();
202 break;
203 case STATE_REPLAYING:
[email protected]dd32b1272013-05-04 14:17:11204 base::MessageLoop::current()->PostTask(
[email protected]926360f2012-06-29 04:45:02205 FROM_HERE,
206 base::Bind(&BufferedResourceHandler::CallReplayReadCompleted,
[email protected]5c1d3e52012-08-01 05:14:27207 weak_ptr_factory_.GetWeakPtr()));
[email protected]926360f2012-06-29 04:45:02208 break;
209 case STATE_STARTING:
210 case STATE_STREAMING:
211 controller()->Resume();
212 break;
213 }
214}
215
216void BufferedResourceHandler::Cancel() {
217 controller()->Cancel();
218}
219
[email protected]2756a8e2012-09-07 18:24:29220void BufferedResourceHandler::CancelAndIgnore() {
221 controller()->CancelAndIgnore();
222}
223
[email protected]af3d4962012-10-19 10:57:26224void BufferedResourceHandler::CancelWithError(int error_code) {
225 controller()->CancelWithError(error_code);
226}
227
[email protected]926360f2012-06-29 04:45:02228bool BufferedResourceHandler::ProcessResponse(bool* defer) {
229 DCHECK_EQ(STATE_PROCESSING, state_);
230
231 // TODO(darin): Stop special-casing 304 responses.
[email protected]fc72bb12013-06-02 21:13:46232 if (!(response_->head.headers.get() &&
[email protected]926360f2012-06-29 04:45:02233 response_->head.headers->response_code() == 304)) {
234 if (!SelectNextHandler(defer))
[email protected]e3c404b2008-12-23 01:07:32235 return false;
[email protected]22b305442012-05-21 18:02:59236 if (*defer)
[email protected]98d6f152011-09-29 19:35:51237 return true;
[email protected]926360f2012-06-29 04:45:02238 }
239
240 state_ = STATE_REPLAYING;
241
242 int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID();
[email protected]fc72bb12013-06-02 21:13:46243 if (!next_handler_->OnResponseStarted(request_id, response_.get(), defer))
[email protected]926360f2012-06-29 04:45:02244 return false;
245
[email protected]fc72bb12013-06-02 21:13:46246 if (!read_buffer_.get()) {
[email protected]926360f2012-06-29 04:45:02247 state_ = STATE_STREAMING;
[email protected]35fa6a22009-08-15 00:04:01248 return true;
[email protected]e3c404b2008-12-23 01:07:32249 }
250
[email protected]926360f2012-06-29 04:45:02251 if (!*defer)
252 return ReplayReadCompleted(defer);
[email protected]5e5e0c82012-01-25 09:12:29253
[email protected]926360f2012-06-29 04:45:02254 return true;
[email protected]e3c404b2008-12-23 01:07:32255}
256
[email protected]926360f2012-06-29 04:45:02257bool BufferedResourceHandler::ShouldSniffContent() {
258 const std::string& mime_type = response_->head.mime_type;
[email protected]e3c404b2008-12-23 01:07:32259
260 std::string content_type_options;
261 request_->GetResponseHeaderByName("x-content-type-options",
262 &content_type_options);
[email protected]306291392009-01-17 19:15:36263
[email protected]926360f2012-06-29 04:45:02264 bool sniffing_blocked =
[email protected]423bd5b842009-01-23 17:30:50265 LowerCaseEqualsASCII(content_type_options, "nosniff");
[email protected]926360f2012-06-29 04:45:02266 bool we_would_like_to_sniff =
267 net::ShouldSniffMimeType(request_->url(), mime_type);
[email protected]306291392009-01-17 19:15:36268
269 RecordSnifferMetrics(sniffing_blocked, we_would_like_to_sniff, mime_type);
270
271 if (!sniffing_blocked && we_would_like_to_sniff) {
[email protected]e3c404b2008-12-23 01:07:32272 // We're going to look at the data before deciding what the content type
273 // is. That means we need to delay sending the ResponseStarted message
274 // over the IPC channel.
[email protected]238667042010-10-23 01:40:00275 VLOG(1) << "To buffer: " << request_->url().spec();
[email protected]e3c404b2008-12-23 01:07:32276 return true;
277 }
278
[email protected]e3c404b2008-12-23 01:07:32279 return false;
280}
281
[email protected]926360f2012-06-29 04:45:02282bool BufferedResourceHandler::DetermineMimeType() {
283 DCHECK_EQ(STATE_BUFFERING, state_);
[email protected]35fa6a22009-08-15 00:04:01284
[email protected]926360f2012-06-29 04:45:02285 const std::string& type_hint = response_->head.mime_type;
286
287 std::string new_type;
288 bool made_final_decision =
289 net::SniffMimeType(read_buffer_->data(), bytes_read_, request_->url(),
290 type_hint, &new_type);
291
292 // SniffMimeType() returns false if there is not enough data to determine
293 // the mime type. However, even if it returns false, it returns a new type
294 // that is probably better than the current one.
295 response_->head.mime_type.assign(new_type);
296
297 return made_final_decision;
[email protected]35fa6a22009-08-15 00:04:01298}
299
[email protected]926360f2012-06-29 04:45:02300bool BufferedResourceHandler::SelectNextHandler(bool* defer) {
301 DCHECK(!response_->head.mime_type.empty());
[email protected]e3c404b2008-12-23 01:07:32302
[email protected]926360f2012-06-29 04:45:02303 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_);
304 const std::string& mime_type = response_->head.mime_type;
[email protected]a755e1072009-10-23 16:58:37305
[email protected]3b455502012-12-11 18:22:58306 if (net::IsSupportedCertificateMimeType(mime_type)) {
307 // Install certificate file.
[email protected]d651cbc2012-05-31 21:33:05308 scoped_ptr<ResourceHandler> handler(
[email protected]3b455502012-12-11 18:22:58309 new CertificateResourceHandler(request_,
310 info->GetChildID(),
311 info->GetRouteID()));
[email protected]926360f2012-06-29 04:45:02312 return UseAlternateNextHandler(handler.Pass());
[email protected]5a9d58fa2012-05-29 15:15:04313 }
314
[email protected]926360f2012-06-29 04:45:02315 if (!info->allow_download())
[email protected]5e5e0c82012-01-25 09:12:29316 return true;
317
[email protected]3ca004f72012-12-18 10:35:21318 bool must_download = MustDownload();
319 if (!must_download) {
[email protected]926360f2012-06-29 04:45:02320 if (net::IsSupportedMimeType(mime_type))
[email protected]35fa6a22009-08-15 00:04:01321 return true;
[email protected]35fa6a22009-08-15 00:04:01322
[email protected]646889822013-03-20 00:26:45323 scoped_ptr<ResourceHandler> handler(
[email protected]fc72bb12013-06-02 21:13:46324 host_->MaybeInterceptAsStream(request_, response_.get()));
[email protected]646889822013-03-20 00:26:45325 if (handler)
326 return UseAlternateNextHandler(handler.Pass());
327
[email protected]ebd71962012-12-20 02:56:55328#if defined(ENABLE_PLUGINS)
[email protected]926360f2012-06-29 04:45:02329 bool stale;
330 bool has_plugin = HasSupportingPlugin(&stale);
[email protected]68598072011-07-29 08:21:28331 if (stale) {
[email protected]926360f2012-06-29 04:45:02332 // Refresh the plugins asynchronously.
333 PluginServiceImpl::GetInstance()->GetPlugins(
[email protected]5c1d3e52012-08-01 05:14:27334 base::Bind(&BufferedResourceHandler::OnPluginsLoaded,
335 weak_ptr_factory_.GetWeakPtr()));
[email protected]926360f2012-06-29 04:45:02336 *defer = true;
[email protected]35fa6a22009-08-15 00:04:01337 return true;
338 }
[email protected]926360f2012-06-29 04:45:02339 if (has_plugin)
340 return true;
[email protected]ebd71962012-12-20 02:56:55341#endif
[email protected]35fa6a22009-08-15 00:04:01342 }
343
[email protected]926360f2012-06-29 04:45:02344 // Install download handler
345 info->set_is_download(true);
346 scoped_ptr<ResourceHandler> handler(
347 host_->CreateResourceHandlerForDownload(
348 request_,
349 true, // is_content_initiated
[email protected]3ca004f72012-12-18 10:35:21350 must_download,
[email protected]8d68a3e02013-01-12 15:57:10351 DownloadId(),
[email protected]c873c862012-10-17 15:32:12352 scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo()),
[email protected]926360f2012-06-29 04:45:02353 DownloadResourceHandler::OnStartedCallback()));
354 return UseAlternateNextHandler(handler.Pass());
[email protected]35fa6a22009-08-15 00:04:01355}
356
[email protected]926360f2012-06-29 04:45:02357bool BufferedResourceHandler::UseAlternateNextHandler(
358 scoped_ptr<ResourceHandler> new_handler) {
[email protected]fc72bb12013-06-02 21:13:46359 if (response_->head.headers.get() && // Can be NULL if FTP.
[email protected]926360f2012-06-29 04:45:02360 response_->head.headers->response_code() / 100 != 2) {
361 // The response code indicates that this is an error page, but we don't
362 // know how to display the content. We follow Firefox here and show our
363 // own error page instead of triggering a download.
364 // TODO(abarth): We should abstract the response_code test, but this kind
365 // of check is scattered throughout our codebase.
366 request_->CancelWithError(net::ERR_FILE_NOT_FOUND);
367 return false;
368 }
369
370 int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID();
371
[email protected]0dc72bbe2010-04-08 15:29:17372 // Inform the original ResourceHandler that this will be handled entirely by
373 // the new ResourceHandler.
[email protected]5e5e0c82012-01-25 09:12:29374 // TODO(darin): We should probably check the return values of these.
[email protected]22b305442012-05-21 18:02:59375 bool defer_ignored = false;
[email protected]fc72bb12013-06-02 21:13:46376 next_handler_->OnResponseStarted(request_id, response_.get(), &defer_ignored);
[email protected]22b305442012-05-21 18:02:59377 DCHECK(!defer_ignored);
[email protected]2756a8e2012-09-07 18:24:29378 net::URLRequestStatus status(net::URLRequestStatus::CANCELED,
379 net::ERR_ABORTED);
[email protected]5e5e0c82012-01-25 09:12:29380 next_handler_->OnResponseCompleted(request_id, status, std::string());
[email protected]0dc72bbe2010-04-08 15:29:17381
382 // This is handled entirely within the new ResourceHandler, so just reset the
383 // original ResourceHandler.
[email protected]926360f2012-06-29 04:45:02384 next_handler_ = new_handler.Pass();
385 next_handler_->SetController(this);
[email protected]5e5e0c82012-01-25 09:12:29386
[email protected]926360f2012-06-29 04:45:02387 return CopyReadBufferToNextHandler(request_id);
[email protected]5e5e0c82012-01-25 09:12:29388}
389
[email protected]926360f2012-06-29 04:45:02390bool BufferedResourceHandler::ReplayReadCompleted(bool* defer) {
[email protected]fc72bb12013-06-02 21:13:46391 DCHECK(read_buffer_.get());
[email protected]5e5e0c82012-01-25 09:12:29392
[email protected]926360f2012-06-29 04:45:02393 int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID();
394 bool result = next_handler_->OnReadCompleted(request_id, bytes_read_, defer);
395
396 read_buffer_ = NULL;
397 read_buffer_size_ = 0;
398 bytes_read_ = 0;
399
400 state_ = STATE_STREAMING;
401
402 return result;
[email protected]5e5e0c82012-01-25 09:12:29403}
404
[email protected]926360f2012-06-29 04:45:02405void BufferedResourceHandler::CallReplayReadCompleted() {
406 bool defer = false;
407 if (!ReplayReadCompleted(&defer)) {
408 controller()->Cancel();
409 } else if (!defer) {
410 state_ = STATE_STREAMING;
411 controller()->Resume();
412 }
413}
414
415bool BufferedResourceHandler::MustDownload() {
416 if (must_download_is_set_)
417 return must_download_;
418
419 must_download_is_set_ = true;
420
421 std::string disposition;
422 request_->GetResponseHeaderByName("content-disposition", &disposition);
423 if (!disposition.empty() &&
424 net::HttpContentDisposition(disposition, std::string()).is_attachment()) {
425 must_download_ = true;
426 } else if (host_->delegate() &&
427 host_->delegate()->ShouldForceDownloadResource(
428 request_->url(), response_->head.mime_type)) {
429 must_download_ = true;
430 } else {
431 must_download_ = false;
432 }
433
434 return must_download_;
435}
436
437bool BufferedResourceHandler::HasSupportingPlugin(bool* stale) {
438 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_);
439
440 bool allow_wildcard = false;
441 webkit::WebPluginInfo plugin;
442 return PluginServiceImpl::GetInstance()->GetPluginInfo(
443 info->GetChildID(), info->GetRouteID(), info->GetContext(),
444 request_->url(), GURL(), response_->head.mime_type, allow_wildcard,
445 stale, &plugin, NULL);
446}
447
448bool BufferedResourceHandler::CopyReadBufferToNextHandler(int request_id) {
[email protected]5e5e0c82012-01-25 09:12:29449 if (!bytes_read_)
[email protected]926360f2012-06-29 04:45:02450 return true;
[email protected]5e5e0c82012-01-25 09:12:29451
452 net::IOBuffer* buf = NULL;
453 int buf_len = 0;
[email protected]926360f2012-06-29 04:45:02454 if (!next_handler_->OnWillRead(request_id, &buf, &buf_len, bytes_read_))
455 return false;
456
457 CHECK((buf_len >= bytes_read_) && (bytes_read_ >= 0));
458 memcpy(buf->data(), read_buffer_->data(), bytes_read_);
459 return true;
[email protected]0dc72bbe2010-04-08 15:29:17460}
461
[email protected]d33e7cc2011-09-23 01:43:56462void BufferedResourceHandler::OnPluginsLoaded(
463 const std::vector<webkit::WebPluginInfo>& plugins) {
[email protected]22b305442012-05-21 18:02:59464 bool defer = false;
[email protected]926360f2012-06-29 04:45:02465 if (!ProcessResponse(&defer)) {
[email protected]56f0b082012-06-14 07:12:32466 controller()->Cancel();
[email protected]926360f2012-06-29 04:45:02467 } else if (!defer) {
[email protected]56f0b082012-06-14 07:12:32468 controller()->Resume();
[email protected]22b305442012-05-21 18:02:59469 }
[email protected]e3c404b2008-12-23 01:07:32470}
[email protected]d18720a2012-01-06 09:53:55471
472} // namespace content