| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 bool accept_ranges_bytes = false; | 49 bool accept_ranges_bytes = false; |
| 50 bool content_encoded = false; | 50 bool content_encoded = false; |
| 51 uint32 content_length = 0; | 51 uint32 content_length = 0; |
| 52 std::string type; | 52 std::string type; |
| 53 std::string disposition; | 53 std::string disposition; |
| 54 if (!response_headers.empty()) { | 54 if (!response_headers.empty()) { |
| 55 net::HttpUtil::HeadersIterator it(response_headers.begin(), | 55 net::HttpUtil::HeadersIterator it(response_headers.begin(), |
| 56 response_headers.end(), "\n"); | 56 response_headers.end(), "\n"); |
| 57 while (it.GetNext()) { | 57 while (it.GetNext()) { |
| 58 if (base::LowerCaseEqualsASCII(it.name(), "content-length")) { | 58 if (LowerCaseEqualsASCII(it.name(), "content-length")) { |
| 59 content_length = atoi(it.values().c_str()); | 59 content_length = atoi(it.values().c_str()); |
| 60 } else if (base::LowerCaseEqualsASCII(it.name(), "accept-ranges")) { | 60 } else if (LowerCaseEqualsASCII(it.name(), "accept-ranges")) { |
| 61 accept_ranges_bytes = base::LowerCaseEqualsASCII(it.values(), "bytes"); | 61 accept_ranges_bytes = LowerCaseEqualsASCII(it.values(), "bytes"); |
| 62 } else if (base::LowerCaseEqualsASCII(it.name(), "content-encoding")) { | 62 } else if (LowerCaseEqualsASCII(it.name(), "content-encoding")) { |
| 63 content_encoded = true; | 63 content_encoded = true; |
| 64 } else if (base::LowerCaseEqualsASCII(it.name(), "content-type")) { | 64 } else if (LowerCaseEqualsASCII(it.name(), "content-type")) { |
| 65 type = it.values(); | 65 type = it.values(); |
| 66 size_t semi_colon_pos = type.find(';'); | 66 size_t semi_colon_pos = type.find(';'); |
| 67 if (semi_colon_pos != std::string::npos) { | 67 if (semi_colon_pos != std::string::npos) { |
| 68 type = type.substr(0, semi_colon_pos); | 68 type = type.substr(0, semi_colon_pos); |
| 69 } | 69 } |
| 70 TrimWhitespace(type, base::TRIM_ALL, &type); | 70 TrimWhitespace(type, base::TRIM_ALL, &type); |
| 71 } else if (base::LowerCaseEqualsASCII(it.name(), "content-disposition")) { | 71 } else if (LowerCaseEqualsASCII(it.name(), "content-disposition")) { |
| 72 disposition = it.values(); | 72 disposition = it.values(); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 if (!type.empty() && | 76 if (!type.empty() && |
| 77 !EndsWith(type, "/pdf", false) && | 77 !EndsWith(type, "/pdf", false) && |
| 78 !EndsWith(type, ".pdf", false) && | 78 !EndsWith(type, ".pdf", false) && |
| 79 !EndsWith(type, "/x-pdf", false) && | 79 !EndsWith(type, "/x-pdf", false) && |
| 80 !EndsWith(type, "/*", false) && | 80 !EndsWith(type, "/*", false) && |
| 81 !EndsWith(type, "/acrobat", false) && | 81 !EndsWith(type, "/acrobat", false) && |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 | 329 |
| 330 ReadMore(); | 330 ReadMore(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 bool DocumentLoader::GetByteRange(const std::string& headers, uint32* start, | 333 bool DocumentLoader::GetByteRange(const std::string& headers, uint32* start, |
| 334 uint32* end) { | 334 uint32* end) { |
| 335 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); | 335 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); |
| 336 while (it.GetNext()) { | 336 while (it.GetNext()) { |
| 337 if (base::LowerCaseEqualsASCII(it.name(), "content-range")) { | 337 if (LowerCaseEqualsASCII(it.name(), "content-range")) { |
| 338 std::string range = it.values().c_str(); | 338 std::string range = it.values().c_str(); |
| 339 if (StartsWithASCII(range, "bytes", false)) { | 339 if (StartsWithASCII(range, "bytes", false)) { |
| 340 range = range.substr(strlen("bytes")); | 340 range = range.substr(strlen("bytes")); |
| 341 std::string::size_type pos = range.find('-'); | 341 std::string::size_type pos = range.find('-'); |
| 342 std::string range_end; | 342 std::string range_end; |
| 343 if (pos != std::string::npos) | 343 if (pos != std::string::npos) |
| 344 range_end = range.substr(pos + 1); | 344 range_end = range.substr(pos + 1); |
| 345 TrimWhitespaceASCII(range, base::TRIM_LEADING, &range); | 345 TrimWhitespaceASCII(range, base::TRIM_LEADING, &range); |
| 346 TrimWhitespaceASCII(range_end, base::TRIM_LEADING, &range_end); | 346 TrimWhitespaceASCII(range_end, base::TRIM_LEADING, &range_end); |
| 347 *start = atoi(range.c_str()); | 347 *start = atoi(range.c_str()); |
| 348 *end = atoi(range_end.c_str()); | 348 *end = atoi(range_end.c_str()); |
| 349 return true; | 349 return true; |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 } | 352 } |
| 353 return false; | 353 return false; |
| 354 } | 354 } |
| 355 | 355 |
| 356 std::string DocumentLoader::GetMultiPartBoundary(const std::string& headers) { | 356 std::string DocumentLoader::GetMultiPartBoundary(const std::string& headers) { |
| 357 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); | 357 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); |
| 358 while (it.GetNext()) { | 358 while (it.GetNext()) { |
| 359 if (base::LowerCaseEqualsASCII(it.name(), "content-type")) { | 359 if (LowerCaseEqualsASCII(it.name(), "content-type")) { |
| 360 std::string type = base::StringToLowerASCII(it.values()); | 360 std::string type = base::StringToLowerASCII(it.values()); |
| 361 if (StartsWithASCII(type, "multipart/", true)) { | 361 if (StartsWithASCII(type, "multipart/", true)) { |
| 362 const char* boundary = strstr(type.c_str(), "boundary="); | 362 const char* boundary = strstr(type.c_str(), "boundary="); |
| 363 if (!boundary) { | 363 if (!boundary) { |
| 364 NOTREACHED(); | 364 NOTREACHED(); |
| 365 break; | 365 break; |
| 366 } | 366 } |
| 367 | 367 |
| 368 return std::string(boundary + 9); | 368 return std::string(boundary + 9); |
| 369 } | 369 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 uint32 DocumentLoader::GetRequestSize() const { | 495 uint32 DocumentLoader::GetRequestSize() const { |
| 496 // Document loading strategy: | 496 // Document loading strategy: |
| 497 // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we | 497 // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we |
| 498 // double the size (64k), and so on, until we cap max request size at 2M for | 498 // double the size (64k), and so on, until we cap max request size at 2M for |
| 499 // 71 or more requests. | 499 // 71 or more requests. |
| 500 uint32 limited_count = std::min(std::max(requests_count_, 10u), 70u); | 500 uint32 limited_count = std::min(std::max(requests_count_, 10u), 70u); |
| 501 return 32*1024 * (1 << ((limited_count - 1) / 10u)); | 501 return 32*1024 * (1 << ((limited_count - 1) / 10u)); |
| 502 } | 502 } |
| 503 | 503 |
| 504 } // namespace chrome_pdf | 504 } // namespace chrome_pdf |
| OLD | NEW |