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 #include "net/filter/filter.h" | 5 #include "net/filter/filter.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/mime_util.h" | 10 #include "net/base/mime_util.h" |
11 #include "net/base/net_util.h" | |
11 #include "net/filter/gzip_filter.h" | 12 #include "net/filter/gzip_filter.h" |
12 #include "net/filter/sdch_filter.h" | 13 #include "net/filter/sdch_filter.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // Filter types (using canonical lower case only): | 17 // Filter types (using canonical lower case only): |
17 const char kDeflate[] = "deflate"; | 18 const char kDeflate[] = "deflate"; |
18 const char kGZip[] = "gzip"; | 19 const char kGZip[] = "gzip"; |
19 const char kXGZip[] = "x-gzip"; | 20 const char kXGZip[] = "x-gzip"; |
20 const char kSdch[] = "sdch"; | 21 const char kSdch[] = "sdch"; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 if (LowerCaseEqualsASCII(mime_type, kApplicationXGzip) || | 164 if (LowerCaseEqualsASCII(mime_type, kApplicationXGzip) || |
164 LowerCaseEqualsASCII(mime_type, kApplicationGzip) || | 165 LowerCaseEqualsASCII(mime_type, kApplicationGzip) || |
165 LowerCaseEqualsASCII(mime_type, kApplicationXGunzip)) | 166 LowerCaseEqualsASCII(mime_type, kApplicationXGunzip)) |
166 // The server has told us that it sent us gziped content with a gzip | 167 // The server has told us that it sent us gziped content with a gzip |
167 // content encoding. Sadly, Apache mistakenly sets these headers for all | 168 // content encoding. Sadly, Apache mistakenly sets these headers for all |
168 // .gz files. We match Firefox's nsHttpChannel::ProcessNormal and ignore | 169 // .gz files. We match Firefox's nsHttpChannel::ProcessNormal and ignore |
169 // the Content-Encoding here. | 170 // the Content-Encoding here. |
170 encoding_types->clear(); | 171 encoding_types->clear(); |
171 | 172 |
172 GURL url; | 173 GURL url; |
174 std::string disposition; | |
173 success = filter_context.GetURL(&url); | 175 success = filter_context.GetURL(&url); |
174 DCHECK(success); | 176 DCHECK(success); |
175 base::FilePath filename = | 177 filter_context.GetContentDisposition(&disposition); |
176 base::FilePath().AppendASCII(url.ExtractFileName()); | 178 // Don't supply a MIME type here, since that may cause disk IO. |
177 base::FilePath::StringType extension = filename.Extension(); | 179 base::string16 filename = |
180 net::GetSuggestedFilename(url, disposition, "UTF-8", "", "", ""); | |
asanka
2014/03/21 18:23:14
Nit: already in net namespace.
Also use GenerateF
| |
181 base::FilePath filepath = base::FilePath::FromUTF16Unsafe(filename); | |
182 base::FilePath::StringType extension = filepath.Extension(); | |
178 | 183 |
179 if (filter_context.IsDownload()) { | 184 if (filter_context.IsDownload()) { |
180 // We don't want to decompress gzipped files when the user explicitly | 185 // We don't want to decompress gzipped files when the user explicitly |
181 // asks to download them. | 186 // asks to download them. |
182 // For the case of svgz files, we use the extension to distinguish | 187 // For the case of svgz files, we use the extension to distinguish |
183 // between svgz files and svg files compressed with gzip by the server. | 188 // between svgz files and svg files compressed with gzip by the server. |
184 // When viewing a .svgz file, we need to uncompress it, but we don't | 189 // When viewing a .svgz file, we need to uncompress it, but we don't |
185 // want to do that when downloading. | 190 // want to do that when downloading. |
186 // See Firefox's nonDecodableExtensions in nsExternalHelperAppService.cpp | 191 // See Firefox's nonDecodableExtensions in nsExternalHelperAppService.cpp |
187 if (EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) || | 192 if (EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) || |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 | 399 |
395 void Filter::PushDataIntoNextFilter() { | 400 void Filter::PushDataIntoNextFilter() { |
396 IOBuffer* next_buffer = next_filter_->stream_buffer(); | 401 IOBuffer* next_buffer = next_filter_->stream_buffer(); |
397 int next_size = next_filter_->stream_buffer_size(); | 402 int next_size = next_filter_->stream_buffer_size(); |
398 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); | 403 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); |
399 if (FILTER_ERROR != last_status_) | 404 if (FILTER_ERROR != last_status_) |
400 next_filter_->FlushStreamBuffer(next_size); | 405 next_filter_->FlushStreamBuffer(next_size); |
401 } | 406 } |
402 | 407 |
403 } // namespace net | 408 } // namespace net |
OLD | NEW |