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

Side by Side Diff: pdf/document_loader.cc

Issue 1242023005: Remove legacy StartsWithASCII function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: y Created 5 years, 5 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
« no previous file with comments | « mojo/runner/shell_apptest.cc ('k') | remoting/host/it2me/it2me_native_messaging_host.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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "pdf/document_loader.h" 5 #include "pdf/document_loader.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "net/http/http_util.h" 9 #include "net/http/http_util.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 11 matching lines...) Expand all
22 // If the headers have a byte-range response, writes the start and end 22 // If the headers have a byte-range response, writes the start and end
23 // positions and returns true if at least the start position was parsed. 23 // positions and returns true if at least the start position was parsed.
24 // The end position will be set to 0 if it was not found or parsed from the 24 // The end position will be set to 0 if it was not found or parsed from the
25 // response. 25 // response.
26 // Returns false if not even a start position could be parsed. 26 // Returns false if not even a start position could be parsed.
27 bool GetByteRange(const std::string& headers, uint32_t* start, uint32_t* end) { 27 bool GetByteRange(const std::string& headers, uint32_t* start, uint32_t* end) {
28 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); 28 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n");
29 while (it.GetNext()) { 29 while (it.GetNext()) {
30 if (base::LowerCaseEqualsASCII(it.name(), "content-range")) { 30 if (base::LowerCaseEqualsASCII(it.name(), "content-range")) {
31 std::string range = it.values().c_str(); 31 std::string range = it.values().c_str();
32 if (base::StartsWithASCII(range, "bytes", false)) { 32 if (base::StartsWith(range, "bytes",
33 base::CompareCase::INSENSITIVE_ASCII)) {
33 range = range.substr(strlen("bytes")); 34 range = range.substr(strlen("bytes"));
34 std::string::size_type pos = range.find('-'); 35 std::string::size_type pos = range.find('-');
35 std::string range_end; 36 std::string range_end;
36 if (pos != std::string::npos) 37 if (pos != std::string::npos)
37 range_end = range.substr(pos + 1); 38 range_end = range.substr(pos + 1);
38 TrimWhitespaceASCII(range, base::TRIM_LEADING, &range); 39 TrimWhitespaceASCII(range, base::TRIM_LEADING, &range);
39 TrimWhitespaceASCII(range_end, base::TRIM_LEADING, &range_end); 40 TrimWhitespaceASCII(range_end, base::TRIM_LEADING, &range_end);
40 *start = atoi(range.c_str()); 41 *start = atoi(range.c_str());
41 *end = atoi(range_end.c_str()); 42 *end = atoi(range_end.c_str());
42 return true; 43 return true;
43 } 44 }
44 } 45 }
45 } 46 }
46 return false; 47 return false;
47 } 48 }
48 49
49 // If the headers have a multi-part response, returns the boundary name. 50 // If the headers have a multi-part response, returns the boundary name.
50 // Otherwise returns an empty string. 51 // Otherwise returns an empty string.
51 std::string GetMultiPartBoundary(const std::string& headers) { 52 std::string GetMultiPartBoundary(const std::string& headers) {
52 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); 53 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n");
53 while (it.GetNext()) { 54 while (it.GetNext()) {
54 if (base::LowerCaseEqualsASCII(it.name(), "content-type")) { 55 if (base::LowerCaseEqualsASCII(it.name(), "content-type")) {
55 std::string type = base::StringToLowerASCII(it.values()); 56 std::string type = base::StringToLowerASCII(it.values());
56 if (base::StartsWithASCII(type, "multipart/", true)) { 57 if (base::StartsWith(type, "multipart/", base::CompareCase::SENSITIVE)) {
57 const char* boundary = strstr(type.c_str(), "boundary="); 58 const char* boundary = strstr(type.c_str(), "boundary=");
58 if (!boundary) { 59 if (!boundary) {
59 NOTREACHED(); 60 NOTREACHED();
60 break; 61 break;
61 } 62 }
62 63
63 return std::string(boundary + 9); 64 return std::string(boundary + 9);
64 } 65 }
65 } 66 }
66 } 67 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 115 }
115 116
116 bool accept_ranges_bytes = false; 117 bool accept_ranges_bytes = false;
117 bool content_encoded = false; 118 bool content_encoded = false;
118 uint32_t content_length = 0; 119 uint32_t content_length = 0;
119 std::string type; 120 std::string type;
120 std::string disposition; 121 std::string disposition;
121 122
122 // This happens for PDFs not loaded from http(s) sources. 123 // This happens for PDFs not loaded from http(s) sources.
123 if (response_headers == "Content-Type: text/plain") { 124 if (response_headers == "Content-Type: text/plain") {
124 if (!base::StartsWithASCII(url, "http://", false) && 125 if (!base::StartsWith(url, "http://",
125 !base::StartsWithASCII(url, "https://", false)) { 126 base::CompareCase::INSENSITIVE_ASCII) &&
127 !base::StartsWith(url, "https://",
128 base::CompareCase::INSENSITIVE_ASCII)) {
126 type = "application/pdf"; 129 type = "application/pdf";
127 } 130 }
128 } 131 }
129 if (type.empty() && !response_headers.empty()) { 132 if (type.empty() && !response_headers.empty()) {
130 net::HttpUtil::HeadersIterator it(response_headers.begin(), 133 net::HttpUtil::HeadersIterator it(response_headers.begin(),
131 response_headers.end(), "\n"); 134 response_headers.end(), "\n");
132 while (it.GetNext()) { 135 while (it.GetNext()) {
133 if (base::LowerCaseEqualsASCII(it.name(), "content-length")) { 136 if (base::LowerCaseEqualsASCII(it.name(), "content-length")) {
134 content_length = atoi(it.values().c_str()); 137 content_length = atoi(it.values().c_str());
135 } else if (base::LowerCaseEqualsASCII(it.name(), "accept-ranges")) { 138 } else if (base::LowerCaseEqualsASCII(it.name(), "accept-ranges")) {
136 accept_ranges_bytes = base::LowerCaseEqualsASCII(it.values(), "bytes"); 139 accept_ranges_bytes = base::LowerCaseEqualsASCII(it.values(), "bytes");
137 } else if (base::LowerCaseEqualsASCII(it.name(), "content-encoding")) { 140 } else if (base::LowerCaseEqualsASCII(it.name(), "content-encoding")) {
138 content_encoded = true; 141 content_encoded = true;
139 } else if (base::LowerCaseEqualsASCII(it.name(), "content-type")) { 142 } else if (base::LowerCaseEqualsASCII(it.name(), "content-type")) {
140 type = it.values(); 143 type = it.values();
141 size_t semi_colon_pos = type.find(';'); 144 size_t semi_colon_pos = type.find(';');
142 if (semi_colon_pos != std::string::npos) { 145 if (semi_colon_pos != std::string::npos) {
143 type = type.substr(0, semi_colon_pos); 146 type = type.substr(0, semi_colon_pos);
144 } 147 }
145 TrimWhitespace(type, base::TRIM_ALL, &type); 148 TrimWhitespace(type, base::TRIM_ALL, &type);
146 } else if (base::LowerCaseEqualsASCII(it.name(), "content-disposition")) { 149 } else if (base::LowerCaseEqualsASCII(it.name(), "content-disposition")) {
147 disposition = it.values(); 150 disposition = it.values();
148 } 151 }
149 } 152 }
150 } 153 }
151 if (!type.empty() && !IsValidContentType(type)) 154 if (!type.empty() && !IsValidContentType(type))
152 return false; 155 return false;
153 if (base::StartsWithASCII(disposition, "attachment", false)) 156 if (base::StartsWith(disposition, "attachment",
157 base::CompareCase::INSENSITIVE_ASCII))
154 return false; 158 return false;
155 159
156 if (content_length > 0) 160 if (content_length > 0)
157 chunk_stream_.Preallocate(content_length); 161 chunk_stream_.Preallocate(content_length);
158 162
159 document_size_ = content_length; 163 document_size_ = content_length;
160 requests_count_ = 0; 164 requests_count_ = 0;
161 165
162 // Enable partial loading only if file size is above the threshold. 166 // Enable partial loading only if file size is above the threshold.
163 // It will allow avoiding latency for multiple requests. 167 // It will allow avoiding latency for multiple requests.
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 uint32_t DocumentLoader::GetRequestSize() const { 533 uint32_t DocumentLoader::GetRequestSize() const {
530 // Document loading strategy: 534 // Document loading strategy:
531 // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we 535 // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we
532 // double the size (64k), and so on, until we cap max request size at 2M for 536 // double the size (64k), and so on, until we cap max request size at 2M for
533 // 71 or more requests. 537 // 71 or more requests.
534 uint32_t limited_count = std::min(std::max(requests_count_, 10u), 70u); 538 uint32_t limited_count = std::min(std::max(requests_count_, 10u), 70u);
535 return 32 * 1024 * (1 << ((limited_count - 1) / 10u)); 539 return 32 * 1024 * (1 << ((limited_count - 1) / 10u));
536 } 540 }
537 541
538 } // namespace chrome_pdf 542 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « mojo/runner/shell_apptest.cc ('k') | remoting/host/it2me/it2me_native_messaging_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698