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_type_resource_handler.h" | 5 #include "content/browser/loader/mime_type_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 16 matching lines...) Expand all Loading... | |
| 27 #include "content/public/browser/plugin_service.h" | 27 #include "content/public/browser/plugin_service.h" |
| 28 #include "content/public/browser/resource_context.h" | 28 #include "content/public/browser/resource_context.h" |
| 29 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 29 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 30 #include "content/public/common/resource_response.h" | 30 #include "content/public/common/resource_response.h" |
| 31 #include "content/public/common/webplugininfo.h" | 31 #include "content/public/common/webplugininfo.h" |
| 32 #include "net/base/io_buffer.h" | 32 #include "net/base/io_buffer.h" |
| 33 #include "net/base/mime_sniffer.h" | 33 #include "net/base/mime_sniffer.h" |
| 34 #include "net/base/mime_util.h" | 34 #include "net/base/mime_util.h" |
| 35 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 36 #include "net/http/http_content_disposition.h" | 36 #include "net/http/http_content_disposition.h" |
| 37 #include "net/http/http_response_headers.h" | 37 #include "net/http/http_response_headers.h" |
|
mmenke
2016/03/31 19:16:31
Probably a pre-existing issue, but should include
Nate Chapin
2016/03/31 23:44:47
Done.
| |
| 38 | 38 |
| 39 namespace content { | 39 namespace content { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 const char kAcceptHeader[] = "Accept"; | |
| 44 const char kFrameAcceptHeader[] = | |
| 45 "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/" | |
| 46 "*;q=0.8"; | |
|
mmenke
2016/03/31 19:23:41
This seems like a weird place to break the string.
Nate Chapin
2016/03/31 23:44:47
Done. I copy/pasted without thinking about it :/
| |
| 47 const char kStylesheetAcceptHeader[] = "text/css,*/*;q=0.1"; | |
| 48 const char kImageAcceptHeader[] = "image/webp,image/*,*/*;q=0.8"; | |
| 49 const char kDefaultAcceptHeader[] = "*/*"; | |
| 50 | |
| 43 // Used to write into an existing IOBuffer at a given offset. | 51 // Used to write into an existing IOBuffer at a given offset. |
| 44 class DependentIOBuffer : public net::WrappedIOBuffer { | 52 class DependentIOBuffer : public net::WrappedIOBuffer { |
| 45 public: | 53 public: |
| 46 DependentIOBuffer(net::IOBuffer* buf, int offset) | 54 DependentIOBuffer(net::IOBuffer* buf, int offset) |
| 47 : net::WrappedIOBuffer(buf->data() + offset), | 55 : net::WrappedIOBuffer(buf->data() + offset), |
| 48 buf_(buf) { | 56 buf_(buf) { |
| 49 } | 57 } |
| 50 | 58 |
| 51 private: | 59 private: |
| 52 ~DependentIOBuffer() override {} | 60 ~DependentIOBuffer() override {} |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 if (response_->head.mime_type == "application/rss+xml" || | 117 if (response_->head.mime_type == "application/rss+xml" || |
| 110 response_->head.mime_type == "application/atom+xml") { | 118 response_->head.mime_type == "application/atom+xml") { |
| 111 response_->head.mime_type.assign("text/plain"); | 119 response_->head.mime_type.assign("text/plain"); |
| 112 } | 120 } |
| 113 } | 121 } |
| 114 | 122 |
| 115 state_ = STATE_PROCESSING; | 123 state_ = STATE_PROCESSING; |
| 116 return ProcessResponse(defer); | 124 return ProcessResponse(defer); |
| 117 } | 125 } |
| 118 | 126 |
| 127 bool MimeTypeResourceHandler::OnWillStart(const GURL& url, bool* defer) { | |
| 128 std::string accept_value; | |
|
mmenke
2016/03/31 19:16:31
const char*? Not sure if it really matters, depen
Nate Chapin
2016/03/31 23:44:47
Done.
| |
| 129 switch (GetRequestInfo()->GetResourceType()) { | |
| 130 case RESOURCE_TYPE_MAIN_FRAME: | |
| 131 case RESOURCE_TYPE_SUB_FRAME: | |
| 132 accept_value = kFrameAcceptHeader; | |
| 133 break; | |
| 134 case RESOURCE_TYPE_STYLESHEET: | |
| 135 accept_value = kStylesheetAcceptHeader; | |
| 136 break; | |
| 137 case RESOURCE_TYPE_IMAGE: | |
| 138 accept_value = kImageAcceptHeader; | |
| 139 break; | |
| 140 case RESOURCE_TYPE_SCRIPT: | |
| 141 case RESOURCE_TYPE_FONT_RESOURCE: | |
| 142 case RESOURCE_TYPE_SUB_RESOURCE: | |
| 143 case RESOURCE_TYPE_OBJECT: | |
| 144 case RESOURCE_TYPE_MEDIA: | |
| 145 case RESOURCE_TYPE_WORKER: | |
| 146 case RESOURCE_TYPE_SHARED_WORKER: | |
| 147 case RESOURCE_TYPE_PREFETCH: | |
| 148 case RESOURCE_TYPE_FAVICON: | |
| 149 case RESOURCE_TYPE_XHR: | |
| 150 case RESOURCE_TYPE_PING: | |
| 151 case RESOURCE_TYPE_SERVICE_WORKER: | |
| 152 case RESOURCE_TYPE_CSP_REPORT: | |
| 153 case RESOURCE_TYPE_PLUGIN_RESOURCE: | |
| 154 accept_value = kDefaultAcceptHeader; | |
| 155 break; | |
| 156 case RESOURCE_TYPE_LAST_TYPE: | |
| 157 NOTREACHED(); | |
| 158 break; | |
| 159 } | |
|
mmenke
2016/03/31 19:16:31
nit: Suggest a blank line here, for easier readin
Nate Chapin
2016/03/31 23:44:47
Done.
| |
| 160 // The false parameter prevents overwriting an existing accept header value, | |
| 161 // which we need because JS can manually set an accept header on an XHR. | |
| 162 request()->SetExtraRequestHeaderByName(kAcceptHeader, accept_value, false); | |
| 163 return next_handler_->OnWillStart(url, defer); | |
| 164 } | |
| 165 | |
| 119 bool MimeTypeResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 166 bool MimeTypeResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 120 int* buf_size, | 167 int* buf_size, |
| 121 int min_size) { | 168 int min_size) { |
| 122 if (state_ == STATE_STREAMING) | 169 if (state_ == STATE_STREAMING) |
| 123 return next_handler_->OnWillRead(buf, buf_size, min_size); | 170 return next_handler_->OnWillRead(buf, buf_size, min_size); |
| 124 | 171 |
| 125 DCHECK_EQ(-1, min_size); | 172 DCHECK_EQ(-1, min_size); |
| 126 | 173 |
| 127 if (read_buffer_.get()) { | 174 if (read_buffer_.get()) { |
| 128 CHECK_LT(bytes_read_, read_buffer_size_); | 175 CHECK_LT(bytes_read_, read_buffer_size_); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 request()->LogUnblocked(); | 531 request()->LogUnblocked(); |
| 485 bool defer = false; | 532 bool defer = false; |
| 486 if (!ProcessResponse(&defer)) { | 533 if (!ProcessResponse(&defer)) { |
| 487 controller()->Cancel(); | 534 controller()->Cancel(); |
| 488 } else if (!defer) { | 535 } else if (!defer) { |
| 489 controller()->Resume(); | 536 controller()->Resume(); |
| 490 } | 537 } |
| 491 } | 538 } |
| 492 | 539 |
| 493 } // namespace content | 540 } // namespace content |
| OLD | NEW |