| Index: content/browser/loader/mime_sniffing_resource_handler.cc
|
| diff --git a/content/browser/loader/mime_sniffing_resource_handler.cc b/content/browser/loader/mime_sniffing_resource_handler.cc
|
| index 3e5e414ff1c08445630977b3f31a4f795a4513ab..31139fa8dc64fe25d8ff02fe33dac5d9cd44d0fd 100644
|
| --- a/content/browser/loader/mime_sniffing_resource_handler.cc
|
| +++ b/content/browser/loader/mime_sniffing_resource_handler.cc
|
| @@ -99,7 +99,8 @@ void MimeSniffingResourceHandler::SetController(
|
| next_handler_->SetController(this);
|
| }
|
|
|
| -bool MimeSniffingResourceHandler::OnWillStart(const GURL& url, bool* defer) {
|
| +void MimeSniffingResourceHandler::OnWillStart(const GURL& url,
|
| + bool* defer_or_cancel) {
|
| const char* accept_value = nullptr;
|
| switch (GetRequestInfo()->GetResourceType()) {
|
| case RESOURCE_TYPE_MAIN_FRAME:
|
| @@ -136,11 +137,11 @@ bool MimeSniffingResourceHandler::OnWillStart(const GURL& url, bool* defer) {
|
| // The false parameter prevents overwriting an existing accept header value,
|
| // which is needed because JS can manually set an accept header on an XHR.
|
| request()->SetExtraRequestHeaderByName(kAcceptHeader, accept_value, false);
|
| - return next_handler_->OnWillStart(url, defer);
|
| + next_handler_->OnWillStart(url, defer_or_cancel);
|
| }
|
|
|
| -bool MimeSniffingResourceHandler::OnResponseStarted(ResourceResponse* response,
|
| - bool* defer) {
|
| +void MimeSniffingResourceHandler::OnResponseStarted(ResourceResponse* response,
|
| + bool* defer_or_cancel) {
|
| DCHECK_EQ(STATE_STARTING, state_);
|
| response_ = response;
|
|
|
| @@ -151,7 +152,7 @@ bool MimeSniffingResourceHandler::OnResponseStarted(ResourceResponse* response,
|
| if (!(response_->head.headers.get() &&
|
| response_->head.headers->response_code() == 304)) {
|
| if (ShouldSniffContent())
|
| - return true;
|
| + return;
|
|
|
| if (response_->head.mime_type.empty()) {
|
| // Ugg. The server told us not to sniff the content but didn't give us a
|
| @@ -167,7 +168,7 @@ bool MimeSniffingResourceHandler::OnResponseStarted(ResourceResponse* response,
|
| }
|
| }
|
|
|
| - return ProcessState(defer);
|
| + ProcessState(defer_or_cancel);
|
| }
|
|
|
| bool MimeSniffingResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
|
| @@ -193,9 +194,12 @@ bool MimeSniffingResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
|
| return true;
|
| }
|
|
|
| -bool MimeSniffingResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
|
| - if (state_ == STATE_STREAMING)
|
| - return next_handler_->OnReadCompleted(bytes_read, defer);
|
| +void MimeSniffingResourceHandler::OnReadCompleted(int bytes_read,
|
| + bool* defer_or_cancel) {
|
| + if (state_ == STATE_STREAMING) {
|
| + next_handler_->OnReadCompleted(bytes_read, defer_or_cancel);
|
| + return;
|
| + }
|
|
|
| DCHECK_EQ(state_, STATE_BUFFERING);
|
| bytes_read_ += bytes_read;
|
| @@ -213,9 +217,9 @@ bool MimeSniffingResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
|
| response_->head.mime_type.assign(new_type);
|
|
|
| if (!made_final_decision && (bytes_read > 0))
|
| - return true;
|
| + return;
|
|
|
| - return ProcessState(defer);
|
| + ProcessState(defer_or_cancel);
|
| }
|
|
|
| void MimeSniffingResourceHandler::OnResponseCompleted(
|
| @@ -261,70 +265,63 @@ void MimeSniffingResourceHandler::CancelWithError(int error_code) {
|
| }
|
|
|
| void MimeSniffingResourceHandler::AdvanceState() {
|
| - bool defer = false;
|
| - if (!ProcessState(&defer)) {
|
| - Cancel();
|
| - } else if (!defer) {
|
| + bool defer_or_cancel = false;
|
| + ProcessState(&defer_or_cancel);
|
| + if (!defer_or_cancel) {
|
| DCHECK_EQ(STATE_STREAMING, state_);
|
| controller()->Resume();
|
| }
|
| }
|
|
|
| -bool MimeSniffingResourceHandler::ProcessState(bool* defer) {
|
| - bool return_value = true;
|
| - while (!*defer && return_value && state_ != STATE_STREAMING) {
|
| +void MimeSniffingResourceHandler::ProcessState(bool* defer_or_cancel) {
|
| + while (!*defer_or_cancel && state_ != STATE_STREAMING) {
|
| switch (state_) {
|
| case STATE_BUFFERING:
|
| - return_value = MaybeIntercept(defer);
|
| + MaybeIntercept(defer_or_cancel);
|
| break;
|
| case STATE_INTERCEPTION_CHECK_DONE:
|
| - return_value = ReplayResponseReceived(defer);
|
| + ReplayResponseReceived(defer_or_cancel);
|
| break;
|
| case STATE_REPLAYING_RESPONSE_RECEIVED:
|
| - return_value = ReplayReadCompleted(defer);
|
| + ReplayReadCompleted(defer_or_cancel);
|
| break;
|
| default:
|
| NOTREACHED();
|
| break;
|
| }
|
| }
|
| - return return_value;
|
| }
|
|
|
| -bool MimeSniffingResourceHandler::MaybeIntercept(bool* defer) {
|
| +void MimeSniffingResourceHandler::MaybeIntercept(bool* defer_or_cancel) {
|
| DCHECK_EQ(STATE_BUFFERING, state_);
|
| // If a request that can be intercepted failed the check for interception
|
| // step, it should be canceled.
|
| - if (!MaybeStartInterception(defer))
|
| - return false;
|
| + MaybeStartInterception(defer_or_cancel);
|
|
|
| - if (!*defer)
|
| + if (!*defer_or_cancel)
|
| state_ = STATE_INTERCEPTION_CHECK_DONE;
|
| -
|
| - return true;
|
| }
|
|
|
| -bool MimeSniffingResourceHandler::ReplayResponseReceived(bool* defer) {
|
| +void MimeSniffingResourceHandler::ReplayResponseReceived(
|
| + bool* defer_or_cancel) {
|
| DCHECK_EQ(STATE_INTERCEPTION_CHECK_DONE, state_);
|
| state_ = STATE_REPLAYING_RESPONSE_RECEIVED;
|
| - return next_handler_->OnResponseStarted(response_.get(), defer);
|
| + next_handler_->OnResponseStarted(response_.get(), defer_or_cancel);
|
| }
|
|
|
| -bool MimeSniffingResourceHandler::ReplayReadCompleted(bool* defer) {
|
| +void MimeSniffingResourceHandler::ReplayReadCompleted(bool* defer_or_cancel) {
|
| DCHECK_EQ(STATE_REPLAYING_RESPONSE_RECEIVED, state_);
|
|
|
| state_ = STATE_STREAMING;
|
|
|
| if (!read_buffer_.get())
|
| - return true;
|
| + return;
|
|
|
| - bool result = next_handler_->OnReadCompleted(bytes_read_, defer);
|
| + next_handler_->OnReadCompleted(bytes_read_, defer_or_cancel);
|
|
|
| read_buffer_ = nullptr;
|
| read_buffer_size_ = 0;
|
| bytes_read_ = 0;
|
| -
|
| - return result;
|
| }
|
|
|
| bool MimeSniffingResourceHandler::ShouldSniffContent() {
|
| @@ -355,9 +352,10 @@ bool MimeSniffingResourceHandler::ShouldSniffContent() {
|
| return false;
|
| }
|
|
|
| -bool MimeSniffingResourceHandler::MaybeStartInterception(bool* defer) {
|
| +void MimeSniffingResourceHandler::MaybeStartInterception(
|
| + bool* defer_or_cancel) {
|
| if (!CanBeIntercepted())
|
| - return true;
|
| + return;
|
|
|
| DCHECK(!response_->head.mime_type.empty());
|
|
|
| @@ -379,14 +377,13 @@ bool MimeSniffingResourceHandler::MaybeStartInterception(bool* defer) {
|
| DCHECK(!info->allow_download());
|
|
|
| bool handled_by_plugin;
|
| - if (!CheckForPluginHandler(defer, &handled_by_plugin))
|
| - return false;
|
| - if (handled_by_plugin || *defer)
|
| - return true;
|
| + CheckForPluginHandler(defer_or_cancel, &handled_by_plugin);
|
| + if (handled_by_plugin || *defer_or_cancel)
|
| + return;
|
| }
|
|
|
| if (!info->allow_download())
|
| - return true;
|
| + return;
|
|
|
| // info->allow_download() == true implies
|
| // info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME or
|
| @@ -397,19 +394,21 @@ bool MimeSniffingResourceHandler::MaybeStartInterception(bool* defer) {
|
| bool must_download = MustDownload();
|
| if (!must_download) {
|
| if (mime_util::IsSupportedMimeType(mime_type))
|
| - return true;
|
| + return;
|
|
|
| bool handled_by_plugin;
|
| - if (!CheckForPluginHandler(defer, &handled_by_plugin))
|
| - return false;
|
| - if (handled_by_plugin || *defer)
|
| - return true;
|
| + CheckForPluginHandler(defer_or_cancel, &handled_by_plugin);
|
| + if (handled_by_plugin || *defer_or_cancel)
|
| + return;
|
| }
|
|
|
| // This request is a download.
|
|
|
| - if (!CheckResponseIsNotProvisional())
|
| - return false;
|
| + if (!CheckResponseIsNotProvisional()) {
|
| + *defer_or_cancel = true;
|
| + controller()->Cancel();
|
| + return;
|
| + }
|
|
|
| info->set_is_download(true);
|
| std::unique_ptr<ResourceHandler> handler(
|
| @@ -418,11 +417,10 @@ bool MimeSniffingResourceHandler::MaybeStartInterception(bool* defer) {
|
| must_download,
|
| false /* is_new_request */));
|
| intercepting_handler_->UseNewHandler(std::move(handler), std::string());
|
| - return true;
|
| }
|
|
|
| -bool MimeSniffingResourceHandler::CheckForPluginHandler(
|
| - bool* defer,
|
| +void MimeSniffingResourceHandler::CheckForPluginHandler(
|
| + bool* defer_or_cancel,
|
| bool* handled_by_plugin) {
|
| *handled_by_plugin = false;
|
| #if defined(ENABLE_PLUGINS)
|
| @@ -441,13 +439,13 @@ bool MimeSniffingResourceHandler::CheckForPluginHandler(
|
| base::Bind(&MimeSniffingResourceHandler::OnPluginsLoaded,
|
| weak_ptr_factory_.GetWeakPtr()));
|
| request()->LogBlockedBy("MimeSniffingResourceHandler");
|
| - *defer = true;
|
| - return true;
|
| + *defer_or_cancel = true;
|
| + return;
|
| }
|
|
|
| if (has_plugin && plugin.type != WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN) {
|
| *handled_by_plugin = true;
|
| - return true;
|
| + return;
|
| }
|
|
|
| // Attempt to intercept the request as a stream.
|
| @@ -458,13 +456,16 @@ bool MimeSniffingResourceHandler::CheckForPluginHandler(
|
| std::unique_ptr<ResourceHandler> handler(host_->MaybeInterceptAsStream(
|
| plugin_path, request(), response_.get(), &payload));
|
| if (handler) {
|
| - if (!CheckResponseIsNotProvisional())
|
| - return false;
|
| + if (!CheckResponseIsNotProvisional()) {
|
| + controller()->Cancel();
|
| + *defer_or_cancel = true;
|
| + return;
|
| + }
|
| *handled_by_plugin = true;
|
| intercepting_handler_->UseNewHandler(std::move(handler), payload);
|
| }
|
| #endif
|
| - return true;
|
| + return;
|
| }
|
|
|
| bool MimeSniffingResourceHandler::CanBeIntercepted() {
|
|
|