Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: trunk/src/net/filter/filter.cc

Issue 474483002: Revert 289312 "Move StringToUpperASCII and LowerCaseEqualsASCII ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/net/base/mime_util.cc ('k') | trunk/src/net/http/http_auth.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/filename_util_unsafe.h" 9 #include "net/base/filename_util_unsafe.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 next_stream_data_ = stream_buffer()->data(); 132 next_stream_data_ = stream_buffer()->data();
133 stream_data_len_ = stream_data_len; 133 stream_data_len_ = stream_data_len;
134 return true; 134 return true;
135 } 135 }
136 136
137 // static 137 // static
138 Filter::FilterType Filter::ConvertEncodingToType( 138 Filter::FilterType Filter::ConvertEncodingToType(
139 const std::string& filter_type) { 139 const std::string& filter_type) {
140 FilterType type_id; 140 FilterType type_id;
141 if (base::LowerCaseEqualsASCII(filter_type, kDeflate)) { 141 if (LowerCaseEqualsASCII(filter_type, kDeflate)) {
142 type_id = FILTER_TYPE_DEFLATE; 142 type_id = FILTER_TYPE_DEFLATE;
143 } else if (base::LowerCaseEqualsASCII(filter_type, kGZip) || 143 } else if (LowerCaseEqualsASCII(filter_type, kGZip) ||
144 base::LowerCaseEqualsASCII(filter_type, kXGZip)) { 144 LowerCaseEqualsASCII(filter_type, kXGZip)) {
145 type_id = FILTER_TYPE_GZIP; 145 type_id = FILTER_TYPE_GZIP;
146 } else if (base::LowerCaseEqualsASCII(filter_type, kSdch)) { 146 } else if (LowerCaseEqualsASCII(filter_type, kSdch)) {
147 type_id = FILTER_TYPE_SDCH; 147 type_id = FILTER_TYPE_SDCH;
148 } else { 148 } else {
149 // Note we also consider "identity" and "uncompressed" UNSUPPORTED as 149 // Note we also consider "identity" and "uncompressed" UNSUPPORTED as
150 // filter should be disabled in such cases. 150 // filter should be disabled in such cases.
151 type_id = FILTER_TYPE_UNSUPPORTED; 151 type_id = FILTER_TYPE_UNSUPPORTED;
152 } 152 }
153 return type_id; 153 return type_id;
154 } 154 }
155 155
156 // static 156 // static
157 void Filter::FixupEncodingTypes( 157 void Filter::FixupEncodingTypes(
158 const FilterContext& filter_context, 158 const FilterContext& filter_context,
159 std::vector<FilterType>* encoding_types) { 159 std::vector<FilterType>* encoding_types) {
160 std::string mime_type; 160 std::string mime_type;
161 bool success = filter_context.GetMimeType(&mime_type); 161 bool success = filter_context.GetMimeType(&mime_type);
162 DCHECK(success || mime_type.empty()); 162 DCHECK(success || mime_type.empty());
163 163
164 if ((1 == encoding_types->size()) && 164 if ((1 == encoding_types->size()) &&
165 (FILTER_TYPE_GZIP == encoding_types->front())) { 165 (FILTER_TYPE_GZIP == encoding_types->front())) {
166 if (base::LowerCaseEqualsASCII(mime_type, kApplicationXGzip) || 166 if (LowerCaseEqualsASCII(mime_type, kApplicationXGzip) ||
167 base::LowerCaseEqualsASCII(mime_type, kApplicationGzip) || 167 LowerCaseEqualsASCII(mime_type, kApplicationGzip) ||
168 base::LowerCaseEqualsASCII(mime_type, kApplicationXGunzip)) 168 LowerCaseEqualsASCII(mime_type, kApplicationXGunzip))
169 // The server has told us that it sent us gziped content with a gzip 169 // The server has told us that it sent us gziped content with a gzip
170 // content encoding. Sadly, Apache mistakenly sets these headers for all 170 // content encoding. Sadly, Apache mistakenly sets these headers for all
171 // .gz files. We match Firefox's nsHttpChannel::ProcessNormal and ignore 171 // .gz files. We match Firefox's nsHttpChannel::ProcessNormal and ignore
172 // the Content-Encoding here. 172 // the Content-Encoding here.
173 encoding_types->clear(); 173 encoding_types->clear();
174 174
175 GURL url; 175 GURL url;
176 std::string disposition; 176 std::string disposition;
177 success = filter_context.GetURL(&url); 177 success = filter_context.GetURL(&url);
178 DCHECK(success); 178 DCHECK(success);
179 filter_context.GetContentDisposition(&disposition); 179 filter_context.GetContentDisposition(&disposition);
180 // Don't supply a MIME type here, since that may cause disk IO. 180 // Don't supply a MIME type here, since that may cause disk IO.
181 base::FilePath::StringType extension = 181 base::FilePath::StringType extension =
182 GenerateFileExtensionUnsafe(url, disposition, "UTF-8", "", "", ""); 182 GenerateFileExtensionUnsafe(url, disposition, "UTF-8", "", "", "");
183 183
184 if (filter_context.IsDownload()) { 184 if (filter_context.IsDownload()) {
185 // 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
186 // asks to download them. 186 // asks to download them.
187 // 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
188 // 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.
189 // 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
190 // want to do that when downloading. 190 // want to do that when downloading.
191 // See Firefox's nonDecodableExtensions in nsExternalHelperAppService.cpp 191 // See Firefox's nonDecodableExtensions in nsExternalHelperAppService.cpp
192 if (EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) || 192 if (EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) ||
193 base::LowerCaseEqualsASCII(extension, ".tgz") || 193 LowerCaseEqualsASCII(extension, ".tgz") ||
194 base::LowerCaseEqualsASCII(extension, ".svgz")) 194 LowerCaseEqualsASCII(extension, ".svgz"))
195 encoding_types->clear(); 195 encoding_types->clear();
196 } else { 196 } else {
197 // When the user does not explicitly ask to download a file, if we get a 197 // When the user does not explicitly ask to download a file, if we get a
198 // supported mime type, then we attempt to decompress in order to view it. 198 // supported mime type, then we attempt to decompress in order to view it.
199 // However, if it's not a supported mime type, then we will attempt to 199 // However, if it's not a supported mime type, then we will attempt to
200 // download it, and in that case, don't decompress .gz/.tgz files. 200 // download it, and in that case, don't decompress .gz/.tgz files.
201 if ((EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) || 201 if ((EndsWith(extension, FILE_PATH_LITERAL(".gz"), false) ||
202 base::LowerCaseEqualsASCII(extension, ".tgz")) && 202 LowerCaseEqualsASCII(extension, ".tgz")) &&
203 !IsSupportedMimeType(mime_type)) 203 !IsSupportedMimeType(mime_type))
204 encoding_types->clear(); 204 encoding_types->clear();
205 } 205 }
206 } 206 }
207 207
208 // If the request was for SDCH content, then we might need additional fixups. 208 // If the request was for SDCH content, then we might need additional fixups.
209 if (!filter_context.IsSdchResponse()) { 209 if (!filter_context.IsSdchResponse()) {
210 // It was not an SDCH request, so we'll just record stats. 210 // It was not an SDCH request, so we'll just record stats.
211 if (1 < encoding_types->size()) { 211 if (1 < encoding_types->size()) {
212 // Multiple filters were intended to only be used for SDCH (thus far!) 212 // Multiple filters were intended to only be used for SDCH (thus far!)
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 400
401 void Filter::PushDataIntoNextFilter() { 401 void Filter::PushDataIntoNextFilter() {
402 IOBuffer* next_buffer = next_filter_->stream_buffer(); 402 IOBuffer* next_buffer = next_filter_->stream_buffer();
403 int next_size = next_filter_->stream_buffer_size(); 403 int next_size = next_filter_->stream_buffer_size();
404 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); 404 last_status_ = ReadFilteredData(next_buffer->data(), &next_size);
405 if (FILTER_ERROR != last_status_) 405 if (FILTER_ERROR != last_status_)
406 next_filter_->FlushStreamBuffer(next_size); 406 next_filter_->FlushStreamBuffer(next_size);
407 } 407 }
408 408
409 } // namespace net 409 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/base/mime_util.cc ('k') | trunk/src/net/http/http_auth.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698