| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 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::StartsWith(range, "bytes", | 32 if (base::StartsWith(range, "bytes", |
| 33 base::CompareCase::INSENSITIVE_ASCII)) { | 33 base::CompareCase::INSENSITIVE_ASCII)) { |
| 34 range = range.substr(strlen("bytes")); | 34 range = range.substr(strlen("bytes")); |
| 35 std::string::size_type pos = range.find('-'); | 35 std::string::size_type pos = range.find('-'); |
| 36 std::string range_end; | 36 std::string range_end; |
| 37 if (pos != std::string::npos) | 37 if (pos != std::string::npos) |
| 38 range_end = range.substr(pos + 1); | 38 range_end = range.substr(pos + 1); |
| 39 TrimWhitespaceASCII(range, base::TRIM_LEADING, &range); | 39 base::TrimWhitespaceASCII(range, base::TRIM_LEADING, &range); |
| 40 TrimWhitespaceASCII(range_end, base::TRIM_LEADING, &range_end); | 40 base::TrimWhitespaceASCII(range_end, base::TRIM_LEADING, &range_end); |
| 41 *start = atoi(range.c_str()); | 41 *start = atoi(range.c_str()); |
| 42 *end = atoi(range_end.c_str()); | 42 *end = atoi(range_end.c_str()); |
| 43 return true; | 43 return true; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 // 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. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } else if (base::LowerCaseEqualsASCII(it.name(), "accept-ranges")) { | 138 } else if (base::LowerCaseEqualsASCII(it.name(), "accept-ranges")) { |
| 139 accept_ranges_bytes = base::LowerCaseEqualsASCII(it.values(), "bytes"); | 139 accept_ranges_bytes = base::LowerCaseEqualsASCII(it.values(), "bytes"); |
| 140 } else if (base::LowerCaseEqualsASCII(it.name(), "content-encoding")) { | 140 } else if (base::LowerCaseEqualsASCII(it.name(), "content-encoding")) { |
| 141 content_encoded = true; | 141 content_encoded = true; |
| 142 } else if (base::LowerCaseEqualsASCII(it.name(), "content-type")) { | 142 } else if (base::LowerCaseEqualsASCII(it.name(), "content-type")) { |
| 143 type = it.values(); | 143 type = it.values(); |
| 144 size_t semi_colon_pos = type.find(';'); | 144 size_t semi_colon_pos = type.find(';'); |
| 145 if (semi_colon_pos != std::string::npos) { | 145 if (semi_colon_pos != std::string::npos) { |
| 146 type = type.substr(0, semi_colon_pos); | 146 type = type.substr(0, semi_colon_pos); |
| 147 } | 147 } |
| 148 TrimWhitespace(type, base::TRIM_ALL, &type); | 148 TrimWhitespaceASCII(type, base::TRIM_ALL, &type); |
| 149 } else if (base::LowerCaseEqualsASCII(it.name(), "content-disposition")) { | 149 } else if (base::LowerCaseEqualsASCII(it.name(), "content-disposition")) { |
| 150 disposition = it.values(); | 150 disposition = it.values(); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 if (!type.empty() && !IsValidContentType(type)) | 154 if (!type.empty() && !IsValidContentType(type)) |
| 155 return false; | 155 return false; |
| 156 if (base::StartsWith(disposition, "attachment", | 156 if (base::StartsWith(disposition, "attachment", |
| 157 base::CompareCase::INSENSITIVE_ASCII)) | 157 base::CompareCase::INSENSITIVE_ASCII)) |
| 158 return false; | 158 return false; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 uint32_t DocumentLoader::GetRequestSize() const { | 533 uint32_t DocumentLoader::GetRequestSize() const { |
| 534 // Document loading strategy: | 534 // Document loading strategy: |
| 535 // 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 |
| 536 // 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 |
| 537 // 71 or more requests. | 537 // 71 or more requests. |
| 538 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); |
| 539 return 32 * 1024 * (1 << ((limited_count - 1) / 10u)); | 539 return 32 * 1024 * (1 << ((limited_count - 1) / 10u)); |
| 540 } | 540 } |
| 541 | 541 |
| 542 } // namespace chrome_pdf | 542 } // namespace chrome_pdf |
| OLD | NEW |