Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/mime_sniffing_resource_handler.h" | 5 #include "content/browser/loader/mime_sniffing_resource_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 } | 538 } |
| 539 | 539 |
| 540 // Attempt to intercept the request as a stream. | 540 // Attempt to intercept the request as a stream. |
| 541 base::FilePath plugin_path; | 541 base::FilePath plugin_path; |
| 542 if (has_plugin) | 542 if (has_plugin) |
| 543 plugin_path = plugin.path; | 543 plugin_path = plugin.path; |
| 544 std::string payload; | 544 std::string payload; |
| 545 std::unique_ptr<ResourceHandler> handler(host_->MaybeInterceptAsStream( | 545 std::unique_ptr<ResourceHandler> handler(host_->MaybeInterceptAsStream( |
| 546 plugin_path, request(), response_.get(), &payload)); | 546 plugin_path, request(), response_.get(), &payload)); |
| 547 if (handler) { | 547 if (handler) { |
| 548 if (!CheckResponseIsNotProvisional()) { | 548 if (!CheckResponseIsNotProvisional()) |
| 549 Cancel(); | |
| 550 return false; | 549 return false; |
| 551 } | |
| 552 *handled_by_plugin = true; | 550 *handled_by_plugin = true; |
| 553 intercepting_handler_->UseNewHandler(std::move(handler), payload); | 551 intercepting_handler_->UseNewHandler(std::move(handler), payload); |
| 554 } | 552 } |
| 555 #endif | 553 #endif |
| 556 return true; | 554 return true; |
| 557 } | 555 } |
| 558 | 556 |
| 559 bool MimeSniffingResourceHandler::CanBeIntercepted() { | 557 bool MimeSniffingResourceHandler::CanBeIntercepted() { |
| 560 if (response_->head.headers.get() && | 558 if (response_->head.headers.get() && |
| 561 response_->head.headers->response_code() == 304) { | 559 response_->head.headers->response_code() == 304) { |
| 562 return false; | 560 return false; |
| 563 } | 561 } |
| 564 | 562 |
| 565 return true; | 563 return true; |
| 566 } | 564 } |
| 567 | 565 |
| 568 bool MimeSniffingResourceHandler::CheckResponseIsNotProvisional() { | 566 bool MimeSniffingResourceHandler::CheckResponseIsNotProvisional() { |
| 569 if (!response_->head.headers.get() || | 567 if (!response_->head.headers.get() || |
| 570 response_->head.headers->response_code() / 100 == 2) { | 568 response_->head.headers->response_code() / 100 == 2) { |
| 571 return true; | 569 return true; |
| 572 } | 570 } |
| 573 | 571 |
| 574 // The response code indicates that this is an error page, but we don't | 572 // The response code indicates that this is an error page, but we don't |
| 575 // know how to display the content. We follow Firefox here and show our | 573 // know how to display the content. We follow Firefox here and show our |
| 576 // own error page instead of intercepting the request as a stream or a | 574 // own error page instead of intercepting the request as a stream or a |
| 577 // download. | 575 // download. |
| 578 // TODO(abarth): We should abstract the response_code test, but this kind | 576 // TODO(abarth): We should abstract the response_code test, but this kind |
| 579 // of check is scattered throughout our codebase. | 577 // of check is scattered throughout our codebase. |
| 580 request()->CancelWithError(net::ERR_INVALID_RESPONSE); | 578 CancelWithError(net::ERR_INVALID_RESPONSE); |
|
mmenke
2017/07/06 17:51:56
I verified that we should be holding onto a contro
| |
| 581 return false; | 579 return false; |
| 582 } | 580 } |
| 583 | 581 |
| 584 bool MimeSniffingResourceHandler::MustDownload() { | 582 bool MimeSniffingResourceHandler::MustDownload() { |
| 585 if (must_download_is_set_) | 583 if (must_download_is_set_) |
| 586 return must_download_; | 584 return must_download_; |
| 587 | 585 |
| 588 must_download_is_set_ = true; | 586 must_download_is_set_ = true; |
| 589 | 587 |
| 590 std::string disposition; | 588 std::string disposition; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 605 | 603 |
| 606 void MimeSniffingResourceHandler::OnPluginsLoaded( | 604 void MimeSniffingResourceHandler::OnPluginsLoaded( |
| 607 const std::vector<WebPluginInfo>& plugins) { | 605 const std::vector<WebPluginInfo>& plugins) { |
| 608 // No longer blocking on the plugins being loaded. | 606 // No longer blocking on the plugins being loaded. |
| 609 request()->LogUnblocked(); | 607 request()->LogUnblocked(); |
| 610 if (state_ == STATE_BUFFERING) | 608 if (state_ == STATE_BUFFERING) |
| 611 AdvanceState(); | 609 AdvanceState(); |
| 612 } | 610 } |
| 613 | 611 |
| 614 } // namespace content | 612 } // namespace content |
| OLD | NEW |