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

Side by Side Diff: content/browser/loader/buffered_resource_handler.cc

Issue 1164073006: Make the logic for stream interception by MimeHandlerViews consistent with starting the plugin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/loader/buffered_resource_handler.h" 5 #include "content/browser/loader/buffered_resource_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 type_hint, &new_type); 284 type_hint, &new_type);
285 285
286 // SniffMimeType() returns false if there is not enough data to determine 286 // SniffMimeType() returns false if there is not enough data to determine
287 // the mime type. However, even if it returns false, it returns a new type 287 // the mime type. However, even if it returns false, it returns a new type
288 // that is probably better than the current one. 288 // that is probably better than the current one.
289 response_->head.mime_type.assign(new_type); 289 response_->head.mime_type.assign(new_type);
290 290
291 return made_final_decision; 291 return made_final_decision;
292 } 292 }
293 293
294 bool BufferedResourceHandler::IsHandledByPlugin(bool* defer,
295 bool* request_handled) {
296 #if defined(ENABLE_PLUGINS)
297 bool stale;
298 WebPluginInfo plugin;
299 bool allow_wildcard = false;
300 ResourceRequestInfoImpl* info = GetRequestInfo();
301 bool has_plugin = plugin_service_->GetPluginInfo(
302 info->GetChildID(), info->GetRenderFrameID(), info->GetContext(),
303 request()->url(), GURL(), response_->head.mime_type, allow_wildcard,
304 &stale, &plugin, NULL);
305
306 if (stale) {
307 // Refresh the plugins asynchronously.
308 plugin_service_->GetPlugins(
309 base::Bind(&BufferedResourceHandler::OnPluginsLoaded,
310 weak_ptr_factory_.GetWeakPtr()));
311 request()->LogBlockedBy("BufferedResourceHandler");
312 *defer = true;
313 return true;
314 }
315
316 if (has_plugin) {
317 if (plugin.type == WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN) {
318 // If it is a MimeHandlerView plugin, intercept the stream.
319 std::string payload;
320 scoped_ptr<ResourceHandler> handler(host_->MaybeInterceptAsStream(
321 plugin.path, request(), response_.get(), &payload));
322 if (handler) {
323 *request_handled = UseAlternateNextHandler(handler.Pass(), payload);
324 return true;
325 }
326 return false;
mmenke 2015/06/05 18:45:49 Can this happen? When?
raymes 2015/06/09 00:10:45 This actually should never happen. If the plugin i
327 } else {
328 return true;
329 }
330 }
331
332 // If execution reaches here then we should try intercepting the stream for
333 // the old streamsPrivate extensions API. This API is deprecated and should
334 // go away.
mmenke 2015/06/05 18:45:49 Don't use "we" in comments
raymes 2015/06/09 00:10:45 Done.
335 std::string payload;
336 scoped_ptr<ResourceHandler> handler(host_->MaybeInterceptAsStream(
337 base::FilePath(), request(), response_.get(), &payload));
338 if (handler) {
339 *request_handled = UseAlternateNextHandler(handler.Pass(), payload);
340 return true;
341 }
342 #endif
343 return false;
344 }
345
294 bool BufferedResourceHandler::SelectNextHandler(bool* defer) { 346 bool BufferedResourceHandler::SelectNextHandler(bool* defer) {
295 DCHECK(!response_->head.mime_type.empty()); 347 DCHECK(!response_->head.mime_type.empty());
296 348
297 ResourceRequestInfoImpl* info = GetRequestInfo(); 349 ResourceRequestInfoImpl* info = GetRequestInfo();
298 const std::string& mime_type = response_->head.mime_type; 350 const std::string& mime_type = response_->head.mime_type;
299 351
300 if (mime_util::IsSupportedCertificateMimeType(mime_type)) { 352 if (mime_util::IsSupportedCertificateMimeType(mime_type)) {
301 // Install certificate file. 353 // Install certificate file.
302 info->set_is_download(true); 354 info->set_is_download(true);
303 scoped_ptr<ResourceHandler> handler( 355 scoped_ptr<ResourceHandler> handler(
304 new CertificateResourceHandler(request())); 356 new CertificateResourceHandler(request()));
305 return UseAlternateNextHandler(handler.Pass(), std::string()); 357 return UseAlternateNextHandler(handler.Pass(), std::string());
306 } 358 }
307 359
308 // Allow requests for object/embed tags to be intercepted as streams. 360 // Allow requests for object/embed tags to be intercepted as streams.
309 if (info->GetResourceType() == content::RESOURCE_TYPE_OBJECT) { 361 if (info->GetResourceType() == content::RESOURCE_TYPE_OBJECT) {
310 DCHECK(!info->allow_download()); 362 DCHECK(!info->allow_download());
311 std::string payload; 363
312 scoped_ptr<ResourceHandler> handler( 364 bool request_handled = true;
313 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); 365 bool handled_by_plugin = IsHandledByPlugin(defer, &request_handled);
314 if (handler) { 366 if (!request_handled)
315 DCHECK(!mime_util::IsSupportedMimeType(mime_type)); 367 return false;
316 return UseAlternateNextHandler(handler.Pass(), payload); 368 if (handled_by_plugin)
317 } 369 return true;
318 } 370 }
319 371
320 if (!info->allow_download()) 372 if (!info->allow_download())
321 return true; 373 return true;
322 374
323 // info->allow_download() == true implies 375 // info->allow_download() == true implies
324 // info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME or 376 // info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME or
325 // info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME. 377 // info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME.
326 DCHECK(info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME || 378 DCHECK(info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME ||
327 info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME); 379 info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME);
328 380
329 bool must_download = MustDownload(); 381 bool must_download = MustDownload();
330 if (!must_download) { 382 if (!must_download) {
331 if (mime_util::IsSupportedMimeType(mime_type)) 383 if (mime_util::IsSupportedMimeType(mime_type))
332 return true; 384 return true;
333 385
334 std::string payload; 386 bool request_handled = true;
335 scoped_ptr<ResourceHandler> handler( 387 bool handled_by_plugin = IsHandledByPlugin(defer, &request_handled);
336 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); 388 if (!request_handled)
337 if (handler) { 389 return false;
338 return UseAlternateNextHandler(handler.Pass(), payload); 390 if (handled_by_plugin)
339 }
340
341 #if defined(ENABLE_PLUGINS)
342 bool stale;
343 bool has_plugin = HasSupportingPlugin(&stale);
344 if (stale) {
345 // Refresh the plugins asynchronously.
346 plugin_service_->GetPlugins(
347 base::Bind(&BufferedResourceHandler::OnPluginsLoaded,
348 weak_ptr_factory_.GetWeakPtr()));
349 request()->LogBlockedBy("BufferedResourceHandler");
350 *defer = true;
351 return true; 391 return true;
352 }
353 if (has_plugin)
354 return true;
355 #endif
356 } 392 }
357 393
358 // Install download handler 394 // Install download handler
359 info->set_is_download(true); 395 info->set_is_download(true);
360 scoped_ptr<ResourceHandler> handler( 396 scoped_ptr<ResourceHandler> handler(
361 host_->CreateResourceHandlerForDownload( 397 host_->CreateResourceHandlerForDownload(
362 request(), 398 request(),
363 true, // is_content_initiated 399 true, // is_content_initiated
364 must_download, 400 must_download,
365 DownloadItem::kInvalidId, 401 DownloadItem::kInvalidId,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 host_->delegate()->ShouldForceDownloadResource( 498 host_->delegate()->ShouldForceDownloadResource(
463 request()->url(), response_->head.mime_type)) { 499 request()->url(), response_->head.mime_type)) {
464 must_download_ = true; 500 must_download_ = true;
465 } else { 501 } else {
466 must_download_ = false; 502 must_download_ = false;
467 } 503 }
468 504
469 return must_download_; 505 return must_download_;
470 } 506 }
471 507
472 bool BufferedResourceHandler::HasSupportingPlugin(bool* stale) {
473 #if defined(ENABLE_PLUGINS)
474 ResourceRequestInfoImpl* info = GetRequestInfo();
475
476 bool allow_wildcard = false;
477 WebPluginInfo plugin;
478 return plugin_service_->GetPluginInfo(
479 info->GetChildID(), info->GetRenderFrameID(), info->GetContext(),
480 request()->url(), GURL(), response_->head.mime_type, allow_wildcard,
481 stale, &plugin, NULL);
482 #else
483 if (stale)
484 *stale = false;
485 return false;
486 #endif
487 }
488
489 bool BufferedResourceHandler::CopyReadBufferToNextHandler() { 508 bool BufferedResourceHandler::CopyReadBufferToNextHandler() {
490 if (!read_buffer_.get()) 509 if (!read_buffer_.get())
491 return true; 510 return true;
492 511
493 scoped_refptr<net::IOBuffer> buf; 512 scoped_refptr<net::IOBuffer> buf;
494 int buf_len = 0; 513 int buf_len = 0;
495 if (!next_handler_->OnWillRead(&buf, &buf_len, bytes_read_)) 514 if (!next_handler_->OnWillRead(&buf, &buf_len, bytes_read_))
496 return false; 515 return false;
497 516
498 CHECK((buf_len >= bytes_read_) && (bytes_read_ >= 0)); 517 CHECK((buf_len >= bytes_read_) && (bytes_read_ >= 0));
499 memcpy(buf->data(), read_buffer_->data(), bytes_read_); 518 memcpy(buf->data(), read_buffer_->data(), bytes_read_);
500 return true; 519 return true;
501 } 520 }
502 521
503 void BufferedResourceHandler::OnPluginsLoaded( 522 void BufferedResourceHandler::OnPluginsLoaded(
504 const std::vector<WebPluginInfo>& plugins) { 523 const std::vector<WebPluginInfo>& plugins) {
505 request()->LogUnblocked(); 524 request()->LogUnblocked();
506 bool defer = false; 525 bool defer = false;
507 if (!ProcessResponse(&defer)) { 526 if (!ProcessResponse(&defer)) {
508 controller()->Cancel(); 527 controller()->Cancel();
509 } else if (!defer) { 528 } else if (!defer) {
510 controller()->Resume(); 529 controller()->Resume();
511 } 530 }
512 } 531 }
513 532
514 } // namespace content 533 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698