OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // The basic usage of the Filter interface is described in the comment at | 5 // The basic usage of the Filter interface is described in the comment at |
6 // the beginning of filter.h. If Filter::Factory is passed a vector of | 6 // the beginning of filter.h. If Filter::Factory is passed a vector of |
7 // size greater than 1, that interface is implemented by a series of filters | 7 // size greater than 1, that interface is implemented by a series of filters |
8 // connected in a chain. In such a case the first filter | 8 // connected in a chain. In such a case the first filter |
9 // in the chain proxies calls to ReadData() so that its return values | 9 // in the chain proxies calls to ReadData() so that its return values |
10 // apply to the entire chain. | 10 // apply to the entire chain. |
11 // | 11 // |
12 // In a filter chain, the data flows from first filter (held by the | 12 // In a filter chain, the data flows from first filter (held by the |
13 // caller) down the chain. When ReadData() is called on any filter | 13 // caller) down the chain. When ReadData() is called on any filter |
14 // except for the last filter, it proxies the call down the chain, | 14 // except for the last filter, it proxies the call down the chain, |
15 // filling in the input buffers of subsequent filters if needed (== | 15 // filling in the input buffers of subsequent filters if needed (== |
16 // that filter's last_status() value is FILTER_NEED_MORE_DATA) and | 16 // that filter's last_status() value is FILTER_NEED_MORE_DATA) and |
17 // available (== the current filter has data it can output). The last | 17 // available (== the current filter has data it can output). The last |
18 // Filter will then output data if possible, and return | 18 // Filter will then output data if possible, and return |
19 // FILTER_NEED_MORE_DATA if not. Because the indirection pushes | 19 // FILTER_NEED_MORE_DATA if not. Because the indirection pushes |
20 // data along the filter chain at each level if it's available and the | 20 // data along the filter chain at each level if it's available and the |
21 // next filter needs it, a return value of FILTER_NEED_MORE_DATA from the | 21 // next filter needs it, a return value of FILTER_NEED_MORE_DATA from the |
22 // final filter will apply to the entire chain. | 22 // final filter will apply to the entire chain. |
23 | 23 |
24 #include "net/filter/filter.h" | 24 #include "net/filter/filter.h" |
25 | 25 |
26 #include "base/files/file_path.h" | 26 #include "base/files/file_path.h" |
27 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
28 #include "net/base/filename_util_unsafe.h" | 28 #include "net/base/filename_util_unsafe.h" |
29 #include "net/base/io_buffer.h" | 29 #include "net/base/io_buffer.h" |
30 #include "net/base/mime_util.h" | |
31 #include "net/base/sdch_net_log_params.h" | 30 #include "net/base/sdch_net_log_params.h" |
32 #include "net/filter/gzip_filter.h" | 31 #include "net/filter/gzip_filter.h" |
33 #include "net/filter/sdch_filter.h" | 32 #include "net/filter/sdch_filter.h" |
34 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
35 #include "url/gurl.h" | 34 #include "url/gurl.h" |
36 | 35 |
37 namespace net { | 36 namespace net { |
38 | 37 |
39 namespace { | 38 namespace { |
40 | 39 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if (EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) || | 241 if (EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) || |
243 LowerCaseEqualsASCII(extension, ".tgz") || | 242 LowerCaseEqualsASCII(extension, ".tgz") || |
244 LowerCaseEqualsASCII(extension, ".svgz")) | 243 LowerCaseEqualsASCII(extension, ".svgz")) |
245 encoding_types->clear(); | 244 encoding_types->clear(); |
246 } else { | 245 } else { |
247 // When the user does not explicitly ask to download a file, if we get a | 246 // When the user does not explicitly ask to download a file, if we get a |
248 // supported mime type, then we attempt to decompress in order to view it. | 247 // supported mime type, then we attempt to decompress in order to view it. |
249 // However, if it's not a supported mime type, then we will attempt to | 248 // However, if it's not a supported mime type, then we will attempt to |
250 // download it, and in that case, don't decompress .gz/.tgz files. | 249 // download it, and in that case, don't decompress .gz/.tgz files. |
251 if ((EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) || | 250 if ((EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) || |
252 LowerCaseEqualsASCII(extension, ".tgz")) && | 251 LowerCaseEqualsASCII(extension, ".tgz"))) { |
253 !IsSupportedMimeType(mime_type)) | 252 NetworkDelegate* net_delegate = |
254 encoding_types->clear(); | 253 filter_context.GetURLRequestContext()->network_delegate(); |
| 254 if (net_delegate && !net_delegate->IsSupportedMimeType(mime_type)) |
| 255 encoding_types->clear(); |
| 256 } |
255 } | 257 } |
256 } | 258 } |
257 | 259 |
258 // If the request was for SDCH content, then we might need additional fixups. | 260 // If the request was for SDCH content, then we might need additional fixups. |
259 if (!filter_context.SdchDictionariesAdvertised()) { | 261 if (!filter_context.SdchDictionariesAdvertised()) { |
260 // It was not an SDCH request, so we'll just record stats. | 262 // It was not an SDCH request, so we'll just record stats. |
261 if (1 < encoding_types->size()) { | 263 if (1 < encoding_types->size()) { |
262 // Multiple filters were intended to only be used for SDCH (thus far!) | 264 // Multiple filters were intended to only be used for SDCH (thus far!) |
263 LogSdchProblem(filter_context, SDCH_MULTIENCODING_FOR_NON_SDCH_REQUEST); | 265 LogSdchProblem(filter_context, SDCH_MULTIENCODING_FOR_NON_SDCH_REQUEST); |
264 } | 266 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 454 |
453 void Filter::PushDataIntoNextFilter() { | 455 void Filter::PushDataIntoNextFilter() { |
454 IOBuffer* next_buffer = next_filter_->stream_buffer(); | 456 IOBuffer* next_buffer = next_filter_->stream_buffer(); |
455 int next_size = next_filter_->stream_buffer_size(); | 457 int next_size = next_filter_->stream_buffer_size(); |
456 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); | 458 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); |
457 if (FILTER_ERROR != last_status_) | 459 if (FILTER_ERROR != last_status_) |
458 next_filter_->FlushStreamBuffer(next_size); | 460 next_filter_->FlushStreamBuffer(next_size); |
459 } | 461 } |
460 | 462 |
461 } // namespace net | 463 } // namespace net |
OLD | NEW |